mirror of
https://github.com/rvtr/ctr_Repair.git
synced 2025-10-31 13:51:08 -04:00
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
230 lines
6.2 KiB
C++
230 lines
6.2 KiB
C++
/*---------------------------------------------------------------------------*
|
|
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 <nn/fs/fs_ApiSysSaveData.h>
|
|
#include <nn/fs/fs_ApiSharedExtSaveData.h>
|
|
|
|
#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 */
|