diff --git a/trunk/ConsoleDataMigration/ConsoleBackup/Exporter.cpp b/trunk/ConsoleDataMigration/ConsoleBackup/Exporter.cpp index 45a4a89..4afdadd 100644 --- a/trunk/ConsoleDataMigration/ConsoleBackup/Exporter.cpp +++ b/trunk/ConsoleDataMigration/ConsoleBackup/Exporter.cpp @@ -56,6 +56,7 @@ nn::os::StackBuffer s_ExportThreadStack; wchar_t s_RootName[256]; +// TODO: Thread.IsAlive に置き換える bool s_IsExportThreadFinished = false; } @@ -284,6 +285,60 @@ void GetSaveDataDirectoryRoot() NN_LOG("%s\n", s_SysSaveRoot.c_str()); } +void CreateTwlDirectory(enum common::TWL_PATHNAME path) +{ + NN_ASSERT(path < common::TWL_PATHNAME_MAX); + + s_SdWriter.CreateDirectory((::std::wstring(common::SDMC_ROOT_DIRECTORY_PATH) + + std::wstring(common::SD_TWL_ROOTNAME_TABLE[path])).c_str()); +} + +void WriteTwlData(enum common::TWL_PATHNAME path) +{ + NN_ASSERT(path < common::TWL_PATHNAME_MAX); + + nn::Result result; + + result = nn::fs::MountSpecialArchive(common::TWL_ARCHIVE_NAME_TABLE[path], common::TWL_FS_ARCHIVE_KIND[path]); + COMMON_LOGGER_RESULT_IF_FAILED_WITH_LINE(result); + + result = common::SdMountManager::Mount(); + + size_t bufSize = common::HeapManager::GetHeap()->GetAllocatableSize(); + NN_LOG("AllocatableSize = %d\n", bufSize); + + void* buf = common::HeapManager::GetHeap()->Allocate(bufSize); + if (buf != NULL) + { + wchar_t archiveName[256]; + ::std::mbstowcs(archiveName, common::TWL_ARCHIVE_NAME_TABLE[path], std::strlen(common::TWL_ARCHIVE_NAME_TABLE[path]) + 1); + std::wstring archiveString(archiveName); + common::CopyDirectory( + (archiveString + ::std::wstring(L"/")).c_str(), + (common::SDMC_ROOT_DIRECTORY_PATH + ::std::wstring(common::SD_TWL_ROOTNAME_TABLE[path])).c_str(), + buf, bufSize); + + common::HeapManager::GetHeap()->Free(buf); + } + + common::SdMountManager::Unmount(); + nn::fs::Unmount(common::TWL_ARCHIVE_NAME_TABLE[path]); + +} + +void WriteTwlPhotoData() +{ + COMMON_LOGGER("Create Twl Photo Backup.\n"); + CreateTwlDirectory(common::TWL_PHOTO); + WriteTwlData(common::TWL_PHOTO); +} + +void WriteTwlSoundData() +{ + COMMON_LOGGER("Create Twl Sound Backup.\n"); + CreateTwlDirectory(common::TWL_SOUND); + WriteTwlData(common::TWL_SOUND); +} void ExportThreadFunc() { @@ -349,7 +404,7 @@ nn::Result WriteSaveData() // セーブデータディレクトリ以下のデータをSDカードにコピー // コピー用ディレクトリ作成 - COMMON_LOGGER("Create Backup Directory.\n"); + COMMON_LOGGER("Create CTR Backup Directory.\n"); s_SdWriter.CreateDirectory((::std::wstring(common::SDMC_ROOT_DIRECTORY_PATH) + ::std::wstring( common::SD_SAVEDATA_ROOT_NAME)).c_str()); s_SdWriter.CreateDirectory((::std::wstring(common::SDMC_ROOT_DIRECTORY_PATH) + ::std::wstring( @@ -392,6 +447,12 @@ void ExportData() // IVSからセーブデータディレクトリ名を計算 GetSaveDataDirectoryRoot(); + // TWL写真領域のデータをSDに書き出す + WriteTwlPhotoData(); + + // TWLサウンド領域のデータをSDに書き出す + WriteTwlSoundData(); + // NANDのセーブデータをSDに書き出す WriteSaveData(); diff --git a/trunk/ConsoleDataMigration/ConsoleRestore/Controller.cpp b/trunk/ConsoleDataMigration/ConsoleRestore/Controller.cpp index 799307b..cf625a5 100644 --- a/trunk/ConsoleDataMigration/ConsoleRestore/Controller.cpp +++ b/trunk/ConsoleDataMigration/ConsoleRestore/Controller.cpp @@ -192,7 +192,7 @@ void ControlState(::std::vector& operationMessage, bool& nextStep, { COMMON_LOGGER("Restore data to the same Console. Initialize.\n"); // 本体初期化を行う - nn::fs::InitializeCtrFileSystem(); + InitializeFileSystem(); error = true; s_RestoreState = REBOOTING; } @@ -213,7 +213,7 @@ void ControlState(::std::vector& operationMessage, bool& nextStep, CreateConsoleInitializedFile(); // 本体初期化を行う - nn::fs::InitializeCtrFileSystem(); + InitializeFileSystem(); error = true; s_RestoreState = REBOOTING; } diff --git a/trunk/ConsoleDataMigration/ConsoleRestore/Importer.cpp b/trunk/ConsoleDataMigration/ConsoleRestore/Importer.cpp index 53025e9..a5cca1f 100644 --- a/trunk/ConsoleDataMigration/ConsoleRestore/Importer.cpp +++ b/trunk/ConsoleDataMigration/ConsoleRestore/Importer.cpp @@ -436,6 +436,89 @@ void ImportCountryLanguageData() } } +void InitializeFileSystem() +{ + nn::Result result; + + for (u32 i = 0; i < common::TWL_PATHNAME_MAX; i++) + { + result = nn::fs::MountSpecialArchive(common::TWL_ARCHIVE_NAME_TABLE[i], common::TWL_FS_ARCHIVE_KIND[i]); + COMMON_LOGGER_RESULT_IF_FAILED_WITH_LINE(result); + if (result.IsSuccess()) + { + nn::fs::Directory dir; + std::vector entryList; //カレントディレクトリのエントリ一覧を格納 + std::vector::iterator entryIndex; + + std::wstring currentDirectory = common::NAND_TWL_ROOT_PATHNAME_WITH_SLASH_TABLE[i]; + result = dir.TryInitialize(currentDirectory.c_str()); + + nn::fs::DirectoryEntry entry; + s32 numEntry; + for (;;) + { + result = dir.TryRead(&numEntry, &entry, 1); + if (result.IsFailure()) + { + dir.Finalize(); + } + if (numEntry == 0) + { + // ルートディレクトリを閉じる + dir.Finalize(); + + // ルートディレクトリの子を開く + for (entryIndex = entryList.begin(); entryIndex != entryList.end(); entryIndex++) + { + // ディレクトリなら削除する + if (entryIndex->attributes.isDirectory) + { + NN_LOG("Try Delete %ls%ls/\n", currentDirectory.c_str(), entryIndex->entryName); + result = nn::fs::TryDeleteDirectoryRecursively((currentDirectory + ::std::wstring( + entryIndex->entryName)).c_str()); + if (result.IsFailure()) + { + COMMON_LOGGER_RESULT_WITH_LINE(result , __LINE__); + } + + } + // ファイルなら削除する + else + { + NN_LOG("Try Delete %ls%ls\n", currentDirectory.c_str(), entryIndex->entryName); + result = nn::fs::TryDeleteFile( + (currentDirectory + ::std::wstring(entryIndex->entryName)).c_str()); + if (result.IsFailure()) + { + COMMON_LOGGER_RESULT_WITH_LINE(result , __LINE__); + } + } + } + + // 削除完了 + break; + } + else + { + // vectorに保存する + entryList.push_back(entry); + if (entry.attributes.isDirectory) + { + NN_LOG("%ls%ls/\n", currentDirectory.c_str(), entry.entryName); + } + else + { + NN_LOG("%ls%ls\n", currentDirectory.c_str(), entry.entryName); + } + } + } + } + nn::fs::Unmount(common::TWL_ARCHIVE_NAME_TABLE[i]); + } + + nn::fs::InitializeCtrFileSystem(); +} + void ImportIvs() { nn::Result result; @@ -1066,6 +1149,52 @@ CheckedNetworkSetting* GetTempNetworkSetting() return &s_CurrentNetowrkSetting1; } +void ImportTwlData(enum common::TWL_PATHNAME path) +{ + NN_ASSERT(path < common::TWL_PATHNAME_MAX); + + nn::Result result; + + result = nn::fs::MountSpecialArchive(common::TWL_ARCHIVE_NAME_TABLE[path], common::TWL_FS_ARCHIVE_KIND[path]); + COMMON_LOGGER_RESULT_IF_FAILED_WITH_LINE(result); + + result = common::SdMountManager::Mount(); + + size_t bufSize = common::HeapManager::GetHeap()->GetAllocatableSize(); + NN_LOG("AllocatableSize = %d\n", bufSize); + + void* buf = common::HeapManager::GetHeap()->Allocate(bufSize); + if (buf != NULL) + { + wchar_t archiveName[256]; + ::std::mbstowcs(archiveName, common::TWL_ARCHIVE_NAME_TABLE[path], std::strlen(common::TWL_ARCHIVE_NAME_TABLE[path]) + 1); + std::wstring archiveString(archiveName); + common::CopyDirectory( + (common::SDMC_ROOT_DIRECTORY_PATH + ::std::wstring(common::SD_TWL_ROOTNAME_TABLE[path])).c_str(), + (archiveString + ::std::wstring(L"/")).c_str(), + buf, bufSize); + + common::HeapManager::GetHeap()->Free(buf); + } + + common::SdMountManager::Unmount(); + nn::fs::Unmount(common::TWL_ARCHIVE_NAME_TABLE[path]); + +} + +void ImportTwlPhotoData() +{ + COMMON_LOGGER("Import Twl Photo Data.\n"); + ImportTwlData(common::TWL_PHOTO); +} + +void ImportTwlSoundData() +{ + COMMON_LOGGER("Import Twl Sound Data.\n"); + ImportTwlData(common::TWL_SOUND); +} + + void ImportData() { static bool init = true; @@ -1080,6 +1209,12 @@ void ImportData() // NORデータを書き込む ImportNorData(); + // TWL写真領域のデータをNANDに書き込む + ImportTwlPhotoData(); + + // TWLサウンド領域のデータをNANDに書き込む + ImportTwlSoundData(); + // SDカードのセーブデータをNANDに書き込む ImportSaveData(); diff --git a/trunk/ConsoleDataMigration/ConsoleRestore/Importer.h b/trunk/ConsoleDataMigration/ConsoleRestore/Importer.h index 3b2bec1..28042e9 100644 --- a/trunk/ConsoleDataMigration/ConsoleRestore/Importer.h +++ b/trunk/ConsoleDataMigration/ConsoleRestore/Importer.h @@ -88,6 +88,9 @@ struct CheckedNetworkSetting CheckedNetworkSetting* GetTempNetworkSetting(); void ImportCountryLanguageData(); +// TWL写真領域を初期化してから本体初期化を行う +void InitializeFileSystem(); + } #endif /* IMPORTER_H_ */ diff --git a/trunk/ConsoleDataMigration/common/FileName.h b/trunk/ConsoleDataMigration/common/FileName.h index fc67ddd..939bb33 100644 --- a/trunk/ConsoleDataMigration/common/FileName.h +++ b/trunk/ConsoleDataMigration/common/FileName.h @@ -16,13 +16,19 @@ #ifndef FILENAME_H_ #define FILENAME_H_ +#include + namespace common { const char* const NAND_ARCHIVE_NAME = "nand:"; const char* const SD_ARCHIVE_NAME = "sdmc:"; +const char* const NAND_TWL_PHOTO_ARCHIVE_NAME = "twlp:"; +const char* const NAND_TWL_SOUND_ARCHIVE_NAME = "twls:"; const wchar_t* const SD_SAVEDATA_ROOT_NAME = L"CTR_ConsoleBackup/"; +const wchar_t* const SD_SAVEDATA_TWL_PHOTO_ROOT_NAME = L"CTR_ConsoleBackup_TwlPhoto/"; +const wchar_t* const SD_SAVEDATA_TWL_SOUND_ROOT_NAME = L"CTR_ConsoleBackup_TwlSound/"; const wchar_t* const COUNTRY_SETTING_PATHNAME = L"sdmc:/CountrySetting.bin"; const wchar_t* const AP_SETTING_FILENAME = L"APSetting.txt"; const wchar_t* const AP_SETTING_PATHNAME = L"sdmc:/APSetting.txt"; @@ -31,11 +37,44 @@ const wchar_t* const SERIAL_PATHNAME = L"sdmc:/serial.bin"; const wchar_t* const IVS_NAND_PATHNAME = L"nand:/private/movable.sed"; const wchar_t* const IVS_PATHNAME = L"sdmc:/movable.sed"; const wchar_t* const NAND_DATA_ROOT_PATHNAME_WITH_SLASH = L"nand:/data/"; +const wchar_t* const NAND_TWL_PHOTO_DATA_ROOT_PATHNAME_WITH_SLASH = L"twlp:/"; +const wchar_t* const NAND_TWL_SOUND_DATA_ROOT_PATHNAME_WITH_SLASH = L"twls:/"; const wchar_t* const SDMC_ROOT_DIRECTORY_PATH = L"sdmc:/"; const wchar_t* const WRITE_FINISHED_PATHNAME = L"sdmc:/WriteFinished"; const wchar_t* const UPDATE_CHECK_PATHNAME = L"sdmc:/UpdateFinished"; const wchar_t* const INITIALIZED_CHECK_PATHNAME = L"sdmc:/ConsoleInitialized"; +enum TWL_PATHNAME +{ + TWL_PHOTO = 0, + TWL_SOUND, + TWL_PATHNAME_MAX +}; + +const char* const TWL_ARCHIVE_NAME_TABLE[TWL_PATHNAME_MAX] = +{ + common::NAND_TWL_PHOTO_ARCHIVE_NAME, + common::NAND_TWL_SOUND_ARCHIVE_NAME +}; + +const wchar_t* const SD_TWL_ROOTNAME_TABLE[TWL_PATHNAME_MAX] = +{ + common::SD_SAVEDATA_TWL_PHOTO_ROOT_NAME, + common::SD_SAVEDATA_TWL_SOUND_ROOT_NAME +}; + +const wchar_t* const NAND_TWL_ROOT_PATHNAME_WITH_SLASH_TABLE[TWL_PATHNAME_MAX] = +{ + common::NAND_TWL_PHOTO_DATA_ROOT_PATHNAME_WITH_SLASH, + common::NAND_TWL_SOUND_DATA_ROOT_PATHNAME_WITH_SLASH +}; + +const u32 TWL_FS_ARCHIVE_KIND[TWL_PATHNAME_MAX] = +{ + nn::fs::CTR::ARCHIVE_TYPE_TWL_PHOTO, + nn::fs::CTR::ARCHIVE_TYPE_TWL_SOUND +}; + } #endif /* FILENAME_H_ */