mirror of
https://github.com/rvtr/ctr_Repair.git
synced 2025-10-31 13:51:08 -04:00
nn::fs::Directoryのハンドリング追加
本体初期化時もResultチェックを行うように git-svn-id: file:///Volumes/Transfer/gigaleak_20231201/2020-05-23%20-%20ctr.7z%20+%20svn_v1.068.zip/ctr/svn/ctr_Repair@369 385bec56-5757-e545-9c3a-d8741f4650f1
This commit is contained in:
parent
34407ba9a2
commit
e0ad38b640
@ -93,10 +93,8 @@ nn::Result DeleteTrash(std::wstring currentDirectory)
|
||||
for (;;)
|
||||
{
|
||||
result = dir.TryRead(&numEntry, &entry, 1);
|
||||
if (result.IsFailure())
|
||||
{
|
||||
dir.Finalize();
|
||||
}
|
||||
COMMON_LOGGER_RETURN_RESULT_IF_FAILED(result);
|
||||
|
||||
if (numEntry == 0)
|
||||
{
|
||||
// ルートディレクトリを閉じる
|
||||
@ -296,37 +294,34 @@ void CreateTwlDirectory(enum common::TWL_PATH_INDEX path)
|
||||
std::wstring(common::SD_TWL_ROOTNAME_TABLE[path])).c_str());
|
||||
}
|
||||
|
||||
void ListTwlSaveData(std::wstring currentDirectory, std::vector<common::SavePathInfo>* list)
|
||||
bool ListTwlSaveData(std::wstring currentDirectory, std::vector<common::SavePathInfo>* list)
|
||||
{
|
||||
nn::fs::Directory dir;
|
||||
nn::fs::DirectoryEntry entry;
|
||||
s32 numEntry;
|
||||
|
||||
nn::Result result = dir.TryInitialize(currentDirectory.c_str());
|
||||
if(result.IsSuccess())
|
||||
{
|
||||
for(;;)
|
||||
{
|
||||
result = dir.TryRead(&numEntry, &entry, 1);
|
||||
if(result.IsFailure())
|
||||
{
|
||||
dir.Finalize();
|
||||
break;
|
||||
}
|
||||
COMMON_LOGGER_RETURN_FALSE_IF_FAILED(result);
|
||||
|
||||
if(numEntry == 0)
|
||||
{
|
||||
dir.Finalize();
|
||||
}
|
||||
else
|
||||
{
|
||||
common::SavePathInfo pathInfo;
|
||||
pathInfo.name = currentDirectory + std::wstring(L"/") + std::wstring(entry.entryName);
|
||||
pathInfo.isDirectory = false;
|
||||
list->push_back(pathInfo);
|
||||
}
|
||||
for (;;)
|
||||
{
|
||||
result = dir.TryRead(&numEntry, &entry, 1);
|
||||
COMMON_LOGGER_RETURN_FALSE_IF_FAILED(result);
|
||||
|
||||
if (numEntry == 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
common::SavePathInfo pathInfo;
|
||||
pathInfo.name = currentDirectory + std::wstring(L"/") + std::wstring(entry.entryName);
|
||||
pathInfo.isDirectory = false;
|
||||
list->push_back(pathInfo);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void AddCurrentProgramIdPath(std::vector<std::wstring>* programIdList, std::wstring currentDir)
|
||||
@ -382,81 +377,80 @@ bool ListTwlSaveDataDirectory(std::wstring currentDirectory, u32 level, std::vec
|
||||
const wchar_t* const TWL_SAVEDATA_DIRECTORY_NAME = L"data";
|
||||
|
||||
result = dir.TryInitialize(currentDirectory.c_str());
|
||||
if (result.IsSuccess())
|
||||
COMMON_LOGGER_RETURN_FALSE_IF_FAILED(result);
|
||||
|
||||
nn::fs::DirectoryEntry entry;
|
||||
s32 numEntry;
|
||||
for (;;)
|
||||
{
|
||||
nn::fs::DirectoryEntry entry;
|
||||
s32 numEntry;
|
||||
for (;;)
|
||||
result = dir.TryRead(&numEntry, &entry, 1);
|
||||
COMMON_LOGGER_RETURN_FALSE_IF_FAILED(result);
|
||||
|
||||
if (numEntry == 0)
|
||||
{
|
||||
result = dir.TryRead(&numEntry, &entry, 1);
|
||||
if (result.IsFailure())
|
||||
{
|
||||
dir.Finalize();
|
||||
}
|
||||
if (numEntry == 0)
|
||||
{
|
||||
dir.Finalize();
|
||||
dir.Finalize();
|
||||
|
||||
bool retValue = false;
|
||||
for (entryIndex = entryList.begin(); entryIndex != entryList.end(); entryIndex++)
|
||||
bool retValue = false;
|
||||
for (entryIndex = entryList.begin(); entryIndex != entryList.end(); entryIndex++)
|
||||
{
|
||||
// レベル2未満のディレクトリなら再帰的に開く
|
||||
if (level < TWL_SAVEDATA_DIRECTORY_LEVEL)
|
||||
{
|
||||
// レベル2未満のディレクトリなら再帰的に開く
|
||||
if(level < TWL_SAVEDATA_DIRECTORY_LEVEL)
|
||||
if (entryIndex->attributes.isDirectory)
|
||||
{
|
||||
if (entryIndex->attributes.isDirectory)
|
||||
if (ListTwlSaveDataDirectory(
|
||||
currentDirectory + std::wstring(L"/") + std::wstring(entryIndex->entryName), level + 1,
|
||||
list, programIdList))
|
||||
{
|
||||
if (ListTwlSaveDataDirectory(
|
||||
currentDirectory + std::wstring(L"/") + std::wstring(entryIndex->entryName),
|
||||
level + 1, list, programIdList))
|
||||
{
|
||||
NN_LOG("%ls/%ls has data directory.\n", currentDirectory.c_str(), entryIndex->entryName);
|
||||
retValue = true;
|
||||
|
||||
AddCurrentDirectory(list, currentDirectory, entryIndex->entryName);
|
||||
}
|
||||
}
|
||||
}
|
||||
// レベル2のディレクトリなら data かどうかチェック
|
||||
else if(level == TWL_SAVEDATA_DIRECTORY_LEVEL && entryIndex->attributes.isDirectory)
|
||||
{
|
||||
if (std::wcscmp(entryIndex->entryName, TWL_SAVEDATA_DIRECTORY_NAME) == 0)
|
||||
{
|
||||
// ファイル一覧を取得する
|
||||
NN_LOG("%ls/%ls has data directory.\n", currentDirectory.c_str(), entryIndex->entryName);
|
||||
retValue = true;
|
||||
ListTwlSaveData(currentDirectory + std::wstring(L"/") + std::wstring(entryIndex->entryName), list);
|
||||
|
||||
AddCurrentDirectory(list, currentDirectory, entryIndex->entryName);
|
||||
AddCurrentProgramIdPath(programIdList, currentDirectory);
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
}
|
||||
// レベル2のディレクトリなら data かどうかチェック
|
||||
else if (level == TWL_SAVEDATA_DIRECTORY_LEVEL && entryIndex->attributes.isDirectory)
|
||||
{
|
||||
if (std::wcscmp(entryIndex->entryName, TWL_SAVEDATA_DIRECTORY_NAME) == 0)
|
||||
{
|
||||
return false;
|
||||
// ファイル一覧を取得する
|
||||
retValue = true;
|
||||
if (!ListTwlSaveData(
|
||||
currentDirectory + std::wstring(L"/") + std::wstring(entryIndex->entryName), list))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
AddCurrentDirectory(list, currentDirectory, entryIndex->entryName);
|
||||
AddCurrentProgramIdPath(programIdList, currentDirectory);
|
||||
}
|
||||
}
|
||||
|
||||
if(level != 0)
|
||||
else
|
||||
{
|
||||
return retValue;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
else
|
||||
if (level != 0)
|
||||
{
|
||||
// vectorに保存する
|
||||
entryList.push_back(entry);
|
||||
return retValue;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
// vectorに保存する
|
||||
entryList.push_back(entry);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
NN_LOG("failed initialize directory\n");
|
||||
COMMON_LOGGER_RESULT_IF_FAILED_WITH_LINE(result);
|
||||
dir.Finalize();
|
||||
}
|
||||
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -793,8 +793,15 @@ void ControlState(common::HardwareStateManager& manager, ::std::vector<std::stri
|
||||
CreateConsoleInitializedFile();
|
||||
|
||||
// ファイルシステムの初期化を行う
|
||||
InitializeFileSystem();
|
||||
s_RestoreState = REBOOTING;
|
||||
if(InitializeFileSystem())
|
||||
{
|
||||
s_RestoreState = REBOOTING;
|
||||
}
|
||||
else
|
||||
{
|
||||
s_RestoreState = FAIL;
|
||||
}
|
||||
|
||||
}
|
||||
break;
|
||||
|
||||
@ -1552,7 +1559,10 @@ void ControlState(common::HardwareStateManager& manager, ::std::vector<std::stri
|
||||
case INITIALIZE_AND_SHUTDOWN:
|
||||
{
|
||||
// 本体初期化を行う
|
||||
InitializeFileSystem();
|
||||
if(!InitializeFileSystem())
|
||||
{
|
||||
s_RestoreState = FAIL;
|
||||
}
|
||||
|
||||
// シャットダウンする
|
||||
nn::ptm::CTR::ShutdownAsync(0, nn::fnd::TimeSpan::FromSeconds(0));
|
||||
|
||||
@ -543,83 +543,83 @@ nn::Result ImportMcuRtc(common::HardwareStateManager& manager)
|
||||
return result;
|
||||
}
|
||||
|
||||
void InitializeFileSystem()
|
||||
bool InitializeFileSystem()
|
||||
{
|
||||
nn::Result result;
|
||||
|
||||
for (u32 i = 0; i < common::TWL_PATHNAME_MAX; i++)
|
||||
{
|
||||
result = nn::fs::MountSpecialArchive(common::TWL_ARCHIVE_NAME_TABLE[i], common::TWL_FS_ARCHIVE_KIND[i]);
|
||||
COMMON_LOGGER_RESULT_IF_FAILED_WITH_LINE(result);
|
||||
if (result.IsSuccess())
|
||||
COMMON_LOGGER_RETURN_FALSE_IF_FAILED(result);
|
||||
|
||||
nn::fs::Directory dir;
|
||||
std::vector<nn::fs::DirectoryEntry> entryList; //カレントディレクトリのエントリ一覧を格納
|
||||
std::vector<nn::fs::DirectoryEntry>::iterator entryIndex;
|
||||
|
||||
std::wstring currentDirectory = common::NAND_TWL_ROOT_PATHNAME_WITH_SLASH_TABLE[i];
|
||||
result = dir.TryInitialize(currentDirectory.c_str());
|
||||
COMMON_LOGGER_RETURN_FALSE_IF_FAILED(result);
|
||||
|
||||
nn::fs::DirectoryEntry entry;
|
||||
s32 numEntry;
|
||||
for (;;)
|
||||
{
|
||||
nn::fs::Directory dir;
|
||||
std::vector<nn::fs::DirectoryEntry> entryList; //カレントディレクトリのエントリ一覧を格納
|
||||
std::vector<nn::fs::DirectoryEntry>::iterator entryIndex;
|
||||
result = dir.TryRead(&numEntry, &entry, 1);
|
||||
COMMON_LOGGER_RETURN_FALSE_IF_FAILED(result);
|
||||
|
||||
std::wstring currentDirectory = common::NAND_TWL_ROOT_PATHNAME_WITH_SLASH_TABLE[i];
|
||||
result = dir.TryInitialize(currentDirectory.c_str());
|
||||
|
||||
nn::fs::DirectoryEntry entry;
|
||||
s32 numEntry;
|
||||
for (;;)
|
||||
if (numEntry == 0)
|
||||
{
|
||||
result = dir.TryRead(&numEntry, &entry, 1);
|
||||
if (result.IsFailure())
|
||||
{
|
||||
dir.Finalize();
|
||||
}
|
||||
if (numEntry == 0)
|
||||
{
|
||||
// ルートディレクトリを閉じる
|
||||
dir.Finalize();
|
||||
// ルートディレクトリを閉じる
|
||||
dir.Finalize();
|
||||
|
||||
// ルートディレクトリの子を開く
|
||||
for (entryIndex = entryList.begin(); entryIndex != entryList.end(); entryIndex++)
|
||||
// ルートディレクトリの子を開く
|
||||
for (entryIndex = entryList.begin(); entryIndex != entryList.end(); entryIndex++)
|
||||
{
|
||||
// ディレクトリなら削除する
|
||||
if (entryIndex->attributes.isDirectory)
|
||||
{
|
||||
// ディレクトリなら削除する
|
||||
if (entryIndex->attributes.isDirectory)
|
||||
{
|
||||
NN_LOG("Try Delete %ls%ls/\n", currentDirectory.c_str(), entryIndex->entryName);
|
||||
result = nn::fs::TryDeleteDirectoryRecursively((currentDirectory + ::std::wstring(
|
||||
entryIndex->entryName)).c_str());
|
||||
COMMON_LOGGER_RESULT_IF_FAILED_WITH_LINE(result);
|
||||
NN_LOG("Try Delete %ls%ls/\n", currentDirectory.c_str(), entryIndex->entryName);
|
||||
result = nn::fs::TryDeleteDirectoryRecursively(
|
||||
(currentDirectory + ::std::wstring(entryIndex->entryName)).c_str());
|
||||
COMMON_LOGGER_RETURN_FALSE_IF_FAILED(result);
|
||||
|
||||
}
|
||||
// ファイルなら削除する
|
||||
else
|
||||
{
|
||||
NN_LOG("Try Delete %ls%ls\n", currentDirectory.c_str(), entryIndex->entryName);
|
||||
result = nn::fs::TryDeleteFile(
|
||||
(currentDirectory + ::std::wstring(entryIndex->entryName)).c_str());
|
||||
COMMON_LOGGER_RESULT_IF_FAILED_WITH_LINE(result);
|
||||
}
|
||||
}
|
||||
// ファイルなら削除する
|
||||
else
|
||||
{
|
||||
NN_LOG("Try Delete %ls%ls\n", currentDirectory.c_str(), entryIndex->entryName);
|
||||
result = nn::fs::TryDeleteFile(
|
||||
(currentDirectory + ::std::wstring(entryIndex->entryName)).c_str());
|
||||
COMMON_LOGGER_RETURN_FALSE_IF_FAILED(result);
|
||||
}
|
||||
}
|
||||
|
||||
// 削除完了
|
||||
break;
|
||||
// 削除完了
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
// vectorに保存する
|
||||
entryList.push_back(entry);
|
||||
if (entry.attributes.isDirectory)
|
||||
{
|
||||
NN_LOG("%ls%ls/\n", currentDirectory.c_str(), entry.entryName);
|
||||
}
|
||||
else
|
||||
{
|
||||
// vectorに保存する
|
||||
entryList.push_back(entry);
|
||||
if (entry.attributes.isDirectory)
|
||||
{
|
||||
NN_LOG("%ls%ls/\n", currentDirectory.c_str(), entry.entryName);
|
||||
}
|
||||
else
|
||||
{
|
||||
NN_LOG("%ls%ls\n", currentDirectory.c_str(), entry.entryName);
|
||||
}
|
||||
NN_LOG("%ls%ls\n", currentDirectory.c_str(), entry.entryName);
|
||||
}
|
||||
}
|
||||
}
|
||||
nn::fs::Unmount(common::TWL_ARCHIVE_NAME_TABLE[i]);
|
||||
|
||||
result = nn::fs::Unmount(common::TWL_ARCHIVE_NAME_TABLE[i]);
|
||||
COMMON_LOGGER_RETURN_FALSE_IF_FAILED(result);
|
||||
}
|
||||
|
||||
result = nn::am::DeleteAllTwlUserPrograms();
|
||||
COMMON_LOGGER_RESULT_IF_FAILED_WITH_LINE(result);
|
||||
COMMON_LOGGER_RETURN_FALSE_IF_FAILED(result);
|
||||
nn::fs::InitializeCtrFileSystem();
|
||||
return true;
|
||||
}
|
||||
|
||||
nn::Result ImportIvs()
|
||||
|
||||
@ -137,7 +137,7 @@ nn::Result ImportCountryLanguageData();
|
||||
nn::Result ImportMcuRtc(common::HardwareStateManager& manager);
|
||||
|
||||
// TWL写真領域を初期化してから本体初期化を行う
|
||||
void InitializeFileSystem();
|
||||
bool InitializeFileSystem();
|
||||
|
||||
// SDカードのファイルと本体情報の比較結果をクリアする
|
||||
void ClearFileReadResult();
|
||||
|
||||
@ -58,7 +58,6 @@ const char* GetCharStr(const wchar_t* path)
|
||||
|
||||
nn::Result CalculateFileNum(std::wstring currentDirectory, u32& fileNum, s64& fileSize)
|
||||
{
|
||||
nn::fs::FileInputStream fis;
|
||||
nn::fs::Directory dir;
|
||||
nn::Result result;
|
||||
std::vector<nn::fs::DirectoryEntry> entryList; //カレントディレクトリのエントリ一覧を格納
|
||||
@ -267,7 +266,9 @@ bool CopyDirectory(ImportDataList* fileList, const wchar_t * from_path, const wc
|
||||
while (1)
|
||||
{
|
||||
result = from_dir.TryRead(&numread, &entry, 1);
|
||||
if (result.IsFailure() || numread != 1)
|
||||
COMMON_LOGGER_RETURN_FALSE_IF_FAILED(result);
|
||||
|
||||
if(numread == 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user