diff --git a/trunk/ConsoleDataMigration/ConsoleBackup/Controller.cpp b/trunk/ConsoleDataMigration/ConsoleBackup/Controller.cpp index 16ab9a1..54ee8c4 100644 --- a/trunk/ConsoleDataMigration/ConsoleBackup/Controller.cpp +++ b/trunk/ConsoleDataMigration/ConsoleBackup/Controller.cpp @@ -31,7 +31,9 @@ namespace typedef enum BackupState { STARTUP, // 初期値 - IN_PROGRESS, // 吸出し中 + EXPORT_TWL_SOUND, // TWLサウンド領域の吸出し中 + EXPORT_TWL_PHOTO, // TWL写真領域の吸出し中 + EXPORT_CTR_NAND, // 吸出し中 DONE, // 吸出し完了 FINISHED, // SDカード抜き完了 FAIL // 失敗 @@ -132,14 +134,54 @@ void ControlState(::std::vector& operationMessage, bool& nextStep, if (nextStep && !error) { COMMON_LOGGER("Start Export Data\n"); - s_BackupState = IN_PROGRESS; + s_BackupState = EXPORT_TWL_SOUND; common::PlaySound(common::SOUND_CURSOR); } } break; + // TWLサウンド領域の吸出し中 + case EXPORT_TWL_SOUND: + { + static bool init = true; + if(init) + { + // データを書き込む + ExportTwlSoundData(); + init = false; + } + + // 処理が完了した + if (IsExportFinished()) + { + FinalizeExportThread(); + s_BackupState = EXPORT_TWL_PHOTO; + } + } + break; + + // TWL写真領域の吸出し中 + case EXPORT_TWL_PHOTO: + { + static bool init = true; + if(init) + { + // データを書き込む + ExportTwlPhotoData(); + init = false; + } + + // 処理が完了した + if (IsExportFinished()) + { + FinalizeExportThread(); + s_BackupState = EXPORT_CTR_NAND; + } + } + break; + // 吸出し中 - case IN_PROGRESS: + case EXPORT_CTR_NAND: { continueBackup = true; @@ -208,7 +250,7 @@ void ControlState(::std::vector& operationMessage, bool& nextStep, bool InProgress() { - return s_BackupState == IN_PROGRESS; + return s_BackupState == EXPORT_CTR_NAND; } bool IsBackupSucceeded() diff --git a/trunk/ConsoleDataMigration/ConsoleBackup/Exporter.cpp b/trunk/ConsoleDataMigration/ConsoleBackup/Exporter.cpp index 940d4f1..43f389e 100644 --- a/trunk/ConsoleDataMigration/ConsoleBackup/Exporter.cpp +++ b/trunk/ConsoleDataMigration/ConsoleBackup/Exporter.cpp @@ -278,7 +278,7 @@ void GetSaveDataDirectoryRoot() NN_LOG("%s\n", s_SysSaveRoot.c_str()); } -void CreateTwlDirectory(enum common::TWL_PATHNAME path) +void CreateTwlDirectory(enum common::TWL_PATH_INDEX path) { NN_ASSERT(path < common::TWL_PATHNAME_MAX); @@ -286,7 +286,7 @@ void CreateTwlDirectory(enum common::TWL_PATHNAME path) std::wstring(common::SD_TWL_ROOTNAME_TABLE[path])).c_str()); } -void WriteTwlData(enum common::TWL_PATHNAME path) +void WriteTwlData(enum common::TWL_PATH_INDEX path) { NN_ASSERT(path < common::TWL_PATHNAME_MAX); @@ -300,6 +300,18 @@ void WriteTwlData(enum common::TWL_PATHNAME path) size_t bufSize = common::HeapManager::GetHeap()->GetAllocatableSize(); NN_LOG("AllocatableSize = %d\n", bufSize); + u32 fileNum = 0; + u32 fileSize = 0; + common::CalculateFileNum(::std::wstring(common::NAND_TWL_ROOT_PATHNAME_WITH_SLASH_TABLE[path]), fileNum, fileSize); + + nn::fs::Unmount(common::NAND_ARCHIVE_NAME); + + NN_LOG("File Number = %d\n", fileNum); + NN_LOG("File Size = %d\n", fileSize); + // 進捗表示用 + common::SetTotalSize(fileSize); + common::ClearFinishedSize(); + void* buf = common::HeapManager::GetHeap()->Allocate(bufSize); if (buf != NULL) { @@ -321,21 +333,35 @@ void WriteTwlData(enum common::TWL_PATHNAME path) void WriteTwlPhotoData() { - COMMON_LOGGER("Create Twl Photo Backup.\n"); + COMMON_LOGGER("Export Twl Photo Data.\n"); CreateTwlDirectory(common::TWL_PHOTO); WriteTwlData(common::TWL_PHOTO); } void WriteTwlSoundData() { - COMMON_LOGGER("Create Twl Sound Backup.\n"); + COMMON_LOGGER("Export Twl Sound Data.\n"); CreateTwlDirectory(common::TWL_SOUND); WriteTwlData(common::TWL_SOUND); } +void ExportTwlPhotoData() +{ + s_ExportThread.Start(WriteTwlPhotoData, s_ExportThreadStack); +} + +void ExportTwlSoundData() +{ + // 不要なデータを削除する + DeleteTrash(); + + s_ExportThread.Start(WriteTwlSoundData, s_ExportThreadStack); +} + + void WriteMcuRtcData() { - COMMON_LOGGER("Create RTC Backup.\n"); + COMMON_LOGGER("Export RTC Data.\n"); nn::Result result; nn::Handle handle = GetMcuHandle(); @@ -404,6 +430,7 @@ nn::Result WriteSaveData() NN_LOG("File Size = %d\n", fileSize); // 進捗表示用 common::SetTotalSize(fileSize); + common::ClearFinishedSize(); ::std::mbstowcs(s_RootName, s_SysSaveRoot.c_str(), s_SysSaveRoot.size() + 1); @@ -445,9 +472,6 @@ void ExportData() if (init) { - // 不要なデータを削除する - DeleteTrash(); - // 国データと言語データをSDに書き込む WriteCountryLanguageData(); @@ -463,12 +487,6 @@ void ExportData() // IVSからセーブデータディレクトリ名を計算 GetSaveDataDirectoryRoot(); - // TWL写真領域のデータをSDに書き出す - WriteTwlPhotoData(); - - // TWLサウンド領域のデータをSDに書き出す - WriteTwlSoundData(); - // プレイ履歴をSDに書き出す //WritePlayHistory(); diff --git a/trunk/ConsoleDataMigration/ConsoleBackup/Exporter.h b/trunk/ConsoleDataMigration/ConsoleBackup/Exporter.h index b102d0b..1523c6c 100644 --- a/trunk/ConsoleDataMigration/ConsoleBackup/Exporter.h +++ b/trunk/ConsoleDataMigration/ConsoleBackup/Exporter.h @@ -21,7 +21,8 @@ namespace ConsoleBackup { - +void ExportTwlPhotoData(); +void ExportTwlSoundData(); void ExportData(); u32 GetProgress(); diff --git a/trunk/ConsoleDataMigration/ConsoleRestore/Controller.cpp b/trunk/ConsoleDataMigration/ConsoleRestore/Controller.cpp index ffabb0d..d4c9625 100644 --- a/trunk/ConsoleDataMigration/ConsoleRestore/Controller.cpp +++ b/trunk/ConsoleDataMigration/ConsoleRestore/Controller.cpp @@ -40,6 +40,8 @@ typedef enum RestoreState SERIAL_IS_NOT_IN_SD, // シリアルナンバーファイルがSDカードにないことを表示 SERIAL_IN_SD, // シリアルナンバーの情報を表示 UPDATE_IN_PROGRESS, // アップデート中 + RESTORE_TWL_SOUND, // TWLサウンドの書き込み中 + RESTORE_TWL_PHOTO, // TWL写真の書き込み中 RESTORE_IN_PROGRESS, // 書き込み中 POST_RESTORE, // 書き込み後の処理 RESTORE_DONE, // 書き込み完了 @@ -320,7 +322,7 @@ void ControlState(::std::vector& operationMessage, bool& nextStep, else { COMMON_LOGGER("Start Import Data\n"); - s_RestoreState = RESTORE_IN_PROGRESS; + s_RestoreState = RESTORE_TWL_SOUND; PlaySound(SOUND_CURSOR); } } @@ -342,7 +344,7 @@ void ControlState(::std::vector& operationMessage, bool& nextStep, if (nextStep) { - s_RestoreState = RESTORE_IN_PROGRESS; + s_RestoreState = RESTORE_TWL_SOUND; } } break; @@ -416,6 +418,47 @@ void ControlState(::std::vector& operationMessage, bool& nextStep, } break; + // TWLサウンド領域の書き込み中 + case RESTORE_TWL_SOUND: + { + static bool init = true; + if (init) + { + // データを書き込む + ImportTwlSoundData(); + init = false; + } + + // 処理が完了した + if (IsImportFinished()) + { + FinalizeImportThread(); + s_RestoreState = RESTORE_TWL_PHOTO; + } + } + break; + + // TWL写真領域の書き込み + case RESTORE_TWL_PHOTO: + { + static bool init = true; + if (init) + { + // データを書き込む + ImportTwlPhotoData(); + init = false; + } + + // 処理が完了した + if (IsImportFinished()) + { + FinalizeImportThread(); + s_RestoreState = RESTORE_IN_PROGRESS; + } + } + break; + + // 書き込み中 case RESTORE_IN_PROGRESS: { diff --git a/trunk/ConsoleDataMigration/ConsoleRestore/Importer.cpp b/trunk/ConsoleDataMigration/ConsoleRestore/Importer.cpp index b56dcbf..fe19cb8 100644 --- a/trunk/ConsoleDataMigration/ConsoleRestore/Importer.cpp +++ b/trunk/ConsoleDataMigration/ConsoleRestore/Importer.cpp @@ -591,6 +591,7 @@ void ImportSaveData() // ファイルサイズ設定 common::SetTotalSize(fileSize); + common::ClearFinishedSize(); NN_LOG("File Number = %d\n", fileNum); NN_LOG("File Size = %d\n", fileSize); @@ -679,6 +680,12 @@ void DeleteConsoleInitializedFile() common::SdMountManager::Unmount(); } +void FinalizeImportThread() +{ + s_ImportThread.Join(); + s_ImportThread.Finalize(); +} + bool IsImportFinished() { return !s_ImportThread.IsAlive(); @@ -1098,7 +1105,7 @@ CheckedNetworkSetting* GetTempNetworkSetting() return &s_CurrentNetowrkSetting1; } -void ImportTwlData(enum common::TWL_PATHNAME path) +void ImportTwlData(enum common::TWL_PATH_INDEX path) { NN_ASSERT(path < common::TWL_PATHNAME_MAX); @@ -1112,6 +1119,20 @@ void ImportTwlData(enum common::TWL_PATHNAME path) size_t bufSize = common::HeapManager::GetHeap()->GetAllocatableSize(); NN_LOG("AllocatableSize = %d\n", bufSize); + + u32 fileNum = 0; + u32 fileSize = 0; + + common::CalculateFileNum(::std::wstring(common::SDMC_ROOT_DIRECTORY_PATH) + ::std::wstring( + common::SD_TWL_ROOTNAME_TABLE[path]), fileNum, fileSize); + // ファイルサイズ設定 + common::SetTotalSize(fileSize); + common::ClearFinishedSize(); + + NN_LOG("File Number = %d\n", fileNum); + NN_LOG("File Size = %d\n", fileSize); + + void* buf = common::HeapManager::GetHeap()->Allocate(bufSize); if (buf != NULL) { @@ -1119,7 +1140,7 @@ void ImportTwlData(enum common::TWL_PATHNAME path) ::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(), + (::std::wstring(common::SDMC_ROOT_DIRECTORY_PATH) + ::std::wstring(common::SD_TWL_ROOTNAME_TABLE[path])).c_str(), (archiveString + ::std::wstring(L"/")).c_str(), buf, bufSize); @@ -1131,18 +1152,29 @@ void ImportTwlData(enum common::TWL_PATHNAME path) } -void ImportTwlPhotoData() +void ImportTwlPhotoDataFunc() { COMMON_LOGGER("Import Twl Photo Data.\n"); ImportTwlData(common::TWL_PHOTO); } -void ImportTwlSoundData() +void ImportTwlSoundDataFunc() { COMMON_LOGGER("Import Twl Sound Data.\n"); ImportTwlData(common::TWL_SOUND); } +void ImportTwlPhotoData() +{ + s_ImportThread.Start(ImportTwlPhotoDataFunc, s_ImportThreadStack); +} + +void ImportTwlSoundData() +{ + s_ImportThread.Start(ImportTwlSoundDataFunc, s_ImportThreadStack); +} + + void ClearFileReadResult() { s_CheckedEqualsIVSFileandIVS = false; @@ -1252,12 +1284,6 @@ void ImportData() // NORデータを書き込む ImportNorData(); - // TWL写真領域のデータをNANDに書き込む - ImportTwlPhotoData(); - - // TWLサウンド領域のデータをNANDに書き込む - ImportTwlSoundData(); - // タッチパネルキャリブレーションデータをSDカードに出力する // 本体初期化後はcal値が設定されている ExportTouchPanelCfgData(); diff --git a/trunk/ConsoleDataMigration/ConsoleRestore/Importer.h b/trunk/ConsoleDataMigration/ConsoleRestore/Importer.h index 1f1c279..fa3b7f9 100644 --- a/trunk/ConsoleDataMigration/ConsoleRestore/Importer.h +++ b/trunk/ConsoleDataMigration/ConsoleRestore/Importer.h @@ -26,7 +26,10 @@ namespace ConsoleRestore bool EqualsIVSFileandIVS(); u8* ReadSerialNumber(); +void FinalizeImportThread(); bool IsImportFinished(); +void ImportTwlSoundData(); +void ImportTwlPhotoData(); void ImportData(); void CreateWriteFinishedFile(); void CreateUpdateFinishedFile(); diff --git a/trunk/ConsoleDataMigration/common/FileName.h b/trunk/ConsoleDataMigration/common/FileName.h index 44bfbff..2bd3496 100644 --- a/trunk/ConsoleDataMigration/common/FileName.h +++ b/trunk/ConsoleDataMigration/common/FileName.h @@ -52,7 +52,7 @@ const wchar_t* const PLAYHISTORY_PATHNAME = L"sdmc:/CTR_Console_Repair/playhisto const wchar_t* const PLAYHISTORY_COUNT_PATHNAME = L"sdmc:/CTR_Console_Repair/playhistoryCount.bin"; const wchar_t* const TOUCH_PANEL_CALIBRATION_PATHNAME = L"sdmc:/CTR_Console_Repair/tpCalibration.bin"; -enum TWL_PATHNAME +enum TWL_PATH_INDEX { TWL_PHOTO = 0, TWL_SOUND, diff --git a/trunk/ConsoleDataMigration/common/FileTransfer.cpp b/trunk/ConsoleDataMigration/common/FileTransfer.cpp index 0a16e0a..cd3a218 100644 --- a/trunk/ConsoleDataMigration/common/FileTransfer.cpp +++ b/trunk/ConsoleDataMigration/common/FileTransfer.cpp @@ -245,4 +245,9 @@ void SetTotalSize(u64 size) s_TotalFileSize = size; } +void ClearFinishedSize() +{ + s_FinishedFileSize = 0; +} + } diff --git a/trunk/ConsoleDataMigration/common/FileTransfer.h b/trunk/ConsoleDataMigration/common/FileTransfer.h index 9d6b878..32c80a8 100644 --- a/trunk/ConsoleDataMigration/common/FileTransfer.h +++ b/trunk/ConsoleDataMigration/common/FileTransfer.h @@ -27,6 +27,7 @@ nn::Result CalculateFileNum(std::wstring currentDirectory, u32& fileNum, u32& fi bool CopyDirectory(const wchar_t * from_path, const wchar_t * to_path, void* buf, const size_t bufSize); u32 GetProgress(); void SetTotalSize(u64 size); +void ClearFinishedSize(); }