From a30fab87eeb149472bc9df081c1cd7ccae1d8c06 Mon Sep 17 00:00:00 2001 From: N2614 Date: Thu, 19 Jan 2012 08:38:15 +0000 Subject: [PATCH] =?UTF-8?q?TitleDownloader=E3=81=A7=E4=BD=BF=E3=81=86?= =?UTF-8?q?=E3=82=BF=E3=82=A4=E3=83=88=E3=83=AB=E3=83=AA=E3=82=B9=E3=83=88?= =?UTF-8?q?=E3=82=92=E5=A4=96=E9=83=A8=E3=81=8B=E3=82=89=E6=8C=87=E5=AE=9A?= =?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@582 385bec56-5757-e545-9c3a-d8741f4650f1 --- .../ConsoleRestore/TitleDownloader.cpp | 103 ++++++++++-------- .../sources/ConsoleRestore/TitleDownloader.h | 11 +- .../TitleDownloader/test_TitleDownloader.cpp | 7 +- 3 files changed, 71 insertions(+), 50 deletions(-) diff --git a/trunk/ConsoleDataMigration/sources/ConsoleRestore/TitleDownloader.cpp b/trunk/ConsoleDataMigration/sources/ConsoleRestore/TitleDownloader.cpp index e438180..f66e35b 100644 --- a/trunk/ConsoleDataMigration/sources/ConsoleRestore/TitleDownloader.cpp +++ b/trunk/ConsoleDataMigration/sources/ConsoleRestore/TitleDownloader.cpp @@ -32,7 +32,7 @@ namespace bit8 s_buffer1[400 * 1024]; -const size_t TITLE_DOWNLOADER_STACK_SIZE = 0x1000; +const size_t TITLE_DOWNLOADER_STACK_SIZE = 0x2000; nn::os::Thread s_TitleDownloaderThread; nn::os::StackBuffer s_TitleDownloaderThreadStack; u64 s_Progress; @@ -120,10 +120,14 @@ void TwlTitleDownloaderThreadFunc() TitleDownloader TwlTitleDownloader; s_Progress = 0; - if(TwlTitleDownloader.ListUpTwlTitles().IsFailure()) + size_t num = 0; + nn::ProgramId list[256]; + TitleDownloader::m_Result = ListUpTwlTitles(list, &num); + if(TitleDownloader::m_Result.IsFailure()) { return; } + TwlTitleDownloader.SetupTitleList(list, num); TwlTitleDownloader.Start(); } @@ -168,6 +172,54 @@ TitleDownloader::~TitleDownloader() } +nn::Result ListUpTwlTitles(nn::ProgramId* list, size_t* num) +{ + nn::Result result; + COMMON_LOGGER("Read TwlTitle List.\n"); + + *num = 0; + size_t heapSize = common::GetAllocatableSize(); + if(heapSize > common::FILE_COPY_HEAP_SIZE) + { + heapSize = common::FILE_COPY_HEAP_SIZE; + } + common::HeapManager heap(heapSize); + char* titleListBuf = reinterpret_cast (heap.GetAddr()); + + size_t readSize = 0; + if (titleListBuf != NULL) + { + common::SdReaderWriter sdReader; + result = sdReader.ReadBufWithCmac(common::TWL_TITLELIST_PATHNAME, titleListBuf, heapSize, &readSize); + COMMON_LOGGER_RESULT_IF_FAILED_WITH_LINE(result); + if (result.IsSuccess()) + { + u32 listHead = 0; + for (u32 i = 0; i < readSize; i++) + { + if (titleListBuf[i] == '\n') + { + char ProgramIdStr[32]; + char *error; + std::memcpy(ProgramIdStr, &titleListBuf[listHead], i - listHead); + list[*num] = std::strtoull(ProgramIdStr, &error, 16); + (*num)++; + COMMON_LOGGER_DETAIL("%016llx\n", list[*num - 1]); + + listHead = i + 1; + } + } + } + COMMON_LOGGER("%d Title(s) found.\n", *num); + } + else + { + result = nn::Result(nn::Result::LEVEL_FATAL, nn::Result::SUMMARY_OUT_OF_RESOURCE, nn::Result::MODULE_COMMON, + nn::Result::DESCRIPTION_OUT_OF_MEMORY); + } + + return result; +} nn::Result WaitCancelled() { @@ -214,51 +266,14 @@ void TitleDownloader::Start() } } -nn::Result TitleDownloader::ListUpTwlTitles() +void TitleDownloader::SetupTitleList(nn::ProgramId* list, size_t num) { - COMMON_LOGGER("Read TwlTitle List.\n"); - - size_t heapSize = common::GetAllocatableSize(); - if(heapSize > common::FILE_COPY_HEAP_SIZE) + const size_t listNum = nn::math::Min(num, IMPORTABLE_TITLE_MAX); + for(u32 i = 0; i < listNum; i++) { - heapSize = common::FILE_COPY_HEAP_SIZE; + m_ProgramIdList[i] = list[i]; } - common::HeapManager heap(heapSize); - char* titleListBuf = reinterpret_cast (heap.GetAddr()); - - size_t readSize = 0; - if (titleListBuf != NULL) - { - common::SdReaderWriter sdReader; - m_Result = sdReader.ReadBufWithCmac(common::TWL_TITLELIST_PATHNAME, titleListBuf, heapSize, &readSize); - COMMON_LOGGER_RESULT_IF_FAILED_WITH_LINE(m_Result); - if (m_Result.IsSuccess()) - { - u32 listHead = 0; - for (u32 i = 0; i < readSize; i++) - { - if (titleListBuf[i] == '\n') - { - char ProgramIdStr[32]; - char *error; - std::memcpy(ProgramIdStr, &titleListBuf[listHead], i - listHead); - m_ProgramIdList[m_TiteNum] = std::strtoull(ProgramIdStr, &error, 16); - m_TiteNum++; - COMMON_LOGGER_DETAIL("%016llx\n", m_ProgramIdList[m_TiteNum - 1]); - - listHead = i + 1; - } - } - } - COMMON_LOGGER("%d Title(s) found.\n", m_TiteNum); - } - else - { - m_Result = nn::Result(nn::Result::LEVEL_FATAL, nn::Result::SUMMARY_OUT_OF_RESOURCE, nn::Result::MODULE_COMMON, - nn::Result::DESCRIPTION_OUT_OF_MEMORY); - } - - return m_Result; + m_TiteNum = listNum; } } diff --git a/trunk/ConsoleDataMigration/sources/ConsoleRestore/TitleDownloader.h b/trunk/ConsoleDataMigration/sources/ConsoleRestore/TitleDownloader.h index 70f6c10..bb37d36 100644 --- a/trunk/ConsoleDataMigration/sources/ConsoleRestore/TitleDownloader.h +++ b/trunk/ConsoleDataMigration/sources/ConsoleRestore/TitleDownloader.h @@ -24,6 +24,9 @@ namespace ConsoleRestore // 新たにスレッドを立て、TWLタイトルのダウンロードを開始する void StartTwlTitleDownload(); +//! @brief ダウンロードするTWLタイトルをSDカードからリストアップする +nn::Result ListUpTwlTitles(nn::ProgramId* list, size_t* num); + // タイトルのダウンロードスレッドが終了したかどうか bool IsDownloadTitleFinished(); @@ -43,14 +46,12 @@ public: TitleDownloader(); virtual ~TitleDownloader(); + //! @brief タイトルリストを設定する + void SetupTitleList(nn::ProgramId* list, size_t num); + // タイトルのダウンロードを開始する void Start(); - // Twlタイトルをリストアップする - nn::Result ListUpTwlTitles(); - - //TODO: プリインストールタイトルをリストアップする - NN_PADDING4; static nn::Result m_Result; diff --git a/trunk/ConsoleDataMigration/sources/tests/ConsoleRestore/TitleDownloader/test_TitleDownloader.cpp b/trunk/ConsoleDataMigration/sources/tests/ConsoleRestore/TitleDownloader/test_TitleDownloader.cpp index 10ab873..e2e7dea 100644 --- a/trunk/ConsoleDataMigration/sources/tests/ConsoleRestore/TitleDownloader/test_TitleDownloader.cpp +++ b/trunk/ConsoleDataMigration/sources/tests/ConsoleRestore/TitleDownloader/test_TitleDownloader.cpp @@ -100,7 +100,12 @@ void TitleDownloaderTest::ListUp() NN_LOG("WriteTwlTitleData\n"); ConsoleRestore::TitleDownloader dl; - dl.ListUpTwlTitles(); + size_t num = 0; + nn::ProgramId list[256]; + + ConsoleRestore::ListUpTwlTitles(list, &num); + dl.SetupTitleList(list, num); + __breakpoint(0); } NN_TEST_DEFINE_MAIN(TitleDownloaderTest)