mirror of
https://github.com/rvtr/ctr_Repair.git
synced 2025-10-31 13:51:08 -04:00
TWLタイトルのリストをeTicketではなくセーブデータディレクトリで判断するように
git-svn-id: file:///Volumes/Transfer/gigaleak_20231201/2020-05-23%20-%20ctr.7z%20+%20svn_v1.068.zip/ctr/svn/ctr_Repair@231 385bec56-5757-e545-9c3a-d8741f4650f1
This commit is contained in:
parent
3806c1f163
commit
192209ec58
@ -30,7 +30,6 @@ namespace
|
|||||||
typedef enum BackupState
|
typedef enum BackupState
|
||||||
{
|
{
|
||||||
STARTUP, // 初期値
|
STARTUP, // 初期値
|
||||||
EXPORT_TWL_LIST, // TWLアプリのリストを書き出し中
|
|
||||||
EXPORT_TWL_NAND, // TWLセーブデータ領域の吸出し中
|
EXPORT_TWL_NAND, // TWLセーブデータ領域の吸出し中
|
||||||
EXPORT_TWL_SOUND, // TWLサウンド領域の吸出し中
|
EXPORT_TWL_SOUND, // TWLサウンド領域の吸出し中
|
||||||
EXPORT_TWL_PHOTO, // TWL写真領域の吸出し中
|
EXPORT_TWL_PHOTO, // TWL写真領域の吸出し中
|
||||||
@ -148,32 +147,12 @@ void ControlState(common::HardwareStateManager& manager, ::std::vector<std::stri
|
|||||||
{
|
{
|
||||||
COMMON_LOGGER("Start Export Data\n");
|
COMMON_LOGGER("Start Export Data\n");
|
||||||
|
|
||||||
s_BackupState = EXPORT_TWL_LIST;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
|
|
||||||
// TWLセーブデータ領域のリスト作成中
|
|
||||||
case EXPORT_TWL_LIST:
|
|
||||||
{
|
|
||||||
static bool init = true;
|
|
||||||
if(init)
|
|
||||||
{
|
|
||||||
// データを書き込む
|
|
||||||
ExportTwlTitleList();
|
|
||||||
init = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 処理が完了した
|
|
||||||
if (IsExportFinished())
|
|
||||||
{
|
|
||||||
FinalizeExportThread();
|
|
||||||
s_BackupState = EXPORT_TWL_NAND;
|
s_BackupState = EXPORT_TWL_NAND;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
||||||
// TWLセーブデータ領域の吸出し中
|
// TWLセーブデータ領域の吸出し中
|
||||||
case EXPORT_TWL_NAND:
|
case EXPORT_TWL_NAND:
|
||||||
{
|
{
|
||||||
|
|||||||
@ -154,64 +154,27 @@ void DeleteTrash(std::wstring currentDirectory)
|
|||||||
common::SdMountManager::Unmount();
|
common::SdMountManager::Unmount();
|
||||||
}
|
}
|
||||||
|
|
||||||
void WriteTwlTitleData()
|
void WriteTwlTitleList(std::vector<std::wstring>& programIdList)
|
||||||
{
|
{
|
||||||
COMMON_LOGGER("Export TwlTitle Data.\n");
|
COMMON_LOGGER("Export TwlTitle List.\n");
|
||||||
|
|
||||||
const u32 AM_TICKET_MAX = 8192;
|
size_t heapSize = common::HeapManager::GetHeap()->GetAllocatableSize();
|
||||||
|
char* titleListBuf = reinterpret_cast<char*> (common::HeapManager::GetHeap()->Allocate(heapSize));
|
||||||
|
|
||||||
s32 personalizedTicketNum;
|
size_t writeSize = 0;
|
||||||
nn::am::TicketInfo *ticketInfoBuffer =
|
if (titleListBuf != NULL)
|
||||||
reinterpret_cast<nn::am::TicketInfo*> (common::HeapManager::GetHeap()->Allocate(
|
|
||||||
sizeof(nn::am::TicketInfo) * AM_TICKET_MAX));
|
|
||||||
if(ticketInfoBuffer == NULL)
|
|
||||||
{
|
{
|
||||||
return;
|
for (std::vector<std::wstring>::iterator it = programIdList.begin(); it != programIdList.end(); it++)
|
||||||
|
{
|
||||||
|
nn::nstd::TSNPrintf(titleListBuf + writeSize, heapSize - writeSize, "%s\n", common::GetCharStr(it->c_str()));
|
||||||
|
NN_LOG("%ls\n", it->c_str());
|
||||||
|
writeSize += it->size() + sizeof('\n');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
nn::Result result=nn::am::GetPersonalizedTicketInfoList(&personalizedTicketNum, ticketInfoBuffer, AM_TICKET_MAX); // 全部
|
nn::Result result = s_SdWriter.WriteBufWithCmac(common::TWL_TITLELIST_PATHNAME, titleListBuf, writeSize);
|
||||||
COMMON_LOGGER_RESULT_IF_FAILED_WITH_LINE(result);
|
COMMON_LOGGER_RESULT_IF_FAILED_WITH_LINE(result);
|
||||||
if(result.IsFailure())
|
common::HeapManager::GetHeap()->Free(titleListBuf);
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
u32 twlTiteNum = 0;
|
|
||||||
for (u32 i = 0; i < personalizedTicketNum; i++)
|
|
||||||
{
|
|
||||||
if (nn::CTR::IsTwlApp(ticketInfoBuffer[i].titleId))
|
|
||||||
{
|
|
||||||
twlTiteNum++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (twlTiteNum > 0)
|
|
||||||
{
|
|
||||||
const size_t BYTES_PER_LINE = sizeof(nn::ProgramID) * 2 + sizeof('\n');
|
|
||||||
char* titleListBuf = reinterpret_cast<char*> (common::HeapManager::GetHeap()->Allocate(
|
|
||||||
BYTES_PER_LINE * twlTiteNum + sizeof('0')));
|
|
||||||
if (titleListBuf != NULL)
|
|
||||||
{
|
|
||||||
for (u32 i = 0; i < personalizedTicketNum; i++)
|
|
||||||
{
|
|
||||||
if (nn::CTR::IsTwlApp(ticketInfoBuffer[i].titleId))
|
|
||||||
{
|
|
||||||
nn::nstd::TSNPrintf(titleListBuf + i * BYTES_PER_LINE,
|
|
||||||
BYTES_PER_LINE * twlTiteNum + sizeof('0') - i * BYTES_PER_LINE, "%016llx\n",
|
|
||||||
ticketInfoBuffer[i].titleId);
|
|
||||||
NN_LOG("%016llx\n", ticketInfoBuffer[i].titleId);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
result = s_SdWriter.WriteBufWithCmac(common::TWL_TITLELIST_PATHNAME, titleListBuf,
|
|
||||||
BYTES_PER_LINE * twlTiteNum);
|
|
||||||
COMMON_LOGGER_RESULT_IF_FAILED_WITH_LINE(result);
|
|
||||||
common::HeapManager::GetHeap()->Free(titleListBuf);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
common::HeapManager::GetHeap()->Free(ticketInfoBuffer);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -357,6 +320,37 @@ void ListTwlSaveData(std::wstring currentDirectory, std::vector<common::SavePath
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void AddCurrentProgramIdPath(std::vector<std::wstring>* programIdList, std::wstring currentDir)
|
||||||
|
{
|
||||||
|
std::wstring currentPath(currentDir);
|
||||||
|
std::wstring token(common::NAND_TWL_DATA_ROOT_PATHNAME_WITHOUT_SLASH);
|
||||||
|
|
||||||
|
std::wstring::size_type pos;
|
||||||
|
pos = currentPath.find(token);
|
||||||
|
if(pos != std::wstring::npos)
|
||||||
|
{
|
||||||
|
std::wstring subStr = currentPath.substr(token.size());
|
||||||
|
|
||||||
|
std::wstring slash(L"/");
|
||||||
|
pos = subStr.find(slash);
|
||||||
|
while(pos != std::wstring::npos)
|
||||||
|
{
|
||||||
|
subStr.erase(pos, slash.size());
|
||||||
|
pos = subStr.find(slash);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::wstring ctrProgramIdHi(L"00048");
|
||||||
|
subStr.replace(0, ctrProgramIdHi.size(), ctrProgramIdHi);
|
||||||
|
|
||||||
|
programIdList->push_back(subStr);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
NN_LOG("Can't find %ls\n", common::NAND_TWL_DATA_ROOT_PATHNAME_WITHOUT_SLASH);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
void AddCurrentDirectory(std::vector<common::SavePathInfo>* list, std::wstring currentDir, wchar_t* currentEntry)
|
void AddCurrentDirectory(std::vector<common::SavePathInfo>* list, std::wstring currentDir, wchar_t* currentEntry)
|
||||||
{
|
{
|
||||||
common::SavePathInfo pathInfo;
|
common::SavePathInfo pathInfo;
|
||||||
@ -367,7 +361,8 @@ void AddCurrentDirectory(std::vector<common::SavePathInfo>* list, std::wstring c
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool ListTwlSaveDataDirectory(std::wstring currentDirectory, u32 level, std::vector<common::SavePathInfo>* list)
|
bool ListTwlSaveDataDirectory(std::wstring currentDirectory, u32 level, std::vector<common::SavePathInfo>* list,
|
||||||
|
std::vector<std::wstring>* programIdList)
|
||||||
{
|
{
|
||||||
// TODO: リードオンリーのファイルが消去できない
|
// TODO: リードオンリーのファイルが消去できない
|
||||||
nn::fs::FileInputStream fis;
|
nn::fs::FileInputStream fis;
|
||||||
@ -404,7 +399,7 @@ bool ListTwlSaveDataDirectory(std::wstring currentDirectory, u32 level, std::vec
|
|||||||
{
|
{
|
||||||
if (ListTwlSaveDataDirectory(
|
if (ListTwlSaveDataDirectory(
|
||||||
currentDirectory + std::wstring(L"/") + std::wstring(entryIndex->entryName),
|
currentDirectory + std::wstring(L"/") + std::wstring(entryIndex->entryName),
|
||||||
level + 1, list))
|
level + 1, list, programIdList))
|
||||||
{
|
{
|
||||||
NN_LOG("%ls/%ls has data directory.\n", currentDirectory.c_str(), entryIndex->entryName);
|
NN_LOG("%ls/%ls has data directory.\n", currentDirectory.c_str(), entryIndex->entryName);
|
||||||
retValue = true;
|
retValue = true;
|
||||||
@ -423,6 +418,7 @@ bool ListTwlSaveDataDirectory(std::wstring currentDirectory, u32 level, std::vec
|
|||||||
ListTwlSaveData(currentDirectory + std::wstring(L"/") + std::wstring(entryIndex->entryName), list);
|
ListTwlSaveData(currentDirectory + std::wstring(L"/") + std::wstring(entryIndex->entryName), list);
|
||||||
|
|
||||||
AddCurrentDirectory(list, currentDirectory, entryIndex->entryName);
|
AddCurrentDirectory(list, currentDirectory, entryIndex->entryName);
|
||||||
|
AddCurrentProgramIdPath(programIdList, currentDirectory);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -550,6 +546,7 @@ void WriteTwlSaveData()
|
|||||||
{
|
{
|
||||||
nn::Result result;
|
nn::Result result;
|
||||||
std::vector<common::SavePathInfo> fileList;
|
std::vector<common::SavePathInfo> fileList;
|
||||||
|
std::vector<std::wstring> programIdList;
|
||||||
|
|
||||||
COMMON_LOGGER("Export Twl Save Data.\n");
|
COMMON_LOGGER("Export Twl Save Data.\n");
|
||||||
|
|
||||||
@ -560,14 +557,16 @@ void WriteTwlSaveData()
|
|||||||
// セーブデータを含むディレクトリ一覧を生成
|
// セーブデータを含むディレクトリ一覧を生成
|
||||||
result = nn::fs::MountSpecialArchive(common::NAND_TWL_ARCHIVE_NAME, nn::fs::CTR::ARCHIVE_TYPE_TWL_NAND);
|
result = nn::fs::MountSpecialArchive(common::NAND_TWL_ARCHIVE_NAME, nn::fs::CTR::ARCHIVE_TYPE_TWL_NAND);
|
||||||
COMMON_LOGGER_RESULT_IF_FAILED(result);
|
COMMON_LOGGER_RESULT_IF_FAILED(result);
|
||||||
ListTwlSaveDataDirectory(std::wstring(common::NAND_TWL_DATA_ROOT_PATHNAME_WITHOUT_SLASH), 0, &fileList);
|
ListTwlSaveDataDirectory(std::wstring(common::NAND_TWL_DATA_ROOT_PATHNAME_WITHOUT_SLASH), 0, &fileList, & programIdList);
|
||||||
|
|
||||||
NN_LOG("\n");
|
NN_LOG("listup Twl Savedata Directory\n");
|
||||||
for (std::vector<common::SavePathInfo>::reverse_iterator it = fileList.rbegin(); it != fileList.rend(); it++)
|
for (std::vector<common::SavePathInfo>::reverse_iterator it = fileList.rbegin(); it != fileList.rend(); it++)
|
||||||
{
|
{
|
||||||
NN_LOG("%ls\n", it->name.c_str());
|
NN_LOG("%ls\n", it->name.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
WriteTwlTitleList(programIdList);
|
||||||
|
|
||||||
// 合計サイズ取得
|
// 合計サイズ取得
|
||||||
s64 fileSize;
|
s64 fileSize;
|
||||||
CalculateTwlSaveData(&fileList, &fileSize);
|
CalculateTwlSaveData(&fileList, &fileSize);
|
||||||
@ -655,16 +654,11 @@ void InitializeFileListContext()
|
|||||||
s_FileListContext.Initialize();
|
s_FileListContext.Initialize();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ExportTwlTitleList()
|
void ExportTwlSaveData()
|
||||||
{
|
{
|
||||||
// 不要なデータを削除する
|
// 不要なデータを削除する
|
||||||
DeleteTrash((std::wstring(common::LOG_ROOT_DIRECTORY_PATH) + std::wstring(L"/")).c_str());
|
DeleteTrash((std::wstring(common::LOG_ROOT_DIRECTORY_PATH) + std::wstring(L"/")).c_str());
|
||||||
|
|
||||||
s_ExportThread.Start(WriteTwlTitleData, s_ExportThreadStack);
|
|
||||||
}
|
|
||||||
|
|
||||||
void ExportTwlSaveData()
|
|
||||||
{
|
|
||||||
s_ExportThread.Start(WriteTwlSaveData, s_ExportThreadStack);
|
s_ExportThread.Start(WriteTwlSaveData, s_ExportThreadStack);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -34,6 +34,8 @@ bool CopyDirectory(ImportDataList* fileList, const wchar_t * from_path, const wc
|
|||||||
u32 GetProgress();
|
u32 GetProgress();
|
||||||
void InitializeTransferProgress(u64 totalSize);
|
void InitializeTransferProgress(u64 totalSize);
|
||||||
|
|
||||||
|
const char* GetCharStr(const wchar_t* path);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* FILETRANSFER_H_ */
|
#endif /* FILETRANSFER_H_ */
|
||||||
|
|||||||
@ -37,10 +37,10 @@ public:
|
|||||||
|
|
||||||
ExporterTest() {
|
ExporterTest() {
|
||||||
SUITE_NAME("TestUtil");
|
SUITE_NAME("TestUtil");
|
||||||
TEST_ADD(ExporterTest::WriteTwlTitleData);
|
TEST_ADD(ExporterTest::ExportTwlSaveData);
|
||||||
}
|
}
|
||||||
private:
|
private:
|
||||||
void WriteTwlTitleData();
|
void ExportTwlSaveData();
|
||||||
};
|
};
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
@ -93,18 +93,18 @@ void ExporterTest::FinalizeSuite()
|
|||||||
// Test Functions
|
// Test Functions
|
||||||
//------------------------------------------------------------------
|
//------------------------------------------------------------------
|
||||||
|
|
||||||
void ExporterTest::WriteTwlTitleData()
|
void ExporterTest::ExportTwlSaveData()
|
||||||
{
|
{
|
||||||
NN_LOG("WriteTwlTitleData\n");
|
NN_LOG("WriteTwlTitleData\n");
|
||||||
ConsoleBackup::ExportTwlTitleList();
|
ConsoleBackup::ExportTwlSaveData();
|
||||||
|
|
||||||
while (!ConsoleBackup::IsExportFinished())
|
while (!ConsoleBackup::IsExportFinished())
|
||||||
{
|
{
|
||||||
nn::os::Thread::Sleep(nn::fnd::TimeSpan::FromMilliSeconds(10));
|
nn::os::Thread::Sleep(nn::fnd::TimeSpan::FromMilliSeconds(10));
|
||||||
}
|
}
|
||||||
ConsoleBackup::FinalizeExportThread();
|
ConsoleBackup::FinalizeExportThread();
|
||||||
}
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
NN_TEST_DEFINE_MAIN(ExporterTest)
|
NN_TEST_DEFINE_MAIN(ExporterTest)
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user