From 92b826fbcc2cbcb0c04413cdbfa1950436ef4735 Mon Sep 17 00:00:00 2001 From: N2614 Date: Mon, 1 Aug 2011 02:33:06 +0000 Subject: [PATCH] =?UTF-8?q?=E3=82=B7=E3=82=B9=E3=83=86=E3=83=A0=E3=82=BB?= =?UTF-8?q?=E3=83=BC=E3=83=96=E3=83=87=E3=83=BC=E3=82=BF=E3=82=92=E3=83=81?= =?UTF-8?q?=E3=82=A7=E3=83=83=E3=82=AF=E3=81=97=E3=81=A6=E5=89=8A=E9=99=A4?= =?UTF-8?q?=E3=81=A7=E3=81=8D=E3=82=8B=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@411 385bec56-5757-e545-9c3a-d8741f4650f1 --- .../sources/ConsoleBackup/Checker.cpp | 40 +++ .../sources/ConsoleBackup/Checker.h | 26 ++ .../sources/ConsoleBackup/OMakefile | 2 + .../sources/ConsoleBackup/SavedataChecker.cpp | 229 ++++++++++++++++++ .../sources/ConsoleBackup/SavedataChecker.h | 180 ++++++++++++++ 5 files changed, 477 insertions(+) create mode 100644 trunk/ConsoleDataMigration/sources/ConsoleBackup/Checker.cpp create mode 100644 trunk/ConsoleDataMigration/sources/ConsoleBackup/Checker.h create mode 100644 trunk/ConsoleDataMigration/sources/ConsoleBackup/SavedataChecker.cpp create mode 100644 trunk/ConsoleDataMigration/sources/ConsoleBackup/SavedataChecker.h diff --git a/trunk/ConsoleDataMigration/sources/ConsoleBackup/Checker.cpp b/trunk/ConsoleDataMigration/sources/ConsoleBackup/Checker.cpp new file mode 100644 index 0000000..a5450b5 --- /dev/null +++ b/trunk/ConsoleDataMigration/sources/ConsoleBackup/Checker.cpp @@ -0,0 +1,40 @@ +/*---------------------------------------------------------------------------* + Project: Horizon + File: Checker.cpp + + Copyright 2009 Nintendo. All rights reserved. + + These coded instructions, statements, and computer programs contain + proprietary information of Nintendo of America Inc. and/or Nintendo + Company Ltd., and are protected by Federal copyright law. They may + not be disclosed to third parties or copied or duplicated in any form, + in whole or in part, without the prior written consent of Nintendo. + + $Rev$ + *---------------------------------------------------------------------------*/ + + +#include "CommonLogger.h" +#include "HeapManager.h" +#include "SaveDataChecker.h" + +namespace ConsoleBackup +{ + +bool CheckSaveData() +{ + size_t bufSize = common::GetAllocatableSize(); + common::HeapManager heap(bufSize); + if(heap.GetAddr() != NULL) + { + SavedataChecker checker(heap.GetAddr(), bufSize); + nn::Result result = checker.CleanUp(); + return result.IsSuccess(); + } + + return false; +} + +} + + diff --git a/trunk/ConsoleDataMigration/sources/ConsoleBackup/Checker.h b/trunk/ConsoleDataMigration/sources/ConsoleBackup/Checker.h new file mode 100644 index 0000000..102c4d2 --- /dev/null +++ b/trunk/ConsoleDataMigration/sources/ConsoleBackup/Checker.h @@ -0,0 +1,26 @@ +/*---------------------------------------------------------------------------* + Project: Horizon + File: Checker.h + + Copyright 2009 Nintendo. All rights reserved. + + These coded instructions, statements, and computer programs contain + proprietary information of Nintendo of America Inc. and/or Nintendo + Company Ltd., and are protected by Federal copyright law. They may + not be disclosed to third parties or copied or duplicated in any form, + in whole or in part, without the prior written consent of Nintendo. + + $Rev$ + *---------------------------------------------------------------------------*/ + +#ifndef CHECKER_H_ +#define CHECKER_H_ + +namespace ConsoleBackup +{ + +bool CheckSaveData(); + +} + +#endif /* CHECKER_H_ */ diff --git a/trunk/ConsoleDataMigration/sources/ConsoleBackup/OMakefile b/trunk/ConsoleDataMigration/sources/ConsoleBackup/OMakefile index 88cdf18..d8e8323 100644 --- a/trunk/ConsoleDataMigration/sources/ConsoleBackup/OMakefile +++ b/trunk/ConsoleDataMigration/sources/ConsoleBackup/OMakefile @@ -26,6 +26,8 @@ SOURCES[] = ConsoleBackup.cpp Controller.cpp Exporter.cpp + Checker.cpp + SavedataChecker.cpp ../common/Util.cpp ../common/DrawSystemState.cpp ../common/FileTransfer.cpp diff --git a/trunk/ConsoleDataMigration/sources/ConsoleBackup/SavedataChecker.cpp b/trunk/ConsoleDataMigration/sources/ConsoleBackup/SavedataChecker.cpp new file mode 100644 index 0000000..586ea14 --- /dev/null +++ b/trunk/ConsoleDataMigration/sources/ConsoleBackup/SavedataChecker.cpp @@ -0,0 +1,229 @@ +/*---------------------------------------------------------------------------* + Project: Horizon + File: SavedataChecker.cpp + + Copyright 2009 Nintendo. All rights reserved. + + These coded instructions, statements, and computer programs contain + proprietary information of Nintendo of America Inc. and/or Nintendo + Company Ltd., and are protected by Federal copyright law. They may + not be disclosed to third parties or copied or duplicated in any form, + in whole or in part, without the prior written consent of Nintendo. + + $Rev$ + *---------------------------------------------------------------------------*/ + +#include +#include + +#include "SavedataChecker.h" +#include "CommonLogger.h" +#include "FileTransfer.h" + +namespace ConsoleBackup +{ + +namespace +{ + +} + + +SavedataChecker::SavedataChecker() +{ + // TODO 自動生成されたコンストラクター・スタブ + +} + +SavedataChecker::SavedataChecker(void* buf, size_t size) : m_Buf(buf), m_Bufsize(size) +{ + +} + +SavedataChecker::~SavedataChecker() +{ + // TODO Auto-generated destructor stub +} + +nn::Result SavedataChecker::CleanUp() +{ + nn::Result result; + { + SystemSavedataChecker syssaveChecker(m_Buf, m_Bufsize); + result = syssaveChecker.CleanUp(); + NN_UTIL_RETURN_IF_FAILED(result); + } + + { + SharedExtSavedataChecker sharedExtSaveChecker(m_Buf, m_Bufsize); + result = sharedExtSaveChecker.CleanUp(); + NN_UTIL_RETURN_IF_FAILED(result); + } + + return nn::ResultSuccess(); +} + +SystemSavedataChecker::SystemSavedataChecker() +{ + +} + +SystemSavedataChecker::SystemSavedataChecker(void* buf, size_t size) : m_Buf(buf), m_Bufsize(size) +{ +} + + +SystemSavedataChecker::~SystemSavedataChecker() +{ +} + + + +nn::Result SystemSavedataChecker::CleanUp() +{ + nn::Result result; + + bool modified = false; + std::wstring currentDirectory; + for (s32 i = 0; i < SYSTEM_SAVE_DATA_NUM; i++) + { + result = nn::fs::MountSystemSaveData(SYSTEM_SAVEDATA_ARCHIVE_NAME, SYSTEM_SAVEDATA_COUPLE_LIST[i].id ); + if (result.IsFailure()) + { + if(result <= nn::fs::ResultVerificationFailed()) + { + NN_LOG("Mount Error: %ls\n", SYSTEM_SAVEDATA_COUPLE_LIST[i].name.c_str()); + // 削除する + COMMON_LOGGER_WARN("Delete Savedata %s\n", common::GetCharStr(SYSTEM_SAVEDATA_COUPLE_LIST[i].name.c_str())); + result = nn::fs::DeleteSystemSaveData(SYSTEM_SAVEDATA_COUPLE_LIST[i].id); + } + } + else + { + NN_LOG("Mount %ls\n", SYSTEM_SAVEDATA_COUPLE_LIST[i].name.c_str()); + // ファイルを個別にチェックする + result = CleanUpFilesRecursively(&modified, L"ssave:/"); + + if(modified) + { + result = nn::fs::CommitSystemSaveData(SYSTEM_SAVEDATA_ARCHIVE_NAME); + } + COMMON_LOGGER_RETURN_RESULT_IF_FAILED(result); + + result = nn::fs::Unmount("ssave:"); + COMMON_LOGGER_RETURN_RESULT_IF_FAILED(result); + } + } + + + return result; +} + +nn::Result SystemSavedataChecker::CleanUpFilesRecursively(bool* modifiled, std::wstring currentDirectory) +{ + nn::fs::Directory dir; + nn::fs::DirectoryEntry entry; + nn::Result result; + + COMMON_LOGGER("%s\n", common::GetCharStr(currentDirectory.c_str())); + result = dir.TryInitialize(currentDirectory.c_str()); + if(result.IsFailure()) + { + COMMON_LOGGER_WARN("Delete Directory %s\n", common::GetCharStr(currentDirectory.c_str())); + result = nn::fs::TryDeleteDirectory(currentDirectory.c_str()); + *modifiled = true; + return result; + } + + for (;;) + { + s32 numRead; + result = dir.TryRead(&numRead, &entry, 1); + if(result.IsFailure()) + { + COMMON_LOGGER_WARN("Delete Directory %s\n", common::GetCharStr(currentDirectory.c_str())); + result = nn::fs::TryDeleteDirectoryRecursively(currentDirectory.c_str()); + *modifiled = true; + continue; + } + + + if(numRead == 0) + { + break; + } + + if (std::wcscmp(entry.entryName, L".") == 0 || std::wcscmp(entry.entryName, L"..") == 0) + { + continue; + } + + + // ディレクトリの場合 + if (entry.attributes.isDirectory) + { + return CleanUpFilesRecursively(modifiled, 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(); + + COMMON_LOGGER("%s\n", common::GetCharStr(path)); + + result = file.TryInitialize(path); + if(result.IsFailure()) + { + COMMON_LOGGER("Cannot Initialize %ls, delete.\n", common::GetCharStr(path)); + result = nn::fs::TryDeleteFile(path); + *modifiled = true; + continue; + } + + for (;;) + { + s32 readSize; + result = file.TryRead(&readSize, m_Buf, m_Bufsize); + if(result.IsFailure()) + { + COMMON_LOGGER("Cannot read %ls, delete.\n", common::GetCharStr(path)); + result = nn::fs::TryDeleteFile(path); + *modifiled = true; + break; + } + + + if(readSize == 0) + { + break; + } + } + } + } + + return nn::ResultSuccess(); +} + +SharedExtSavedataChecker::SharedExtSavedataChecker() +{ +} + +SharedExtSavedataChecker::SharedExtSavedataChecker(void* buf, size_t size) : m_Buf(buf), m_Bufsize(size) +{ +} + + + +SharedExtSavedataChecker::~SharedExtSavedataChecker() +{ + +} + +nn::Result SharedExtSavedataChecker::CleanUp() +{ + return nn::ResultSuccess(); +} + +} /* namespace ConsoleBackup */ diff --git a/trunk/ConsoleDataMigration/sources/ConsoleBackup/SavedataChecker.h b/trunk/ConsoleDataMigration/sources/ConsoleBackup/SavedataChecker.h new file mode 100644 index 0000000..0b4dfa3 --- /dev/null +++ b/trunk/ConsoleDataMigration/sources/ConsoleBackup/SavedataChecker.h @@ -0,0 +1,180 @@ +/*---------------------------------------------------------------------------* + Project: Horizon + File: SavedataChecker.h + + Copyright 2009 Nintendo. All rights reserved. + + These coded instructions, statements, and computer programs contain + proprietary information of Nintendo of America Inc. and/or Nintendo + Company Ltd., and are protected by Federal copyright law. They may + not be disclosed to third parties or copied or duplicated in any form, + in whole or in part, without the prior written consent of Nintendo. + + $Rev$ + *---------------------------------------------------------------------------*/ + +#ifndef SAVEDATACHECKER_H_ +#define SAVEDATACHECKER_H_ + +#include + +#include +#include + +namespace ConsoleBackup +{ + +struct SystemSaveDataCouple +{ + std::wstring name; + nn::fs::SystemSaveDataId id; +}; + +const SystemSaveDataCouple SYSTEM_SAVEDATA_COUPLE_LIST[] = +{ + { L"fill_data", 0x00010000 }, + { L"cfg", 0x00010017 }, + { L"ptm", 0x00010022 }, + { L"cecd", 0x00010026 }, + { L"nim", 0x0001002C }, + { L"friends", 0x00010032 }, + { L"boss", 0x00010034 }, + { L"news", 0x00010035 }, + + { L"PLOG_JP", 0x00020202 }, + { L"PLOG_US", 0x00020212 }, + { L"PLOG_EU", 0x00020222 }, + + { L"EDIT_JP", 0x00020207 }, + { L"EDIT_US", 0x00020217 }, + { L"EDIT_EU", 0x00020227 }, + + { L"PNOTE_JP", 0x00020204 }, + { L"PNOTE_US", 0x00020214 }, + { L"PNOTE_EU", 0x00020224 }, + + { L"SNOTE_JP", 0x00020205 }, + { L"SNOTE_US", 0x00020215 }, + { L"SNOTE_EU", 0x00020225 }, + + { L"TIGER_JP", 0x00020209 }, + { L"TIGER_US", 0x00020219 }, + { L"TIGER_EU", 0x00020229 }, + + { L"MARS_JP", 0x0002020b }, + { L"MARS_US", 0x0002021b }, + { L"MARS_EU", 0x0002022b }, + + { L"CARDBOARD_JP", 0x0002020a }, + { L"CARDBOARD_US", 0x0002021a }, + { L"CARDBOARD_EU", 0x0002022a }, + + { L"FRUIT_JP", 0x0002020c }, + { L"FRUIT_US", 0x0002021c }, + { L"FRUIT_EU", 0x0002022c }, + + { L"MEET_JP", 0x00020208 }, + { L"MEET_US", 0x00020218 }, + { L"MEET_EU", 0x00020228 }, + + { L"CPLAY_HAL_JP", 0x0002020d }, + { L"CPLAY_HAL_US", 0x0002021d }, + { L"CPLAY_HAL_EU", 0x0002022d }, + + { L"CPLAY_NCL_JP", 0x0002020e }, + { L"CPLAY_NCL_US", 0x0002021e }, + { L"CPLAY_NCL_EU", 0x0002022e }, + + { L"MMEN_JP", 0x00020081 }, + { L"MMEN_US", 0x0002008f }, + { L"MMEN_EU", 0x00020098 }, + + { L"friend_JP", 0x0002008d }, + { L"friend_US", 0x00020096 }, + { L"friend_EU", 0x0002009f }, + + { L"SPIDER_JP", 0x00020088 }, + { L"SPIDER_US", 0x0002009d }, + { L"SPIDER_EU", 0x00020094 }, + + { L"EBIRD_JP", 0x00020086 }, + { L"EBIRD_US", 0x00020092 }, + { L"EBIRD_EU", 0x0002009b }, + + { L"CHERRY_JP", 0x00020087 }, + { L"CHERRY_US", 0x00020093 }, + { L"CHERRY_EU", 0x0002009c }, + + { L"error", 0x000200c5 } + +}; + +const char* const SYSTEM_SAVEDATA_ARCHIVE_NAME = "ssave:"; + +const size_t SYSTEM_SAVE_DATA_NUM = sizeof(SYSTEM_SAVEDATA_COUPLE_LIST)/sizeof(SYSTEM_SAVEDATA_COUPLE_LIST[0]); + +//! @brief システムセーブデータをチェックするためのクラス +class SystemSavedataChecker +{ +public: + SystemSavedataChecker(); + SystemSavedataChecker(void* buf, size_t size); + ~SystemSavedataChecker(); + + //! @brief システムセーブデータを調べて問題があるファイルを削除する + nn::Result CleanUp(); + +private: + //! @brief システムセーブデータアーカイブ内のファイルを調べて問題があるファイルを削除する + nn::Result CleanUpFilesRecursively(bool* modified, std::wstring currentDirectory); + + //! バッファ + void* m_Buf; + + //! バッファサイズ + size_t m_Bufsize; +}; + +//! @brief 共有拡張セーブデータをチェックするためのクラス +class SharedExtSavedataChecker +{ +public: + SharedExtSavedataChecker(); + SharedExtSavedataChecker(void* buf, size_t size); + ~SharedExtSavedataChecker(); + + //! @brief 共有拡張セーブデータを調べて問題があるファイルを削除する + nn::Result CleanUp(); + +private: + //! @brief 共有拡張セーブデータアーカイブ内のファイルを調べて問題があるファイルを削除する + nn::Result CleanUpFilesRecursively(bool* modified, std::wstring currentDirectory); + + //! バッファ + void* m_Buf; + + //! バッファサイズ + size_t m_Bufsize; + +}; + + +class SavedataChecker +{ +public: + SavedataChecker(); + SavedataChecker(void* buf, size_t size); + ~SavedataChecker(); + + nn::Result CleanUp(); + +private: + //! バッファ + void* m_Buf; + + //! バッファサイズ + size_t m_Bufsize; +}; + +} /* namespace ConsoleBackup */ +#endif /* SAVEDATACHECKER_H_ */