書き込み後CTR-NAND領域をチェックするように

git-svn-id: file:///Volumes/Transfer/gigaleak_20231201/2020-05-23%20-%20ctr.7z%20+%20svn_v1.068.zip/ctr/svn/ctr_Repair@373 385bec56-5757-e545-9c3a-d8741f4650f1
This commit is contained in:
N2614 2011-07-08 07:32:01 +00:00
parent ed0c6756d9
commit a4834ca886
5 changed files with 299 additions and 78 deletions

View File

@ -135,6 +135,7 @@ typedef enum RestoreState
RESTORE_IN_PROGRESS, // 書き込み中
POST_RESTORE, // 書き込み後の処理
RESTORE_DONE, // 書き込み完了
RESTORE_TEST, // 書き込み後のチェック
REBOOTING, // 再起動を行う
ERASE, // 削除処理を行う
RESTORE_CAL, // cfgの一部をcal値で上書きする
@ -777,15 +778,14 @@ void ControlState(common::HardwareStateManager& manager, ::std::vector<std::stri
// 状態遷移Controller
switch (s_RestoreState)
{
// 起動時
case STARTUP:
// 起動時
case STARTUP:
{
CheckSdInserted(manager, operationMessage, nextStep);
}
break;
case INITIALIZE_CONSOLE:
case INITIALIZE_CONSOLE:
{
COMMON_LOGGER("Initialize Console\n");
@ -793,7 +793,7 @@ void ControlState(common::HardwareStateManager& manager, ::std::vector<std::stri
CreateConsoleInitializedFile();
// ファイルシステムの初期化を行う
if(InitializeFileSystem())
if (InitializeFileSystem())
{
s_RestoreState = REBOOTING;
}
@ -805,7 +805,7 @@ void ControlState(common::HardwareStateManager& manager, ::std::vector<std::stri
}
break;
case WAIT_START_UPDATE:
case WAIT_START_UPDATE:
{
operationMessage.push_back(::std::string("Push A or START Button"));
operationMessage.push_back(::std::string("Network Update Mode"));
@ -823,13 +823,13 @@ void ControlState(common::HardwareStateManager& manager, ::std::vector<std::stri
}
break;
case WAIT_START_IMPORT:
case WAIT_START_IMPORT:
{
u8 serial[nn::cfg::CTR::CFG_SECURE_INFO_SERIAL_NO_LEN];
result = ReadSerialNumber(serial);
if (result.IsSuccess())
{
::std::string serialStr(reinterpret_cast<char*> (serial));
::std::string serialStr(reinterpret_cast<char*>(serial));
operationMessage.push_back(::std::string("Serial Number in SD : ") + serialStr);
}
else
@ -852,7 +852,7 @@ void ControlState(common::HardwareStateManager& manager, ::std::vector<std::stri
}
break;
case WAIT_START_SYNC_CLOCK:
case WAIT_START_SYNC_CLOCK:
{
operationMessage.push_back(::std::string("Push A or START Button"));
operationMessage.push_back(::std::string("DownLoad Twl Title and Clock Sync Mode"));
@ -870,7 +870,7 @@ void ControlState(common::HardwareStateManager& manager, ::std::vector<std::stri
}
break;
case IMPORT_RTC:
case IMPORT_RTC:
{
result = nn::ResultSuccess();
if (HasValidRtcData())
@ -906,8 +906,8 @@ void ControlState(common::HardwareStateManager& manager, ::std::vector<std::stri
}
break;
// シリアルナンバーがSDカードにないこと警告
case SERIAL_IS_NOT_IN_SD:
// シリアルナンバーがSDカードにないこと警告
case SERIAL_IS_NOT_IN_SD:
{
operationMessage.push_back(::std::string("Serial Number Is Not In SD Card"));
operationMessage.push_back(::std::string("Push A or START Button"));
@ -926,15 +926,15 @@ void ControlState(common::HardwareStateManager& manager, ::std::vector<std::stri
}
break;
// アップデート中
case UPDATE_IN_PROGRESS:
// アップデート中
case UPDATE_IN_PROGRESS:
{
UpdateOperation(manager, operationMessage, UPDATE_DONE);
}
break;
// アップデート完了
case UPDATE_DONE:
// アップデート完了
case UPDATE_DONE:
{
operationMessage.push_back(::std::string("Network Update Done."));
operationMessage.push_back(::std::string("Press A or START Button to Reboot"));
@ -952,15 +952,14 @@ void ControlState(common::HardwareStateManager& manager, ::std::vector<std::stri
}
break;
case DOWNLOAD_IVS:
case DOWNLOAD_IVS:
{
ShopOperationSingleTemplate(manager, operationMessage, SHOP_OPERATION_GET_IVS, "Get SDCI",
"Get SDCI Finished.\n", "Get SDCI Failed. Retrying...", DOWNLOAD_IVS_DONE);
}
break;
case DOWNLOAD_IVS_DONE:
case DOWNLOAD_IVS_DONE:
{
operationMessage.push_back(::std::string("Get SDCI Done."));
operationMessage.push_back(::std::string("Press A or START Button to Reboot"));
@ -978,13 +977,13 @@ void ControlState(common::HardwareStateManager& manager, ::std::vector<std::stri
}
break;
case CHECK_IVS:
case CHECK_IVS:
{
operationMessage.push_back(::std::string("Insert User's SD Card"));
}
break;
case CHECK_SD_DIRECTORY:
case CHECK_SD_DIRECTORY:
{
if (nn::fs::IsSdmcInserted())
{
@ -1017,23 +1016,23 @@ void ControlState(common::HardwareStateManager& manager, ::std::vector<std::stri
}
break;
case CHECK_SD_DIRECTORY_SUCCESS:
case CHECK_SD_DIRECTORY_SUCCESS:
{
operationMessage.push_back(::std::string("Check User's SD Card Succeeded."));
operationMessage.push_back(::std::string("Pull Out SD Card"));
}
break;
case CHECK_SD_DIRECTORY_FAIL:
case CHECK_SD_DIRECTORY_FAIL:
{
operationMessage.push_back(::std::string("Check User's SD Card Failed."));
operationMessage.push_back(::std::string("Pull Out SD Card"));
}
break;
case WAIT_START_TRANSFER_ACCOUNT:
case WAIT_START_TRANSFER_ACCOUNT:
{
if(s_SkipNupMode)
if (s_SkipNupMode)
{
operationMessage.push_back(::std::string("After Operating BMS Account Transfer,"));
}
@ -1054,21 +1053,21 @@ void ControlState(common::HardwareStateManager& manager, ::std::vector<std::stri
}
break;
case TRANSFER_ACCOUNT:
case TRANSFER_ACCOUNT:
{
ShopOperationSingleTemplate(manager, operationMessage, SHOP_OPERATION_CONNECT, "Transfer Account",
"Transfer Account Finished.\n", "Transfer Account Failed. Retrying...", TRANSFER_ACCOUNT_DONE);
}
break;
case TRANSFER_ACCOUNT_DONE:
case TRANSFER_ACCOUNT_DONE:
{
CreateTransferAccountFinishedFile();
s_RestoreState = STARTUP;
}
break;
case WAIT_START_DELETE_ACCOUNT:
case WAIT_START_DELETE_ACCOUNT:
{
operationMessage.push_back(::std::string("Push A or START Button"));
operationMessage.push_back(::std::string("Delete Account Mode"));
@ -1086,12 +1085,13 @@ void ControlState(common::HardwareStateManager& manager, ::std::vector<std::stri
}
break;
case DELETE_ACCOUNT:
case DELETE_ACCOUNT:
{
if(s_NupOnlyMode)
if (s_NupOnlyMode)
{
ShopOperationSingleTemplate(manager, operationMessage, SHOP_OPERATION_FORCE_UNREGISTER, "Deleting Account",
"Delete Account Finished.\n", "Delete Account Failed. Retrying...", DELETE_ACCOUNT_DONE);
ShopOperationSingleTemplate(manager, operationMessage, SHOP_OPERATION_FORCE_UNREGISTER,
"Deleting Account", "Delete Account Finished.\n", "Delete Account Failed. Retrying...",
DELETE_ACCOUNT_DONE);
}
else
@ -1102,9 +1102,9 @@ void ControlState(common::HardwareStateManager& manager, ::std::vector<std::stri
}
break;
case DELETE_ACCOUNT_DONE:
case DELETE_ACCOUNT_DONE:
{
if(s_NupOnlyMode)
if (s_NupOnlyMode)
{
s_RestoreState = NUP_ONLY_WAIT_SD_EJECT;
@ -1132,7 +1132,7 @@ void ControlState(common::HardwareStateManager& manager, ::std::vector<std::stri
}
break;
case READ_FILELIST:
case READ_FILELIST:
{
result = SetupFileList();
COMMON_LOGGER_RESULT_IF_FAILED_WITH_LINE(result);
@ -1156,8 +1156,8 @@ void ControlState(common::HardwareStateManager& manager, ::std::vector<std::stri
}
break;
// TWLサウンド領域の書き込み中
case RESTORE_TWL_SOUND:
// TWLサウンド領域の書き込み中
case RESTORE_TWL_SOUND:
{
static bool init = true;
if (init)
@ -1173,7 +1173,7 @@ void ControlState(common::HardwareStateManager& manager, ::std::vector<std::stri
if (IsImportThreadFinished())
{
FinalizeImportThread();
if(IsImportSucceeded())
if (IsImportSucceeded())
{
s_RestoreState = RESTORE_TWL_PHOTO;
}
@ -1181,13 +1181,12 @@ void ControlState(common::HardwareStateManager& manager, ::std::vector<std::stri
{
s_RestoreState = FAIL;
}
}
}
break;
// TWL写真領域の書き込み
case RESTORE_TWL_PHOTO:
// TWL写真領域の書き込み
case RESTORE_TWL_PHOTO:
{
static bool init = true;
if (init)
@ -1203,7 +1202,7 @@ void ControlState(common::HardwareStateManager& manager, ::std::vector<std::stri
if (IsImportThreadFinished())
{
FinalizeImportThread();
if(IsImportSucceeded())
if (IsImportSucceeded())
{
s_RestoreState = RESTORE_IN_PROGRESS;
}
@ -1216,8 +1215,8 @@ void ControlState(common::HardwareStateManager& manager, ::std::vector<std::stri
}
break;
// 書き込み中
case RESTORE_IN_PROGRESS:
// 書き込み中
case RESTORE_IN_PROGRESS:
{
// ACアダプタが必要か
if (NeedsAcAdater(manager))
@ -1237,6 +1236,7 @@ void ControlState(common::HardwareStateManager& manager, ::std::vector<std::stri
// 処理が完了した
if (!NeedsAcAdater(manager) && IsImportThreadFinished())
{
FinalizeImportThread();
if (IsImportSucceeded())
{
@ -1244,7 +1244,7 @@ void ControlState(common::HardwareStateManager& manager, ::std::vector<std::stri
if (GetProgress() > 99)
{
s_RestoreState = POST_RESTORE;
s_RestoreState = RESTORE_TEST;
}
else
{
@ -1260,8 +1260,8 @@ void ControlState(common::HardwareStateManager& manager, ::std::vector<std::stri
}
break;
// リブート中
case REBOOTING:
// リブート中
case REBOOTING:
{
static bool init = true;
@ -1288,13 +1288,39 @@ void ControlState(common::HardwareStateManager& manager, ::std::vector<std::stri
}
break;
// 書き込み後の処理
case POST_RESTORE:
case RESTORE_TEST:
{
PutAliveMessage(operationMessage, "Checking Data");
static bool init = true;
if (init)
{
TestCtrData();
init = false;
}
if (IsImportThreadFinished())
{
FinalizeImportThread();
if (IsImportSucceeded())
{
s_RestoreState = POST_RESTORE;
}
else
{
s_RestoreState = FAIL;
}
}
}
break;
// 書き込み後の処理
case POST_RESTORE:
{
operationMessage.push_back(::std::string("Post Process..."));
// SDカードのIVSファイルを書き込む
if(ImportIvsData())
if (ImportIvsData())
{
// 書き込み完了ファイルを作成
CreateWriteFinishedFile();
@ -1308,8 +1334,8 @@ void ControlState(common::HardwareStateManager& manager, ::std::vector<std::stri
}
break;
// 書き込み完了
case RESTORE_DONE:
// 書き込み完了
case RESTORE_DONE:
{
operationMessage.push_back(::std::string("Restore Done."));
operationMessage.push_back(::std::string("Press A or START Button to Reboot"));
@ -1327,16 +1353,16 @@ void ControlState(common::HardwareStateManager& manager, ::std::vector<std::stri
}
break;
// 削除処理
case ERASE:
// 削除処理
case ERASE:
{
Cleanup();
s_RestoreState = RESTORE_CAL;
}
break;
// 削除処理
case RESTORE_CAL:
// 削除処理
case RESTORE_CAL:
{
// ptmのセーブデータ移行後に時計を無効化する
nn::ptm::CTR::InvalidateSystemTime();
@ -1353,9 +1379,9 @@ void ControlState(common::HardwareStateManager& manager, ::std::vector<std::stri
}
break;
case SYNC_TICKET:
case SYNC_TICKET:
{
if(s_GetIvsOnlyMode)
if (s_GetIvsOnlyMode)
{
ShopOperationSingleTemplate(manager, operationMessage, SHOP_OPERATION_CONNECT, "Shop Connect",
"Shop Connect Finished.\n", "Shop Connect Failed. Retrying...", WAIT_SD_EJECT);
@ -1368,10 +1394,10 @@ void ControlState(common::HardwareStateManager& manager, ::std::vector<std::stri
}
break;
case DOWNLOAD_TWL:
case DOWNLOAD_TWL:
{
// ファイルリストがなければ次へ
if( !ExistsTwlTitleListFile())
if (!ExistsTwlTitleListFile())
{
s_IsSyncClock = true;
s_RestoreState = READ_FILELIST;
@ -1418,8 +1444,8 @@ void ControlState(common::HardwareStateManager& manager, ::std::vector<std::stri
}
break;
// TWL NAND領域の書き込み中
case RESTORE_TWL_NAND:
// TWL NAND領域の書き込み中
case RESTORE_TWL_NAND:
{
static bool init = true;
if (init)
@ -1440,8 +1466,8 @@ void ControlState(common::HardwareStateManager& manager, ::std::vector<std::stri
}
break;
// 時計あわせ
case TIME_ADJUST:
// 時計あわせ
case TIME_ADJUST:
{
static bool init = true;
if (init)
@ -1473,8 +1499,8 @@ void ControlState(common::HardwareStateManager& manager, ::std::vector<std::stri
}
break;
// すべて完了
case WAIT_SD_EJECT:
// すべて完了
case WAIT_SD_EJECT:
{
operationMessage.push_back(::std::string("ALL Done. Pull Out SD Card."));
// SDカード抜けのみで次の状態に遷移する
@ -1488,8 +1514,8 @@ void ControlState(common::HardwareStateManager& manager, ::std::vector<std::stri
}
break;
// すべて完了
case ALL_DONE:
// すべて完了
case ALL_DONE:
{
operationMessage.push_back(::std::string("Restore Succeeded!!"));
static bool init = true;
@ -1501,8 +1527,8 @@ void ControlState(common::HardwareStateManager& manager, ::std::vector<std::stri
}
break;
// 書き込み失敗
case FAIL:
// 書き込み失敗
case FAIL:
{
static bool init = true;
if (init)
@ -1521,7 +1547,7 @@ void ControlState(common::HardwareStateManager& manager, ::std::vector<std::stri
}
break;
case NUP_ONLY_WAIT_SD_EJECT:
case NUP_ONLY_WAIT_SD_EJECT:
{
operationMessage.push_back(::std::string("Update Done. Pull Out SD Card."));
@ -1534,10 +1560,10 @@ void ControlState(common::HardwareStateManager& manager, ::std::vector<std::stri
}
break;
case DOWNLOAD_IVS_WAIT_NEXT:
case DOWNLOAD_IVS_WAIT_NEXT:
{
operationMessage.push_back(::std::string("Press A or START Button to Continue."));
if(nextStep)
if (nextStep)
{
s_RestoreState = SYNC_TICKET;
DeleteAllCheckFiles();
@ -1545,7 +1571,7 @@ void ControlState(common::HardwareStateManager& manager, ::std::vector<std::stri
}
break;
case NUP_ONLY_WAIT_NEXT:
case NUP_ONLY_WAIT_NEXT:
{
operationMessage.push_back(::std::string("Press A or START Button to Shutdown."));
@ -1556,10 +1582,10 @@ void ControlState(common::HardwareStateManager& manager, ::std::vector<std::stri
}
break;
case INITIALIZE_AND_SHUTDOWN:
case INITIALIZE_AND_SHUTDOWN:
{
// 本体初期化を行う
if(!InitializeFileSystem())
if (!InitializeFileSystem())
{
s_RestoreState = FAIL;
}
@ -1568,7 +1594,6 @@ void ControlState(common::HardwareStateManager& manager, ::std::vector<std::stri
nn::ptm::CTR::ShutdownAsync(0, nn::fnd::TimeSpan::FromSeconds(0));
}
break;
}
}
@ -1660,6 +1685,7 @@ u32 GetProgress()
s_RestoreState == RESTORE_TWL_NAND ||
s_RestoreState == RESTORE_IN_PROGRESS ||
s_RestoreState == POST_RESTORE ||
s_RestoreState == RESTORE_TEST ||
s_RestoreState == RESTORE_DONE)
{
return GetImportProgress();

View File

@ -16,6 +16,7 @@
#include <nn.h>
#include <nn/fs/CTR/fs_ArchiveTypesForSystem.h>
#include <nn/fs/CTR/MPCore/fs_FileSystemBasePrivate.h>
#include <nn/fs/CTR/MPCore/fs_ApiIntegrityVerificationSeed.h>
#include <nn/cfg/CTR/cfg_ApiInit.h>
#include <nn/cfg/CTR/cfg_ApiNor.h> // cfg:norの初期化に必要
#include <nn/cfg/CTR/cfg_Api.h>
@ -622,6 +623,43 @@ bool InitializeFileSystem()
return true;
}
nn::Result GetNewIvs(void* oldBuf, size_t oldBufSize, void* newBuf, size_t newBufSize, size_t* newIvsSize)
{
if (oldBufSize < nn::fs::CTR::SIZE_INTEGRITY_VERIFICATION_SEED
|| newBufSize < nn::fs::CTR::SIZE_INTEGRITY_VERIFICATION_SEED
|| oldBuf == NULL || newBuf == NULL
)
{
return nn::Result(nn::Result::LEVEL_FATAL, nn::Result::SUMMARY_OUT_OF_RESOURCE, nn::Result::MODULE_COMMON,
nn::Result::DESCRIPTION_OUT_OF_MEMORY);
}
nn::Result result;
result = common::SdMountManager::Mount();
COMMON_LOGGER_RETURN_RESULT_IF_FAILED(result);
common::SdReaderWriter sdReader;
size_t readSize;
result = sdReader.ReadBufWithCmac(common::IVS_PATHNAME, oldBuf, oldBufSize, &readSize);
COMMON_LOGGER_RETURN_RESULT_IF_FAILED(result);
*newIvsSize = readSize;
// AES復号化する
nn::crypto::Initialize();
nn::crypto::SwAesCtrContext swAesCtrContest;
swAesCtrContest.Initialize(common::iv, common::key, sizeof(common::key));
result = swAesCtrContest.Decrypt(newBuf, oldBuf, readSize);
COMMON_LOGGER_RETURN_RESULT_IF_FAILED(result);
nn::crypto::Finalize();
result = common::SdMountManager::Unmount();
COMMON_LOGGER_RETURN_RESULT_IF_FAILED(result);
return nn::ResultSuccess();
}
nn::Result ImportIvs()
{
nn::Result result = nn::ResultSuccess();
@ -636,7 +674,7 @@ nn::Result ImportIvs()
size_t readSize;
result = sdReader.ReadBufWithCmac(common::IVS_PATHNAME, enc, bufSize, &readSize);
if(result.IsSuccess())
if (result.IsSuccess())
{
// SDから読み出し成功
result = nn::fs::MountSpecialArchive(common::NAND_ARCHIVE_NAME, nn::fs::CTR::ARCHIVE_TYPE_CTR_NAND);
@ -732,6 +770,7 @@ void ImportThreadFunc()
NN_LOG("Import Thread Finalize\n");
}
namespace
{
@ -1856,6 +1895,72 @@ bool IsImportSucceeded()
return s_IsImportSucceeded;
}
nn::Result GetNewSaveDirRoot(std::wstring& sysSaveRoot)
{
nn::Result result;
const size_t BUF_SIZE = 1024;
common::HeapManager oldBuf(BUF_SIZE);
common::HeapManager newBuf(BUF_SIZE);
size_t ivsSize;
result = GetNewIvs(oldBuf.GetAddr(), BUF_SIZE, newBuf.GetAddr(), BUF_SIZE, &ivsSize);
COMMON_LOGGER_RETURN_RESULT_IF_FAILED(result);
std::string root;
common::Util::GetSaveDataDirectoryRoot(root, newBuf.GetAddr(), ivsSize);
wchar_t rootName[256];
std::mbstowcs(rootName, root.c_str(), root.size() + 1);
sysSaveRoot = rootName;
return nn::ResultSuccess();
}
void TestCtrDataThreadFunc()
{
nn::Result result;
s_IsImportSucceeded = true;
// 新IVSディレクトリを取得
std::wstring sysSaveRoot;
result = GetNewSaveDirRoot(sysSaveRoot);
COMMON_LOGGER_RETURN_VOID_SET_BOOL_IF_FAILED(result, s_IsImportSucceeded);
result = nn::fs::MountSpecialArchive(common::NAND_ARCHIVE_NAME, nn::fs::CTR::ARCHIVE_TYPE_CTR_NAND);
COMMON_LOGGER_RETURN_VOID_SET_BOOL_IF_FAILED(result, s_IsImportSucceeded);
u32 fileNum = 0;
s64 fileSize = 0;
result = common::CalculateFileNum(
::std::wstring(common::NAND_DATA_ROOT_PATHNAME_WITH_SLASH) + sysSaveRoot + std::wstring(L"/"), fileNum,
fileSize);
COMMON_LOGGER_RETURN_VOID_SET_BOOL_IF_FAILED(result, s_IsImportSucceeded);
common::InitializeTransferProgress(fileSize);
size_t bufSize = common::GetAllocatableSize(AES_BLOCK_SIZE);
common::HeapManager buf(bufSize, AES_BLOCK_SIZE);
if(!common::TestReadDirectory((std::wstring(common::NAND_DATA_ROOT_PATHNAME_WITH_SLASH) + sysSaveRoot + std::wstring(L"/")).c_str(), buf.GetAddr(), bufSize
))
{
s_IsImportSucceeded = false;
return;
}
result = nn::fs::Unmount(common::NAND_ARCHIVE_NAME);
COMMON_LOGGER_RETURN_VOID_SET_BOOL_IF_FAILED(result, s_IsImportSucceeded);
}
void TestCtrData()
{
COMMON_LOGGER("Test NAND Data Start...\n");
s_ImportThread.Start(TestCtrDataThreadFunc, s_ImportThreadStack);
}
nn::Result ImportData()
{
static nn::Result result = nn::ResultSuccess();

View File

@ -160,6 +160,9 @@ bool ImportIvsData();
// 書き込みが成功したかどうか
bool IsImportSucceeded();
// 新たにスレッドを立て、CTR-NAND領域をテストする
void TestCtrData();
}
#endif /* IMPORTER_H_ */

View File

@ -767,4 +767,88 @@ bool AddPathNameAndUpdateContext(nn::fs::FileOutputStream* file, const wchar_t *
return true;
}
bool TestReadDirectory(const wchar_t* path, void* buf, const size_t bufSize)
{
nn::fs::Directory dir;
nn::fs::DirectoryEntry entry;
s32 numread = 0;
std::wostringstream targetStream;
NN_LOG("Read Directory %ls\n", path);
nn::Result result = dir.TryInitialize(path);
COMMON_LOGGER_RETURN_FALSE_IF_FAILED(result);
while (1)
{
result = dir.TryRead(&numread, &entry, 1);
COMMON_LOGGER_RETURN_FALSE_IF_FAILED(result);
if(numread == 0)
{
break;
}
if (std::wcscmp(entry.entryName, L".") == 0 || std::wcscmp(entry.entryName, L"..") == 0)
{
continue;
}
targetStream.str(L"");
targetStream.clear(std::stringstream::goodbit);
targetStream << path << entry.entryName;
// ディレクトリの場合
if (entry.attributes.isDirectory)
{
targetStream << L"/";
// 再帰処理
if (!TestReadDirectory(targetStream.str().c_str(), buf, bufSize))
{
return false;
}
}
// ファイルの場合
else
{
// ファイル作成
nn::fs::FileInputStream file;
s64 filesize;
s32 readsize;
NN_LOG("Read File %ls\n", targetStream.str().c_str());
// 読み込み対象ファイル開く
result = file.TryInitialize(targetStream.str().c_str());
COMMON_LOGGER_RETURN_FALSE_IF_FAILED(result);
// 読み込み対象ファイルのサイズ取得
result = file.TryGetSize(&filesize);
COMMON_LOGGER_RETURN_FALSE_IF_FAILED(result);
// ファイル全体を読みきるまでループ
while (1)
{
result = file.TryRead(&readsize, buf, bufSize);
COMMON_LOGGER_RETURN_FALSE_IF_FAILED(result);
if (readsize == 0)
{
break;
}
else
{
s_FinishedFileSize += readsize;
s_Progress = s_FinishedFileSize * 100 / s_TotalFileSize;
NN_LOG(
"finish = %lld, total = %lld, progress = %lld\n", s_FinishedFileSize, s_TotalFileSize, s_Progress);
}
}
}
}
return true;
}
}

View File

@ -57,6 +57,9 @@ void InitializeTransferProgress(u64 totalSize);
// 内部のバッファを使用するためスレッドアンセーフ
const char* GetCharStr(const wchar_t* path);
// pathで指定したディレクトリ以下を再帰的に読み込んでエラーが発生しないかテストする
bool TestReadDirectory(const wchar_t* path, void* buf, const size_t bufSize);
}
#endif /* FILETRANSFER_H_ */