///*---------------------------------------------------------------------------* // 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: 14479 $ // *---------------------------------------------------------------------------*/ // #include #include #include #include #include #include #include #include #include "applet.h" #include "sdAccessor.h" #include "window.h" #include "draw.h" // アプリが使用するヒープ nn::fnd::ExpHeap s_AppHeap; // TwlBackup に使用するバッファへのポインタ bit8 *addrForAm; // バナーを格納するバッファ const size_t BANNER_BUFFER_SIZE = 1024*16; bit8 bannerBuffer[BANNER_BUFFER_SIZE]; // SD カード挿抜イベント nn::os::LightEvent sdInsertEvent(false); nn::os::LightEvent sdEjectEvent(false); nn::fs::Directory dir; //バイナリファイル・フォルダの読み込み用 SdAccessor sdAccessor; //上下ウィンドウ操作 Window topWindow(screenHeight); Window bottomWindow(screenHeight); //現在のディレクトリ、バイナリファイル名前格納用 wchar_t fileName[512]; wchar_t binaryName[256]; void Initialize() { // ヒープの初期化 s_AppHeap.Initialize(nn::os::GetDeviceMemoryAddress(), NN_OS_DEVICE_MEMORY_SIZE, nn::os::ALLOCATE_OPTION_LINEAR); // fs の初期化 nn::fs::Initialize(); // am への接続 NN_UTIL_PANIC_IF_FAILED(nn::am::InitializeForSystemMenu()); // TwlBackup のためのワークバッファを確保 addrForAm = reinterpret_cast(s_AppHeap.Allocate(nn::am::TWL_BKP_WORK_BUFFER_SIZE)); // hid の初期化 NN_UTIL_PANIC_IF_FAILED(nn::hid::InitializeWithPrivilege()); // HID の入力が落ち着くまで待つ nn::os::Thread::Sleep(nn::fnd::TimeSpan::FromSeconds(1)); // グラフィックスの初期化 InitializeGraphics(); // SD カードの挿抜チェック sdInsertEvent.ClearSignal(); sdEjectEvent.ClearSignal(); nn::fs::RegisterSdmcInsertedEvent(&sdInsertEvent); nn::fs::RegisterSdmcEjectedEvent(&sdEjectEvent); // SD カードのマウント if (nn::fs::IsSdmcInserted()) { sdAccessor.SetIsSdMount(true); nn::fs::MountSdmc(); sdAccessor.Initialize(dir,L"sdmc:/"); } bottomWindow.isSelectedWindow = true; } void Update(nn::hid::PadStatus& status) { SdAccessor::BinaryInfo* binary = sdAccessor.GetBinary(); SdAccessor::DirectoryInfo* directory = sdAccessor.GetDirectory(); bool isSdInsert; bool isSdEject; // SD の挿抜 isSdInsert = sdInsertEvent.TryWait(); isSdEject = sdEjectEvent.TryWait(); if (isSdInsert) { if (!sdAccessor.IsSdMount()) { sdAccessor.SetIsSdMount(true); nn::fs::MountSdmc(); sdAccessor.Initialize(dir,L"sdmc:/"); topWindow.Initialize(); bottomWindow.Initialize(); bottomWindow.isSelectedWindow = true; } } if (isSdEject) { if (sdAccessor.IsSdMount()) { dir.Finalize(); sdAccessor.SetIsSdMount(false); nn::fs::Unmount("sdmc:"); } } //キー入力 if(sdAccessor.IsSdMount()) { if(binary->size == 0) { topWindow.isSelectedWindow = false; bottomWindow.isSelectedWindow = true; } //操作画面切り替え if ((status.trigger & nn::hid::BUTTON_START) && binary->size != 0) { bottomWindow.isSelectedWindow = topWindow.isSelectedWindow; topWindow.isSelectedWindow = !topWindow.isSelectedWindow; } //上画面操作 if(topWindow.isSelectedWindow) { NN_ASSERT(!bottomWindow.isSelectedWindow); //全ファイルインポート中 if( sdAccessor.IsImportAll() ) { topWindow.Import(sdAccessor.GetImportCount()); topWindow.Update(binary->size); sdAccessor.ImportAll(addrForAm); if( !sdAccessor.IsImportAll() ) { topWindow.Import(sdAccessor.GetImportCount()); topWindow.Update(binary->size); } } else { topWindow.UpDown(status); topWindow.Update(binary->size); if(binary->size != 0) { if (status.trigger & nn::hid::BUTTON_X) { //全ファイルインポート topWindow.Import(sdAccessor.GetImportCount()); topWindow.Update(binary->size); sdAccessor.ImportAll(addrForAm); } else if(status.trigger & nn::hid::BUTTON_A) { //選択ファイルインポート sdAccessor.Import(topWindow.GetIndex(),addrForAm); } else if (status.trigger & nn::hid::BUTTON_Y) { sdAccessor.ExportAll(); } } } } //下画面操作 else if (bottomWindow.isSelectedWindow) { NN_ASSERT(!topWindow.isSelectedWindow); bottomWindow.UpDown(status); bottomWindow.Update(directory->size); if (status.trigger & nn::hid::BUTTON_A) { //ディレクトリ決定 sdAccessor.Add( bottomWindow.GetIndex() ); dir.Finalize(); sdAccessor.DirectoryInitialize(dir); topWindow.Initialize(); bottomWindow.Initialize(); bottomWindow.isSelectedWindow = true; } } } } extern "C" void nnMain( void ) { NN_LOG("DSiWare SD Card Export and Import Test\n"); TransitionHandler::Initialize(); // 初期化 Initialize(); nn::hid::PadReader padReader; nn::hid::PadStatus padStatus; if (!TransitionHandler::IsExitRequired()) { TransitionHandler::EnableSleep(); while (1) { padReader.ReadLatest(&padStatus); Update(padStatus); // 描画 Draw(topWindow,bottomWindow,sdAccessor); TransitionHandler::Process(); // 終了通知が来ていないかを確認します。 if (TransitionHandler::IsExitRequired()) { break; } } } TransitionHandler::Finalize(); nn::applet::CloseApplication(); }