色々と追加忘れ

進捗と結果を表示するように

git-svn-id: file:///Volumes/Transfer/gigaleak_20231201/2020-05-23%20-%20ctr.7z%20+%20svn_v1.068.zip/ctr/svn/ctr_Repair@654 385bec56-5757-e545-9c3a-d8741f4650f1
This commit is contained in:
N2614 2012-02-24 01:45:44 +00:00
parent 70f75a8afb
commit e2c5a298a4
12 changed files with 938 additions and 28 deletions

View File

@ -0,0 +1,370 @@
/*---------------------------------------------------------------------------*
Project: Horizon
File: CfgChanger.cpp
Copyright 2009-2011 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 "CfgChanger.h"
#include <nn/cfg/CTR/cfg_ApiSys.h>
#include <nn/cfg/CTR/detail/cfg_Keys.h>
#include <nn/cfg/CTR/detail/cfg_DataStructures.h>
#include <nn/cfg/CTR/cfg_NtrSettings.h>
#include <nn/cfg/CTR/cfg_ApiNor.h>
#include <nn/ac/CTR/private/ac_InternalApi.h>
#include <nn/ac/CTR/private/ac_NetworkSetting.h>
namespace
{
struct SaveData
{
// NANDデータ
s64 m_RtcUserTimeOffsetCfgData;
s64 m_RtcSystemTimeOffsetCfgData;
nn::cfg::CTR::detail::BackLightCfgData m_BackLight;
nn::cfg::CTR::detail::SoundSettingCfgData m_SoundSetting;
NN_PADDING1;
// インターネット接続設定
nn::ac::CTR::NetworkSetting m_NetworkSetting[3];
nn::cfg::CTR::detail::UserNameCfgData m_UserName;
nn::cfg::CTR::detail::BirthdayCfgData m_Birthday;
nn::cfg::CTR::detail::LanguageCfgData m_Language;
NN_PADDING1;
nn::cfg::CTR::detail::SimpleAddressIdCfgData m_SimpleAddressId;
nn::cfg::CTR::detail::SimpleAddressCountryNameCfgData m_SimpleAddressCountryName;
nn::cfg::CTR::detail::SimpleAddressRegionNameCfgData m_SimpleAddressRegionName;
nn::cfg::CTR::detail::SimpleAddressPositionCfgData m_SimpleAddressPos;
nn::cfg::CTR::detail::ParentalControlInfoCfgData m_ParentalControl;
nn::cfg::CTR::detail::CoppacsCfgData m_CoppacsCfgData;
nn::cfg::CTR::detail::EulaInfoCfgData m_EulaInfo;
nn::cfg::CTR::detail::BossSettingCfgData m_BossSetting;
NN_PADDING3;
NN_PADDING4;
nn::cfg::CTR::detail::SystemInfoCfgData m_SystemInfo;
nn::cfg::CTR::detail::PseudoRomIdCfgData m_PseudoRomId;
nn::cfg::CTR::detail::HomeButtonSettingCfgData m_HomeButtonSetting;
NN_PADDING3;
// TWL 本体設定
nn::cfg::CTR::detail::TwlEulaInfoCfgData m_TwlEulaInfo;
NN_PADDING2;
nn::cfg::CTR::detail::TwlParentalControlInfoCfgData m_ParentalCtrlInfo;
nn::cfg::CTR::detail::TwlCountryCodeCfgData m_TwlCountryCode;
NN_PADDING3;
nn::cfg::CTR::detail::FirstLaunchInfoCfgData m_FirstLaunchInfoCfgData;
NN_PADDING4;
nn::cfg::CTR::detail::MenuInfoCfgData m_MenuInfoCfgData;
nn::cfg::CTR::detail::DebugParamCfgData m_DebugParam;
// NOR
// NTR 本体設定
nn::cfg::CTR::NtrSettingData m_NtrSettingData;
nn::cfg::CTR::NtrSettingDataEx m_NtrSettingDataEx;
NN_PADDING2;
// 時間
nn::fnd::DateTime m_DateTime;
};
SaveData s_SaveData;
}
CfgChanger::CfgChanger()
{
// TODO 自動生成されたコンストラクター・スタブ
}
CfgChanger::~CfgChanger()
{
// TODO Auto-generated destructor stub
}
nn::Result CfgChanger::RestoreFromBackup()
{
NN_UTIL_RETURN_IF_FAILED(
nn::fs::MountSaveData("data:")
);
NN_UTIL_RETURN_IF_FAILED(
CheckBackupFormat()
);
NN_UTIL_RETURN_IF_FAILED(
RestoreCfgDataFromBackup()
);
NN_UTIL_RETURN_IF_FAILED(
nn::fs::Unmount("data:")
);
return nn::ResultSuccess();
}
nn::Result CfgChanger::CheckBackupFormat()
{
size_t maxFiles;
size_t maxDirectories;
bool isDuplicateAll;
NN_UTIL_RETURN_IF_FAILED(
nn::fs::GetSaveDataFormatInfo(&maxFiles, &maxDirectories, &isDuplicateAll)
);
NN_LOG("%d, %d, %d\n", maxFiles, maxDirectories, isDuplicateAll);
if(maxFiles != FILE_NUM ||
maxDirectories != DIR_NUM ||
isDuplicateAll != DUPLICATE
)
{
return nn::MakePermanentResult(nn::Result::SUMMARY_INVALID_STATE, nn::Result::MODULE_APPLICATION,
nn::Result::DESCRIPTION_INVALID_RESULT_VALUE);
}
return nn::ResultSuccess();
}
nn::Result CfgChanger::ImportToBackup()
{
// バックアップメモリをフォーマットします
NN_UTIL_RETURN_IF_FAILED(
nn::fs::FormatSaveData(FILE_NUM, DIR_NUM, DUPLICATE)
);
NN_UTIL_RETURN_IF_FAILED(
ImportCfgDataToBackup()
);
return nn::ResultSuccess();
}
nn::Result CfgChanger::ImportCfgDataToBackup()
{
using namespace nn::cfg::CTR::detail;
nn::Result result;
nn::cfg::CTR::system::Initialize();
s_SaveData.m_DateTime = nn::fnd::DateTime::GetNow();
// cfg の情報取得
result = nn::cfg::CTR::system::GetConfig(&s_SaveData.m_RtcUserTimeOffsetCfgData, sizeof(s_SaveData.m_RtcUserTimeOffsetCfgData), GET_CFG_KEY(NN_CFG_RTC, NN_CFG_RTC_USERTIME_OFFSET));
NN_UTIL_RETURN_IF_FAILED(result);
result = nn::cfg::CTR::system::GetConfig(&s_SaveData.m_RtcSystemTimeOffsetCfgData, sizeof(s_SaveData.m_RtcSystemTimeOffsetCfgData), GET_CFG_KEY(NN_CFG_RTC, NN_CFG_RTC_SYSTEMTIME_OFFSET));
NN_UTIL_RETURN_IF_FAILED(result);
result = nn::cfg::CTR::system::GetConfig(&s_SaveData.m_BackLight, sizeof(s_SaveData.m_BackLight), GET_CFG_KEY(NN_CFG_LCD, NN_CFG_LCD_BACKLIGHT));
NN_UTIL_RETURN_IF_FAILED(result);
result = nn::cfg::CTR::system::GetConfig(&s_SaveData.m_SoundSetting, sizeof(s_SaveData.m_SoundSetting), GET_CFG_KEY(NN_CFG_SOUND, NN_CFG_SOUND_SETTING));
NN_UTIL_RETURN_IF_FAILED(result);
// インターネット接続設定取得
result = nn::ac::CTR::InitializeInternal();
if (result.IsSuccess())
{
for(s32 i = 0; i < 3; i++)
{
result = nn::ac::CTR::LoadNetworkSetting(i, s_SaveData.m_NetworkSetting[i]);
if(result.IsFailure())
{
std::memset(&s_SaveData.m_NetworkSetting[i], 0 , sizeof(s_SaveData.m_NetworkSetting[i]));
}
}
}
else
{
std::memset(s_SaveData.m_NetworkSetting, 0, sizeof(s_SaveData.m_NetworkSetting));
}
result = nn::cfg::CTR::system::GetConfig(&s_SaveData.m_UserName, sizeof(s_SaveData.m_UserName), GET_CFG_KEY(NN_CFG_USER_INFO, NN_CFG_USER_INFO_USER_NAME));
NN_UTIL_RETURN_IF_FAILED(result);
result = nn::cfg::CTR::system::GetConfig(&s_SaveData.m_Birthday, sizeof(s_SaveData.m_Birthday), GET_CFG_KEY(NN_CFG_USER_INFO, NN_CFG_USER_INFO_BIRTHDAY));
NN_UTIL_RETURN_IF_FAILED(result);
result = nn::cfg::CTR::system::GetConfig(&s_SaveData.m_Language, sizeof(s_SaveData.m_Language), GET_CFG_KEY(NN_CFG_USER_INFO, NN_CFG_USER_INFO_LANGUAGE));
NN_UTIL_RETURN_IF_FAILED(result);
result = nn::cfg::CTR::system::GetConfig(&s_SaveData.m_SimpleAddressId, sizeof(s_SaveData.m_SimpleAddressId), GET_CFG_KEY(NN_CFG_SIMPLE_ADDRESS, NN_CFG_SIMPLE_ADDRESS_ID));
NN_UTIL_RETURN_IF_FAILED(result);
result = nn::cfg::CTR::system::GetConfig(&s_SaveData.m_SimpleAddressCountryName, sizeof(s_SaveData.m_SimpleAddressCountryName), GET_CFG_KEY(NN_CFG_SIMPLE_ADDRESS, NN_CFG_SIMPLE_ADDRESS_COUNTRY_NAME));
NN_UTIL_RETURN_IF_FAILED(result);
result = nn::cfg::CTR::system::GetConfig(&s_SaveData.m_SimpleAddressRegionName, sizeof(s_SaveData.m_SimpleAddressRegionName), GET_CFG_KEY(NN_CFG_SIMPLE_ADDRESS, NN_CFG_SIMPLE_ADDRESS_REGION_NAME));
NN_UTIL_RETURN_IF_FAILED(result);
result = nn::cfg::CTR::system::GetConfig(&s_SaveData.m_SimpleAddressPos, sizeof(s_SaveData.m_SimpleAddressPos), GET_CFG_KEY(NN_CFG_SIMPLE_ADDRESS, NN_CFG_SIMPLE_ADDRESS_POSITION));
NN_UTIL_RETURN_IF_FAILED(result);
result = nn::cfg::CTR::system::GetConfig(&s_SaveData.m_ParentalControl, sizeof(s_SaveData.m_ParentalControl), GET_CFG_KEY(NN_CFG_PARENTAL_CONTROL, NN_CFG_PARENTAL_CONTROL_INFO));
NN_UTIL_RETURN_IF_FAILED(result);
result = nn::cfg::CTR::system::GetConfig(&s_SaveData.m_CoppacsCfgData, sizeof(s_SaveData.m_CoppacsCfgData), GET_CFG_KEY(NN_CFG_PARENTAL_CONTROL, NN_CFG_PARENTAL_CONTROL_COPPACS));
NN_UTIL_RETURN_IF_FAILED(result);
result = nn::cfg::CTR::system::GetConfig(&s_SaveData.m_EulaInfo, sizeof(s_SaveData.m_EulaInfo), GET_CFG_KEY(NN_CFG_EULA, NN_CFG_EULA_INFO));
NN_UTIL_RETURN_IF_FAILED(result);
result = nn::cfg::CTR::system::GetConfig(&s_SaveData.m_BossSetting, sizeof(s_SaveData.m_BossSetting), GET_CFG_KEY(NN_CFG_BOSS, NN_CFG_BOSS_SETTING));
NN_UTIL_RETURN_IF_FAILED(result);
result = nn::cfg::CTR::system::GetConfig(&s_SaveData.m_SystemInfo, sizeof(s_SaveData.m_SystemInfo), GET_CFG_KEY(NN_CFG_SYSTEM, NN_CFG_SYSTEM_INFO));
NN_UTIL_RETURN_IF_FAILED(result);
result = nn::cfg::CTR::system::GetConfig(&s_SaveData.m_PseudoRomId, sizeof(s_SaveData.m_PseudoRomId), GET_CFG_KEY(NN_CFG_SYSTEM, NN_CFG_SYSTEM_PSEUDO_ROM_ID));
NN_UTIL_RETURN_IF_FAILED(result);
result = nn::cfg::CTR::system::GetConfig(&s_SaveData.m_HomeButtonSetting, sizeof(s_SaveData.m_HomeButtonSetting), GET_CFG_KEY(NN_CFG_SYSTEM, NN_CFG_SYSTEM_HOME_BUTTON));
NN_UTIL_RETURN_IF_FAILED(result);
// Twl 設定
result = nn::cfg::CTR::system::GetConfig(&s_SaveData.m_TwlEulaInfo, sizeof(s_SaveData.m_TwlEulaInfo), GET_CFG_KEY(NN_CFG_TWL, NN_CFG_TWL_EULA_INFO));
NN_UTIL_RETURN_IF_FAILED(result);
result = nn::cfg::CTR::system::GetConfig(&s_SaveData.m_ParentalCtrlInfo, sizeof(s_SaveData.m_ParentalCtrlInfo), GET_CFG_KEY(NN_CFG_TWL, NN_CFG_TWL_PARENTAL_CONTROL_INFO));
NN_UTIL_RETURN_IF_FAILED(result);
result = nn::cfg::CTR::system::GetConfig(&s_SaveData.m_TwlCountryCode, sizeof(s_SaveData.m_TwlCountryCode), GET_CFG_KEY(NN_CFG_TWL, NN_CFG_TWL_COUNTRY_CODE));
NN_UTIL_RETURN_IF_FAILED(result);
result = nn::cfg::CTR::system::GetConfig(&s_SaveData.m_FirstLaunchInfoCfgData, sizeof(s_SaveData.m_FirstLaunchInfoCfgData), GET_CFG_KEY(NN_CFG_MENU, NN_CFG_MENU_FIRST_LAUNCH));
NN_UTIL_RETURN_IF_FAILED(result);
result = nn::cfg::CTR::system::GetConfig(&s_SaveData.m_MenuInfoCfgData, sizeof(s_SaveData.m_MenuInfoCfgData), GET_CFG_KEY(NN_CFG_MENU, NN_CFG_MENU_MENU_INFO));
NN_UTIL_RETURN_IF_FAILED(result);
result = nn::cfg::CTR::system::GetConfig(&s_SaveData.m_DebugParam, sizeof(s_SaveData.m_DebugParam), GET_CFG_KEY(NN_CFG_DBG, NN_CFG_DBG_PARAM));
NN_UTIL_RETURN_IF_FAILED(result);
nn::cfg::CTR::system::Finalize();
// NTR 設定 (NOR)
nn::cfg::nor::CTR::Initialize();
result = nn::cfg::nor::CTR::GetNtrSetting(&s_SaveData.m_NtrSettingData, &s_SaveData.m_NtrSettingDataEx);
NN_UTIL_RETURN_IF_FAILED(result);
nn::cfg::nor::CTR::Finalize();
result = nn::fs::MountSaveData("data:");
NN_UTIL_RETURN_IF_FAILED(result);
nn::fs::FileOutputStream file;
result = file.TryInitialize(L"data:/savedata.bin", true);
NN_UTIL_RETURN_IF_FAILED(result);
s32 writeSize;
result = file.TryWrite(&writeSize, &s_SaveData, sizeof(s_SaveData), true);
NN_UTIL_RETURN_IF_FAILED(result);
result = nn::fs::CommitSaveData("data:");
NN_UTIL_RETURN_IF_FAILED(result);
result = nn::fs::Unmount("data:");
NN_UTIL_RETURN_IF_FAILED(result);
return nn::ResultSuccess();
}
nn::Result CfgChanger::RestoreCfgDataFromBackup()
{
using namespace nn::cfg::CTR::detail;
nn::Result result;
nn::fs::FileInputStream file;
result = file.TryInitialize(L"data:/savedata.bin");
NN_UTIL_RETURN_IF_FAILED(result);
s32 readSize;
result = file.TryRead(&readSize, &s_SaveData, sizeof(s_SaveData));
NN_UTIL_RETURN_IF_FAILED(result);
nn::cfg::CTR::system::Initialize();
nn::fnd::DateTime now = nn::fnd::DateTime::GetNow();
s64 usertimeOffset;
result = nn::cfg::CTR::system::GetConfig(&usertimeOffset, sizeof(usertimeOffset), GET_CFG_KEY(NN_CFG_RTC, NN_CFG_RTC_USERTIME_OFFSET));
NN_UTIL_RETURN_IF_FAILED(result);
usertimeOffset += (s_SaveData.m_DateTime - now).GetNanoSeconds();
// cfg の情報設定
result = nn::cfg::CTR::system::SetConfig(GET_CFG_KEY(NN_CFG_RTC, NN_CFG_RTC_USERTIME_OFFSET), &usertimeOffset, sizeof(usertimeOffset));
NN_UTIL_RETURN_IF_FAILED(result);
result = nn::cfg::CTR::system::SetConfig(GET_CFG_KEY(NN_CFG_RTC, NN_CFG_RTC_SYSTEMTIME_OFFSET), &s_SaveData.m_RtcSystemTimeOffsetCfgData, sizeof(s_SaveData.m_RtcSystemTimeOffsetCfgData));
NN_UTIL_RETURN_IF_FAILED(result);
result = nn::cfg::CTR::system::SetConfig(GET_CFG_KEY(NN_CFG_LCD, NN_CFG_LCD_BACKLIGHT), &s_SaveData.m_BackLight, sizeof(s_SaveData.m_BackLight));
NN_UTIL_RETURN_IF_FAILED(result);
result = nn::cfg::CTR::system::SetConfig(GET_CFG_KEY(NN_CFG_SOUND, NN_CFG_SOUND_SETTING), &s_SaveData.m_SoundSetting, sizeof(s_SaveData.m_SoundSetting));
NN_UTIL_RETURN_IF_FAILED(result);
// インターネット接続設定
result = nn::ac::CTR::InitializeInternal();
if (result.IsSuccess())
{
for(s32 i = 0; i < 3; i++)
{
result = nn::ac::CTR::UpdateNetworkSetting(i, s_SaveData.m_NetworkSetting[i]);
if(result.IsFailure())
{
std::memset(&s_SaveData.m_NetworkSetting[i], 0 , sizeof(s_SaveData.m_NetworkSetting[i]));
}
}
result = nn::ac::CTR::FlushNetworkSetting();
NN_UTIL_RETURN_IF_FAILED(result);
}
else
{
std::memset(s_SaveData.m_NetworkSetting, 0, sizeof(s_SaveData.m_NetworkSetting));
}
result = nn::cfg::CTR::system::SetConfig(GET_CFG_KEY(NN_CFG_USER_INFO, NN_CFG_USER_INFO_USER_NAME), &s_SaveData.m_UserName, sizeof(s_SaveData.m_UserName));
NN_UTIL_RETURN_IF_FAILED(result);
result = nn::cfg::CTR::system::SetConfig(GET_CFG_KEY(NN_CFG_USER_INFO, NN_CFG_USER_INFO_BIRTHDAY), &s_SaveData.m_Birthday, sizeof(s_SaveData.m_Birthday));
NN_UTIL_RETURN_IF_FAILED(result);
result = nn::cfg::CTR::system::SetConfig(GET_CFG_KEY(NN_CFG_USER_INFO, NN_CFG_USER_INFO_LANGUAGE), &s_SaveData.m_Language, sizeof(s_SaveData.m_Language));
NN_UTIL_RETURN_IF_FAILED(result);
result = nn::cfg::CTR::system::SetConfig(GET_CFG_KEY(NN_CFG_SIMPLE_ADDRESS, NN_CFG_SIMPLE_ADDRESS_ID), &s_SaveData.m_SimpleAddressId, sizeof(s_SaveData.m_SimpleAddressId));
NN_UTIL_RETURN_IF_FAILED(result);
result = nn::cfg::CTR::system::SetConfig(GET_CFG_KEY(NN_CFG_SIMPLE_ADDRESS, NN_CFG_SIMPLE_ADDRESS_COUNTRY_NAME), &s_SaveData.m_SimpleAddressCountryName, sizeof(s_SaveData.m_SimpleAddressCountryName));
NN_UTIL_RETURN_IF_FAILED(result);
result = nn::cfg::CTR::system::SetConfig(GET_CFG_KEY(NN_CFG_SIMPLE_ADDRESS, NN_CFG_SIMPLE_ADDRESS_REGION_NAME), &s_SaveData.m_SimpleAddressRegionName, sizeof(s_SaveData.m_SimpleAddressRegionName));
NN_UTIL_RETURN_IF_FAILED(result);
result = nn::cfg::CTR::system::SetConfig(GET_CFG_KEY(NN_CFG_SIMPLE_ADDRESS, NN_CFG_SIMPLE_ADDRESS_POSITION), &s_SaveData.m_SimpleAddressPos, sizeof(s_SaveData.m_SimpleAddressPos));
NN_UTIL_RETURN_IF_FAILED(result);
result = nn::cfg::CTR::system::SetConfig(GET_CFG_KEY(NN_CFG_PARENTAL_CONTROL, NN_CFG_PARENTAL_CONTROL_INFO), &s_SaveData.m_ParentalControl, sizeof(s_SaveData.m_ParentalControl));
NN_UTIL_RETURN_IF_FAILED(result);
result = nn::cfg::CTR::system::SetConfig(GET_CFG_KEY(NN_CFG_PARENTAL_CONTROL, NN_CFG_PARENTAL_CONTROL_COPPACS), &s_SaveData.m_CoppacsCfgData, sizeof(s_SaveData.m_CoppacsCfgData));
NN_UTIL_RETURN_IF_FAILED(result);
result = nn::cfg::CTR::system::SetConfig(GET_CFG_KEY(NN_CFG_EULA, NN_CFG_EULA_INFO), &s_SaveData.m_EulaInfo, sizeof(s_SaveData.m_EulaInfo));
NN_UTIL_RETURN_IF_FAILED(result);
result = nn::cfg::CTR::system::SetConfig(GET_CFG_KEY(NN_CFG_BOSS, NN_CFG_BOSS_SETTING), &s_SaveData.m_BossSetting, sizeof(s_SaveData.m_BossSetting));
NN_UTIL_RETURN_IF_FAILED(result);
result = nn::cfg::CTR::system::SetConfig(GET_CFG_KEY(NN_CFG_SYSTEM, NN_CFG_SYSTEM_INFO), &s_SaveData.m_SystemInfo, sizeof(s_SaveData.m_SystemInfo));
NN_UTIL_RETURN_IF_FAILED(result);
result = nn::cfg::CTR::system::SetConfig(GET_CFG_KEY(NN_CFG_SYSTEM, NN_CFG_SYSTEM_PSEUDO_ROM_ID), &s_SaveData.m_PseudoRomId, sizeof(s_SaveData.m_PseudoRomId));
NN_UTIL_RETURN_IF_FAILED(result);
result = nn::cfg::CTR::system::SetConfig(GET_CFG_KEY(NN_CFG_SYSTEM, NN_CFG_SYSTEM_HOME_BUTTON), &s_SaveData.m_HomeButtonSetting, sizeof(s_SaveData.m_HomeButtonSetting));
NN_UTIL_RETURN_IF_FAILED(result);
// Twl 設定
result = nn::cfg::CTR::system::SetConfig(GET_CFG_KEY(NN_CFG_TWL, NN_CFG_TWL_EULA_INFO), &s_SaveData.m_TwlEulaInfo, sizeof(s_SaveData.m_TwlEulaInfo));
NN_UTIL_RETURN_IF_FAILED(result);
result = nn::cfg::CTR::system::SetConfig(GET_CFG_KEY(NN_CFG_TWL, NN_CFG_TWL_PARENTAL_CONTROL_INFO), &s_SaveData.m_ParentalCtrlInfo, sizeof(s_SaveData.m_ParentalCtrlInfo));
NN_UTIL_RETURN_IF_FAILED(result);
result = nn::cfg::CTR::system::SetConfig(GET_CFG_KEY(NN_CFG_TWL, NN_CFG_TWL_COUNTRY_CODE), &s_SaveData.m_TwlCountryCode, sizeof(s_SaveData.m_TwlCountryCode));
NN_UTIL_RETURN_IF_FAILED(result);
result = nn::cfg::CTR::system::SetConfig(GET_CFG_KEY(NN_CFG_MENU, NN_CFG_MENU_FIRST_LAUNCH), &s_SaveData.m_FirstLaunchInfoCfgData, sizeof(s_SaveData.m_FirstLaunchInfoCfgData));
NN_UTIL_RETURN_IF_FAILED(result);
result = nn::cfg::CTR::system::SetConfig(GET_CFG_KEY(NN_CFG_MENU, NN_CFG_MENU_MENU_INFO), &s_SaveData.m_MenuInfoCfgData, sizeof(s_SaveData.m_MenuInfoCfgData));
NN_UTIL_RETURN_IF_FAILED(result);
result = nn::cfg::CTR::system::SetConfig(GET_CFG_KEY(NN_CFG_DBG, NN_CFG_DBG_PARAM), &s_SaveData.m_DebugParam, sizeof(s_SaveData.m_DebugParam));
NN_UTIL_RETURN_IF_FAILED(result);
nn::cfg::CTR::system::Finalize();
// NTR 設定 (NOR)
nn::cfg::nor::CTR::Initialize();
result = nn::cfg::nor::CTR::SetNtrSetting(&s_SaveData.m_NtrSettingData, &s_SaveData.m_NtrSettingDataEx);
NN_UTIL_RETURN_IF_FAILED(result);
nn::cfg::nor::CTR::Finalize();
return nn::ResultSuccess();
}

View File

@ -0,0 +1,49 @@
/*---------------------------------------------------------------------------*
Project: Horizon
File: CfgChanger.h
Copyright 2009-2011 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 CFGCHANGER_H_
#define CFGCHANGER_H_
#include <nn.h>
class CfgChanger
{
public:
CfgChanger();
virtual ~CfgChanger();
// バックアップメモリからデータを読み取ってcfgに反映します
nn::Result RestoreFromBackup();
// 現在のcfgの値をバックアップメモリに取り込みます。
// バックアップメモリは初期化されます
nn::Result ImportToBackup();
private:
// バックアップメモリのフォーマットをチェックします
nn::Result CheckBackupFormat();
// CFGデータをバックアップメモリに書き込みます
nn::Result ImportCfgDataToBackup();
// CFGのデータをバックアップメモリから書き込みます
nn::Result RestoreCfgDataFromBackup();
static const size_t FILE_NUM = 1;
static const size_t DIR_NUM = 1;
static const bool DUPLICATE = true;
};
#endif /* CFGCHANGER_H_ */

View File

@ -0,0 +1,64 @@
/*---------------------------------------------------------------------------*
Project: Horizon
File: HeapManager.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 "HeapManager.h"
namespace common
{
nn::fnd::ThreadSafeExpHeap s_AppHeap;
HeapManager::HeapManager(size_t byteSize, s32 alignment, bit8 groupId, nn::fnd::ExpHeapBase::AllocationMode mode, bool reuse)
{
m_Ptr = s_AppHeap.Allocate(byteSize, alignment, groupId, mode, reuse);
}
HeapManager::~HeapManager()
{
if(m_Ptr != NULL)
{
s_AppHeap.Free(m_Ptr);
}
}
void* HeapManager::GetAddr()
{
return m_Ptr;
}
void InitializeHeap()
{
s_AppHeap.Initialize(nn::os::GetDeviceMemoryAddress() + nn::os::GetDeviceMemorySize() / 2, nn::os::GetDeviceMemorySize() / 2, nn::os::ALLOCATE_OPTION_LINEAR);
}
size_t GetAllocatableSize(s32 alignment)
{
return s_AppHeap.GetAllocatableSize(alignment);
}
void* ForceAllocate(size_t byteSize, s32 alignment, bit8 groupId, nn::fnd::ExpHeapBase::AllocationMode mode, bool reuse)
{
return s_AppHeap.Allocate(byteSize, alignment, groupId, mode, reuse);
}
void ForceFree(void* ptr)
{
if(ptr != NULL)
{
s_AppHeap.Free(ptr);
}
}
}

View File

@ -0,0 +1,51 @@
/*---------------------------------------------------------------------------*
Project: Horizon
File: HeapManager.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 HEAPMANAGER_H_
#define HEAPMANAGER_H_
#include <nn.h>
#include <nn/fnd.h>
namespace common
{
class HeapManager
{
public:
explicit HeapManager(size_t byteSize, s32 alignment = nn::fnd::ExpHeapBase::DEFAULT_ALIGNMENT, bit8 groupId = 0,
nn::fnd::ExpHeapBase::AllocationMode mode = nn::fnd::ExpHeapBase::ALLOCATION_MODE_FIRST_FIT, bool reuse = false);
virtual ~HeapManager();
void* GetAddr();
private:
void* m_Ptr;
};
void InitializeHeap();
size_t GetAllocatableSize(s32 alignment = nn::fnd::ExpHeapBase::DEFAULT_ALIGNMENT);
// HeapManagerを使わず確保する場合のみ
void* ForceAllocate(size_t byteSize, s32 alignment = nn::fnd::ExpHeapBase::DEFAULT_ALIGNMENT, bit8 groupId = 0,
nn::fnd::ExpHeapBase::AllocationMode mode = nn::fnd::ExpHeapBase::ALLOCATION_MODE_FIRST_FIT, bool reuse = false);
// HeapManagerを使わず解放する場合のみ
void ForceFree(void* ptr);
} // namespace common
#endif /* HEAPMANAGER_H_ */

View File

@ -30,6 +30,7 @@ INCLUDES += $(SAMPLED_DEMOS_COMMON_INCLUDE_DIR) \
SOURCES[] =
main.cpp
HeapManager.cpp
StateManager.cpp
CfgChanger.cpp
syokaikidou.cpp
sysSharedExtSaveData.cpp
@ -51,6 +52,7 @@ DESCRIPTOR = $(HORIZON_ROOT)/resources/specfiles/systemapplications/M
LIBS += lib_demo \
libnn_ns \
libnn_am \
lib_scene \
include $(ROOT_OMAKE)/modulerules

View File

@ -11,7 +11,7 @@ TitleInfo:
SystemControlInfo:
AppType : Application
StackSize : 0x8000
StackSize : 0xA000
Dependency :
- codec
- hid

View File

@ -0,0 +1,227 @@
/*---------------------------------------------------------------------------*
Project: Horizon
File: StateManager.cpp
Copyright (C)2011 Nintendo Co., Ltd. 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 <nn/news/CTR/system/news_BossUtil.h>
#include "StateManager.h"
#include "CfgChanger.h"
#include "syokaikidou.h"
#define STATE_MANAGER_SET_RESULT_RETURN_VOID_IF_FAILED(result)\
do\
{\
s_Result = result;\
if(s_Result.IsFailure())\
{\
return;\
}\
}while(0)
#define STATE_MANAGER_CHECK_RESULT()\
do\
{\
if(s_Result.IsFailure())\
{\
m_State = STATE_ERROR;\
return false;\
}\
}while(0)
#define STATE_MANAGER_WAIT_THREAD()\
do\
{\
if(s_Thread.IsAlive())\
{\
return false;\
}\
else\
{\
s_Thread.Join();\
s_Thread.Finalize();\
STATE_MANAGER_CHECK_RESULT();\
return true;\
}\
}while(0)
namespace
{
const size_t THREAD_STACK_SIZE = 0xA000;
nn::os::Thread s_Thread;
nn::os::StackBuffer<THREAD_STACK_SIZE> s_ThreadStack;
nn::Result s_Result;
void ImportToBackup()
{
CfgChanger changer;
STATE_MANAGER_SET_RESULT_RETURN_VOID_IF_FAILED(
changer.ImportToBackup()
);
}
void ApplyBackuptoCfg()
{
NN_LOG("Set SaveData");
CfgChanger changer;
STATE_MANAGER_SET_RESULT_RETURN_VOID_IF_FAILED(
changer.RestoreFromBackup()
);
STATE_MANAGER_SET_RESULT_RETURN_VOID_IF_FAILED(
nn::news::CTR::boss::Initialize()
);
fnc_1st_setting();
fnc_starting_set();
}
}
StateManager::StateManager(Mode mode) : m_State(STATE_START), m_Counter(0)
{
m_Mode = mode;
}
StateManager::~StateManager()
{
// TODO Auto-generated destructor stub
}
bool StateManager::Exec(bool goNext, scene::TextWriter* pTextWriter)
{
pTextWriter->SetTextColor(255, 255, 255, 255);
switch (m_State)
{
case STATE_START:
{
return true;
}
case STATE_CONFIRM_OVERWRITE:
{
pTextWriter->Printf(0, 22, L"Press A or START Button to Update Backup");
if(goNext)
{
s_Thread.Start(ImportToBackup, s_ThreadStack);
return true;
}
}
break;
case STATE_OVERWRITING:
{
pTextWriter->Printf(0, 22, L"Importing current settings to Backup Memory");
DrawBusyIcon(pTextWriter);
STATE_MANAGER_WAIT_THREAD();
}
case STATE_SETTING_IMPORT:
{
DrawBusyIcon(pTextWriter);
s_Thread.Start(ApplyBackuptoCfg, s_ThreadStack);
return true;
}
case STATE_SETTING_IMPORTING:
{
pTextWriter->Printf(0, 22, L"Applying settings in Backup Memory");
DrawBusyIcon(pTextWriter);
STATE_MANAGER_WAIT_THREAD();
}
case STATE_DONE:
{
pTextWriter->Printf(0, 22, L"Finished");
}
break;
case STATE_ERROR:
{
pTextWriter->Printf(0, 22, L"Error Occurred: %08X", s_Result.GetPrintableBits());
}
break;
}
return false;
}
void StateManager::GoNext()
{
switch (m_State)
{
case STATE_START:
{
if(m_Mode == MODE_OVERWITE)
{
m_State = STATE_CONFIRM_OVERWRITE;
}
else if(m_Mode == MODE_APPLY)
{
m_State = STATE_SETTING_IMPORT;
}
}
break;
case STATE_CONFIRM_OVERWRITE:
{
m_State = STATE_OVERWRITING;
}
break;
case STATE_OVERWRITING:
{
m_State = STATE_DONE;
}
break;
case STATE_SETTING_IMPORT:
{
m_State = STATE_SETTING_IMPORTING;
}
break;
case STATE_SETTING_IMPORTING:
{
m_State = STATE_DONE;
}
break;
case STATE_DONE:
{
}
break;
case STATE_ERROR:
{
}
break;
}
}
bool StateManager::IsFinished()
{
return m_State == STATE_DONE;
}
bool StateManager::IsError()
{
return m_State == STATE_ERROR;
}
void StateManager::DrawBusyIcon(scene::TextWriter* pTextWriter)
{
scene::DrawBusyIcon(pTextWriter, 380, 0, m_Counter++);
}

View File

@ -0,0 +1,77 @@
/*---------------------------------------------------------------------------*
Project: Horizon
File: StateManager.h
Copyright 2009-2011 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 STATEMANAGER_H_
#define STATEMANAGER_H_
#include <nn.h>
#include <scene.h>
//! @brief 進捗状態を管理します
class StateManager
{
enum State
{
STATE_START, // 起動直後
STATE_CONFIRM_OVERWRITE, // セーブデータを上書きしても良いか確認
STATE_OVERWRITING, // アップデート中
STATE_SETTING_IMPORT, // 書き込み開始
STATE_SETTING_IMPORTING, // 設定書き込み中
STATE_DONE, // 完了
STATE_ERROR, // エラー
STATE_NUM_MAX //
};
public:
enum Mode
{
MODE_OVERWITE, // セーブデータ上書き
MODE_APPLY, // セーブデータ反映
MODE_NUM_MAX
};
public:
//! @param[in] mode MODE_OVERWRITE, MODE_APPLYのいずれかを引数にとり、</br>
//! セーブデータ上書きモードかセーブデータ反映モードで動作します
StateManager(Mode mode);
virtual ~StateManager();
//! @brief 現状態に合わせて処理を実行します
//! @param[in] goNext 外部入力によって次の状態に遷移するか判断するために使われます
//! @param[in] pTextWriter 文字表示に使用されます
//! @return 次の状態に遷移してもよいかどうか
bool Exec(bool goNext, scene::TextWriter* pTextWriter);
//! @brief 次の状態に遷移します
void GoNext();
//! @brief 処理が完了したかどうか
bool IsFinished();
//! @brief エラーが発生したかどうか
bool IsError();
private:
void DrawBusyIcon(scene::TextWriter* pTextWriter);
Mode m_Mode;
State m_State;
NN_PADDING2;
u32 m_Counter;
};
#endif /* STATEMANAGER_H_ */

View File

@ -19,12 +19,13 @@
#include <nn/cfg/CTR/cfg_ApiInit.h>
#include <nn/cfg/CTR/detail/cfg_Keys.h>
#include <nn/ns.h>
#include <nn/news/CTR/system/news_BossUtil.h>
#include <nn/hid/CTR/hid_ApiWithPrivilege.h>
#include <scene.h>
#include "HeapManager.h"
#include "syokaikidou.h"
#include "CfgChanger.h"
#include "StateManager.h"
#include "demo.h"
@ -69,14 +70,16 @@ extern "C" void nnMain()
nn::cfg::CTR::init::Initialize();
// RenderSystem の準備
common::InitializeHeap();
const size_t s_GxHeapSize = 8 * 1024 * 1024;
common::HeapManager gxHeap(s_GxHeapSize);
void* heapForGx = gxHeap.GetAddr();
s_RenderSystem.Initialize(reinterpret_cast<uptr>(heapForGx), s_GxHeapSize);
const size_t gxHeapSize = nn::os::GetDeviceMemorySize() / 2;
const size_t heapSizeofRender = 8 * 1024 * 1024;
nn::fnd::ExpHeap heapForGx;
heapForGx.Initialize(nn::os::GetDeviceMemoryAddress(), gxHeapSize, nn::os::ALLOCATE_OPTION_LINEAR);
void* heapBuf = heapForGx.Allocate(heapSizeofRender);
s_RenderSystem.Initialize(reinterpret_cast<uptr>(heapBuf), heapSizeofRender);
s_RenderSystem.SetClearColor(NN_GX_DISPLAY_BOTH, 0, 1, 0, 1);
common::InitializeHeap();
result = nn::ns::InitializeForShell();
HANDLE_ERROR(result);
@ -86,38 +89,43 @@ extern "C" void nnMain()
nn::hid::PadReader padReader;
nn::hid::PadStatus padStatus;
scene::TextWriter textWriter;
textWriter.Initialize(&heapForGx);
// タイトル設定
wchar_t title[] = L"CTR User Setting Manager";
scene::SetTitle(title, sizeof(title)/sizeof(wchar_t));
StateManager* pManager;
bool updateSaveData = false;
padReader.ReadLatest(&padStatus);
if(padStatus.hold & nn::hid::BUTTON_Y)
{
NN_LOG("Updating SaveData\n");
updateSaveData = true;
CfgChanger changer;
result = changer.ImportToBackup();
if(result.IsFailure())
{
NN_DBG_PRINT_RESULT(result);
}
else
{
NN_LOG("Updating SaveData done.\n");
}
}
if(!updateSaveData)
if(updateSaveData)
{
NN_LOG("Set SaveData");
CfgChanger changer;
if(changer.RestoreFromBackup().IsSuccess())
{
nn::news::CTR::boss::Initialize();
fnc_1st_setting();
fnc_starting_set();
}
pManager = new StateManager(StateManager::MODE_OVERWITE);
}
else
{
pManager = new StateManager(StateManager::MODE_APPLY);
}
for(;;)
{
bool goNext = false;
padReader.ReadLatest(&padStatus);
if(padStatus.trigger & nn::hid::BUTTON_A ||
padStatus.trigger & nn::hid::BUTTON_START
)
{
goNext = true;
}
// 電源ボタン短押しでシステムにシャットダウン通知を投げる
if( nn::applet::IsExpectedToProcessPowerButton())
{
@ -139,7 +147,28 @@ extern "C" void nnMain()
}
s_RenderSystem.SetRenderTarget(NN_GX_DISPLAY0);
if(pManager->IsError())
{
s_RenderSystem.SetClearColor(NN_GX_DISPLAY_BOTH, 1, 0, 0, 1);
}
else if(pManager->IsFinished())
{
s_RenderSystem.SetClearColor(NN_GX_DISPLAY_BOTH, 0, 1, 0, 1);
}
else
{
s_RenderSystem.SetClearColor(NN_GX_DISPLAY_BOTH, 0, 0, 0, 1);
}
s_RenderSystem.Clear();
textWriter.BeginRender(NN_GX_DISPLAY0);
scene::DrawTitle(&textWriter);
if(pManager->Exec(goNext, &textWriter))
{
pManager->GoNext();
}
textWriter.EndRender();
s_RenderSystem.SwapBuffers();
s_RenderSystem.SetRenderTarget(NN_GX_DISPLAY1);
s_RenderSystem.Clear();

View File

@ -26,6 +26,11 @@ nn::cfg::CfgLanguageCode getCfgLanguage()
return nn::cfg::GetLanguage();
}
nn::cfg::CfgCountryCode getCfgCountryCode()
{
return nn::cfg::GetCountry();
}
}
@ -40,8 +45,10 @@ void fnc_1st_setting()
// IDBの初期化
{
u32 size = IDB_GetBufferSize();
NN_LOG("idbBufferSize = %d\n", size);
common::HeapManager heap(size);
void* buf = heap.GetAddr();
NN_ASSERT(buf);
IDB_Initialize( reinterpret_cast<u8*>(buf), false, false );

View File

@ -0,0 +1,34 @@
/*---------------------------------------------------------------------------*
Project: Horizon
File: syokaikidou.h
Copyright 2009-2011 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 SYOKAIKIDOU_H_
#define SYOKAIKIDOU_H_
#include <nn/cfg.h>
void fnc_1st_setting();
void fnc_starting_set();
namespace System
{
nn::cfg::CfgRegionCode getRegion();
nn::cfg::CfgLanguageCode getCfgLanguage();
nn::cfg::CfgCountryCode getCfgCountryCode();
}
#endif /* SYOKAIKIDOU_H_ */

View File

@ -2035,7 +2035,7 @@ void UserInfoAccessor::setBossTask()
if( msFirstInfo.mmen != 0 ) // 初回起動のときセットしない
{
const char* lang = nn::cfg::CTR::GetLanguageCodeA2( (nn::cfg::CTR::CfgLanguageCode)System::getCfgLanguage() );
const char* country = nn::cfg::CTR::GetCountryCodeA2( (nn::cfg::CTR::CfgCountryCode)( msUserInfo.usr_address.id>>24 ) );
const char* country = nn::cfg::CTR::GetCountryCodeA2( (nn::cfg::CTR::CfgCountryCode)( System::getCfgCountryCode()));
const char* boss_code = nn::news::CTR::boss::GetBossCodeA3( (nn::cfg::CTR::CfgRegionCode)System::getRegion() );
nn::news::CTR::boss::RegisterSystemTask( boss_code, country, lang );