diff --git a/TwlBackupChecker/DataExportImportTool/OMakefile b/TwlBackupChecker/DataExportImportTool/OMakefile new file mode 100644 index 0000000..01cfcf1 --- /dev/null +++ b/TwlBackupChecker/DataExportImportTool/OMakefile @@ -0,0 +1,43 @@ +#!/usr/bin/env omake +#---------------------------------------------------------------------------- +# Project: Horizon +# File: OMakefile +# +# 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: 34658 $ +#---------------------------------------------------------------------------- +SUPPORTED_TARGETS = CTR-*.Process.MPCore.* + +SAMPLED_DEMOS_COMMON_INCLUDE_DIR = $(dir ../../../CTR_SDK-2_4/SampleDemos/common/include) +INCLUDES += $(SAMPLED_DEMOS_COMMON_INCLUDE_DIR) + + +SOURCES[] = + main.cpp + draw.cpp + sdAccessor.cpp + window.cpp + +TARGET_PROGRAM = twlSdExportImport + +LIBS += libnn_am lib_demo lib_applet + +ROM_SPEC_FILE = twlSdExportImport.rsf +DESCRIPTOR = $(HORIZON_ROOT)/resources/specfiles/systemapplications/Mset.desc + +# files �t�H���_�ɓ���Ă���� backupSample.cia �����炩���� devmenu ����C���|�[�g���Ă���N�����ĉ����� + +# srl �����p�u���b�V������ cia �̍��� +# makecia �R�}���h�ňȉ��̂悤�ɂ��ĉ����� +# makecia -s -padding + +include $(ROOT_OMAKE)/modulerules + +build: $(DEFAULT_TARGETS) diff --git a/TwlBackupChecker/DataExportImportTool/OMakeroot b/TwlBackupChecker/DataExportImportTool/OMakeroot new file mode 100644 index 0000000..7ee1cb5 --- /dev/null +++ b/TwlBackupChecker/DataExportImportTool/OMakeroot @@ -0,0 +1,73 @@ +#!/usr/bin/env omake +#---------------------------------------------------------------------------- +# Project: Horizon +# File: OMakeroot +# +# 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:$ +#---------------------------------------------------------------------------- + +# fBNgCAEgɂ‚Ă̐ +# +# a) \[XR[h[gfBNgɔzuꍇ +# : +# /OMakeroot +# /foo/bar/OMakefile +# +# : +# OMakefile ƓfBNgȉ objects images ܂B +# +# /foo/bar/objects/... +# /foo/bar/images/.. +# +# +# b) \[XR[h sources ȉɔzuꍇ +# : +# /OMakeroot +# /sources/foo/bar/OMakefile +# +# : +# [gfBNgȉ objects images ܂B +# +# /objects/foo/bar/... +# /images/foo/bar/... +# +# + +# [g‹ϐ̎擾 +public.HORIZON_ROOT = +if $(defined-env HORIZON_ROOT) + HORIZON_ROOT = $(absname $(getenv HORIZON_ROOT)) + export + +if $(defined-env CTRSDK_ROOT) + CTRSDK_ROOT = $(absname $(getenv CTRSDK_ROOT)) + if $(and $(defined-env HORIZON_ROOT), $(not $(equal $(HORIZON_ROOT), $(CTRSDK_ROOT)))) + eprintln(HORIZON_ROOT CTRSDK_ROOT v܂BpXݒ肷邩Aǂ炩`ĉB) + exit(1) + HORIZON_ROOT = $(CTRSDK_ROOT) + export + +if $(not $(HORIZON_ROOT)) + eprintln($"$$CTRSDK_ROOT `Ă܂") + exit(1) + +include $(HORIZON_ROOT)/build/omake/commondefs + +DefineCommandVars() + +.PHONY: all build clean clobber +.PHONY: run run-scripts run-emumem + +# +# OMakefile ̓ǂݍ +# +.SUBDIRS: . + diff --git a/TwlBackupChecker/DataExportImportTool/draw.cpp b/TwlBackupChecker/DataExportImportTool/draw.cpp new file mode 100644 index 0000000..0783cb4 --- /dev/null +++ b/TwlBackupChecker/DataExportImportTool/draw.cpp @@ -0,0 +1,310 @@ +///*---------------------------------------------------------------------------* +// Project: Horizon +// File: draw.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 "demo.h" +#include "sdAccessor.h" +#include "draw.h" + + +/* ExpHeap for app. */ +extern nn::fnd::ExpHeap s_AppHeap; +uptr s_HeapForGx; +const u32 s_GxHeapSize = 0x800000; +u16 xErrorPos = 130; +u16 yErrorPos = 5; + + +demo::RenderSystemExt s_RenderSystem; + +void InitializeGraphics() { + s_HeapForGx = reinterpret_cast (s_AppHeap.Allocate(s_GxHeapSize)); + + /* Initialize display */ + s_RenderSystem.Initialize(s_HeapForGx, s_GxHeapSize); + + s_RenderSystem.SetClearColor(NN_GX_DISPLAY0, 0.f, 0.f, 0.f, 1.0f); + s_RenderSystem.SetClearColor(NN_GX_DISPLAY1, 0.f, 0.f, 0.f, 1.0f); + + s_RenderSystem.SetFontSize(8.0f); + s_RenderSystem.SetColor(1.f, 1.f, 1.f); // WHITE +} + +u16 Min(u16 a, u16 b) +{ + return (a > b) ? b : a; +} + +//選択ウィンドウによって色変化 +void ChangeColorMode(Window& window) +{ + if(window.isSelectedWindow) + { + s_RenderSystem.SetColor(1.0f, 1.0f, 1.0f); + } + else + { + s_RenderSystem.SetColor(0.5f, 0.5f, 0.5f); + } +} + + +void DrawDefaultTop(void) +{ + s_RenderSystem.DrawText(0, 0, "BinaryFile"); + s_RenderSystem.DrawText(X_SCALE + xErrorPos, 0, " ErrorCode"); + s_RenderSystem.SetLineWidth(1.f); + s_RenderSystem.DrawLine(0,(fileStartPos - 0.5 ) * Y_SCALE,200,( fileStartPos -0.5) * Y_SCALE); + s_RenderSystem.DrawLine(X_SCALE + xErrorPos - 1,0, X_SCALE + xErrorPos - 1,240); +} + +void DrawDefaultBottom(void) +{ + s_RenderSystem.DrawText(0, 0, "Directory"); + s_RenderSystem.SetLineWidth(1.f); + s_RenderSystem.DrawLine(0,(fileStartPos - 0.5 ) * Y_SCALE,100,( fileStartPos -0.5) * Y_SCALE); +} + +void DrawCursor(Window& window) +{ + s_RenderSystem.DrawText(X_SCALE, Y_SCALE * (fileStartPos + window.GetSelectPos()), ">"); +} + +void DrawBinaryFile(Window& window, SdAccessor::BinaryInfo* binary) +{ + for (u16 i = 0; i < Min(screenHeight,binary->size); i++) + { + if(window.isSelectedWindow) + { + switch (binary->binaryType[i+ window.GetOriginIndex()].state) + { + case SdAccessor::IMPORTED_NOT: + s_RenderSystem.SetColor(1.f, 1.f, 1.f); + break; + case SdAccessor::IMPORTED_CLEAR: + s_RenderSystem.SetColor(0.f, 0.f, 1.f); + break; + case SdAccessor::IMPORTED_ERROR: + s_RenderSystem.SetColor(1.f, 0.f, 0.f); + break; + } + } + else + { + s_RenderSystem.SetColor(0.5f, 0.5f, 0.5f); + } + s_RenderSystem.DrawText(X_SCALE, Y_SCALE* (i + fileStartPos), " %ls ", + binary->binaryType[ i + window.GetOriginIndex()].directoryEntry.entryName); + s_RenderSystem.SetColor(1.f, 1.f, 1.f); + } +} +void DrawDirectory(Window& window, SdAccessor::DirectoryInfo* directory) +{ + for (u16 i = 0; i < Min(manualStartPos - 2,directory->size) ; i++) + { + if(!window.isSelectedWindow) + { + s_RenderSystem.SetColor(0.5f, 0.5f, 0.5f); + } + else if (window.GetIndex() == i + window.GetOriginIndex()) { + s_RenderSystem.SetColor(1.f, 1.f, 0.f); // YELLOW + } + s_RenderSystem.DrawText(X_SCALE * 2 , Y_SCALE * (i + fileStartPos), "%ls", + directory->directoryEntry[i + window.GetOriginIndex()].entryName); + s_RenderSystem.SetColor(1.f, 1.f, 1.f); // WHITE + } +} +//エラーリスト表示 +void DrawErrorList(Window& top,SdAccessor::BinaryInfo* binary) +{ + u16 index = top.GetIndex(); + //インポートされていなければ非表示 + if(binary->binaryType[index].state != SdAccessor::IMPORTED_NOT) + { + nn::Result result = binary->binaryType[index].result; + u16 y = fileStartPos; + ChangeColorMode(top); + s_RenderSystem.DrawText( X_SCALE + xErrorPos, Y_SCALE * y," Level\n"); + y += 2; + s_RenderSystem.DrawText( X_SCALE + xErrorPos, Y_SCALE * y," %s (%d)\n" + , nn::dbg::GetLevelString(result), result.GetLevel()); + y += 3; + s_RenderSystem.DrawText( X_SCALE + xErrorPos, Y_SCALE * y," Summary\n"); + y += 2; + s_RenderSystem.DrawText( X_SCALE + xErrorPos, Y_SCALE * y," %s (%d)\n" + , nn::dbg::GetSummaryString(result), result.GetSummary()); + y += 3; + s_RenderSystem.DrawText( X_SCALE + xErrorPos, Y_SCALE * y," Module\n"); + y += 2; + s_RenderSystem.DrawText( X_SCALE + xErrorPos, Y_SCALE * y," %s (%d)\n" + , nn::dbg::GetModuleString(result), result.GetModule()); + y += 3; + s_RenderSystem.DrawText( X_SCALE + xErrorPos, Y_SCALE * y," Description\n"); + y += 2; + s_RenderSystem.DrawText( X_SCALE + xErrorPos, Y_SCALE * y," %s\n" + , nn::dbg::GetDescriptionString(result)); + y += 2; + s_RenderSystem.DrawText( X_SCALE + xErrorPos, Y_SCALE * y," (%d)\n", result.GetDescription()); + + y += 4; + s_RenderSystem.DrawText( X_SCALE + xErrorPos, Y_SCALE * y," ErrorCode : %x \n",result.GetPrintableBits()); + + + s_RenderSystem.SetColor(1.f, 1.f, 1.f); + + } +} +//上画面左描画 +void DrawLeft(Window& window, SdAccessor::BinaryInfo* binary) +{ + if(binary->size != 0) + { + ChangeColorMode(window); + DrawDefaultTop(); + s_RenderSystem.SetColor(1.f, 1.f, 1.f); // WHITE + if(window.isSelectedWindow) + { + DrawCursor(window); + } + DrawBinaryFile(window,binary); + } + else + { + s_RenderSystem.DrawText(X_SCALE, Y_SCALE,"No Binary File in this directory.."); + } +} +//上画面右描画 +void DrawRight(Window& window, SdAccessor::BinaryInfo* binary) +{ + DrawErrorList(window,binary); +} +//操作説明 +void DrawManual(Window& top,Window& bottom, SdAccessor& sd) +{ + f32 x = 1; + f32 y = manualStartPos; + s_RenderSystem.SetLineWidth(1.2f); + s_RenderSystem.DrawLine(0,(manualStartPos - 0.5) * Y_SCALE,320,( manualStartPos - 0.5) * Y_SCALE); + s_RenderSystem.SetLineWidth(1.f); + s_RenderSystem.DrawLine(0,(manualStartPos + 1.5 ) * Y_SCALE,100,( manualStartPos + 1.5) * Y_SCALE); + s_RenderSystem.DrawText(0, Y_SCALE*y++, "Manual"); + y ++; + //上画面選択時 + if(top.isSelectedWindow) + { + SdAccessor::BinaryInfo* binary = sd.GetBinary(); + if(sd.GetImportCount() == 0) + { + s_RenderSystem.DrawText(X_SCALE*x, Y_SCALE*y++, "Current File :"); + } + else + { + s_RenderSystem.DrawText(X_SCALE*x, Y_SCALE*y++, "Importing File :"); + } + s_RenderSystem.DrawText(X_SCALE*x, Y_SCALE*y++, "%ls", binary->binaryType[top.GetIndex()].directoryEntry.entryName); + y ++; + s_RenderSystem.DrawText(X_SCALE*x, Y_SCALE*y++, " A : Import %ls", binary->binaryType[top.GetIndex()].directoryEntry.entryName); + s_RenderSystem.DrawText(X_SCALE*x, Y_SCALE*y++, " X : Import all files"); + s_RenderSystem.DrawText(X_SCALE*x, Y_SCALE*y++, " Y : Export result"); + s_RenderSystem.DrawText(X_SCALE*x, Y_SCALE*y++, " to 'Result%d.csv' ",sd.GetExportCount()); + y++; + s_RenderSystem.DrawText(X_SCALE*x, Y_SCALE*y++, " Start: to directory screen"); + } + //下画面選択時 + else + { + s_RenderSystem.DrawText(X_SCALE*x, Y_SCALE*y++, "Current directory :" ); + wchar_t path[128]; + SdAccessor::DirectoryInfo* directory = sd.GetDirectory(); + + //ディレクトリ名の行分け + std::wcscpy( path,sd.GetFileName() ); + u16 width = 240/Y_SCALE -1; + u16 height = 4; + wchar_t fileList[height][width]; + for(u16 row = 0; row < height ; row++) + { + for(u16 col = 0; col < width;col++) + { + fileList[row][col] = path[row * width + col]; + } + } + for(u16 i = 0; i < height; i++) + { + s_RenderSystem.DrawText(X_SCALE*x, Y_SCALE*y++, "%ls",fileList[i]); + } + + y++; + s_RenderSystem.DrawText(X_SCALE*x, Y_SCALE*y++, " A : Select %ls", directory->directoryEntry[bottom.GetIndex()].entryName); + y++; + s_RenderSystem.DrawText(X_SCALE*x, Y_SCALE*y++, " Start : to file screen"); + } +} +//上画面描画 +void DrawDisplay0(Window& topWindow,SdAccessor& sd) +{ + SdAccessor::BinaryInfo* binary = sd.GetBinary(); + s_RenderSystem.SetRenderTarget(NN_GX_DISPLAY0); + s_RenderSystem.Clear(); + DrawLeft(topWindow,binary); + DrawRight(topWindow,binary); + s_RenderSystem.Transfer(); + s_RenderSystem.SwapBuffers(); +} +//下画面描画 +void DrawDisplay1(Window& topWindow,Window& bottomWindow, SdAccessor& sd) +{ + SdAccessor::DirectoryInfo* directory = sd.GetDirectory(); + s_RenderSystem.SetRenderTarget(NN_GX_DISPLAY1); + s_RenderSystem.Clear(); + ChangeColorMode(bottomWindow); + DrawDefaultBottom(); + s_RenderSystem.SetColor(1.f, 1.f, 1.f); // WHITE + if(bottomWindow.isSelectedWindow) + { + DrawCursor(bottomWindow); + } + DrawDirectory(bottomWindow,directory); + DrawManual(topWindow,bottomWindow,sd); + s_RenderSystem.Transfer(); + s_RenderSystem.SwapBuffers(); +} +void DrawNoSd(void) { + s_RenderSystem.SetRenderTarget(NN_GX_DISPLAY0); + s_RenderSystem.Clear(); + s_RenderSystem.Transfer(); + s_RenderSystem.SwapBuffers(); + s_RenderSystem.SetRenderTarget(NN_GX_DISPLAY1); + s_RenderSystem.Clear(); + s_RenderSystem.DrawText(X_SCALE, Y_SCALE, "No Sd Card Inserted"); + s_RenderSystem.Transfer(); + s_RenderSystem.SwapBuffers(); +} +void Draw(Window& topWindow, Window& bottomWindow,SdAccessor& sd) +{ + if(sd.IsSdMount()) + { + DrawDisplay0(topWindow, sd ); + DrawDisplay1(topWindow,bottomWindow, sd); + } + else + { + DrawNoSd(); + } +} diff --git a/TwlBackupChecker/DataExportImportTool/draw.h b/TwlBackupChecker/DataExportImportTool/draw.h new file mode 100644 index 0000000..cf8c59d --- /dev/null +++ b/TwlBackupChecker/DataExportImportTool/draw.h @@ -0,0 +1,19 @@ +#ifndef DRAW_H_ +#define DRAW_H_ + +#include +#include "sdAccessor.h" +#include "window.h" + +const u16 fileStartPos = 2; +const u16 manualStartPos = 16; +const size_t X_SCALE = 8; +const size_t Y_SCALE = 8; + +const u16 screenHeight = ( 240 - (Y_SCALE * fileStartPos) )/ Y_SCALE; + + +void InitializeGraphics(void); +void Draw(Window& top, Window& bottom,SdAccessor& sd); + +#endif /* DRAW_H_ */ diff --git a/TwlBackupChecker/DataExportImportTool/main.cpp b/TwlBackupChecker/DataExportImportTool/main.cpp new file mode 100644 index 0000000..4c99536 --- /dev/null +++ b/TwlBackupChecker/DataExportImportTool/main.cpp @@ -0,0 +1,236 @@ +///*---------------------------------------------------------------------------* +// 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(); + +} diff --git a/TwlBackupChecker/DataExportImportTool/sdAccessor.cpp b/TwlBackupChecker/DataExportImportTool/sdAccessor.cpp new file mode 100644 index 0000000..f809a9c --- /dev/null +++ b/TwlBackupChecker/DataExportImportTool/sdAccessor.cpp @@ -0,0 +1,209 @@ +#include "sdAccessor.h" +#include "draw.h" + +const bit32 CLEAR = 0x00000000;//追加情報なし +const bit32 CLEAR_INFO = 0x08000000;//追加情報あり + +SdAccessor::SdAccessor(): + mImportCount(0), + mExportCount(0), + mIsImportAll(false), + mIsSdMount(false) +{ + mEntryMax = sizeof(mBinary.binaryType)/sizeof(mBinary.binaryType[0]); + for(u16 i = 0; i < mEntryMax; i++) + { + mBinary.binaryType[i].state = IMPORTED_NOT; + } + for(u16 i = 0; i < 512; i++) + { + mFileName[i] = L'\0'; + } + mBinary.size = 0; + mDirectory.size = 0; +} + + +static bool directoryEntryComp(const nn::fs::DirectoryEntry &lhs, const nn::fs::DirectoryEntry &rhs) +{ + return std::wcscmp(lhs.entryName, rhs.entryName) < 0; +} + +static bool binaryInfoComp(const SdAccessor::BinaryType &lhs, const SdAccessor::BinaryType &rhs) +{ + return directoryEntryComp(lhs.directoryEntry, rhs.directoryEntry); +} + +void SdAccessor::Initialize(nn::fs::Directory& dir, wchar_t* fileName) +{ + std::wcscpy(mFileName,fileName); + DirectoryInitialize(dir); +} + +void SdAccessor::DirectoryInitialize(nn::fs::Directory& dir) +{ + mBinary.size = 0; + mExportCount = 0; + mImportCount = 0; + mIsImportAll = false; + + for(u16 i = 0; i < mEntryMax; i++) + { + mBinary.binaryType[i].state = IMPORTED_NOT; + } + std::wcscpy(mDirectory.directoryEntry[0].entryName, L"../"); + nn::fs::DirectoryEntry* entry = new nn::fs::DirectoryEntry[mEntryMax]; + dir.Initialize(mFileName); + s32 readCount = dir.Read(entry,mEntryMax); + if(readCount == 0) + { + mBinary.size= 0; + mDirectory.size = 1; + } + else + { + u16 j = 0; + u16 k = 1; + //バイナリファイル・フォルダに分割 + for(u16 i = 0; i < readCount; i++) + { + if(entry[i].shortName.valid) + { + if(std::strcmp(entry[i].shortName.ext, "BIN") == 0) + { + mBinary.binaryType[j].directoryEntry = entry[i]; + j++; + } + if(entry[i].attributes.isDirectory) + { + mDirectory.directoryEntry[k] = entry[i]; + k++; + } + } + } + mBinary.size = j; + mDirectory.size = k; + //フォルダ・ファイルそれぞれソート + std::sort(&mBinary.binaryType[0], &mBinary.binaryType[mBinary.size], binaryInfoComp); + std::sort(&mDirectory.directoryEntry[0], &mDirectory.directoryEntry[mDirectory.size], directoryEntryComp); + } + delete[] entry; +} + + +void SdAccessor::Add(u16 index) +{ + if(index == 0) + { + if( std::wcscmp(mFileName, L"sdmc:/") != 0) + { + size_t directoryLen,i; + directoryLen = std::wcslen(mFileName); + mFileName[directoryLen - 1] = L'\0'; + for(i = directoryLen - 2; mFileName[i] != L'/';i--) + { + mFileName[i] = L'\0'; + } + } + } + else if (mDirectory.size != 1) + { + std::wcscat(mFileName,mDirectory.directoryEntry[index].entryName); + std::wcscat(mFileName,L"/"); + } +} + +void SdAccessor::Import(u16 index,bit8* addrForAm) +{ + std::wcscpy(mBinaryName, mFileName); + std::wcscat(mBinaryName, mBinary.binaryType[index].directoryEntry.entryName); + mBinary.binaryType[index].result = nn::am::ImportTwlBackup(mBinaryName, addrForAm); + if(mBinary.binaryType[index].result.GetPrintableBits() == CLEAR || mBinary.binaryType[index].result.GetPrintableBits() == CLEAR_INFO) + { + mBinary.binaryType[index].state = IMPORTED_CLEAR; + } + else + { + mBinary.binaryType[index].state = IMPORTED_ERROR; + } +} + +void SdAccessor::ImportAll(bit8* addrForAm) +{ + if (mImportCount == 0) { + mIsImportAll = true; + } + Import(mImportCount, addrForAm); + mImportCount++; + if (mImportCount >= mBinary.size) { + mImportCount = 0; + mIsImportAll = false; + } +} +//全ファイル結果保存 +void SdAccessor::ExportAll(void) +{ + wchar_t exportPath[128]; + wchar_t outFileName[32]; + char c_buffer[1024]; + u16 fileSize = 256; + s32 ret,ret2; + nn::fs::FileStream f; + std::wcscpy(exportPath,mFileName); + std::swprintf(outFileName,32,L"Result%d.csv",mExportCount); + std::wcscat(exportPath,outFileName); + mExportCount++; + nn::Result resultFile = f.TryInitialize(exportPath, nn::fs::OPEN_MODE_READ); + if( !resultFile.IsSuccess() ) + { + resultFile = nn::fs::TryCreateFile(exportPath, fileSize); + NN_UTIL_PANIC_IF_FAILED(resultFile); + resultFile = f.TryInitialize(exportPath, nn::fs::OPEN_MODE_READ); + NN_UTIL_PANIC_IF_FAILED(resultFile); + } + resultFile = f.TrySeek(0,nn::fs::POSITION_BASE_BEGIN); + NN_UTIL_PANIC_IF_FAILED(resultFile); + + resultFile = f.TryRead(&ret,c_buffer,sizeof(c_buffer)); + NN_UTIL_PANIC_IF_FAILED(resultFile); + for(u16 i = 0; i < ret ; i++) + { + c_buffer[i] = '\0'; + } + f.Finalize(); + resultFile = f.TryInitialize(exportPath, nn::fs::OPEN_MODE_WRITE); + NN_UTIL_PANIC_IF_FAILED(resultFile); + resultFile = f.TrySeek(0,nn::fs::POSITION_BASE_BEGIN); + NN_UTIL_PANIC_IF_FAILED(resultFile); + resultFile = f.TryWrite(&ret2,c_buffer,ret); + NN_UTIL_PANIC_IF_FAILED(resultFile); + resultFile = f.TrySeek(0,nn::fs::POSITION_BASE_BEGIN); + NN_UTIL_PANIC_IF_FAILED(resultFile); + + std::strcpy(c_buffer,"File,Level,Summary,Module,Description\n"); + resultFile = f.TryWrite(&ret,c_buffer,std::strlen(c_buffer)); + NN_UTIL_PANIC_IF_FAILED(resultFile); + + + for(u16 i = 0; i < mBinary.size; i++) + { + if(mBinary.binaryType[i].state != IMPORTED_NOT) + { + nn::Result result = mBinary.binaryType[i].result; + std::sprintf(c_buffer, "%ls,%s (%d),%s (%d),%s (%d),%s (%d)\n" + ,mBinary.binaryType[i].directoryEntry.entryName + ,nn::dbg::GetLevelString(result) + ,result.GetLevel() + ,nn::dbg::GetSummaryString(result) + ,result.GetSummary() + ,nn::dbg::GetModuleString(result) + ,result.GetModule() + ,nn::dbg::GetDescriptionString(result) + ,result.GetDescription() + ); + resultFile = f.TryWrite(&ret,c_buffer,std::strlen(c_buffer)); + NN_UTIL_PANIC_IF_FAILED(resultFile); + } + } + f.Finalize(); +} diff --git a/TwlBackupChecker/DataExportImportTool/sdAccessor.h b/TwlBackupChecker/DataExportImportTool/sdAccessor.h new file mode 100644 index 0000000..62ce377 --- /dev/null +++ b/TwlBackupChecker/DataExportImportTool/sdAccessor.h @@ -0,0 +1,109 @@ +#ifndef SDACCESSOR_H_ +#define SDACCESSOR_H_ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + + +#include"demo.h" + +class SdAccessor { +public: + SdAccessor(); + virtual ~SdAccessor(){ + } + + + enum BinaryState + { + IMPORTED_NOT = 0, + IMPORTED_CLEAR = 1, + IMPORTED_ERROR = 2 + }; + + struct BinaryType + { + nn::fs::DirectoryEntry directoryEntry; + BinaryState state; + NN_PADDING3; + nn::Result result; + }; + + struct BinaryInfo + { + BinaryType binaryType[256]; + u16 size; + }; + + struct DirectoryInfo + { + nn::fs::DirectoryEntry directoryEntry[256]; + u16 size; + }; + void Initialize(nn::fs::Directory& dir, wchar_t* fileName); + void DirectoryInitialize(nn::fs::Directory& dir); + void Add(u16 index); + wchar_t* GetFileName(void) + { + return mFileName; + } + void GetPreFileName(void); + void Import(u16 index,bit8* addrForAm); + void ImportAll(bit8* addrForAm); + void Export(u16 index); + void ExportAll(void); + void SetIsSdMount(bool t) + { + mIsSdMount = t; + } + BinaryInfo* GetBinary(void) + { + return &mBinary; + } + DirectoryInfo* GetDirectory(void) + { + return &mDirectory; + } + u16 GetImportCount(void) + { + return mImportCount; + } + u16 GetExportCount(void) + { + return mExportCount; + } + bool IsImportAll(void) + { + return mIsImportAll; + } + bool IsSdMount(void) + { + return mIsSdMount; + } + +private: + NN_PADDING4; + wchar_t mFileName[512]; + wchar_t mPreFileName[64][512]; + wchar_t mBinaryName[512]; + wchar_t mEmpty[128]; + + BinaryInfo mBinary; + DirectoryInfo mDirectory; + + u16 mEntryMax; + u16 mImportCount; + u16 mExportCount; + bool mIsImportAll; + bool mIsSdMount; +}; + +#endif /* SDACCESSOR_H_ */ diff --git a/TwlBackupChecker/DataExportImportTool/twlSdExportImport.cci b/TwlBackupChecker/DataExportImportTool/twlSdExportImport.cci new file mode 100644 index 0000000..65d10a0 Binary files /dev/null and b/TwlBackupChecker/DataExportImportTool/twlSdExportImport.cci differ diff --git a/TwlBackupChecker/DataExportImportTool/twlSdExportImport.rsf b/TwlBackupChecker/DataExportImportTool/twlSdExportImport.rsf new file mode 100644 index 0000000..148d67e --- /dev/null +++ b/TwlBackupChecker/DataExportImportTool/twlSdExportImport.rsf @@ -0,0 +1,25 @@ +BasicInfo: + Title : twlSdExportImport + BackupMemoryType : None + +CardInfo: + CardDevice : None + +TitleInfo: + UniqueId : 0x200 + Version : 00 + +SystemControlInfo: + AppType : System + StackSize : 0x4000 + +AccessControlInfo: + AffinityMask : 0x1 + IdealProcessor : 0 + Priority : 24 + FileSystemAccess: + - DirectSdmc + +Rom: + # ROM �Ɋ܂߂�t�@�C���V�X�e���̃��[�g�p�X���w�肵�܂��B + HostRoot: "$(ROMFS_ROOT)" diff --git a/TwlBackupChecker/DataExportImportTool/window.cpp b/TwlBackupChecker/DataExportImportTool/window.cpp new file mode 100644 index 0000000..05e739d --- /dev/null +++ b/TwlBackupChecker/DataExportImportTool/window.cpp @@ -0,0 +1,98 @@ +/* + * window.cpp + * + * Created on: 2011/07/14 + * Author: N2885 + */ + +#include "window.h" + +u16 waitTime = 40; +u16 waitAcceleTime = 5; +u16 n = 4; + +void Window::Initialize(void) +{ + mIndex = 0; + mOriginIndex = 0; + mSelectPos = 0; + mCursorCounter = 0; + mAcceleCounter = 0; + isSelectedWindow = false; +} + +//カーソル上下・押しっぱなしで加速 +void Window::UpDown(nn::hid::PadStatus& status) +{ + if(mCursorCounter == 0) + { + if(status.hold & nn::hid::BUTTON_UP || status.hold & nn::hid::BUTTON_DOWN) + { + if(status.hold & nn::hid::BUTTON_UP) + { + mSelectPos--; + } + else + { + mSelectPos++; + } + mAcceleCounter++; + for(u16 i = 1; i < n; i++) + { + if( mAcceleCounter >= waitAcceleTime * ( i - 1 ) && mAcceleCounter <= waitAcceleTime * i ) + { + mCursorCounter = waitTime/ i; + i = n; + } + else + { + mCursorCounter = waitTime / n; + } + } + } + else + { + mAcceleCounter = 0; + } + } + else + { + mCursorCounter--; + } +} +static u16 Min(u16 a, u16 b) +{ + return (a > b) ? b : a; +} + +void Window::Update(u16 fileSize) +{ + if( mSelectPos < 0 ) + { + if( mOriginIndex == 0 ) + { + mSelectPos = Min(fileSize, mScreenHeight) - 1; + mOriginIndex = fileSize - Min(fileSize,mScreenHeight); + } + else + { + mSelectPos = 0; + mOriginIndex--; + } + } + else if( mSelectPos >= Min(fileSize, mScreenHeight) ) + { + if( mOriginIndex < fileSize - mScreenHeight) + { + mSelectPos = mScreenHeight - 1; + mOriginIndex++; + } + else + { + mSelectPos = 0; + mOriginIndex = 0; + } + } + mIndex = mSelectPos + mOriginIndex; +} + diff --git a/TwlBackupChecker/DataExportImportTool/window.h b/TwlBackupChecker/DataExportImportTool/window.h new file mode 100644 index 0000000..3b41d25 --- /dev/null +++ b/TwlBackupChecker/DataExportImportTool/window.h @@ -0,0 +1,65 @@ +#ifndef WINDOW_H_ +#define WINDOW_H_ + +#include +#include +#include +#include +#include +#include +#include +#include + +class Window { +public: + //screenHeight:縦方向に画面に入る文字数 + //screenHeight = windowHeight / Y_SCALE + Window(u16 screenHeight): + isSelectedWindow(false), + mIndex(0), + mOriginIndex(0), + mSelectPos(0) + { + mScreenHeight = screenHeight; + } + virtual ~Window(){} + void Initialize(void); + void UpDown(nn::hid::PadStatus& status); + void Update(u16 fileSize); + void Import(u16 count) + { + mSelectPos = count + 1; + if(count == 0) + { + mSelectPos = 0; + mOriginIndex = 0; + } + } + + s16 GetIndex(void) + { + return mIndex; + } + s16 GetOriginIndex(void) + { + return mOriginIndex; + } + s16 GetSelectPos(void) + { + return mSelectPos; + } + + NN_PADDING3; + bool isSelectedWindow; + +private: + s16 mIndex; + s16 mOriginIndex; + s16 mSelectPos; + u16 mScreenHeight; + u16 mCursorCounter; + u16 mAcceleCounter; + +}; + +#endif /* WINDOW_H_ */