From 2551da56f78203e23e8d5dccdc744a4692fa9c4c Mon Sep 17 00:00:00 2001 From: N2614 Date: Wed, 20 Apr 2011 08:19:08 +0000 Subject: [PATCH] =?UTF-8?q?Controller=E3=82=92=E6=89=8B=E7=9B=B4=E3=81=97?= =?UTF-8?q?=20IVS=E3=81=AE=E3=83=80=E3=82=A6=E3=83=B3=E3=83=AD=E3=83=BC?= =?UTF-8?q?=E3=83=89=E3=80=81Unregister=E3=80=81Shop::Connect=E3=82=92?= =?UTF-8?q?=E8=A1=8C=E3=81=88=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@207 385bec56-5757-e545-9c3a-d8741f4650f1 --- .../ConsoleRestore/ConsoleRestore.cpp | 3 +- .../ConsoleRestore/Controller.cpp | 1074 ++++++++++++----- .../ConsoleRestore/Controller.h | 2 +- .../ConsoleRestore/Importer.cpp | 40 +- .../ConsoleRestore/Importer.h | 2 + .../ConsoleRestore/OMakefile | 2 + .../ConsoleRestore/Shop.cpp | 321 +++++ .../ConsoleRestore/Shop.h | 40 + .../ConsoleRestore/TitleDownloader.cpp | 59 + .../ConsoleRestore/TitleDownloader.h | 42 + .../common/FileChecker.cpp | 11 +- .../ConsoleDataMigration/common/FileChecker.h | 8 +- trunk/ConsoleDataMigration/common/FileName.h | 2 + 13 files changed, 1277 insertions(+), 329 deletions(-) create mode 100644 trunk/ConsoleDataMigration/ConsoleRestore/Shop.cpp create mode 100644 trunk/ConsoleDataMigration/ConsoleRestore/Shop.h create mode 100644 trunk/ConsoleDataMigration/ConsoleRestore/TitleDownloader.cpp create mode 100644 trunk/ConsoleDataMigration/ConsoleRestore/TitleDownloader.h diff --git a/trunk/ConsoleDataMigration/ConsoleRestore/ConsoleRestore.cpp b/trunk/ConsoleDataMigration/ConsoleRestore/ConsoleRestore.cpp index 36ba997..1bae2a3 100644 --- a/trunk/ConsoleDataMigration/ConsoleRestore/ConsoleRestore.cpp +++ b/trunk/ConsoleDataMigration/ConsoleRestore/ConsoleRestore.cpp @@ -321,7 +321,6 @@ extern "C" void nnMain(void) bool flip = false; - bool continueRestore = false; for(;;) { @@ -383,7 +382,7 @@ extern "C" void nnMain(void) // 進捗確認メッセージを兼ねる? ::std::vector operationMessage; - ControlState(operationMessage, nextStep, continueRestore); + ControlState(operationMessage, nextStep); nn::util::FloatColor titleColor; diff --git a/trunk/ConsoleDataMigration/ConsoleRestore/Controller.cpp b/trunk/ConsoleDataMigration/ConsoleRestore/Controller.cpp index 42d4f5f..970c7c5 100644 --- a/trunk/ConsoleDataMigration/ConsoleRestore/Controller.cpp +++ b/trunk/ConsoleDataMigration/ConsoleRestore/Controller.cpp @@ -31,6 +31,8 @@ #include "Importer.h" #include "Updater.h" #include "NtpClient.h" +#include "TitleDownloader.h" +#include "Shop.h" namespace ConsoleRestore { @@ -38,37 +40,6 @@ namespace ConsoleRestore namespace { -typedef enum RestoreState -{ - STARTUP, // 初期値 - SERIAL_IS_NOT_IN_SD, // シリアルナンバーファイルがSDカードにないことを表示 - SERIAL_IN_SD, // シリアルナンバーの情報を表示 - UPDATE_IN_PROGRESS, // アップデート中 - UPDATE_DONE, // アップデート完了 - NUP_ONLY_WAIT_SD_EJECT, // NUP_ONLYモードでSDカード抜き待ち - NUP_ONLY_WAIT_NEXT, // NUP_ONLYモードでキー入力待ち - RESTORE_READ_FILELIST, // ファイル一覧の読み込み - RESTORE_TWL_NAND, // TWL NANDの書き込み中 - RESTORE_TWL_SOUND, // TWLサウンドの書き込み中 - RESTORE_TWL_PHOTO, // TWL写真の書き込み中 - RESTORE_IN_PROGRESS, // 書き込み中 - POST_RESTORE, // 書き込み後の処理 - RESTORE_DONE, // 書き込み完了 - REBOOTING, // 再起動を行う - ERASE, // 削除処理を行う - RESTORE_CAL, // cfgの一部をcal値で上書きする - TIME_ADJUST, // 時計あわせを行う - WAIT_SD_EJECT, // SDカードぬき待ち - ALL_DONE, // すべて完了 - SHUTDOWN, // シャットダウン中 - FAIL // 失敗 -} RestoreState; - -// Restore状態管理 -RestoreState s_RestoreState = STARTUP; -// Restoreモード管理 -RestoreMode s_RestoreMode = RESTORE_MODE_RESTORE; - // インターネット設定を読んだかどうか bool s_ReadSettingDone = false; // インターネット設定を読んだ結果 @@ -99,15 +70,369 @@ bool s_WifiStatusOffAnnotation = false; bool s_ExecuteFgNup = false; // FGNUPを何回リトライしたか u32 s_FgNupRetryCount = 0; +// 時計同期モードかどうか +bool s_IsSyncClock = false; +// アカウント削除を開始したかどうか +bool s_ExecuteDeleteAccount = false; +// アカウント削除を何回リトライしたか +u32 s_DeleteAccountRetryCount = 0; +// IVS取得を開始したかどうか +bool s_ExecuteGetIvs = false; +// IVS取得を何回リトライしたか +u32 s_GetIvsRetryCount = 0; +// ConnectOnlyを開始したかどうか +bool s_ExecuteConnectOnly = false; +// ConnectOnlyを回リトライしたか +u32 s_ConnectOnlyRetryCount = 0; - -} // namespace +bool CheckAndReadAPSetting(::std::vector& operationMessage); bool NeedsAcAdater() { return IsBatteryLower() && !IsAdapterConnected(); } +typedef enum RestoreState +{ + STARTUP, // 初期値 + INITIALIZE_CONSOLE, // セーブデータ領域のNAND初期化を行う + SERIAL_IS_NOT_IN_SD, // シリアルナンバーファイルがSDカードにないことを表示 + SERIAL_IN_SD, // シリアルナンバーの情報を表示 + WAIT_START_UPDATE, // アップデート開始入力待ち + WAIT_START_IMPORT, // 書き込み開始入力待ち + WAIT_START_SYNC_CLOCK, // 時計合わせ開始入力待ち + IMPORT_RTC, // RTC同期お + UPDATE_IN_PROGRESS, // アップデート中 + UPDATE_DONE, // アップデート完了 + NUP_ONLY_WAIT_SD_EJECT, // NUP_ONLYモードでSDカード抜き待ち + NUP_ONLY_WAIT_NEXT, // NUP_ONLYモードでキー入力待ち + DOWNLOAD_IVS, // インフラからIVSを取得する + DOWNLOAD_IVS_DONE, // インフラからIVSを取得完了 + DELETE_ACCOUNT, // ショップアカウントを削除する + DELETE_ACCOUNT_DONE, // ショップアカウント削除完了 + CONNECT_ONLY, // ショップに接続するのみ + READ_FILELIST, // ファイル一覧の読み込み + RESTORE_TWL_NAND, // TWL NANDの書き込み中 + RESTORE_TWL_SOUND, // TWLサウンドの書き込み中 + RESTORE_TWL_PHOTO, // TWL写真の書き込み中 + RESTORE_IN_PROGRESS, // 書き込み中 + POST_RESTORE, // 書き込み後の処理 + RESTORE_DONE, // 書き込み完了 + REBOOTING, // 再起動を行う + ERASE, // 削除処理を行う + RESTORE_CAL, // cfgの一部をcal値で上書きする + TIME_ADJUST, // 時計あわせを行う + DOWNLOAD_TWL, // TWLアプリ本体をダウンロードする + WAIT_SD_EJECT, // SDカードぬき待ち + ALL_DONE, // すべて完了 + SHUTDOWN, // シャットダウン中 + FAIL // 失敗 +} RestoreState; + + + +// Restore状態管理 +RestoreState s_RestoreState = STARTUP; +// Restoreモード管理 +RestoreMode s_RestoreMode = RESTORE_MODE_RESTORE; + +void CheckSdInserted(::std::vector& message, bool& goNextStep); +void CheckAcAdapter(::std::vector& message, bool& goNextStep); +void CheckSdWritable(::std::vector& message, bool& goNextStep); +void CheckApSetting(::std::vector& message, bool& goNextStep); +void CheckNupExecuted(::std::vector& message, bool& goNextStep); +void CheckDownloadIvs(::std::vector& message, bool& goNextStep); +void CheckAccountDeleted(::std::vector& message, bool& goNextStep); +void CheckWriteFinished(::std::vector& message, bool& goNextStep); +void CheckReadIvs(::std::vector& message, bool& goNextStep); +void CheckConsoleInitialized(::std::vector& message, bool& goNextStep); +void CheckExistsSerialNumber(::std::vector& message, bool& goNextStep); +void CheckIvsinSd(::std::vector& message, bool& goNextStep); +void CheckRegioinSd(::std::vector& message, bool& goNextStep); + +// SDカード挿入チェック +void CheckSdInserted(::std::vector& message, bool& goNextStep) +{ + if (nn::fs::IsSdmcInserted()) + { + CheckAcAdapter(message, goNextStep); + } + else + { + message.push_back(::std::string("Insert SD Card!!")); + s_RestoreState = STARTUP; + } +} + +// ACアダプタが必要かどうかチェック +void CheckAcAdapter(::std::vector& message, bool& goNextStep) +{ + // ACアダプタが必要か? + if (NeedsAcAdater()) + { + message.push_back(::std::string("Connect AC Adapter!!")); + s_RestoreState = STARTUP; + } + else + { + CheckSdWritable(message, goNextStep); + } +} + +// SDカード書き込みチェック +void CheckSdWritable(::std::vector& message, bool& goNextStep) +{ + // SDカードに書き込みできるか? + if (nn::fs::IsSdmcWritable()) + { + CheckApSetting(message, goNextStep); + } + else + { + if (!s_SdWriteProetctAnnotation) + { + s_SdWriteProetctAnnotation = true; + common::PlaySound(common::SOUND_ANNOTATION); + } + message.push_back(::std::string("Can't Write SD Card!!\n")); + s_RestoreState = STARTUP; + } +} + + +// 設定ファイル書式チェック +void CheckApSetting(::std::vector& message, bool& goNextStep) +{ + if (CheckAndReadAPSetting(message)) + { + CheckNupExecuted(message, goNextStep); + } + else + { + s_RestoreState = STARTUP; + } +} + +// NUP済みかどうかチェック +void CheckNupExecuted(::std::vector& message, bool& goNextStep) +{ + if (common::ExistsUpdateCheckedFile()) + { + if (s_NupOnlyMode) + { + s_RestoreState = NUP_ONLY_WAIT_SD_EJECT; + + // リストア状態チェックファイルをすべて削除 + DeleteAllCheckFiles(); + } + else + { + CheckAccountDeleted(message, goNextStep); + } + } + else + { + // NUPを実行 + if (CheckAndReadAPSetting(message)) + { + if (nn::nwm::CTR::IsWifiOn()) + { + // ネットワークアップデートを行う + s_RestoreState = WAIT_START_UPDATE; + } + else + { + if (!s_WifiStatusOffAnnotation) + { + s_WifiStatusOffAnnotation = true; + common::PlaySound(common::SOUND_ANNOTATION); + } + + message.push_back(::std::string("Wireless is Off\n")); + s_RestoreState = STARTUP; + } + } + } +} + +// インフラからIVS取得済みかチェック +void CheckDownloadIvs(::std::vector& message, bool& goNextStep) +{ + NN_UNUSED_VAR(message); + NN_UNUSED_VAR(goNextStep); + + // IVS取得確認ファイルがあるか? + if (common::ExistsDownloadIvsCheckedFile()) + { + s_RestoreState = CONNECT_ONLY; + } + else + { + s_RestoreState = DOWNLOAD_IVS; + } + +} + +// アカウント削除済みかチェック +void CheckAccountDeleted(::std::vector& message, bool& goNextStep) +{ + // アカウント削除確認ファイルがあるか? + if (common::ExistsDeleteAccountChecked()) + { + CheckDownloadIvs(message, goNextStep); + } + else + { + // 同一本体下記書き戻しの場合はアカウント削除しない + if(EqualsDeviceIdFileandDeviceId().IsSuccess()) + { + CreateDeleteAccountFinishedFile(); + CheckDownloadIvs(message, goNextStep); + } + else + { + s_RestoreState = DELETE_ACCOUNT; + } + } +} + +// 書き込み完了かどうかチェック +void CheckWriteFinished(::std::vector& message, bool& goNextStep) +{ + NN_UNUSED_VAR(goNextStep); + + // SDカードに書き込み完了ファイルがあるか? + if (common::ExistsWriteFinishedFile()) + { + if (CheckAndReadAPSetting(message)) + { + if (nn::nwm::CTR::IsWifiOn()) + { + // 削除処理を行う + s_RestoreState = WAIT_START_SYNC_CLOCK; + } + else + { + if (!s_WifiStatusOffAnnotation) + { + s_WifiStatusOffAnnotation = true; + common::PlaySound(common::SOUND_ANNOTATION); + } + message.push_back(::std::string("Wireless is Off\n")); + } + } + } + else + { + CheckReadIvs(message, goNextStep); + } +} + +// IVSを読めるかどうかチェック +void CheckReadIvs(::std::vector& message, bool& goNextStep) +{ + // IVSを読めるか? + if (CanReadIVS()) + { + CheckConsoleInitialized(message, goNextStep); + } + else + { + s_RestoreState = FAIL; + COMMON_LOGGER("Can't Read IVS!!"); + } +} + +// 本体初期化済みかどうかチェック +void CheckConsoleInitialized(::std::vector& message, bool& goNextStep) +{ + // 本体初期化完了ファイルがあるか? + if (common::ExistsConsoleInitializedFile()) + { + CheckExistsSerialNumber(message, goNextStep); + } + else + { + CheckIvsinSd(message, goNextStep); + } +} + +// シリアルナンバーがあるかどうかチェック +void CheckExistsSerialNumber(::std::vector& message, bool& goNextStep) +{ + NN_UNUSED_VAR(goNextStep); + + // SDカードにシリアルナンバーがあるか? + if (common::ExistsSerialNumberFile()) + { + u8 serial[nn::cfg::CTR::CFG_SECURE_INFO_SERIAL_NO_LEN]; + nn::Result result = ReadSerialNumber(serial); + if (result.IsSuccess()) + { + ::std::string serialStr(reinterpret_cast (serial)); + message.push_back(::std::string("Serial Number in SD : ") + serialStr); + CheckRegioinSd(message, goNextStep); + } + else + { + s_RestoreState = FAIL; + } + } + else + { + COMMON_LOGGER("Can't Read Serial Number in SD Card!!\n"); + s_RestoreState = SERIAL_IS_NOT_IN_SD; + CheckRegioinSd(message, goNextStep); + } +} + +// SDカードにIVSがあるかどうかチェック +void CheckIvsinSd(::std::vector& message, bool& goNextStep) +{ + NN_UNUSED_VAR(message); + NN_UNUSED_VAR(goNextStep); + + if (common::ExistsIVSFile()) + { + s_RestoreState = INITIALIZE_CONSOLE; + } + else + { + // 移行不能なのでFAIL + COMMON_LOGGER("Can't Read IVS in SD Card!!\n"); + s_RestoreState = FAIL; + } +} + +// SDカードにリージョンデータがあるかどうかチェック +void CheckRegioinSd(::std::vector& message, bool& goNextStep) +{ + NN_UNUSED_VAR(message); + NN_UNUSED_VAR(goNextStep); + + // SDカードにリージョンデータがあるか? + if (common::ExistsRegionData()) + { + // リージョンデータは一致しているか? + if (EqualsRegionDataandRegion().IsFailure()) + { + COMMON_LOGGER("Current Region and Region in SD differ!!\n"); + s_RestoreState = FAIL; + } + else + { + s_RestoreState = WAIT_START_IMPORT; + } + + } + else + { + // 移行不能なのでFAIL + COMMON_LOGGER("Can't Read Region in SD Card!!\n"); + s_RestoreState = FAIL; + } +} + bool CheckAndReadAPSetting(::std::vector& operationMessage) { using namespace common; @@ -188,7 +513,9 @@ nn::Result ExecSyncMcuRtc() return result; } -void ControlState(::std::vector& operationMessage, bool& nextStep, bool& continueRestore) +} // namespace + +void ControlState(::std::vector& operationMessage, bool& nextStep) { using namespace common; nn::Result result; @@ -199,240 +526,87 @@ void ControlState(::std::vector& operationMessage, bool& nextStep, // 起動時 case STARTUP: { - bool error = false; - bool needsUpdate = false; - bool needsErase = false; - bool validApSetting = false; + CheckSdInserted(operationMessage, nextStep); + } + break; - // SDカードが挿入されているか? - if (nn::fs::IsSdmcInserted()) + + case INITIALIZE_CONSOLE: + { + COMMON_LOGGER("Initialize Console\n"); + + // 本体初期化完了ファイルを作る + CreateConsoleInitializedFile(); + + // ファイルシステムの初期化を行う + InitializeFileSystem(); + s_RestoreState = REBOOTING; + } + break; + + case WAIT_START_UPDATE: + { + operationMessage.push_back(::std::string("Push A or START Button")); + operationMessage.push_back(::std::string("Network Update Mode")); + if (!s_PlayedStartCursor) { - // SDカードに書き込みできるか? - if (!nn::fs::IsSdmcWritable()) - { - if (!s_SdWriteProetctAnnotation) - { - s_SdWriteProetctAnnotation = true; - PlaySound(SOUND_ANNOTATION); - } - operationMessage.push_back(::std::string("Can't Write SD Card!!\n")); - break; - } + PlaySound(SOUND_CURSOR); + s_PlayedStartCursor = true; + } - validApSetting = CheckAndReadAPSetting(operationMessage); - if (!validApSetting) - { - error = true; - } - else - { - // NUP済みかどうか - if (ExistsUpdateCheckedFile()) - { - if (s_NupOnlyMode) - { - s_RestoreState = NUP_ONLY_WAIT_SD_EJECT; + if (nextStep) + { + COMMON_LOGGER("Start Network Update\n"); + s_RestoreState = IMPORT_RTC; + } + } + break; - // リストア状態チェックファイルをすべて削除 - DeleteAllCheckFiles(); + case WAIT_START_IMPORT: + { + operationMessage.push_back(::std::string("Push A or START Button")); + operationMessage.push_back(::std::string("Import Data Mode")); + if (!s_PlayedStartCursor) + { + PlaySound(SOUND_CURSOR); + s_PlayedStartCursor = true; + } - break; - } + if (nextStep) + { + s_RestoreState = READ_FILELIST; + } + } + break; - // SDカードに書き込み完了ファイルがあるか? - if (!ExistsWriteFinishedFile()) - { - // IVSを読めるか? - if (CanReadIVS()) - { - // 本体初期化完了ファイルがあるか? - if (ExistsConsoleInitializedFile()) - { - // SDカードにシリアルナンバーがあるか? - if (!ExistsSerialNumberFile()) - { - COMMON_LOGGER("Can't Read Serial Number in SD Card!!\n"); - error = true; - s_RestoreState = SERIAL_IS_NOT_IN_SD; - } - else - { - u8 serial[nn::cfg::CTR::CFG_SECURE_INFO_SERIAL_NO_LEN]; - result = ReadSerialNumber(serial); - if(result.IsSuccess()) - { - ::std::string serialStr(reinterpret_cast (serial)); - operationMessage.push_back(::std::string("Serial Number in SD : ") + serialStr); - } - else - { - error = true; - s_RestoreState = FAIL; - } - } + 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")); + if (!s_PlayedStartCursor) + { + PlaySound(SOUND_CURSOR); + s_PlayedStartCursor = true; + } + if (nextStep) + { + COMMON_LOGGER("Erase Trash\n"); + s_RestoreState = ERASE; + } + } + break; - // SDカードにリージョンデータがあるか? - if (ExistsRegionData()) - { - // リージョンデータは一致しているか? - if (EqualsRegionDataandRegion().IsFailure()) - { - COMMON_LOGGER("Current Region and Region in SD differ!!\n"); - error = true; - s_RestoreState = FAIL; - } - } - else - { - // 移行不能なのでFAIL - COMMON_LOGGER("Can't Read Region in SD Card!!\n"); - error = true; - s_RestoreState = FAIL; - } - - } - else - { - if (!ExistsIVSFile()) - { - // 移行不能なのでFAIL - COMMON_LOGGER("Can't Read IVS in SD Card!!\n"); - error = true; - s_RestoreState = FAIL; - } - else - { - COMMON_LOGGER("Initialize Console\n"); - - // 本体初期化完了ファイルを作る - CreateConsoleInitializedFile(); - - // ファイルシステムの初期化を行う - InitializeFileSystem(); - error = true; - s_RestoreState = REBOOTING; - } - } - } - else - { - error = true; - operationMessage.push_back(::std::string("Can't Read IVS!!")); - } - } - else - { - if (validApSetting) - { - if(nn::nwm::CTR::IsWifiOn()) - { - // 削除処理を行う - needsErase = true; - } - else - { - if(!s_WifiStatusOffAnnotation) - { - s_WifiStatusOffAnnotation = true; - PlaySound(SOUND_ANNOTATION); - } - operationMessage.push_back(::std::string("Wireless is Off\n")); - error = true; - } - } - } - } - else - { - if (validApSetting) - { - if(nn::nwm::CTR::IsWifiOn()) - { - // ネットワークアップデートを行う - needsUpdate = true; - } - else - { - if (!s_WifiStatusOffAnnotation) - { - s_WifiStatusOffAnnotation = true; - PlaySound(SOUND_ANNOTATION); - } - - operationMessage.push_back(::std::string("Wireless is Off\n")); - error = true; - } - } - } - - } + case IMPORT_RTC: + { + result = ExecSyncMcuRtc(); + if (result <= nn::fs::ResultVerificationFailed()) + { + s_RestoreState = FAIL; } else { - error = true; - operationMessage.push_back(::std::string("Insert SD Card!!")); - } - - // ACアダプタが必要か? - if (NeedsAcAdater()) - { - error = true; - operationMessage.push_back(::std::string("Connect AC Adapter!!")); - } - - // エラーが無ければ進行用メッセージ表示 - if (!error) - { - operationMessage.push_back(::std::string("Push A or START Button")); - if(needsUpdate) - { - operationMessage.push_back(::std::string("Network Update Mode")); - } - else if(needsErase) - { - operationMessage.push_back(::std::string("Clock Sync Mode")); - } - else - { - operationMessage.push_back(::std::string("Import Data Mode")); - } - - if(!s_PlayedStartCursor) - { - PlaySound(SOUND_CURSOR); - s_PlayedStartCursor = true; - } - } - - if (nextStep && !error) - { - if (needsUpdate) - { - COMMON_LOGGER("Start Network Update\n"); - s_RestoreState = UPDATE_IN_PROGRESS; - } - else if(needsErase) - { - COMMON_LOGGER("Erase Trash\n"); - s_RestoreState = ERASE; - } - else - { - COMMON_LOGGER("Start Import Data\n"); - // Zero NUP限定 - // RTC同期を行う - // NUPされない場合があるのでここで同期 - result = ExecSyncMcuRtc(); - if(result <= nn::fs::ResultVerificationFailed()) - { - s_RestoreState = FAIL; - } - else - { - s_RestoreState = RESTORE_READ_FILELIST; - } - } + s_RestoreState = UPDATE_IN_PROGRESS; } } break; @@ -452,7 +626,7 @@ void ControlState(::std::vector& operationMessage, bool& nextStep, if (nextStep) { - s_RestoreState = RESTORE_READ_FILELIST; + s_RestoreState = READ_FILELIST; } } break; @@ -460,19 +634,16 @@ void ControlState(::std::vector& operationMessage, bool& nextStep, // アップデート中 case UPDATE_IN_PROGRESS: { - continueRestore = true; - // ACアダプタが必要か? if (NeedsAcAdater()) { - continueRestore = false; operationMessage.push_back(::std::string("Connect AC Adapter!!")); } // アップデートを行う - if(!s_ExecuteFgNup) + if (!s_ExecuteFgNup) { - if(ImportCountryLanguageData().IsSuccess()) + if (ImportCountryLanguageData().IsSuccess()) { StartFGNetworkUpdate(); s_ExecuteFgNup = true; @@ -488,15 +659,14 @@ void ControlState(::std::vector& operationMessage, bool& nextStep, PutAliveMessage(operationMessage, "Updating"); } - if (IsNetworkUpdateFinished()) { FinishFGNetworkUpdate(); // エラーがあったら表示する - if(GetUpdateResult().IsFailure()) + if (GetUpdateResult().IsFailure()) { // APが見つからない - if(GetUpdateResult() == nn::ac::ResultNotFoundAccessPoint()) + if (GetUpdateResult() == nn::ac::ResultNotFoundAccessPoint()) { COMMON_LOGGER("No Access Point Found!"); } @@ -532,13 +702,13 @@ void ControlState(::std::vector& operationMessage, bool& nextStep, } break; - // アップデート完了 + // アップデート完了 case UPDATE_DONE: { operationMessage.push_back(::std::string("Network Update Done.")); operationMessage.push_back(::std::string("Press A or START Button to Reboot")); - if(!s_PlayedRebootCursor) + if (!s_PlayedRebootCursor) { PlaySound(SOUND_CURSOR); s_PlayedRebootCursor = true; @@ -551,14 +721,267 @@ void ControlState(::std::vector& operationMessage, bool& nextStep, } break; - case RESTORE_READ_FILELIST: + case DOWNLOAD_IVS: + { + // ACアダプタが必要か? + if (NeedsAcAdater()) + { + operationMessage.push_back(::std::string("Connect AC Adapter!!")); + } + + // アップデートを行う + if (!s_ExecuteGetIvs) + { + if (ImportCountryLanguageData().IsSuccess()) + { + StartShopOperationSingle(SHOP_OPERATION_GET_IVS); + s_ExecuteGetIvs = true; + } + else + { + s_RestoreState = FAIL; + } + } + + // 動いていることを表示 + { + PutAliveMessage(operationMessage, "Get Ivs"); + } + + if (IsShopOperationSingleFinished()) + { + FinishShopOperationSingle(); + // エラーがあったら表示する + if (GetShopOperationSingleResult().IsFailure()) + { + // APが見つからない + if (GetUpdateResult() == nn::ac::ResultNotFoundAccessPoint()) + { + COMMON_LOGGER("No Access Point Found!"); + } + } + + if (GetShopOperationSingleResult().IsSuccess()) + { + COMMON_LOGGER("Get Ivs Finished.\n"); + // IVS取得完了ファイルを作成 + CreateDownloadIvsFinishedFile(); + + s_RestoreState = DOWNLOAD_IVS_DONE; + } + else + { + if (s_GetIvsRetryCount++ < RETRY_MAX) + { + // エラーのためやり直す + COMMON_LOGGER_RESULT_IF_FAILED(GetShopOperationSingleResult()); + COMMON_LOGGER("Get Ivs Failed. Retrying... %d\n", s_GetIvsRetryCount); + + // Unregister用のスレッドを作るとこからやり直し + s_ExecuteGetIvs = false; + } + else + { + s_RestoreState = FAIL; + } + } + + } + } + break; + + + case DOWNLOAD_IVS_DONE: + { + operationMessage.push_back(::std::string("Get Ivs Done.")); + operationMessage.push_back(::std::string("Press A or START Button to Reboot")); + + if (!s_PlayedRebootCursor) + { + PlaySound(SOUND_CURSOR); + s_PlayedRebootCursor = true; + } + + if (nextStep) + { + s_RestoreState = REBOOTING; + } + } + break; + + + case DELETE_ACCOUNT: + { + // ACアダプタが必要か? + if (NeedsAcAdater()) + { + operationMessage.push_back(::std::string("Connect AC Adapter!!")); + } + + // アップデートを行う + if (!s_ExecuteDeleteAccount) + { + if (ImportCountryLanguageData().IsSuccess()) + { + StartShopOperationSingle(SHOP_OPERATION_UNREGISTER); + s_ExecuteDeleteAccount = true; + } + else + { + s_RestoreState = FAIL; + } + } + + // 動いていることを表示 + { + PutAliveMessage(operationMessage, "Deleting Account"); + } + + if (IsShopOperationSingleFinished()) + { + FinishShopOperationSingle(); + // エラーがあったら表示する + if (GetShopOperationSingleResult().IsFailure()) + { + // APが見つからない + if (GetUpdateResult() == nn::ac::ResultNotFoundAccessPoint()) + { + COMMON_LOGGER("No Access Point Found!"); + } + } + + if (GetShopOperationSingleResult().IsSuccess()) + { + COMMON_LOGGER("Delete Account Finished.\n"); + // アカウント削除完了ファイルを作成 + CreateDeleteAccountFinishedFile(); + + s_RestoreState = DELETE_ACCOUNT_DONE; + } + else + { + if (s_DeleteAccountRetryCount++ < RETRY_MAX) + { + // エラーのためやり直す + COMMON_LOGGER_RESULT_IF_FAILED(GetShopOperationSingleResult()); + COMMON_LOGGER("Delete Account Failed. Retrying... %d\n", s_DeleteAccountRetryCount); + + // Unregister用のスレッドを作るとこからやり直し + s_ExecuteDeleteAccount = false; + } + else + { + s_RestoreState = FAIL; + } + } + + } + } + break; + + case DELETE_ACCOUNT_DONE: + { + operationMessage.push_back(::std::string("Delete Account Done.")); + operationMessage.push_back(::std::string("Operate BMS.")); + operationMessage.push_back(::std::string("")); + operationMessage.push_back(::std::string("Press A or START Button to Reboot")); + + if (!s_PlayedRebootCursor) + { + PlaySound(SOUND_CURSOR); + s_PlayedRebootCursor = true; + } + + if (nextStep) + { + s_RestoreState = REBOOTING; + } + } + break; + + case CONNECT_ONLY: + { + // ACアダプタが必要か? + if (NeedsAcAdater()) + { + operationMessage.push_back(::std::string("Connect AC Adapter!!")); + } + + // アップデートを行う + if (!s_ExecuteConnectOnly) + { + if (ImportCountryLanguageData().IsSuccess()) + { + StartShopOperationSingle(SHOP_OPERATION_CONNECT_ONLY); + s_ExecuteConnectOnly = true; + } + else + { + s_RestoreState = FAIL; + } + } + + // 動いていることを表示 + { + PutAliveMessage(operationMessage, "Shop Connect"); + } + + if (IsShopOperationSingleFinished()) + { + FinishShopOperationSingle(); + // エラーがあったら表示する + if (GetShopOperationSingleResult().IsFailure()) + { + // APが見つからない + if (GetUpdateResult() == nn::ac::ResultNotFoundAccessPoint()) + { + COMMON_LOGGER("No Access Point Found!"); + } + } + + if (GetShopOperationSingleResult().IsSuccess()) + { + COMMON_LOGGER("Shop Connect Finished.\n"); + + CheckWriteFinished(operationMessage, nextStep); + } + else + { + if (s_ConnectOnlyRetryCount++ < RETRY_MAX) + { + // エラーのためやり直す + COMMON_LOGGER_RESULT_IF_FAILED(GetShopOperationSingleResult()); + COMMON_LOGGER("Shop Connect Failed. Retrying... %d\n", s_ConnectOnlyRetryCount); + + // Unregister用のスレッドを作るとこからやり直し + s_ExecuteConnectOnly = false; + } + else + { + s_RestoreState = FAIL; + } + } + + } + } + break; + + case READ_FILELIST: { result = SetupFileList(); COMMON_LOGGER_RESULT_IF_FAILED_WITH_LINE(result); - if(result.IsSuccess()) + if (result.IsSuccess()) { - s_RestoreState = RESTORE_TWL_NAND; + if (s_IsSyncClock) + { + s_RestoreState = RESTORE_TWL_NAND; + } + else + { + s_RestoreState = RESTORE_TWL_SOUND; + } + } else { @@ -567,28 +990,7 @@ void ControlState(::std::vector& operationMessage, bool& nextStep, } break; - // TWL NAND領域の書き込み中 - case RESTORE_TWL_NAND: - { - static bool init = true; - if (init) - { - // データを書き込む - ImportTwlSaveData(); - init = false; - } - - // 処理が完了した - if (IsImportFinished()) - { - FinalizeImportThread(); - s_RestoreState = RESTORE_TWL_SOUND; - } - } - break; - - - // TWLサウンド領域の書き込み中 + // TWLサウンド領域の書き込み中 case RESTORE_TWL_SOUND: { static bool init = true; @@ -608,7 +1010,7 @@ void ControlState(::std::vector& operationMessage, bool& nextStep, } break; - // TWL写真領域の書き込み + // TWL写真領域の書き込み case RESTORE_TWL_PHOTO: { static bool init = true; @@ -628,27 +1030,23 @@ void ControlState(::std::vector& operationMessage, bool& nextStep, } break; - // 書き込み中 case RESTORE_IN_PROGRESS: { - continueRestore = true; - // ACアダプタが必要か? if (NeedsAcAdater()) { - continueRestore = false; operationMessage.push_back(::std::string("Connect AC Adapter!!")); } // データを読み込む - if(ImportData().IsFailure()) + if (ImportData().IsFailure()) { s_RestoreState = FAIL; } // 処理が完了した - if (continueRestore && IsImportFinished()) + if (!NeedsAcAdater() && IsImportFinished()) { COMMON_LOGGER("Import NAND Data Finished.\n"); @@ -710,7 +1108,7 @@ void ControlState(::std::vector& operationMessage, bool& nextStep, operationMessage.push_back(::std::string("Restore Done.")); operationMessage.push_back(::std::string("Press A or START Button to Reboot")); - if(!s_PlayedRebootCursor) + if (!s_PlayedRebootCursor) { PlaySound(SOUND_CURSOR); s_PlayedRebootCursor = true; @@ -723,7 +1121,7 @@ void ControlState(::std::vector& operationMessage, bool& nextStep, } break; - // 削除処理 + // 削除処理 case ERASE: { Cleanup(); @@ -731,7 +1129,7 @@ void ControlState(::std::vector& operationMessage, bool& nextStep, } break; - // 削除処理 + // 削除処理 case RESTORE_CAL: { static bool init = true; @@ -742,7 +1140,7 @@ void ControlState(::std::vector& operationMessage, bool& nextStep, // cfgの本体固有値をcal値で初期化する result = InitializeHardwareDependentSetting(); - if(result.IsFailure()) + if (result.IsFailure()) { s_RestoreState = FAIL; } @@ -750,15 +1148,63 @@ void ControlState(::std::vector& operationMessage, bool& nextStep, init = false; } - s_RestoreState = TIME_ADJUST; + s_RestoreState = DOWNLOAD_TWL; } + case DOWNLOAD_TWL: + { + static bool init = true; + if (init) + { + COMMON_LOGGER("Download Twl Title\n"); + init = false; + } - // 時計あわせ + // 動いていることを表示 + { + PutAliveMessage(operationMessage, "Download Twl Title"); + } + + if (TitleDownloader::Finished()) + { + if (TitleDownloader::Succeeded()) + { + s_IsSyncClock = true; + s_RestoreState = READ_FILELIST; + } + else + { + s_RestoreState = FAIL; + } + } + } + break; + + // TWL NAND領域の書き込み中 + case RESTORE_TWL_NAND: + { + static bool init = true; + if (init) + { + // データを書き込む + ImportTwlSaveData(); + init = false; + } + + // 処理が完了した + if (IsImportFinished()) + { + FinalizeImportThread(); + s_RestoreState = TIME_ADJUST; + } + } + break; + + // 時計あわせ case TIME_ADJUST: { static bool init = true; - if(init) + if (init) { COMMON_LOGGER("Adjust Time\n"); AdjustTime(); @@ -770,9 +1216,9 @@ void ControlState(::std::vector& operationMessage, bool& nextStep, PutAliveMessage(operationMessage, "Sync Clock"); } - if(IsTimeAdjustFinished()) + if (IsTimeAdjustFinished()) { - if(IsTimeAdjustSuccessed()) + if (IsTimeAdjustSuccessed()) { s_RestoreState = WAIT_SD_EJECT; } @@ -787,7 +1233,7 @@ void ControlState(::std::vector& operationMessage, bool& nextStep, } break; - // すべて完了 + // すべて完了 case WAIT_SD_EJECT: { operationMessage.push_back(::std::string("ALL Done. Pull Out SD Card.")); @@ -802,7 +1248,7 @@ void ControlState(::std::vector& operationMessage, bool& nextStep, } break; - // すべて完了 + // すべて完了 case ALL_DONE: { operationMessage.push_back(::std::string("Restore Succeeded!!")); @@ -815,11 +1261,11 @@ void ControlState(::std::vector& operationMessage, bool& nextStep, } break; - // 書き込み失敗 + // 書き込み失敗 case FAIL: { static bool init = true; - if(init) + if (init) { // 状態初期化 DeleteAllCheckFiles(); @@ -852,7 +1298,7 @@ void ControlState(::std::vector& operationMessage, bool& nextStep, { operationMessage.push_back(::std::string("A or START Button to Shutdown.")); - if(nextStep) + if (nextStep) { s_RestoreState = SHUTDOWN; } diff --git a/trunk/ConsoleDataMigration/ConsoleRestore/Controller.h b/trunk/ConsoleDataMigration/ConsoleRestore/Controller.h index d2b802b..4d2072b 100644 --- a/trunk/ConsoleDataMigration/ConsoleRestore/Controller.h +++ b/trunk/ConsoleDataMigration/ConsoleRestore/Controller.h @@ -31,7 +31,7 @@ typedef enum RestoreMode const u32 RETRY_MAX = 3; -void ControlState(::std::vector& operationMessage, bool& nextStep, bool& continueRestore); +void ControlState(::std::vector& operationMessage, bool& nextStep); bool InProgress(); bool IsRestoreSucceeded(); bool IsRestoreFailed(); diff --git a/trunk/ConsoleDataMigration/ConsoleRestore/Importer.cpp b/trunk/ConsoleDataMigration/ConsoleRestore/Importer.cpp index d74a19d..783b57d 100644 --- a/trunk/ConsoleDataMigration/ConsoleRestore/Importer.cpp +++ b/trunk/ConsoleDataMigration/ConsoleRestore/Importer.cpp @@ -264,24 +264,34 @@ nn::Result EqualsDeviceIdFileandDeviceId() bit32 sdDeviceId; common::SdReaderWriter sdReader; size_t totalSize; - result = sdReader.ReadBufWithCmac(common::DEVICE_ID_PATHNAME, &sdDeviceId, sizeof(sdDeviceId), &totalSize); - s_CheckedEqualsDeviceIdFileandDeviceId = true; - if(result.IsSuccess()) + size_t bufSize = common::HeapManager::GetHeap()->GetAllocatableSize(); + void* buf = common::HeapManager::GetHeap()->Allocate(bufSize); + if (buf != NULL) { - if(GetDeviceId() == sdDeviceId) + result = sdReader.ReadBufWithCmac(common::DEVICE_ID_PATHNAME, buf, bufSize, &totalSize); + if (result.IsSuccess()) { - result = nn::ResultSuccess(); + s_CheckedEqualsDeviceIdFileandDeviceId = true; + std::memcpy(&sdDeviceId, buf, sizeof(sdDeviceId)); + + if (GetDeviceId() == sdDeviceId) + { + result = nn::ResultSuccess(); + } + + result = nn::Result(nn::Result::LEVEL_STATUS, nn::Result::SUMMARY_INVALID_RESULT_VALUE, + nn::Result::MODULE_COMMON, nn::Result::DESCRIPTION_INVALID_RESULT_VALUE); return result; } - - result = nn::Result(nn::Result::LEVEL_STATUS, nn::Result::SUMMARY_INVALID_RESULT_VALUE, nn::Result::MODULE_COMMON, - nn::Result::DESCRIPTION_INVALID_RESULT_VALUE); - return result; + common::HeapManager::GetHeap()->Free(buf); } else { - return result; + 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 EqualsRegionDataandRegion() @@ -879,6 +889,16 @@ void CreateRtcSyncFinishedFile() CreateEmptyFile(common::RTC_SYNC_CHECK_PATHNAME); } +void CreateDownloadIvsFinishedFile() +{ + CreateEmptyFile(common::DOWNLOAD_IVS_CHECK_PATHNAME); +} + +void CreateDeleteAccountFinishedFile() +{ + CreateEmptyFile(common::DELETE_ACCOUNT_CHECK_PATHNAME); +} + u32 GetImportProgress() { return common::GetProgress(); diff --git a/trunk/ConsoleDataMigration/ConsoleRestore/Importer.h b/trunk/ConsoleDataMigration/ConsoleRestore/Importer.h index bf55266..9af534f 100644 --- a/trunk/ConsoleDataMigration/ConsoleRestore/Importer.h +++ b/trunk/ConsoleDataMigration/ConsoleRestore/Importer.h @@ -38,6 +38,8 @@ void CreateWriteFinishedFile(); void CreateUpdateFinishedFile(); void CreateConsoleInitializedFile(); void CreateRtcSyncFinishedFile(); +void CreateDownloadIvsFinishedFile(); +void CreateDeleteAccountFinishedFile(); u32 GetImportProgress(); // NANDのごみを削除する diff --git a/trunk/ConsoleDataMigration/ConsoleRestore/OMakefile b/trunk/ConsoleDataMigration/ConsoleRestore/OMakefile index 9941735..404f8d7 100644 --- a/trunk/ConsoleDataMigration/ConsoleRestore/OMakefile +++ b/trunk/ConsoleDataMigration/ConsoleRestore/OMakefile @@ -31,6 +31,8 @@ SOURCES[] = Importer.cpp Updater.cpp Ntpclient.cpp + TitleDownloader.cpp + Shop.cpp ../common/HardwareInfo.cpp ../common/DrawSystemState.cpp ../common/FileTransfer.cpp diff --git a/trunk/ConsoleDataMigration/ConsoleRestore/Shop.cpp b/trunk/ConsoleDataMigration/ConsoleRestore/Shop.cpp new file mode 100644 index 0000000..cd29312 --- /dev/null +++ b/trunk/ConsoleDataMigration/ConsoleRestore/Shop.cpp @@ -0,0 +1,321 @@ +/*---------------------------------------------------------------------------* + Project: Horizon + File: Shop.cpp + + Copyright 2009 Nintendo. All rights reserved. + + These coded instructions, statements, and computer programs contain + proprietary information of Nintendo of America Inc. and/or Nintendo + Company Ltd., and are protected by Federal copyright law. They may + not be disclosed to third parties or copied or duplicated in any form, + in whole or in part, without the prior written consent of Nintendo. + + $Rev$ + *---------------------------------------------------------------------------*/ + +#include +#include +#include +#include +#include +#include +#include + +#include "Shop.h" +#include "CommonLogger.h" + +using namespace ES_NAMESPACE; +using namespace EC_NAMESPACE; + +#define NIM_UNREGISTER_RESULT_CHECK(result) \ +do { \ + if (result.IsFailure()) \ + { \ + ECCustomerSupportCode csc; \ + NN_UTIL_PANIC_IF_FAILED( \ + nn::nim::Shop::GetCustomerSupportCode(&csc)); \ + COMMON_LOGGER("CSCode: %d\n", csc); \ + nn::dbg::PrintResult(result); \ + s_Result = result; \ + goto LABEL_FINALIZE; \ + } \ +} while(0) +namespace +{ + +nn::Result s_Result = nn::ResultSuccess(); + +const size_t UNREGISTER_THREAD_STACK_SIZE = 0x1000; +nn::os::Thread s_UnregisterThread; +nn::os::StackBuffer s_UnregisterThreadStack; + +static const size_t ecBufferSize = 128 * 1024; +static u8 ecBufffer[ecBufferSize]; + +#ifndef NN_SWITCH_DISABLE_DEBUG_PRINT +// 空文字列と NULL ポインタをそれぞれ と NULL として返す +const char* Cstr(const char* p) +{ + return p ? (p[0] ? p : "") : "NULL"; +} + +// ECTicketVersions を出力 +void PrintECTicketVersions(const ECTicketVersions& ticketVersions) +{ + if (ticketVersions.nTicketVersions == 0) + { + NN_LOG("No TicketVersions\n"); + return; + } + + NN_LOG("----- ECTicketVersions -----\n"); + for (u32 i = 0; i < ticketVersions.nTicketVersions; i++) + { + ECTicketVersion version = ticketVersions.ticketVersions[i]; + NN_LOG("%03d: 0x%016llx v%d\n", i, version.ticketId, version.version); + } + NN_LOG("---------------------------\n"); +} + +// ECAccountInfo の情報を出力 +void PrintECAccountInfo(const ECAccountInfo& accountInfo) +{ + NN_LOG("========== ECAccountInfo ==========\n"); + + NN_LOG("accountId\n %s\n", Cstr(accountInfo.accountId)); + + NN_LOG("accountStatus\n %s\n", Cstr(accountInfo.accountStatus)); + + if (accountInfo.accountBalance == NULL) + { + NN_LOG("accountBalance\n NULL\n"); + } + else + { + NN_LOG("accountBalance->amount\n %s\n", + Cstr(accountInfo.accountBalance->amount)); + NN_LOG("accountBalance->currency\n %s\n", + Cstr(accountInfo.accountBalance->currency)); + } + + if (accountInfo.agreedEULAVersion == NULL) + { + NN_LOG("agreedEULAVersion\n NULL\n"); + } + else + { + NN_LOG("agreedEULAVersion\n %lld\n", + *accountInfo.agreedEULAVersion); + } + + if (accountInfo.latestEULAVersion == NULL) + { + NN_LOG("latestEULAVersion\n NULL\n"); + } + else + { + NN_LOG("latestEULAVersion\n %lld\n", + *accountInfo.latestEULAVersion); + } + + NN_LOG("country\n %s\n", Cstr(accountInfo.country)); + + NN_LOG("extAccountId\n %s\n", Cstr(accountInfo.extAccountId)); + + NN_LOG("deviceToken\n %s\n", Cstr(accountInfo.deviceToken)); + + NN_LOG("weakToken\n %s\n", Cstr(accountInfo.weakToken)); + + NN_LOG("isStandbyMode\n %d\n", accountInfo.isStandbyMode); + + if (accountInfo.owned == NULL) + { + NN_LOG("owned\n NULL\n"); + } + else + { + PrintECTicketVersions(*(accountInfo.owned)); + } +} +#endif //NN_SWITCH_DISABLE_DEBUG_PRINT + +nn::Result PrintNetworkSetting() +{ + nn::ac::NetworkSetting networkSetting; + NN_UTIL_RETURN_IF_FAILED(nn::ac::LoadNetworkSetting(0, networkSetting)); + COMMON_LOGGER("SSID: %s\n", networkSetting.wireless.essidSecurity.ssid); + COMMON_LOGGER("DNS : %d.%d.%d.%d\n", + networkSetting.ip.dns[0][0], networkSetting.ip.dns[0][1], + networkSetting.ip.dns[0][2], networkSetting.ip.dns[0][3]); + return nn::ResultSuccess(); +} + + +nn::Result ConnectNetwork() +{ + nn::Result result = nn::ResultSuccess(); + nn::ac::Config config; + + result = nn::ac::CreateDefaultConfig(&config); + NN_UTIL_RETURN_IF_FAILED(result); + + result = nn::ac::ConnectWithoutEula(config); + NN_UTIL_RETURN_IF_FAILED(result); + + NN_LOG("Success nn::ac::ConnectWithoutEula\n"); + + NN_UTIL_RETURN_IF_FAILED(PrintNetworkSetting()); + + return nn::ResultSuccess(); +} + +nn::Result InitializeInternal() +{ + nn::Result result = nn::ResultSuccess(); + + result = nn::ac::InitializeInternal(); + NN_UTIL_RETURN_IF_FAILED(result); + + result = ConnectNetwork(); + NN_UTIL_RETURN_IF_FAILED(result); + + return nn::ResultSuccess(); +} + +nn::Result FinalizeInternal() +{ + nn::Result result = nn::ResultSuccess(); + + nn::ac::CloseAll(); + + result = nn::ac::FinalizeInternal(); + NN_UTIL_RETURN_IF_FAILED(result); + + return nn::ResultSuccess(); +} + +} + + +namespace ConsoleRestore{ + +// メイン関数 +void ShopOperationSingleThreadFunc(ShopOperation op) +{ + nn::Result result = nn::ResultSuccess(); + + NN_LOG("util::ac::Initialize\n"); + InitializeInternal(); + + /* ------------------------------------------------------------------- + Initialize + -------------------------------------------------------------------- */ + NN_LOG("nim::InitializeForShop\n"); + result = nn::nim::InitializeForShop(); + NIM_UNREGISTER_RESULT_CHECK(result); + + /* ------------------------------------------------------------------- + SetParameter + -------------------------------------------------------------------- */ + NN_LOG("nim::Shop::SetTIN\n"); + result = nn::nim::Shop::SetTin(NIM_TIN); + NIM_UNREGISTER_RESULT_CHECK(result); + + switch(op) + { + case SHOP_OPERATION_CONNECT_ONLY: + { + // Connectするのみ + /* ------------------------------------------------------------------- + Connect + -------------------------------------------------------------------- */ + NN_LOG("nim::Shop::Connect\n"); + ECAccountInfo* pAccountInfo; + result = nn::nim::Shop::Connect(&pAccountInfo, ecBufffer, ecBufferSize); + NIM_UNREGISTER_RESULT_CHECK(result); + +#ifndef NN_SWITCH_DISABLE_DEBUG_PRINT + PrintECAccountInfo(*pAccountInfo); + NN_LOG("\n"); +#endif //NN_SWITCH_DISABLE_DEBUG_PRINT + } + break; + + case SHOP_OPERATION_GET_IVS: + { + // IVSを取得する + result = nn::nim::Shop::ImportIvsFromInfrastructure(); + NIM_UNREGISTER_RESULT_CHECK(result); + } + break; + + case SHOP_OPERATION_UNREGISTER: + { + /* ------------------------------------------------------------------- + Connect + -------------------------------------------------------------------- */ + NN_LOG("nim::Shop::Connect\n"); + ECAccountInfo* pAccountInfo; + result = nn::nim::Shop::Connect(&pAccountInfo, ecBufffer, ecBufferSize); + NIM_UNREGISTER_RESULT_CHECK(result); + +#ifndef NN_SWITCH_DISABLE_DEBUG_PRINT + PrintECAccountInfo(*pAccountInfo); + NN_LOG("\n"); +#endif //NN_SWITCH_DISABLE_DEBUG_PRINT + if (pAccountInfo->accountStatus && pAccountInfo->accountStatus[0] == 'R') + { + /* --------------------------------------------------------------- + Unregister + ---------------------------------------------------------------- */ + NN_LOG("nim::Shop::Unregister\n"); + result = nn::nim::Shop::Unregister(); + NIM_UNREGISTER_RESULT_CHECK(result); + } + else + { + NN_LOG("Not registered.\n"); + } + } + break; + } + + + LABEL_FINALIZE: + + /* ------------------------------------------------------------------- + Finalize + -------------------------------------------------------------------- */ + NN_LOG("nim::FinalizeForShop\n"); + result = nn::nim::FinalizeForShop(); + NIM_UNREGISTER_RESULT_CHECK(result); + + NN_LOG("util::ac::Initialize\n"); + FinalizeInternal(); +} + +void StartShopOperationSingle(ShopOperation op) +{ + NN_LOG("Start ShopOperationSingle"); + s_Result = nn::ResultSuccess(); + s_UnregisterThread.Start(ShopOperationSingleThreadFunc, op, s_UnregisterThreadStack); +} + +void FinishShopOperationSingle() +{ + NN_LOG("Finalize ShopOperationSingle\n"); + s_UnregisterThread.Join(); + s_UnregisterThread.Finalize(); +} + +bool IsShopOperationSingleFinished() +{ + return s_UnregisterThread.IsValid() && !s_UnregisterThread.IsAlive(); +} + +nn::Result GetShopOperationSingleResult() +{ + return s_Result; +} + +} diff --git a/trunk/ConsoleDataMigration/ConsoleRestore/Shop.h b/trunk/ConsoleDataMigration/ConsoleRestore/Shop.h new file mode 100644 index 0000000..1878635 --- /dev/null +++ b/trunk/ConsoleDataMigration/ConsoleRestore/Shop.h @@ -0,0 +1,40 @@ +/*---------------------------------------------------------------------------* + Project: Horizon + File: Shop.h + + Copyright 2009 Nintendo. All rights reserved. + + These coded instructions, statements, and computer programs contain + proprietary information of Nintendo of America Inc. and/or Nintendo + Company Ltd., and are protected by Federal copyright law. They may + not be disclosed to third parties or copied or duplicated in any form, + in whole or in part, without the prior written consent of Nintendo. + + $Rev$ + *---------------------------------------------------------------------------*/ + +#ifndef SHOP_H_ +#define SHOP_H_ + +#include + +#define NIM_TIN "56789" + +namespace ConsoleRestore +{ + +typedef enum SHOP_OPERATION +{ + SHOP_OPERATION_CONNECT_ONLY, + SHOP_OPERATION_GET_IVS, + SHOP_OPERATION_UNREGISTER +} ShopOperation; + +void StartShopOperationSingle(ShopOperation op); +void FinishShopOperationSingle(); +bool IsShopOperationSingleFinished(); +nn::Result GetShopOperationSingleResult(); + +} + +#endif /* SHOP_H_ */ diff --git a/trunk/ConsoleDataMigration/ConsoleRestore/TitleDownloader.cpp b/trunk/ConsoleDataMigration/ConsoleRestore/TitleDownloader.cpp new file mode 100644 index 0000000..a58b874 --- /dev/null +++ b/trunk/ConsoleDataMigration/ConsoleRestore/TitleDownloader.cpp @@ -0,0 +1,59 @@ +/*---------------------------------------------------------------------------* + Project: Horizon + File: TitleDownloader.cpp + + Copyright 2009 Nintendo. All rights reserved. + + These coded instructions, statements, and computer programs contain + proprietary information of Nintendo of America Inc. and/or Nintendo + Company Ltd., and are protected by Federal copyright law. They may + not be disclosed to third parties or copied or duplicated in any form, + in whole or in part, without the prior written consent of Nintendo. + + $Rev$ + *---------------------------------------------------------------------------*/ + +#include "TitleDownloader.h" +#include + +namespace ConsoleRestore +{ + +TitleDownloader::TitleDownloader() : m_Executing(false) +{ + // TODO 自動生成されたコンストラクター・スタブ + +} + +TitleDownloader::~TitleDownloader() +{ + // TODO Auto-generated destructor stub +} + + +void TitleDownloader::Start(nn::ProgramID* programIdList, size_t listNum) +{ + if(m_Executing) + { + return; + } + + m_Executing = true; + + + +} + + +bool TitleDownloader::Succeeded() +{ + return true; +} + +bool TitleDownloader::Finished() +{ + return true; +} + + +} diff --git a/trunk/ConsoleDataMigration/ConsoleRestore/TitleDownloader.h b/trunk/ConsoleDataMigration/ConsoleRestore/TitleDownloader.h new file mode 100644 index 0000000..11bcac6 --- /dev/null +++ b/trunk/ConsoleDataMigration/ConsoleRestore/TitleDownloader.h @@ -0,0 +1,42 @@ +/*---------------------------------------------------------------------------* + Project: Horizon + File: TitleDownloader.h + + Copyright 2009 Nintendo. All rights reserved. + + These coded instructions, statements, and computer programs contain + proprietary information of Nintendo of America Inc. and/or Nintendo + Company Ltd., and are protected by Federal copyright law. They may + not be disclosed to third parties or copied or duplicated in any form, + in whole or in part, without the prior written consent of Nintendo. + + $Rev$ + *---------------------------------------------------------------------------*/ + +#ifndef TITLEDOWNLOADER_H_ +#define TITLEDOWNLOADER_H_ + +#include + +namespace ConsoleRestore +{ + +class TitleDownloader +{ +public: + TitleDownloader(); + virtual ~TitleDownloader(); + + void Start(nn::ProgramID* programIdList, size_t listNum); + + static bool Succeeded(); + static bool Finished(); + +private: + bool m_Executing; + +}; + +} + +#endif /* TITLEDOWNLOADER_H_ */ diff --git a/trunk/ConsoleDataMigration/common/FileChecker.cpp b/trunk/ConsoleDataMigration/common/FileChecker.cpp index 05f8b41..69723cf 100644 --- a/trunk/ConsoleDataMigration/common/FileChecker.cpp +++ b/trunk/ConsoleDataMigration/common/FileChecker.cpp @@ -82,7 +82,6 @@ bool ExistsIVSFile() bool ExistsConsoleInitializedFile() { - // どちらかのファイルがあれば初期化済み return ExistsFile(EXISTS_CONSOLE_INTIALIZED); } @@ -116,6 +115,16 @@ bool ExistsRegionData() return ExistsFile(EXISTS_REGION_DATA); } +bool ExistsDeleteAccountChecked() +{ + return ExistsFile(EXISTS_DELETE_ACCOUNT); +} + +bool ExistsDownloadIvsCheckedFile() +{ + return ExistsFile(EXISTS_DOWNLOAD_IVS); +} + void InitializeFileCheck() { for(u32 i = 0; i < EXISTS_MAX; i++) diff --git a/trunk/ConsoleDataMigration/common/FileChecker.h b/trunk/ConsoleDataMigration/common/FileChecker.h index 96b189c..8c20a4b 100644 --- a/trunk/ConsoleDataMigration/common/FileChecker.h +++ b/trunk/ConsoleDataMigration/common/FileChecker.h @@ -33,6 +33,8 @@ typedef enum FILE_EXISTS_CHECK EXISTS_COUNTRY_LANGUAGE, EXISTS_VERSION_DATA, EXISTS_REGION_DATA, + EXISTS_DELETE_ACCOUNT, + EXISTS_DOWNLOAD_IVS, EXISTS_MAX } FileExistsCheck; @@ -47,7 +49,9 @@ const wchar_t* const FILENAME_TABLE[EXISTS_MAX] = common::RTC_SYNC_CHECK_PATHNAME, common::COUNTRY_SETTING_PATHNAME, common::VERSION_DATA_PATHNAME, - common::REGION_DATA_PATHNAME + common::REGION_DATA_PATHNAME, + common::DELETE_ACCOUNT_CHECK_PATHNAME, + common::DOWNLOAD_IVS_CHECK_PATHNAME }; bool CheckFileExists(const wchar_t* path); @@ -61,6 +65,8 @@ bool ExistsRtcSyncFinishedFile(); bool ExistsCountryLanguageFile(); bool ExistsVersionData(); bool ExistsRegionData(); +bool ExistsDeleteAccountChecked(); +bool ExistsDownloadIvsCheckedFile(); void InitializeFileCheck(); diff --git a/trunk/ConsoleDataMigration/common/FileName.h b/trunk/ConsoleDataMigration/common/FileName.h index 6bd3784..8600547 100644 --- a/trunk/ConsoleDataMigration/common/FileName.h +++ b/trunk/ConsoleDataMigration/common/FileName.h @@ -50,6 +50,8 @@ const wchar_t* const NAND_TWL_DATA_ROOT_PATHNAME_WITHOUT_SLASH = L"twln:/title"; const wchar_t* const SDMC_ROOT_DIRECTORY_PATH = L"sdmc:/"; const wchar_t* const WRITE_FINISHED_CHECK_PATHNAME = L"sdmc:/CTR_Console_Repair/WriteFinished"; const wchar_t* const UPDATE_CHECK_PATHNAME = L"sdmc:/CTR_Console_Repair/UpdateFinished"; +const wchar_t* const DELETE_ACCOUNT_CHECK_PATHNAME = L"sdmc:/CTR_Console_Repair/AccountDeletedChecked"; +const wchar_t* const DOWNLOAD_IVS_CHECK_PATHNAME = L"sdmc:/CTR_Console_Repair/DownloadIvsFinished"; const wchar_t* const INITIALIZED_CHECK_PATHNAME = L"sdmc:/CTR_Console_Repair/ConsoleInitialized"; const wchar_t* const RTC_SYNC_CHECK_PATHNAME = L"sdmc:/CTR_Console_Repair/RtcSyncFinished"; const wchar_t* const PLAYHISTORY_PATHNAME = L"sdmc:/CTR_Console_Repair/playhistory.bin";