diff --git a/trunk/ConsoleDataMigration/ConsoleBackup/Exporter.cpp b/trunk/ConsoleDataMigration/ConsoleBackup/Exporter.cpp index 6294195..45a4a89 100644 --- a/trunk/ConsoleDataMigration/ConsoleBackup/Exporter.cpp +++ b/trunk/ConsoleDataMigration/ConsoleBackup/Exporter.cpp @@ -20,6 +20,7 @@ #include #include #include +#include #include // cfg:norの初期化に必要 #include #include @@ -45,6 +46,7 @@ namespace common::SdReaderWriter s_SdWriter; common::NtrNorData s_NtrNorData; +common::CfgCountryLanguage s_CountryLanguage; ::std::string s_SysSaveRoot; @@ -151,6 +153,23 @@ void DeleteTrash() common::SdMountManager::Unmount(); } +void WriteCountryLanguageData() +{ + COMMON_LOGGER("Export Country and Language Data.\n"); + + nn::Result result; + + nn::cfg::nor::CTR::Initialize(); + + // 国設定 + s_CountryLanguage.country = nn::cfg::CTR::GetCountry(); + + // 言語設定 + s_CountryLanguage.language = nn::cfg::CTR::GetLanguage(); + + s_SdWriter.WriteBuf(common::COUNTRY_SETTING_PATHNAME, &s_CountryLanguage, sizeof(s_CountryLanguage)); +} + void WriteNorData() { COMMON_LOGGER("Export NOR Data.\n"); @@ -358,6 +377,9 @@ void ExportData() // 不要なデータを削除する DeleteTrash(); + // 国データと言語データをSDに書き込む + WriteCountryLanguageData(); + // NORデータをSDカードに書き込む WriteNorData(); diff --git a/trunk/ConsoleDataMigration/ConsoleRestore/Controller.cpp b/trunk/ConsoleDataMigration/ConsoleRestore/Controller.cpp index 227709f..777251a 100644 --- a/trunk/ConsoleDataMigration/ConsoleRestore/Controller.cpp +++ b/trunk/ConsoleDataMigration/ConsoleRestore/Controller.cpp @@ -317,6 +317,7 @@ void ControlState(::std::vector& operationMessage, bool& nextStep, // アップデートを行う if(!s_ExecuteFgNup) { + ImportCountryLanguageData(); StartFGNetworkUpdate(); s_ExecuteFgNup = true; } diff --git a/trunk/ConsoleDataMigration/ConsoleRestore/Importer.cpp b/trunk/ConsoleDataMigration/ConsoleRestore/Importer.cpp index 709b561..f6f5a9c 100644 --- a/trunk/ConsoleDataMigration/ConsoleRestore/Importer.cpp +++ b/trunk/ConsoleDataMigration/ConsoleRestore/Importer.cpp @@ -16,10 +16,14 @@ #include #include #include +#include #include // cfg:norの初期化に必要 +#include #include #include #include +#include +#include #include #include #include @@ -367,6 +371,71 @@ bool ExistsConsoleInitializedFile() return ExistsFile(EXISTS_CONSOLE_INTIALIZED); } +void SetCountry(nn::cfg::CTR::CfgCountryCode countryCode) +{ + using namespace nn::cfg::CTR; + using namespace nn::cfg::CTR::detail; + + SimpleAddressIdCfgData simpleAddressId; + TwlCountryCodeCfgData countryData; + + nn::cfg::CTR::system::Initialize(); + + NN_UTIL_PANIC_IF_FAILED(nn::cfg::CTR::system::GetConfig(&simpleAddressId, sizeof(SimpleAddressIdCfgData), GET_CFG_KEY(NN_CFG_SIMPLE_ADDRESS, NN_CFG_SIMPLE_ADDRESS_ID))); + NN_UTIL_PANIC_IF_FAILED(nn::cfg::CTR::system::GetConfig(&countryData, sizeof(TwlCountryCodeCfgData), GET_CFG_KEY(NN_CFG_TWL, NN_CFG_TWL_COUNTRY_CODE))); + nn::cfg::CTR::system::Finalize(); + + simpleAddressId.id = (countryCode << CFG_SIMPLE_ADDRESS_ID_COUNTRY_SHIFT) | (1 + << CFG_SIMPLE_ADDRESS_ID_REGION_SHIFT); + countryData.country = countryCode; + + nn::cfg::CTR::system::Initialize(); + NN_UTIL_PANIC_IF_FAILED(nn::cfg::CTR::system::SetConfig(GET_CFG_KEY(NN_CFG_SIMPLE_ADDRESS, NN_CFG_SIMPLE_ADDRESS_ID), &simpleAddressId, sizeof(SimpleAddressIdCfgData))); + NN_UTIL_PANIC_IF_FAILED(nn::cfg::CTR::system::SetConfig(GET_CFG_KEY(NN_CFG_TWL, NN_CFG_TWL_COUNTRY_CODE), &countryData, sizeof(TwlCountryCodeCfgData))); + nn::cfg::CTR::system::FlushConfig(); + nn::cfg::CTR::system::Finalize(); +} + +void SetLanguage(nn::cfg::CTR::CfgLanguageCode languageCode) +{ + NN_UTIL_PANIC_IF_FAILED(nn::cfg::CTR::init::SetConfig( + GET_CFG_KEY(nn::cfg::CTR::detail::NN_CFG_USER_INFO, + nn::cfg::CTR::detail::NN_CFG_USER_INFO_LANGUAGE), + &languageCode, + sizeof(nn::cfg::CTR::detail::LanguageCfgData))); + NN_UTIL_PANIC_IF_FAILED(nn::cfg::CTR::init::FlushConfig()); + nn::cfg::nor::CTR::Initialize(); + NN_UTIL_PANIC_IF_FAILED(nn::cfg::nor::CTR::SetLanguage(static_cast(languageCode))); + nn::cfg::nor::CTR::Finalize(); +} + +void ImportCountryLanguageData() +{ + nn::Result result; + + size_t bufSize = common::HeapManager::GetHeap()->GetAllocatableSize(); + void* buf = common::HeapManager::GetHeap()->Allocate(bufSize); + if (buf != NULL) + { + common::SdReaderWriter sdReader; + + size_t readSize; + result = sdReader.ReadBuf(common::COUNTRY_SETTING_PATHNAME, buf, bufSize, &readSize); + if(result.IsSuccess()) + { + // SDから読み出し成功 + SetCountry(reinterpret_cast(buf)->country); + + SetLanguage(reinterpret_cast(buf)->language); + } + else + { + COMMON_LOGGER_RESULT_IF_FAILED_WITH_LINE(result); + } + common::HeapManager::GetHeap()->Free(buf); + } +} + void ImportIvs() { nn::Result result; diff --git a/trunk/ConsoleDataMigration/ConsoleRestore/Importer.h b/trunk/ConsoleDataMigration/ConsoleRestore/Importer.h index f978ec8..3b2bec1 100644 --- a/trunk/ConsoleDataMigration/ConsoleRestore/Importer.h +++ b/trunk/ConsoleDataMigration/ConsoleRestore/Importer.h @@ -86,6 +86,7 @@ struct CheckedNetworkSetting }; CheckedNetworkSetting* GetTempNetworkSetting(); +void ImportCountryLanguageData(); } diff --git a/trunk/ConsoleDataMigration/common/FileName.h b/trunk/ConsoleDataMigration/common/FileName.h index 412b126..fc67ddd 100644 --- a/trunk/ConsoleDataMigration/common/FileName.h +++ b/trunk/ConsoleDataMigration/common/FileName.h @@ -23,6 +23,7 @@ const char* const NAND_ARCHIVE_NAME = "nand:"; const char* const SD_ARCHIVE_NAME = "sdmc:"; const wchar_t* const SD_SAVEDATA_ROOT_NAME = L"CTR_ConsoleBackup/"; +const wchar_t* const COUNTRY_SETTING_PATHNAME = L"sdmc:/CountrySetting.bin"; const wchar_t* const AP_SETTING_FILENAME = L"APSetting.txt"; const wchar_t* const AP_SETTING_PATHNAME = L"sdmc:/APSetting.txt"; const wchar_t* const NOR_PATHNAME = L"sdmc:/NtrNorSetting.bin"; diff --git a/trunk/ConsoleDataMigration/common/common_Types.h b/trunk/ConsoleDataMigration/common/common_Types.h index 4a69164..c66cce1 100644 --- a/trunk/ConsoleDataMigration/common/common_Types.h +++ b/trunk/ConsoleDataMigration/common/common_Types.h @@ -17,6 +17,8 @@ #define COMMON_TYPES_H_ #include +#include +#include namespace common { @@ -33,6 +35,13 @@ struct NtrNorData u8 NtrWiFiSetting[NTR_WIFI_SETTING_SIZE]; }; +struct CfgCountryLanguage +{ + enum nn::cfg::CTR::CfgCountryCode country; + enum nn::cfg::CTR::CfgLanguageCode language; + NN_PADDING1; +}; + }