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)