From e0ad38b640d13846ef3550245bc318b3968c6f0e Mon Sep 17 00:00:00 2001 From: N2614 Date: Thu, 7 Jul 2011 07:46:20 +0000 Subject: [PATCH] =?UTF-8?q?nn::fs::Directory=E3=81=AE=E3=83=8F=E3=83=B3?= =?UTF-8?q?=E3=83=89=E3=83=AA=E3=83=B3=E3=82=B0=E8=BF=BD=E5=8A=A0=20?= =?UTF-8?q?=E6=9C=AC=E4=BD=93=E5=88=9D=E6=9C=9F=E5=8C=96=E6=99=82=E3=82=82?= =?UTF-8?q?Result=E3=83=81=E3=82=A7=E3=83=83=E3=82=AF=E3=82=92=E8=A1=8C?= =?UTF-8?q?=E3=81=86=E3=82=88=E3=81=86=E3=81=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit git-svn-id: file:///Volumes/Transfer/gigaleak_20231201/2020-05-23%20-%20ctr.7z%20+%20svn_v1.068.zip/ctr/svn/ctr_Repair@369 385bec56-5757-e545-9c3a-d8741f4650f1 --- .../sources/ConsoleBackup/Exporter.cpp | 152 +++++++++--------- .../sources/ConsoleRestore/Controller.cpp | 16 +- .../sources/ConsoleRestore/Importer.cpp | 106 ++++++------ .../sources/ConsoleRestore/Importer.h | 2 +- .../sources/common/FileTransfer.cpp | 5 +- 5 files changed, 143 insertions(+), 138 deletions(-) diff --git a/trunk/ConsoleDataMigration/sources/ConsoleBackup/Exporter.cpp b/trunk/ConsoleDataMigration/sources/ConsoleBackup/Exporter.cpp index 861aed3..119bd79 100644 --- a/trunk/ConsoleDataMigration/sources/ConsoleBackup/Exporter.cpp +++ b/trunk/ConsoleDataMigration/sources/ConsoleBackup/Exporter.cpp @@ -93,10 +93,8 @@ nn::Result DeleteTrash(std::wstring currentDirectory) for (;;) { result = dir.TryRead(&numEntry, &entry, 1); - if (result.IsFailure()) - { - dir.Finalize(); - } + COMMON_LOGGER_RETURN_RESULT_IF_FAILED(result); + if (numEntry == 0) { // ルートディレクトリを閉じる @@ -296,37 +294,34 @@ void CreateTwlDirectory(enum common::TWL_PATH_INDEX path) std::wstring(common::SD_TWL_ROOTNAME_TABLE[path])).c_str()); } -void ListTwlSaveData(std::wstring currentDirectory, std::vector* list) +bool ListTwlSaveData(std::wstring currentDirectory, std::vector* list) { nn::fs::Directory dir; nn::fs::DirectoryEntry entry; s32 numEntry; nn::Result result = dir.TryInitialize(currentDirectory.c_str()); - if(result.IsSuccess()) - { - for(;;) - { - result = dir.TryRead(&numEntry, &entry, 1); - if(result.IsFailure()) - { - dir.Finalize(); - break; - } + COMMON_LOGGER_RETURN_FALSE_IF_FAILED(result); - if(numEntry == 0) - { - dir.Finalize(); - } - else - { - common::SavePathInfo pathInfo; - pathInfo.name = currentDirectory + std::wstring(L"/") + std::wstring(entry.entryName); - pathInfo.isDirectory = false; - list->push_back(pathInfo); - } + for (;;) + { + result = dir.TryRead(&numEntry, &entry, 1); + COMMON_LOGGER_RETURN_FALSE_IF_FAILED(result); + + if (numEntry == 0) + { + break; + } + else + { + common::SavePathInfo pathInfo; + pathInfo.name = currentDirectory + std::wstring(L"/") + std::wstring(entry.entryName); + pathInfo.isDirectory = false; + list->push_back(pathInfo); } } + + return true; } void AddCurrentProgramIdPath(std::vector* programIdList, std::wstring currentDir) @@ -382,81 +377,80 @@ bool ListTwlSaveDataDirectory(std::wstring currentDirectory, u32 level, std::vec const wchar_t* const TWL_SAVEDATA_DIRECTORY_NAME = L"data"; result = dir.TryInitialize(currentDirectory.c_str()); - if (result.IsSuccess()) + COMMON_LOGGER_RETURN_FALSE_IF_FAILED(result); + + nn::fs::DirectoryEntry entry; + s32 numEntry; + for (;;) { - nn::fs::DirectoryEntry entry; - s32 numEntry; - for (;;) + result = dir.TryRead(&numEntry, &entry, 1); + COMMON_LOGGER_RETURN_FALSE_IF_FAILED(result); + + if (numEntry == 0) { - result = dir.TryRead(&numEntry, &entry, 1); - if (result.IsFailure()) - { - dir.Finalize(); - } - if (numEntry == 0) - { - dir.Finalize(); + dir.Finalize(); - bool retValue = false; - for (entryIndex = entryList.begin(); entryIndex != entryList.end(); entryIndex++) + bool retValue = false; + for (entryIndex = entryList.begin(); entryIndex != entryList.end(); entryIndex++) + { + // レベル2未満のディレクトリなら再帰的に開く + if (level < TWL_SAVEDATA_DIRECTORY_LEVEL) { - // レベル2未満のディレクトリなら再帰的に開く - if(level < TWL_SAVEDATA_DIRECTORY_LEVEL) + if (entryIndex->attributes.isDirectory) { - if (entryIndex->attributes.isDirectory) + if (ListTwlSaveDataDirectory( + currentDirectory + std::wstring(L"/") + std::wstring(entryIndex->entryName), level + 1, + list, programIdList)) { - if (ListTwlSaveDataDirectory( - currentDirectory + std::wstring(L"/") + std::wstring(entryIndex->entryName), - level + 1, list, programIdList)) - { - NN_LOG("%ls/%ls has data directory.\n", currentDirectory.c_str(), entryIndex->entryName); - retValue = true; - - AddCurrentDirectory(list, currentDirectory, entryIndex->entryName); - } - } - } - // レベル2のディレクトリなら data かどうかチェック - else if(level == TWL_SAVEDATA_DIRECTORY_LEVEL && entryIndex->attributes.isDirectory) - { - if (std::wcscmp(entryIndex->entryName, TWL_SAVEDATA_DIRECTORY_NAME) == 0) - { - // ファイル一覧を取得する + NN_LOG("%ls/%ls has data directory.\n", currentDirectory.c_str(), entryIndex->entryName); retValue = true; - ListTwlSaveData(currentDirectory + std::wstring(L"/") + std::wstring(entryIndex->entryName), list); AddCurrentDirectory(list, currentDirectory, entryIndex->entryName); - AddCurrentProgramIdPath(programIdList, currentDirectory); + } + else + { + return false; } } - else + } + // レベル2のディレクトリなら data かどうかチェック + else if (level == TWL_SAVEDATA_DIRECTORY_LEVEL && entryIndex->attributes.isDirectory) + { + if (std::wcscmp(entryIndex->entryName, TWL_SAVEDATA_DIRECTORY_NAME) == 0) { - return false; + // ファイル一覧を取得する + retValue = true; + if (!ListTwlSaveData( + currentDirectory + std::wstring(L"/") + std::wstring(entryIndex->entryName), list)) + { + return false; + } + + AddCurrentDirectory(list, currentDirectory, entryIndex->entryName); + AddCurrentProgramIdPath(programIdList, currentDirectory); } } - - if(level != 0) + else { - return retValue; + return false; } + } - break; - } - else + if (level != 0) { - // vectorに保存する - entryList.push_back(entry); + return retValue; } + + break; + } + else + { + // vectorに保存する + entryList.push_back(entry); } } - else - { - NN_LOG("failed initialize directory\n"); - COMMON_LOGGER_RESULT_IF_FAILED_WITH_LINE(result); - dir.Finalize(); - } - return false; + return true; } diff --git a/trunk/ConsoleDataMigration/sources/ConsoleRestore/Controller.cpp b/trunk/ConsoleDataMigration/sources/ConsoleRestore/Controller.cpp index 102b17b..62b0d87 100644 --- a/trunk/ConsoleDataMigration/sources/ConsoleRestore/Controller.cpp +++ b/trunk/ConsoleDataMigration/sources/ConsoleRestore/Controller.cpp @@ -793,8 +793,15 @@ void ControlState(common::HardwareStateManager& manager, ::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()); + COMMON_LOGGER_RETURN_FALSE_IF_FAILED(result); + + nn::fs::DirectoryEntry entry; + s32 numEntry; + for (;;) { - nn::fs::Directory dir; - std::vector entryList; //カレントディレクトリのエントリ一覧を格納 - std::vector::iterator entryIndex; + result = dir.TryRead(&numEntry, &entry, 1); + COMMON_LOGGER_RETURN_FALSE_IF_FAILED(result); - 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 (;;) + if (numEntry == 0) { - result = dir.TryRead(&numEntry, &entry, 1); - if (result.IsFailure()) - { - dir.Finalize(); - } - if (numEntry == 0) - { - // ルートディレクトリを閉じる - dir.Finalize(); + // ルートディレクトリを閉じる + dir.Finalize(); - // ルートディレクトリの子を開く - for (entryIndex = entryList.begin(); entryIndex != entryList.end(); entryIndex++) + // ルートディレクトリの子を開く + for (entryIndex = entryList.begin(); entryIndex != entryList.end(); entryIndex++) + { + // ディレクトリなら削除する + if (entryIndex->attributes.isDirectory) { - // ディレクトリなら削除する - 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()); - COMMON_LOGGER_RESULT_IF_FAILED_WITH_LINE(result); + NN_LOG("Try Delete %ls%ls/\n", currentDirectory.c_str(), entryIndex->entryName); + result = nn::fs::TryDeleteDirectoryRecursively( + (currentDirectory + ::std::wstring(entryIndex->entryName)).c_str()); + COMMON_LOGGER_RETURN_FALSE_IF_FAILED(result); - } - // ファイルなら削除する - else - { - NN_LOG("Try Delete %ls%ls\n", currentDirectory.c_str(), entryIndex->entryName); - result = nn::fs::TryDeleteFile( - (currentDirectory + ::std::wstring(entryIndex->entryName)).c_str()); - COMMON_LOGGER_RESULT_IF_FAILED_WITH_LINE(result); - } } + // ファイルなら削除する + else + { + NN_LOG("Try Delete %ls%ls\n", currentDirectory.c_str(), entryIndex->entryName); + result = nn::fs::TryDeleteFile( + (currentDirectory + ::std::wstring(entryIndex->entryName)).c_str()); + COMMON_LOGGER_RETURN_FALSE_IF_FAILED(result); + } + } - // 削除完了 - break; + // 削除完了 + break; + } + else + { + // vectorに保存する + entryList.push_back(entry); + if (entry.attributes.isDirectory) + { + NN_LOG("%ls%ls/\n", currentDirectory.c_str(), entry.entryName); } 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_LOG("%ls%ls\n", currentDirectory.c_str(), entry.entryName); } } } - nn::fs::Unmount(common::TWL_ARCHIVE_NAME_TABLE[i]); + + result = nn::fs::Unmount(common::TWL_ARCHIVE_NAME_TABLE[i]); + COMMON_LOGGER_RETURN_FALSE_IF_FAILED(result); } result = nn::am::DeleteAllTwlUserPrograms(); - COMMON_LOGGER_RESULT_IF_FAILED_WITH_LINE(result); + COMMON_LOGGER_RETURN_FALSE_IF_FAILED(result); nn::fs::InitializeCtrFileSystem(); + return true; } nn::Result ImportIvs() diff --git a/trunk/ConsoleDataMigration/sources/ConsoleRestore/Importer.h b/trunk/ConsoleDataMigration/sources/ConsoleRestore/Importer.h index 8e1ab26..e2c49b1 100644 --- a/trunk/ConsoleDataMigration/sources/ConsoleRestore/Importer.h +++ b/trunk/ConsoleDataMigration/sources/ConsoleRestore/Importer.h @@ -137,7 +137,7 @@ nn::Result ImportCountryLanguageData(); nn::Result ImportMcuRtc(common::HardwareStateManager& manager); // TWL写真領域を初期化してから本体初期化を行う -void InitializeFileSystem(); +bool InitializeFileSystem(); // SDカードのファイルと本体情報の比較結果をクリアする void ClearFileReadResult(); diff --git a/trunk/ConsoleDataMigration/sources/common/FileTransfer.cpp b/trunk/ConsoleDataMigration/sources/common/FileTransfer.cpp index bfe7d55..16bea31 100644 --- a/trunk/ConsoleDataMigration/sources/common/FileTransfer.cpp +++ b/trunk/ConsoleDataMigration/sources/common/FileTransfer.cpp @@ -58,7 +58,6 @@ const char* GetCharStr(const wchar_t* path) nn::Result CalculateFileNum(std::wstring currentDirectory, u32& fileNum, s64& fileSize) { - nn::fs::FileInputStream fis; nn::fs::Directory dir; nn::Result result; std::vector entryList; //カレントディレクトリのエントリ一覧を格納 @@ -267,7 +266,9 @@ bool CopyDirectory(ImportDataList* fileList, const wchar_t * from_path, const wc while (1) { result = from_dir.TryRead(&numread, &entry, 1); - if (result.IsFailure() || numread != 1) + COMMON_LOGGER_RETURN_FALSE_IF_FAILED(result); + + if(numread == 0) { break; }