ctr_Repair/branches/0thNUP_No_NUP/CardSaveDataMover/Imp/source/main.cpp
N2614 e3eb8c9f31 NUPを実行しない0th NUP版のためのブランチ
git-svn-id: file:///Volumes/Transfer/gigaleak_20231201/2020-05-23%20-%20ctr.7z%20+%20svn_v1.068.zip/ctr/svn/ctr_Repair@305 385bec56-5757-e545-9c3a-d8741f4650f1
2011-06-02 06:58:24 +00:00

224 lines
6.9 KiB
C++
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*---------------------------------------------------------------------------*
Project: Horizon
File: main.cpp
Copyright (C)2009 Nintendo Co., Ltd. All rights reserved.
These coded instructions, statements, and computer programs contain
proprietary information of Nintendo of America Inc. and/or Nintendo
Company Ltd., and are protected by Federal copyright law. They may
not be disclosed to third parties or copied or duplicated in any form,
in whole or in part, without the prior written consent of Nintendo.
$Rev$
*---------------------------------------------------------------------------*/
#include <nn.h>
//#include <nn/srv.h>
#include <nn/fs.h>
//#include <nn/ns/CTR/ns_ApiShell.h>
//#include <nn/ns/CTR/ns_Shell.h>
#include <nn/am/am_ApiLocalImporter.h>
#include <nn/am/am_ApiSystemMenu.h>
#include <nn/applet.h>
#include <nn/ndm.h>
#include <stdio.h>
#include "demo.h"
#include "../common/ver.h"
#include "../common/sleep.h"
#include "../common/common.h"
#include "../common/shfnt.h"
#include "test_data.h"
demo::RenderSystemDrawing s_RenderSystem;
nn::fnd::ExpHeap appHeap;
uptr heapForGx;
namespace
{
bit8 readBuf[64 * 1024];
}
bool ImportFile(nn::fs::MediaType mediaType, wchar_t* filename)
{
nn::Result result;
nn::fs::FileOutputStream* stream;
result = nn::am::BeginImportProgram(&stream, mediaType);
if (result.IsSuccess())
{
//NN_LOG("Importing: %ls...", filename);
nn::fs::FileInputStream in(filename);
while(s32 read = in.Read(readBuf, sizeof(readBuf)))
{
stream->Write(readBuf, read);
}
result = nn::am::EndImportProgram(stream);
}
return result.IsSuccess();
}
//#define setColor(r,g,b,a) s_RenderSystem.SetColor(r,g,b,a)
void setColor(f32 r,f32 g,f32 b,f32 a){ shf_SetColor(r,g,b,a);}
//#define setText(x,y,s) s_RenderSystem.DrawText(x,y,s)
void drawText(u16 x,u16 y,char *s){ shf_DrawText_0( x,y,s);}
nn::hid::PadReader *hpr;
//---------------------------------------------------------------- 入力待ち
nn::hid::PadStatus padStatus;
u32 WaitKey(u32 mask)
{
while(1){
hpr->ReadLatest(&padStatus);
if(padStatus.trigger & mask)return padStatus.trigger;
CheckSysBreak();
}
}
void endfunc()
{
nn::hid::Finalize();
SharedFontFinalize();
nngxWaitVSync(NN_GX_DISPLAY_BOTH);//SDK2.0以降では不要かも?
s_RenderSystem.Finalize();
}
char ver[16];
void nnMain( void )
{
nn::Result result;
nn::os::Initialize();
nn::fs::Initialize();
//DEA-SUPにて推奨のフリーズ暫定対策無線デーモンを停止 (2011.3.1 現在)
//ただし、スリープ時の"いつのまに通信"は止まらない
//無線は使わないが念の為、本体スイッチで切っとくのが確実
nn::ndm::SuspendScheduler();
//中断処理の準備
InitSysBreak((uptr)endfunc);
// グラフィックスライブラリの初期化は、以降で行わなければならない
// 他、アプリケーションの初期化処理
nn::hid::Initialize();
nn::hid::PadReader padReader;
hpr = &padReader;
//result = nn::ns::CTR::InitializeForShell();
//if (result.IsSuccess())
result = nn::am::InitializeForLocalImporter();
nn::applet::DisableSleep();//スリープ非対応
const size_t ROMFS_BUFFER_SIZE = 1024 * 64;
static char buffer[ROMFS_BUFFER_SIZE];
// ヒープの確保
appHeap.Initialize(nn::os::GetDeviceMemoryAddress(), nn::os::GetDeviceMemorySize(), nn::os::ALLOCATE_OPTION_LINEAR);
const u32 s_GxHeapSize = 0x800000;
// RenderSystem の準備
heapForGx = reinterpret_cast<uptr>(appHeap.Allocate(s_GxHeapSize));
s_RenderSystem.Initialize(heapForGx, s_GxHeapSize);
SharedFontInit();
// スリープ要求に対する返答を有効にする
// また、蓋の状態チェックを行い蓋が閉じられているならスリープ要求が発生する
// nn::applet::EnableSleep(true);
s_RenderSystem.SetRenderTarget(NN_GX_DISPLAY0);
s_RenderSystem.Clear();
// s_RenderSystem.SetFontSize(12);
shf_SetScale(0.8,0.6);
setColor(1.0,1.0,1.0,1.0);
drawText(20,20,"CTR Card Savedata Mover Setup");
s_RenderSystem.SwapBuffers();
shf_SetScale(0.5,0.5);
sprintf(ver,"version %.2f",VERSION);
drawText(250,40,ver);
shf_SetScale(0.7,0.7);
if (result.IsFailure()){//初期化に失敗
setColor(1.0, 0.0, 0.0,1.0);
drawText(10,70,"Initialize Error");
drawText(10,90,"check *.desc file");
drawText(10,110,"Push B : Quit");
s_RenderSystem.SwapBuffers();
while(1){
padReader.ReadLatest(&padStatus);
if(padStatus.trigger & nn::hid::BUTTON_B)break;
}
finish();
}
nn::fs::MountRom(16, 16, buffer, ROMFS_BUFFER_SIZE);
drawText(80,100,"Push X : Import");
drawText(80,140,"Push Y : Delete");
drawText(80,160,"Push R : Test Data");
s_RenderSystem.SwapBuffers();
u32 trg = WaitKey(nn::hid::BUTTON_X | nn::hid::BUTTON_Y | nn::hid::BUTTON_R);
if (trg & nn::hid::BUTTON_R){
shf_SetScale(0.6,0.6);
TestMain();//テストデータへ
}
shf_SetScale(0.8,0.8);
// CIA のプログラム ID を取得する。
nn::am::ProgramInfo programInfo;
if (nn::am::GetProgramInfoFromCia(&programInfo, ROMFS_IMPORTEE_PATH).IsFailure())
{
s_RenderSystem.Clear();
setColor(1.0, 0.0, 0.0,1.0);
drawText(10,50,"cia infomation Error");
drawText(10,120,"Push B : Quit");
s_RenderSystem.SwapBuffers();
while(1){
padReader.ReadLatest(&padStatus);
if(padStatus.trigger & nn::hid::BUTTON_B)break;
}
} else
{
s_RenderSystem.Clear();
if(padStatus.trigger & nn::hid::BUTTON_X)
drawText(10,120,"Importing");
else drawText(10,120,"Delete");
s_RenderSystem.SwapBuffers();
// 既に存在するものをインポートするとエラーが返ってくるので、あらかじめ消しておく。
nn::am::DeleteProgram(nn::fs::MEDIA_TYPE_NAND, programInfo.id);
// タイトル鍵が違うケースに対応するために、チケットも消しておく。
nn::am::DeleteTicket(programInfo.id);
if(padStatus.trigger & nn::hid::BUTTON_X)
{
// CIA をインポート
if (ImportFile(nn::fs::MEDIA_TYPE_NAND, ROMFS_IMPORTEE_PATH)==false)
{
s_RenderSystem.Clear();
setColor(1.0, 0.0, 0.0,1.0);
drawText(10,50,"Impoprt fail");
s_RenderSystem.SwapBuffers();
}
}
s_RenderSystem.Clear();
drawText(10,50,"Complate");
}
drawText(10,120,"Push Power Button & Power Off");
s_RenderSystem.SwapBuffers();
WaitKey(0);
}