From 6159f0be9ef9292d7c780c439ec54765dc5ad80a Mon Sep 17 00:00:00 2001 From: N2614 Date: Thu, 10 Nov 2011 10:17:54 +0000 Subject: [PATCH] =?UTF-8?q?trunk=20r475,481=E3=81=AE=E3=83=9E=E3=83=BC?= =?UTF-8?q?=E3=82=B8?= 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@494 385bec56-5757-e545-9c3a-d8741f4650f1 --- .../sources/ConsoleBackup/SavedataChecker.cpp | 60 +------------------ .../sources/ConsoleRestore/Importer.cpp | 2 +- .../sources/common/FileTransfer.cpp | 59 ++++++++++++++++++ .../sources/common/FileTransfer.h | 3 + 4 files changed, 66 insertions(+), 58 deletions(-) diff --git a/branches/1stNUP_1_5_CUP/sources/ConsoleBackup/SavedataChecker.cpp b/branches/1stNUP_1_5_CUP/sources/ConsoleBackup/SavedataChecker.cpp index 21d0325..5e52bcb 100644 --- a/branches/1stNUP_1_5_CUP/sources/ConsoleBackup/SavedataChecker.cpp +++ b/branches/1stNUP_1_5_CUP/sources/ConsoleBackup/SavedataChecker.cpp @@ -115,7 +115,7 @@ nn::Result SavedataCheckerBase::CleanUpFilesRecursively(bool* modified, std::str result = file.TryInitialize(path); if(result.IsFailure()) { - nn::dbg::PrintResult(result); + COMMON_LOGGER_RESULT_IF_FAILED(result); const bool silent = IsForceDeleteFile(common::GetCharStr(entry.entryName)); if(!silent) { @@ -140,7 +140,7 @@ nn::Result SavedataCheckerBase::CleanUpFilesRecursively(bool* modified, std::str result = file.TryRead(&readSize, m_Buf, m_Bufsize); if(result.IsFailure()) { - nn::dbg::PrintResult(result); + COMMON_LOGGER_RESULT_IF_FAILED(result); const bool silent = IsForceDeleteFile(common::GetCharStr(entry.entryName)); if(!silent) { @@ -180,61 +180,7 @@ nn::Result SavedataCheckerBase::CleanUpFilesRecursively(bool* modified, std::str nn::Result SavedataCheckerBase::GetFileSize(std::wstring currentDirectory) { - nn::fs::Directory dir; - nn::fs::DirectoryEntry entry; - nn::Result result; - - NN_LOG("%s\n", common::GetCharStr(currentDirectory.c_str())); - result = dir.TryInitialize(currentDirectory.c_str()); - if(result.IsFailure()) - { - return result; - } - - for (;;) - { - s32 numRead; - result = dir.TryRead(&numRead, &entry, 1); - if(result.IsFailure()) - { - continue; - } - - - if(numRead == 0) - { - break; - } - - if (std::wcscmp(entry.entryName, L".") == 0 || std::wcscmp(entry.entryName, L"..") == 0) - { - continue; - } - - - // ディレクトリの場合 - if (entry.attributes.isDirectory) - { - return GetFileSize(currentDirectory + std::wstring(entry.entryName) + std::wstring(L"/")); - } - // ファイルの場合 - else - { - nn::fs::FileInputStream file; - std::wstring filePath = (currentDirectory + std::wstring(entry.entryName)).c_str(); - const wchar_t* path = filePath.c_str(); - - result = file.TryInitialize(path); - if(result.IsFailure()) - { - continue; - } - - m_CalculatedFileSize += file.GetSize(); - } - } - - return nn::ResultSuccess(); + return common::CalculateFileSizeRecursively(currentDirectory, m_CalculatedFileSize); } s64 SavedataCheckerBase::GetCalculatedSize() diff --git a/branches/1stNUP_1_5_CUP/sources/ConsoleRestore/Importer.cpp b/branches/1stNUP_1_5_CUP/sources/ConsoleRestore/Importer.cpp index f41baa3..1a5d951 100644 --- a/branches/1stNUP_1_5_CUP/sources/ConsoleRestore/Importer.cpp +++ b/branches/1stNUP_1_5_CUP/sources/ConsoleRestore/Importer.cpp @@ -894,7 +894,7 @@ bool ExistsIvsDirectory(std::string& ivsRoot) result = dir.TryInitialize(common::SD_NINTENDO_3DS_ROOT_PATH); if(result.IsFailure()) { - NN_DBG_PRINT_RESULT(result); + COMMON_LOGGER_RESULT_IF_FAILED(result); common::SdMountManager::Unmount(); return false; } diff --git a/branches/1stNUP_1_5_CUP/sources/common/FileTransfer.cpp b/branches/1stNUP_1_5_CUP/sources/common/FileTransfer.cpp index cc76f83..227b7d8 100644 --- a/branches/1stNUP_1_5_CUP/sources/common/FileTransfer.cpp +++ b/branches/1stNUP_1_5_CUP/sources/common/FileTransfer.cpp @@ -768,4 +768,63 @@ bool AddPathNameAndUpdateContext(nn::fs::FileOutputStream* file, const wchar_t * return true; } +nn::Result CalculateFileSizeRecursively(std::wstring currentDirectory, s64& fileSize) +{ + nn::fs::Directory dir; + nn::fs::DirectoryEntry entry; + nn::Result result; + + NN_LOG("%s\n", common::GetCharStr(currentDirectory.c_str())); + result = dir.TryInitialize(currentDirectory.c_str()); + if(result.IsFailure()) + { + return result; + } + + for (;;) + { + s32 numRead; + result = dir.TryRead(&numRead, &entry, 1); + if(result.IsFailure()) + { + continue; + } + + + if(numRead == 0) + { + break; + } + + if (std::wcscmp(entry.entryName, L".") == 0 || std::wcscmp(entry.entryName, L"..") == 0) + { + continue; + } + + + // ディレクトリの場合 + if (entry.attributes.isDirectory) + { + return CalculateFileSizeRecursively(currentDirectory + std::wstring(entry.entryName) + std::wstring(L"/"), fileSize); + } + // ファイルの場合 + else + { + nn::fs::FileInputStream file; + std::wstring filePath = (currentDirectory + std::wstring(entry.entryName)).c_str(); + const wchar_t* path = filePath.c_str(); + + result = file.TryInitialize(path); + if(result.IsFailure()) + { + continue; + } + + fileSize += file.GetSize(); + } + } + + return nn::ResultSuccess(); +} + } diff --git a/branches/1stNUP_1_5_CUP/sources/common/FileTransfer.h b/branches/1stNUP_1_5_CUP/sources/common/FileTransfer.h index 02042c2..d74fa78 100644 --- a/branches/1stNUP_1_5_CUP/sources/common/FileTransfer.h +++ b/branches/1stNUP_1_5_CUP/sources/common/FileTransfer.h @@ -59,6 +59,9 @@ const char* GetCharStr(const wchar_t* path); void AddPkcsPadding(u8* paddingSize, void* buf, size_t bufSize, s32* readSize); +// ディレクトリ以下のファイルサイズを計算する +nn::Result CalculateFileSizeRecursively(std::wstring currentDirectory, s64& fileSize); + } #endif /* FILETRANSFER_H_ */