diff --git a/trunk/ConsoleDataMigration/ConsoleRestore/Importer.cpp b/trunk/ConsoleDataMigration/ConsoleRestore/Importer.cpp index b9e48fc..3ea970d 100644 --- a/trunk/ConsoleDataMigration/ConsoleRestore/Importer.cpp +++ b/trunk/ConsoleDataMigration/ConsoleRestore/Importer.cpp @@ -84,6 +84,13 @@ nn::Result ImportNorData(); // SDカードに保存してあるバージョン情報 common::VerDef s_SDVersionData; +struct ImportDataEntry +{ + std::string fileName; + NN_PADDING3; + bool isDirectory; +}; + } CheckedNetworkSetting s_CurrentNetowrkSetting1; @@ -1518,6 +1525,91 @@ nn::Result InitializeHardwareDependentSetting() return result; } +nn::Result ReadFileList(s64* totalFileSize, std::vector* fileList) +{ + nn::Result result = nn::ResultSuccess(); + + COMMON_LOGGER("Read File List\n"); + + size_t readSize; + common::SdReaderWriter sdReader; + s64 fileSize; + { + nn::fs::FileInputStream file; + + // サイズ取得のため一時的に開く + result = file.TryInitialize(common::FILE_LIST_PATHNAME); + NN_UTIL_RETURN_IF_FAILED(result); + + result = file.TryGetSize(&fileSize); + if (result.IsFailure()) + { + file.Finalize(); + return result; + } + file.Finalize(); + } + + void* buf = common::HeapManager::GetHeap()->Allocate(fileSize); + if(buf != NULL) + { + result = sdReader.ReadBufWithCmac(common::FILE_LIST_PATHNAME, buf, fileSize, &readSize); + if(result.IsSuccess()) + { + // ファイル一覧 + const char comma[] = ","; + const char newLine[] = "\n"; + char *token = NULL; + token = std::strtok(reinterpret_cast(buf), comma); + bool parseFileName = false; + ImportDataEntry entry; + + entry.fileName = std::string(token); + while( token != NULL) + { + if(parseFileName) + { + token = std::strtok(NULL, comma); + if(token != NULL) + { + entry.fileName = std::string(token); + } + } + else + { + token = std::strtok(NULL, newLine); + if(token != NULL) + { + s64 size = std::atoll(token); + if(size != -1) + { + *totalFileSize += size; + entry.isDirectory = false; + } + else + { + entry.isDirectory = true; + } + + fileList->push_back(entry); + } + } + parseFileName = !parseFileName; + + } + + } + common::HeapManager::GetHeap()->Free(buf); + } + else + { + result = nn::Result(nn::Result::LEVEL_FATAL, nn::Result::SUMMARY_OUT_OF_RESOURCE, nn::Result::MODULE_COMMON, + nn::Result::DESCRIPTION_OUT_OF_MEMORY); + } + return result; + +} + nn::Result ImportData() { static nn::Result result = nn::ResultSuccess(); @@ -1529,6 +1621,12 @@ nn::Result ImportData() // NANDのごみを削除する Cleanup(); + // ファイル一覧を読み込む + s64 totalFileSize = 0; + std::vector fileList; + result = ReadFileList(&totalFileSize, &fileList); + NN_UTIL_RETURN_IF_FAILED(result); + // SDカードのIVSファイルを書き込む result = ImportIvs(); NN_UTIL_RETURN_IF_FAILED(result); diff --git a/trunk/ConsoleDataMigration/common/FileTransfer.cpp b/trunk/ConsoleDataMigration/common/FileTransfer.cpp index f22507f..eb80e54 100644 --- a/trunk/ConsoleDataMigration/common/FileTransfer.cpp +++ b/trunk/ConsoleDataMigration/common/FileTransfer.cpp @@ -170,7 +170,7 @@ bool CopyDirectory(const wchar_t * from_path, const wchar_t * to_path, void* buf target_to << L"/"; if(encode) { - AddPathNameAndUpdateContext(list, target_to.str().c_str(), 0, listContext); + AddPathNameAndUpdateContext(list, target_to.str().c_str(), -1, listContext); } @@ -644,8 +644,11 @@ void AddPathNameAndUpdateContext(nn::fs::FileOutputStream* file, const wchar_t * context->Update(&comma, sizeof(comma)); COMMON_LOGGER_RESULT_IF_FAILED_WITH_LINE(result); - result = file->TryWrite(&writeSize, &fileSize, sizeof(fileSize), true); - context->Update(&fileSize, sizeof(fileSize)); + char sizeStr[10]; + std::memset(sizeStr, 0, sizeof(sizeStr)); + s32 sizeStrSize = std::snprintf(sizeStr, sizeof(sizeStr), "%lld", fileSize); + result = file->TryWrite(&writeSize, sizeStr, sizeStrSize, true); + context->Update(sizeStr, sizeStrSize); COMMON_LOGGER_RESULT_IF_FAILED_WITH_LINE(result); char newLine = '\n'; diff --git a/trunk/ConsoleDataMigration/common/SdReaderWriter.cpp b/trunk/ConsoleDataMigration/common/SdReaderWriter.cpp index 4bea638..3a72428 100644 --- a/trunk/ConsoleDataMigration/common/SdReaderWriter.cpp +++ b/trunk/ConsoleDataMigration/common/SdReaderWriter.cpp @@ -225,6 +225,9 @@ nn::Result SdReaderWriter::ReadBufWithCmac(const wchar_t* path, void* buf, size_ return nn::fs::ResultVerificationFailed(); } + // CMACを0埋め + std::memset(reinterpret_cast(buf) + *totalSize, 0, sizeof(cmac)); + return result; }