mirror of
https://github.com/rvtr/ctr_Repair.git
synced 2025-10-31 13:51:08 -04:00
ハードウェア状態に依存する処理を分離
git-svn-id: file:///Volumes/Transfer/gigaleak_20231201/2020-05-23%20-%20ctr.7z%20+%20svn_v1.068.zip/ctr/svn/ctr_Repair@223 385bec56-5757-e545-9c3a-d8741f4650f1
This commit is contained in:
parent
23dd0ae63f
commit
9e8a601585
@ -23,8 +23,6 @@
|
||||
#include <nn/ps.h>
|
||||
#include <nn/nwm.h>
|
||||
#include <nn/ac.h>
|
||||
#include <nn/friends.h>
|
||||
#include <nn/friends/CTR/friends_ApiPrivate.h>
|
||||
#include <nn/fs/CTR/fs_ArchiveTypesForSystem.h>
|
||||
#include <nn/fs/CTR/MPCore/fs_FileSystemBasePrivate.h>
|
||||
#include <nn/fs/fs_ApiSysSaveData.h>
|
||||
@ -55,6 +53,7 @@
|
||||
#include "VersionDetect.h"
|
||||
#include "Util.h"
|
||||
#include "ResFont.h"
|
||||
#include "HardwareStateManager.h"
|
||||
|
||||
// svnリビジョン埋め込み用
|
||||
#include "../../generated/ConsoleBackup/version.h"
|
||||
@ -67,83 +66,12 @@ namespace {
|
||||
// グラフィックスに割り当てるメモリ
|
||||
const size_t s_GxHeapSize = 0x800000;
|
||||
|
||||
|
||||
// バッテリ残量
|
||||
u8 batteryRemain = 100;
|
||||
|
||||
// シリアルナンバー
|
||||
u8 s_SerialNo[nn::cfg::CTR::CFG_SECURE_INFO_SERIAL_NO_LEN];
|
||||
|
||||
// デバイスID
|
||||
bit32 s_DeviceId;
|
||||
|
||||
// シリアルナンバーが読めるかどうか
|
||||
bool s_CanReadSerialNumber = false;
|
||||
|
||||
// IVSへのポインタ
|
||||
void* sp_Ivs;
|
||||
|
||||
size_t s_SizeofIvs;
|
||||
|
||||
// IVSが読めるかどうか
|
||||
bool s_CanReadIvs = false;
|
||||
|
||||
// バージョン情報
|
||||
common::VerDef s_VerData;
|
||||
|
||||
nn::Handle s_McuSession;
|
||||
common::Util s_HwUtility;
|
||||
|
||||
} // namespace <unnamed>
|
||||
|
||||
namespace ConsoleBackup{
|
||||
|
||||
bool IsAdapterConnected()
|
||||
{
|
||||
return nn::ptm::CTR::GetAdapterState() == nn::ptm::CTR::ADAPTERSTATE_CONNECTED;
|
||||
}
|
||||
|
||||
bool IsBatteryLower()
|
||||
{
|
||||
return batteryRemain <= 10;
|
||||
}
|
||||
|
||||
bool CanReadIVS()
|
||||
{
|
||||
return s_CanReadIvs;
|
||||
}
|
||||
|
||||
bool CanReadSerialNumber()
|
||||
{
|
||||
return s_CanReadSerialNumber;
|
||||
}
|
||||
|
||||
void GetSerialNumber(u8** serial, size_t* size)
|
||||
{
|
||||
*serial = s_SerialNo;
|
||||
*size = nn::cfg::CTR::CFG_SECURE_INFO_SERIAL_NO_LEN;
|
||||
}
|
||||
|
||||
void GetIvs(void** ivs, size_t* size)
|
||||
{
|
||||
*ivs = sp_Ivs;
|
||||
*size = s_SizeofIvs;
|
||||
}
|
||||
|
||||
bit32 GetDeviceId()
|
||||
{
|
||||
return s_DeviceId;
|
||||
}
|
||||
|
||||
void GetVersionData(common::VerDef* version)
|
||||
{
|
||||
*version = s_VerData;
|
||||
}
|
||||
|
||||
nn::Handle GetMcuHandle()
|
||||
{
|
||||
return s_McuSession;
|
||||
}
|
||||
|
||||
|
||||
extern "C" void nnMain(void)
|
||||
{
|
||||
@ -180,14 +108,6 @@ extern "C" void nnMain(void)
|
||||
// ps の初期化
|
||||
nn::ps::Initialize();
|
||||
|
||||
// friendsの初期化
|
||||
result = nn::friends::detail::Initialize();
|
||||
|
||||
// mcuの初期化
|
||||
nn::mcu::CTR::InitializeHwCheck(&s_McuSession);
|
||||
|
||||
nn::mcu::CTR::HwCheck mcu(s_McuSession);
|
||||
|
||||
// amの初期化
|
||||
nn::am::InitializeForSystemMenu();
|
||||
|
||||
@ -196,8 +116,8 @@ extern "C" void nnMain(void)
|
||||
|
||||
// RenderSystem の準備
|
||||
uptr heapForGx = reinterpret_cast<uptr>(common::HeapManager::GetHeap()->Allocate(s_GxHeapSize));
|
||||
demo::RenderSystemDrawing s_RenderSystem;
|
||||
s_RenderSystem.Initialize(heapForGx, s_GxHeapSize);
|
||||
demo::RenderSystemDrawing renderSystem;
|
||||
renderSystem.Initialize(heapForGx, s_GxHeapSize);
|
||||
|
||||
// ResFontの初期化
|
||||
common::InitializeResFont();
|
||||
@ -206,7 +126,7 @@ extern "C" void nnMain(void)
|
||||
common::InitializeSimplePlayer();
|
||||
|
||||
// ログ描画の初期化
|
||||
common::Logger::GetLoggerInstance()->Initialize(CONSOLE_WIDTH, CONSOLE_HEIGHT, CONSOLE_MAX_LINE, &s_RenderSystem);
|
||||
common::Logger::GetLoggerInstance()->Initialize(CONSOLE_WIDTH, CONSOLE_HEIGHT, CONSOLE_MAX_LINE, &renderSystem);
|
||||
|
||||
// RenderSystemを作ってからログが出せる
|
||||
common::Logger::InitializeEjectThread();
|
||||
@ -222,89 +142,24 @@ extern "C" void nnMain(void)
|
||||
nn::hid::PadStatus padStatus;
|
||||
|
||||
// データの準備
|
||||
|
||||
// 完全性検証SEEDの取得
|
||||
result = nn::fs::MountSpecialArchive(common::NAND_ARCHIVE_NAME, nn::fs::CTR::ARCHIVE_TYPE_CTR_NAND);
|
||||
if (result.IsSuccess())
|
||||
{
|
||||
nn::fs::FileInputStream fis;
|
||||
|
||||
result = fis.TryInitialize(common::IVS_NAND_PATHNAME);
|
||||
if (result.IsSuccess())
|
||||
{
|
||||
s64 fileSize = fis.GetSize();
|
||||
s32 ret;
|
||||
void* addr = NULL;
|
||||
addr = common::HeapManager::GetHeap()->Allocate(fileSize);
|
||||
if (addr != NULL)
|
||||
{
|
||||
sp_Ivs = addr;
|
||||
s_SizeofIvs = fileSize;
|
||||
result = fis.TryRead(&ret, addr, fileSize);
|
||||
if (result.IsSuccess())
|
||||
{
|
||||
s_CanReadIvs = true;
|
||||
}
|
||||
// 後でIVSを参照するのでFreeしない
|
||||
}
|
||||
}
|
||||
fis.Finalize();
|
||||
}
|
||||
// 一旦アンマウントしておく
|
||||
nn::fs::Unmount(common::NAND_ARCHIVE_NAME);
|
||||
|
||||
// リージョンの取得
|
||||
nn::cfg::CTR::CfgRegionCode region;
|
||||
region = nn::cfg::CTR::GetRegion();
|
||||
|
||||
// シリアルナンバーの取得
|
||||
std::memset(s_SerialNo, '\0',
|
||||
nn::cfg::CTR::CFG_SECURE_INFO_SERIAL_NO_LEN);
|
||||
result = nn::cfg::CTR::system::GetSerialNo(s_SerialNo);
|
||||
if(result.IsSuccess())
|
||||
{
|
||||
s_CanReadSerialNumber = true;
|
||||
}
|
||||
COMMON_LOGGER_RESULT_IF_FAILED_WITH_LINE(result);
|
||||
|
||||
common::Util::AddCheckDigit(reinterpret_cast<char*>(s_SerialNo));
|
||||
|
||||
// デバイスIDの取得
|
||||
result = nn::ps::CTR::GetDeviceId(&s_DeviceId);
|
||||
COMMON_LOGGER_RESULT_IF_FAILED_WITH_LINE(result);
|
||||
bit64 infraDeviceId;
|
||||
infraDeviceId = s_DeviceId + common::INFRA_DEVICE_ID_OFFSET;
|
||||
|
||||
// MACアドレスの取得
|
||||
nn::nwm::Mac mac;
|
||||
char8 macAddress[nn::nwm::Mac::MAC_STRING_SIZE];
|
||||
|
||||
result = nn::nwm::GetMacAddress(mac);
|
||||
COMMON_LOGGER_RESULT_IF_FAILED_WITH_LINE(result);
|
||||
mac.GetString(macAddress);
|
||||
COMMON_LOGGER_RESULT_IF_FAILED_WITH_LINE(result);
|
||||
|
||||
// フレンドコードの取得
|
||||
nn::friends::CTR::FriendKey friendKey;
|
||||
result = nn::friends::CTR::GetMyFriendKey(&friendKey);
|
||||
COMMON_LOGGER_RESULT_IF_FAILED_WITH_LINE(result);
|
||||
u64 friendCode = nn::friends::CTR::FriendKeyToFriendCode(friendKey);
|
||||
|
||||
// バージョンの取得
|
||||
common::GetSystemVersion(&s_VerData, region);
|
||||
s_HwUtility.Initialize();
|
||||
common::HardwareStateManager manager(s_HwUtility);
|
||||
|
||||
// 情報出力
|
||||
COMMON_LOGGER("CTR Console Backup %s Rev.%s\n", __DATE__, BACKUP_VERSION_NUM);
|
||||
COMMON_LOGGER("System Ver. %d.%d.%d-%d\n", s_VerData.cup.majorVersion, s_VerData.cup.minorVersion, s_VerData.cup.microVersion,
|
||||
s_VerData.nup.majorVersion);
|
||||
COMMON_LOGGER("System Region %s\n", nn::cfg::CTR::GetRegionCodeA3(region));
|
||||
COMMON_LOGGER("Serial Number %s\n", s_SerialNo);
|
||||
COMMON_LOGGER("Device ID %llu\n", infraDeviceId);
|
||||
COMMON_LOGGER("MAC Address %s\n", macAddress);
|
||||
COMMON_LOGGER("System Ver. %d.%d.%d-%d\n",
|
||||
s_HwUtility.GetCupMajorVersion(),
|
||||
s_HwUtility.GetCupMinorVersion(),
|
||||
s_HwUtility.GetCupMicroVersion(),
|
||||
s_HwUtility.GetNupVersion());
|
||||
COMMON_LOGGER("System Region %s\n", s_HwUtility.GetRegionCodeA3());
|
||||
COMMON_LOGGER("Serial Number %s\n", s_HwUtility.GetSerialNumber());
|
||||
COMMON_LOGGER("Device ID %llu\n", s_HwUtility.GetInfraDeviceId());
|
||||
COMMON_LOGGER("MAC Address %s\n", s_HwUtility.GetMacAddress());
|
||||
COMMON_LOGGER("Friend Code %04u-%04u-%04u\n",
|
||||
static_cast<u32>(friendCode / 100000000ULL % 10000ULL),
|
||||
static_cast<u32>(friendCode / 10000ULL % 10000ULL),
|
||||
static_cast<u32>(friendCode % 10000ULL) );
|
||||
static_cast<u32>(s_HwUtility.GetFriendcode() / 100000000ULL % 10000ULL),
|
||||
static_cast<u32>(s_HwUtility.GetFriendcode() / 10000ULL % 10000ULL),
|
||||
static_cast<u32>(s_HwUtility.GetFriendcode() % 10000ULL) );
|
||||
|
||||
|
||||
bool flip = false;
|
||||
@ -353,11 +208,9 @@ extern "C" void nnMain(void)
|
||||
|
||||
|
||||
// 情報更新
|
||||
// バッテリ
|
||||
mcu.GetBatteryRemain(&batteryRemain);
|
||||
// ACアダプタ
|
||||
std::string adapterState;
|
||||
if(IsAdapterConnected())
|
||||
if(manager.IsAdapterConnected())
|
||||
{
|
||||
adapterState += ::std::string("Connected");
|
||||
}
|
||||
@ -370,7 +223,7 @@ extern "C" void nnMain(void)
|
||||
// 進捗確認メッセージを兼ねる?
|
||||
::std::vector<std::string> operationMessage;
|
||||
|
||||
ControlState(operationMessage, nextStep, continueBackup);
|
||||
ControlState(manager, operationMessage, nextStep, continueBackup);
|
||||
|
||||
nn::util::FloatColor titleColor;
|
||||
|
||||
@ -380,44 +233,47 @@ extern "C" void nnMain(void)
|
||||
|
||||
// 上画面表示
|
||||
common::DrawSystemState("CTR Console Backup",
|
||||
s_RenderSystem,
|
||||
renderSystem,
|
||||
titleColor,
|
||||
flip,
|
||||
adapterState,
|
||||
BACKUP_VERSION_NUM,
|
||||
&s_VerData,
|
||||
batteryRemain,
|
||||
infraDeviceId,
|
||||
friendCode,
|
||||
s_HwUtility.GetCupMajorVersion(),
|
||||
s_HwUtility.GetCupMinorVersion(),
|
||||
s_HwUtility.GetCupMicroVersion(),
|
||||
s_HwUtility.GetNupVersion(),
|
||||
s_HwUtility.GetBatteryRemain(),
|
||||
s_HwUtility.GetInfraDeviceId(),
|
||||
s_HwUtility.GetFriendcode(),
|
||||
GetProgress(),
|
||||
IsBackupFailed(),
|
||||
IsBackupSucceeded(),
|
||||
macAddress,
|
||||
s_HwUtility.GetMacAddress(),
|
||||
operationMessage,
|
||||
region,
|
||||
s_SerialNo
|
||||
s_HwUtility.GetRegion(),
|
||||
s_HwUtility.GetSerialNumber()
|
||||
);
|
||||
|
||||
s_RenderSystem.SwapBuffers();
|
||||
renderSystem.SwapBuffers();
|
||||
|
||||
// デフォルトで下画面に描画するもの
|
||||
s_RenderSystem.SetRenderTarget(common::GetRenderTarget(NN_GX_DISPLAY1, flip));
|
||||
renderSystem.SetRenderTarget(common::GetRenderTarget(NN_GX_DISPLAY1, flip));
|
||||
if(IsBackupSucceeded())
|
||||
{
|
||||
s_RenderSystem.SetClearColor(common::GetRenderTarget(NN_GX_DISPLAY1, flip), SUCCESS_COLOR);
|
||||
renderSystem.SetClearColor(common::GetRenderTarget(NN_GX_DISPLAY1, flip), SUCCESS_COLOR);
|
||||
}
|
||||
if(IsBackupFailed())
|
||||
{
|
||||
s_RenderSystem.SetClearColor(common::GetRenderTarget(NN_GX_DISPLAY1, flip), FAIL_COLOR);
|
||||
renderSystem.SetClearColor(common::GetRenderTarget(NN_GX_DISPLAY1, flip), FAIL_COLOR);
|
||||
}
|
||||
s_RenderSystem.Clear();
|
||||
s_RenderSystem.SetColor(1.f, 1.f, 1.f);
|
||||
renderSystem.Clear();
|
||||
renderSystem.SetColor(1.f, 1.f, 1.f);
|
||||
|
||||
common::Logger::GetLoggerInstance()->DrawConsole();
|
||||
s_RenderSystem.SwapBuffers();
|
||||
renderSystem.SwapBuffers();
|
||||
|
||||
|
||||
s_RenderSystem.WaitVsync(NN_GX_DISPLAY_BOTH);
|
||||
renderSystem.WaitVsync(NN_GX_DISPLAY_BOTH);
|
||||
|
||||
// 電源長押しで終了
|
||||
if ( nn::applet::IsExpectedToCloseApplication())
|
||||
@ -426,10 +282,8 @@ extern "C" void nnMain(void)
|
||||
// アンマウント
|
||||
nn::fs::Unmount(common::NAND_ARCHIVE_NAME);
|
||||
nn::fs::Unmount(common::SDMC_ARCHIVE_NAME);
|
||||
s_RenderSystem.Finalize();
|
||||
renderSystem.Finalize();
|
||||
|
||||
nn::mcu::CTR::FinalizeHwCheck(&s_McuSession);
|
||||
nn::friends::detail::Finalize();
|
||||
nn::ps::Finalize();
|
||||
nn::ptm::CTR::FinalizeForSystemMenu();
|
||||
nn::cfg::CTR::system::Finalize();
|
||||
|
||||
@ -16,22 +16,9 @@
|
||||
#ifndef NN_CONSOLEBACKUP_H_
|
||||
#define NN_CONSOLEBACKUP_H_
|
||||
|
||||
#include <nn.h>
|
||||
#include "VersionDetect.h"
|
||||
|
||||
namespace ConsoleBackup
|
||||
{
|
||||
|
||||
bool IsAdapterConnected();
|
||||
bool IsBatteryLower();
|
||||
bool CanReadIVS();
|
||||
bool CanReadSerialNumber();
|
||||
void GetSerialNumber(u8** serial, size_t* size);
|
||||
void GetIvs(void** ivs, size_t* size);
|
||||
nn::Handle GetMcuHandle();
|
||||
void GetVersionData(common::VerDef* version);
|
||||
bit32 GetDeviceId();
|
||||
|
||||
const u32 CONSOLE_WIDTH = 38;
|
||||
const u32 CONSOLE_HEIGHT = 24;
|
||||
const u32 CONSOLE_MAX_LINE = 1000;
|
||||
|
||||
@ -15,7 +15,6 @@
|
||||
|
||||
#include "Controller.h"
|
||||
#include "FileChecker.h"
|
||||
#include "ConsoleBackup.h"
|
||||
#include "Exporter.h"
|
||||
#include "SimplePlayer.h"
|
||||
#include "CommonLogger.h"
|
||||
@ -56,12 +55,13 @@ bool s_PlayedFailSound = false;
|
||||
|
||||
} // namespace <unnamed>
|
||||
|
||||
bool NeedsAcAdateper()
|
||||
bool NeedsAcAdapter(common::HardwareStateManager& manager)
|
||||
{
|
||||
return IsBatteryLower() && !IsAdapterConnected();
|
||||
return manager.IsBatteryLower() && !manager.IsAdapterConnected();
|
||||
}
|
||||
|
||||
void ControlState(::std::vector<std::string>& operationMessage, bool& nextStep, bool& continueBackup)
|
||||
void ControlState(common::HardwareStateManager& manager, ::std::vector<std::string>& operationMessage, bool& nextStep,
|
||||
bool& continueBackup)
|
||||
{
|
||||
// 状態遷移Controller
|
||||
switch (s_BackupState)
|
||||
@ -72,7 +72,7 @@ void ControlState(::std::vector<std::string>& operationMessage, bool& nextStep,
|
||||
{
|
||||
bool error = false;
|
||||
// 完全性検証SEEDを読めるか?
|
||||
if (CanReadIVS())
|
||||
if (manager.CanReadIvs())
|
||||
{
|
||||
// SDカードが挿入されているか?
|
||||
if (nn::fs::IsSdmcInserted())
|
||||
@ -96,7 +96,7 @@ void ControlState(::std::vector<std::string>& operationMessage, bool& nextStep,
|
||||
if (nextStep)
|
||||
{
|
||||
// シリアルナンバーを読み取れるか?
|
||||
if (!CanReadSerialNumber())
|
||||
if (!manager.CanReadSerialNumber())
|
||||
{
|
||||
common::PlaySound(common::SOUND_ANNOTATION);
|
||||
COMMON_LOGGER("Can't Read Serial Number\n");
|
||||
@ -127,7 +127,7 @@ void ControlState(::std::vector<std::string>& operationMessage, bool& nextStep,
|
||||
}
|
||||
|
||||
// ACアダプタが必要か?
|
||||
if (NeedsAcAdateper())
|
||||
if (NeedsAcAdapter(manager))
|
||||
{
|
||||
error = true;
|
||||
operationMessage.push_back(::std::string("Connect AC Adapter!!"));
|
||||
@ -243,14 +243,14 @@ void ControlState(::std::vector<std::string>& operationMessage, bool& nextStep,
|
||||
continueBackup = true;
|
||||
|
||||
// ACアダプタが必要か?
|
||||
if (NeedsAcAdateper())
|
||||
if (NeedsAcAdapter(manager))
|
||||
{
|
||||
continueBackup = false;
|
||||
operationMessage.push_back(::std::string("Connect AC Adapter!!"));
|
||||
}
|
||||
|
||||
// データを書き込む
|
||||
ExportData();
|
||||
ExportData(manager);
|
||||
|
||||
// 処理が完了した
|
||||
if (continueBackup && IsExportFinished())
|
||||
|
||||
@ -18,11 +18,13 @@
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include "HardwareStateManager.h"
|
||||
|
||||
namespace ConsoleBackup
|
||||
{
|
||||
|
||||
void ControlState(::std::vector<std::string>& operationMessage, bool& nextStep, bool& continueBackup);
|
||||
void ControlState(common::HardwareStateManager& manager, ::std::vector<std::string>& operationMessage, bool& nextStep,
|
||||
bool& continueBackup);
|
||||
bool InProgress();
|
||||
bool IsBackupSucceeded();
|
||||
bool IsBackupFailed();
|
||||
|
||||
@ -36,7 +36,6 @@
|
||||
#include "Exporter.h"
|
||||
#include "CommonLogger.h"
|
||||
#include "SDMountManager.h"
|
||||
#include "ConsoleBackup.h"
|
||||
#include "HeapManager.h"
|
||||
#include "SdReaderWriter.h"
|
||||
#include "FileName.h"
|
||||
@ -270,33 +269,33 @@ void WriteNorData()
|
||||
s_SdWriter.WriteBufWithCmac(common::NOR_PATHNAME, &s_NtrNorData, sizeof(common::NtrNorData));
|
||||
}
|
||||
|
||||
void WriteSerialNumber()
|
||||
void WriteSerialNumber(common::HardwareStateManager& manager)
|
||||
{
|
||||
COMMON_LOGGER("Export Serial Number.\n");
|
||||
|
||||
u8* serial;
|
||||
size_t size;
|
||||
GetSerialNumber(&serial, &size);
|
||||
manager.GetSerialNumber(&serial, &size);
|
||||
|
||||
s_SdWriter.WriteBufWithCmac(common::SERIAL_PATHNAME, serial, size);
|
||||
}
|
||||
|
||||
void WriteDeviceId()
|
||||
void WriteDeviceId(common::HardwareStateManager& manager)
|
||||
{
|
||||
COMMON_LOGGER("Export Device ID.\n");
|
||||
|
||||
bit32 deviceId = GetDeviceId();
|
||||
bit32 deviceId = manager.GetDeviceId();
|
||||
|
||||
s_SdWriter.WriteBufWithCmac(common::DEVICE_ID_PATHNAME, &deviceId, sizeof(deviceId));
|
||||
}
|
||||
|
||||
void WriteIvs()
|
||||
void WriteIvs(common::HardwareStateManager& manager)
|
||||
{
|
||||
COMMON_LOGGER("Export IVS.\n");
|
||||
|
||||
void* ivs;
|
||||
size_t size;
|
||||
GetIvs(&ivs, &size);
|
||||
manager.GetIvs(&ivs, &size);
|
||||
|
||||
void* enc;
|
||||
nn::Result result;
|
||||
@ -680,11 +679,11 @@ void ExportTwlSoundData()
|
||||
}
|
||||
|
||||
|
||||
void WriteMcuRtcData()
|
||||
void WriteMcuRtcData(common::HardwareStateManager& manager)
|
||||
{
|
||||
COMMON_LOGGER("Export RTC Data.\n");
|
||||
nn::Result result;
|
||||
nn::Handle handle = GetMcuHandle();
|
||||
nn::Handle handle = manager.GetMcuHandle();
|
||||
|
||||
if(handle.IsValid())
|
||||
{
|
||||
@ -795,12 +794,12 @@ void FinalizeExportThread()
|
||||
s_ExportThread.Finalize();
|
||||
}
|
||||
|
||||
void WriteVersionData()
|
||||
void WriteVersionData(common::HardwareStateManager& manager)
|
||||
{
|
||||
COMMON_LOGGER("Export Version Data.\n");
|
||||
|
||||
common::VerDef versionData;
|
||||
GetVersionData(&versionData);
|
||||
manager.GetVersionData(&versionData);
|
||||
|
||||
s_SdWriter.WriteBufWithCmac(common::VERSION_DATA_PATHNAME, &versionData, sizeof(common::VerDef));
|
||||
}
|
||||
@ -833,7 +832,7 @@ void DeleteNimSaveData()
|
||||
}
|
||||
|
||||
|
||||
void ExportData()
|
||||
void ExportData(common::HardwareStateManager& manager)
|
||||
{
|
||||
static bool init = true;
|
||||
|
||||
@ -849,18 +848,18 @@ void ExportData()
|
||||
WriteNorData();
|
||||
|
||||
// シリアルナンバーをSDカードに書き込む
|
||||
WriteSerialNumber();
|
||||
WriteSerialNumber(manager);
|
||||
|
||||
// デバイスIDをSDカードに書き込む
|
||||
WriteDeviceId();
|
||||
WriteDeviceId(manager);
|
||||
|
||||
// 完全性検証SEEDをSDカードに書き込む
|
||||
WriteIvs();
|
||||
WriteIvs(manager);
|
||||
|
||||
::std::string systemSaveRoot;
|
||||
void* ivs;
|
||||
size_t size;
|
||||
GetIvs(&ivs, &size);
|
||||
manager.GetIvs(&ivs, &size);
|
||||
// IVSからセーブデータディレクトリ名を計算
|
||||
common::Util::GetSaveDataDirectoryRoot(systemSaveRoot, ivs, size);
|
||||
|
||||
@ -868,10 +867,10 @@ void ExportData()
|
||||
//WritePlayHistory();
|
||||
|
||||
// RTCをSDに書き出す
|
||||
WriteMcuRtcData();
|
||||
WriteMcuRtcData(manager);
|
||||
|
||||
// バージョン情報をSDに書き出す
|
||||
WriteVersionData();
|
||||
WriteVersionData(manager);
|
||||
|
||||
// NANDのセーブデータをSDに書き出す
|
||||
WriteSaveData(systemSaveRoot);
|
||||
|
||||
@ -17,6 +17,7 @@
|
||||
#define EXPORTER_H_
|
||||
|
||||
#include <nn.h>
|
||||
#include "HardwareStateManager.h"
|
||||
|
||||
namespace ConsoleBackup
|
||||
{
|
||||
@ -26,7 +27,7 @@ void ExportTwlTitleList();
|
||||
void ExportTwlSaveData();
|
||||
void ExportTwlPhotoData();
|
||||
void ExportTwlSoundData();
|
||||
void ExportData();
|
||||
void ExportData(common::HardwareStateManager& manager);
|
||||
void DeleteNimSaveData();
|
||||
|
||||
u32 GetProgress();
|
||||
|
||||
@ -44,6 +44,7 @@ SOURCES[] =
|
||||
../common/PlayHistoryManager.cpp
|
||||
../common/VersionDetect.cpp
|
||||
../common/ResFont.cpp
|
||||
../common/HardwareStateManager.cpp
|
||||
|
||||
CTR_BANNER_SPEC = $(TARGET_PROGRAM).bsf
|
||||
|
||||
|
||||
@ -23,8 +23,6 @@
|
||||
#include <nn/ps.h>
|
||||
#include <nn/nwm.h>
|
||||
#include <nn/ac.h>
|
||||
#include <nn/friends.h>
|
||||
#include <nn/friends/CTR/friends_ApiPrivate.h>
|
||||
#include <nn/fs/CTR/fs_ArchiveTypesForSystem.h>
|
||||
#include <nn/fs/CTR/MPCore/fs_FileSystemBasePrivate.h>
|
||||
#include <nn/fs/fs_ApiSysSaveData.h>
|
||||
@ -48,6 +46,7 @@
|
||||
#include "VersionDetect.h"
|
||||
#include "Util.h"
|
||||
#include "ResFont.h"
|
||||
#include "HardwareStateManager.h"
|
||||
|
||||
// svnリビジョン埋め込み用
|
||||
#include "../../generated/ConsoleRestore/version.h"
|
||||
@ -60,79 +59,15 @@ namespace {
|
||||
// グラフィックスに割り当てるメモリ
|
||||
const size_t s_GxHeapSize = 0x800000;
|
||||
|
||||
common::Util s_HwUtility;
|
||||
|
||||
demo::RenderSystemDrawing s_RenderSystem;
|
||||
nn::Handle s_McuSession;
|
||||
|
||||
// バッテリ残量
|
||||
u8 batteryRemain = 100;
|
||||
|
||||
// シリアルナンバー
|
||||
u8 s_SerialNo[nn::cfg::CTR::CFG_SECURE_INFO_SERIAL_NO_LEN];
|
||||
|
||||
// デバイスID
|
||||
bit32 s_DeviceId;
|
||||
|
||||
// シリアルナンバーが読めるかどうか
|
||||
bool s_CanReadSerialNumber = false;
|
||||
|
||||
// IVSへのポインタ
|
||||
void* sp_Ivs;
|
||||
|
||||
size_t s_SizeofIvs;
|
||||
|
||||
// IVSが読めるかどうか
|
||||
bool s_CanReadIvs = false;
|
||||
|
||||
// バージョン情報
|
||||
common::VerDef s_VerData;
|
||||
|
||||
} // namespace <unnamed>
|
||||
|
||||
namespace ConsoleRestore{
|
||||
|
||||
bool IsAdapterConnected()
|
||||
{
|
||||
return nn::ptm::CTR::GetAdapterState() == nn::ptm::CTR::ADAPTERSTATE_CONNECTED;
|
||||
}
|
||||
|
||||
bool IsBatteryLower()
|
||||
{
|
||||
return batteryRemain <= 10;
|
||||
}
|
||||
|
||||
bool CanReadIVS()
|
||||
{
|
||||
return s_CanReadIvs;
|
||||
}
|
||||
|
||||
bool CanReadSerialNumber()
|
||||
{
|
||||
return s_CanReadSerialNumber;
|
||||
}
|
||||
|
||||
void GetSerialNumber(u8** serial, size_t* size)
|
||||
{
|
||||
*serial = s_SerialNo;
|
||||
*size = nn::cfg::CTR::CFG_SECURE_INFO_SERIAL_NO_LEN;
|
||||
}
|
||||
|
||||
void GetIvs(void** ivs, size_t* size)
|
||||
{
|
||||
*ivs = sp_Ivs;
|
||||
*size = s_SizeofIvs;
|
||||
}
|
||||
|
||||
bit32 GetDeviceId()
|
||||
{
|
||||
return s_DeviceId;
|
||||
}
|
||||
|
||||
void GetVersionData(common::VerDef* version)
|
||||
{
|
||||
*version = s_VerData;
|
||||
}
|
||||
|
||||
void FinalizeAll()
|
||||
void FinalizeAll(common::HardwareStateManager& manager)
|
||||
{
|
||||
common::Logger::GetLoggerInstance()->Finalize();
|
||||
// アンマウント
|
||||
@ -140,8 +75,7 @@ void FinalizeAll()
|
||||
nn::fs::Unmount("sdmc:");
|
||||
s_RenderSystem.Finalize();
|
||||
|
||||
nn::mcu::CTR::FinalizeHwCheck(&s_McuSession);
|
||||
nn::friends::detail::Finalize();
|
||||
manager.Finalize();
|
||||
nn::ps::Finalize();
|
||||
nn::ptm::CTR::FinalizeForSystemMenu();
|
||||
nn::cfg::CTR::system::Finalize();
|
||||
@ -153,11 +87,6 @@ void FinalizeAll()
|
||||
nn::applet::CloseApplication();
|
||||
}
|
||||
|
||||
nn::Handle GetMcuHandle()
|
||||
{
|
||||
return s_McuSession;
|
||||
}
|
||||
|
||||
extern "C" void nnMain(void)
|
||||
{
|
||||
nn::Result result;
|
||||
@ -199,13 +128,6 @@ extern "C" void nnMain(void)
|
||||
// ps の初期化
|
||||
nn::ps::Initialize();
|
||||
|
||||
// friendsの初期化
|
||||
result = nn::friends::detail::Initialize();
|
||||
|
||||
// mcuの初期化
|
||||
nn::mcu::CTR::InitializeHwCheck(&s_McuSession);
|
||||
nn::mcu::CTR::HwCheck mcu(s_McuSession);
|
||||
|
||||
// amの初期化
|
||||
nn::am::InitializeForSystemMenu();
|
||||
|
||||
@ -237,87 +159,23 @@ extern "C" void nnMain(void)
|
||||
nn::hid::PadStatus padStatus;
|
||||
|
||||
// データの準備
|
||||
|
||||
// 完全性検証SEEDの取得
|
||||
result = nn::fs::MountSpecialArchive("nand:", nn::fs::CTR::ARCHIVE_TYPE_CTR_NAND);
|
||||
if (result.IsSuccess())
|
||||
{
|
||||
nn::fs::FileInputStream fis;
|
||||
|
||||
result = fis.TryInitialize(L"nand:/private/movable.sed");
|
||||
if (result.IsSuccess())
|
||||
{
|
||||
s64 fileSize = fis.GetSize();
|
||||
s32 ret;
|
||||
void* addr = NULL;
|
||||
addr = common::HeapManager::GetHeap()->Allocate(fileSize);
|
||||
if (addr != NULL)
|
||||
{
|
||||
sp_Ivs = addr;
|
||||
s_SizeofIvs = fileSize;
|
||||
result = fis.TryRead(&ret, addr, fileSize);
|
||||
if (result.IsSuccess())
|
||||
{
|
||||
s_CanReadIvs = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
fis.Finalize();
|
||||
}
|
||||
// 一旦アンマウントしておく
|
||||
nn::fs::Unmount("nand:");
|
||||
|
||||
// リージョンの取得
|
||||
nn::cfg::CTR::CfgRegionCode region;
|
||||
region = nn::cfg::CTR::GetRegion();
|
||||
|
||||
// シリアルナンバーの取得
|
||||
std::memset(s_SerialNo, '\0',
|
||||
nn::cfg::CTR::CFG_SECURE_INFO_SERIAL_NO_LEN);
|
||||
result = nn::cfg::CTR::system::GetSerialNo(s_SerialNo);
|
||||
common::Util::AddCheckDigit(reinterpret_cast<char*>(s_SerialNo));
|
||||
if(result.IsSuccess())
|
||||
{
|
||||
s_CanReadSerialNumber = true;
|
||||
}
|
||||
COMMON_LOGGER_RESULT_IF_FAILED_WITH_LINE(result);
|
||||
|
||||
// デバイスIDの取得
|
||||
result = nn::ps::CTR::GetDeviceId(&s_DeviceId);
|
||||
COMMON_LOGGER_RESULT_IF_FAILED_WITH_LINE(result);
|
||||
bit64 infraDeviceId;
|
||||
infraDeviceId = s_DeviceId + common::INFRA_DEVICE_ID_OFFSET;
|
||||
|
||||
// MACアドレスの取得
|
||||
nn::nwm::Mac mac;
|
||||
char8 macAddress[nn::nwm::Mac::MAC_STRING_SIZE];
|
||||
|
||||
result = nn::nwm::GetMacAddress(mac);
|
||||
COMMON_LOGGER_RESULT_IF_FAILED_WITH_LINE(result);
|
||||
mac.GetString(macAddress);
|
||||
COMMON_LOGGER_RESULT_IF_FAILED_WITH_LINE(result);
|
||||
|
||||
// フレンドコードの取得
|
||||
nn::friends::CTR::FriendKey friendKey;
|
||||
result = nn::friends::CTR::GetMyFriendKey(&friendKey);
|
||||
COMMON_LOGGER_RESULT_IF_FAILED_WITH_LINE(result);
|
||||
u64 friendCode = nn::friends::CTR::FriendKeyToFriendCode(friendKey);
|
||||
|
||||
// バージョンの取得
|
||||
common::GetSystemVersion(&s_VerData, region);
|
||||
s_HwUtility.Initialize();
|
||||
common::HardwareStateManager manager(s_HwUtility);
|
||||
|
||||
// 情報出力
|
||||
COMMON_LOGGER("CTR Console Restore %s Rev.%s\n", __DATE__, RESTORE_VERSION_NUM);
|
||||
COMMON_LOGGER("System Ver. %d.%d.%d-%d\n", s_VerData.cup.majorVersion, s_VerData.cup.minorVersion, s_VerData.cup.microVersion,
|
||||
s_VerData.nup.majorVersion);
|
||||
COMMON_LOGGER("System Region %s\n", nn::cfg::CTR::GetRegionCodeA3(region));
|
||||
COMMON_LOGGER("Serial Number %s\n", s_SerialNo);
|
||||
COMMON_LOGGER("Device ID %llu\n", infraDeviceId);
|
||||
COMMON_LOGGER("MAC Address %s\n", macAddress);
|
||||
COMMON_LOGGER("System Ver. %d.%d.%d-%d\n", s_HwUtility.GetCupMajorVersion(),
|
||||
s_HwUtility.GetCupMinorVersion(),
|
||||
s_HwUtility.GetCupMicroVersion(),
|
||||
s_HwUtility.GetCupMajorVersion());
|
||||
COMMON_LOGGER("System Region %s\n", s_HwUtility.GetRegionCodeA3());
|
||||
COMMON_LOGGER("Serial Number %s\n", s_HwUtility.GetSerialNumber());
|
||||
COMMON_LOGGER("Device ID %llu\n", s_HwUtility.GetInfraDeviceId());
|
||||
COMMON_LOGGER("MAC Address %s\n", s_HwUtility.GetMacAddress());
|
||||
COMMON_LOGGER("Friend Code %04u-%04u-%04u\n",
|
||||
static_cast<u32>(friendCode / 100000000ULL % 10000ULL),
|
||||
static_cast<u32>(friendCode / 10000ULL % 10000ULL),
|
||||
static_cast<u32>(friendCode % 10000ULL) );
|
||||
static_cast<u32>(s_HwUtility.GetFriendcode() / 100000000ULL % 10000ULL),
|
||||
static_cast<u32>(s_HwUtility.GetFriendcode() / 10000ULL % 10000ULL),
|
||||
static_cast<u32>(s_HwUtility.GetFriendcode() % 10000ULL) );
|
||||
|
||||
|
||||
bool flip = false;
|
||||
@ -366,11 +224,9 @@ extern "C" void nnMain(void)
|
||||
}
|
||||
|
||||
// 情報更新
|
||||
// バッテリ
|
||||
mcu.GetBatteryRemain(&batteryRemain);
|
||||
// ACアダプタ
|
||||
std::string adapterState;
|
||||
if(IsAdapterConnected())
|
||||
if(manager.IsAdapterConnected())
|
||||
{
|
||||
adapterState += ::std::string("Connected");
|
||||
}
|
||||
@ -383,7 +239,7 @@ extern "C" void nnMain(void)
|
||||
// 進捗確認メッセージを兼ねる?
|
||||
::std::vector<std::string> operationMessage;
|
||||
|
||||
ControlState(operationMessage, nextStep);
|
||||
ControlState(manager, operationMessage, nextStep);
|
||||
|
||||
nn::util::FloatColor titleColor;
|
||||
|
||||
@ -413,17 +269,20 @@ extern "C" void nnMain(void)
|
||||
flip,
|
||||
adapterState,
|
||||
RESTORE_VERSION_NUM,
|
||||
&s_VerData,
|
||||
batteryRemain,
|
||||
infraDeviceId,
|
||||
friendCode,
|
||||
s_HwUtility.GetCupMajorVersion(),
|
||||
s_HwUtility.GetCupMinorVersion(),
|
||||
s_HwUtility.GetCupMicroVersion(),
|
||||
s_HwUtility.GetNupVersion(),
|
||||
s_HwUtility.GetBatteryRemain(),
|
||||
s_HwUtility.GetInfraDeviceId(),
|
||||
s_HwUtility.GetFriendcode(),
|
||||
GetProgress(),
|
||||
IsRestoreFailed(),
|
||||
IsRestoreSucceeded(),
|
||||
macAddress,
|
||||
s_HwUtility.GetMacAddress(),
|
||||
operationMessage,
|
||||
region,
|
||||
s_SerialNo
|
||||
s_HwUtility.GetRegion(),
|
||||
s_HwUtility.GetSerialNumber()
|
||||
);
|
||||
|
||||
if (GetRestoreMode() != RESTORE_MODE_RESTORE)
|
||||
@ -476,7 +335,7 @@ extern "C" void nnMain(void)
|
||||
// 電源長押しで終了
|
||||
if ( nn::applet::IsExpectedToCloseApplication())
|
||||
{
|
||||
FinalizeAll();
|
||||
FinalizeAll(manager);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -22,18 +22,6 @@
|
||||
namespace ConsoleRestore
|
||||
{
|
||||
|
||||
bool IsAdapterConnected();
|
||||
bool IsBatteryLower();
|
||||
bool CanReadIVS();
|
||||
bool CanReadSerialNumber();
|
||||
void GetSerialNumber(u8** serial, size_t* size);
|
||||
void GetIvs(void** ivs, size_t* size);
|
||||
nn::Handle GetMcuHandle();
|
||||
void GetVersionData(common::VerDef* version);
|
||||
bit32 GetDeviceId();
|
||||
|
||||
void FinalizeAll();
|
||||
|
||||
const u32 CONSOLE_WIDTH = 38;
|
||||
const u32 CONSOLE_HEIGHT = 24;
|
||||
const u32 CONSOLE_MAX_LINE = 1000;
|
||||
|
||||
@ -88,9 +88,9 @@ u32 s_ShopOperationRetryCount[SHOP_OPERATION_NUM_MAX];
|
||||
void PutAliveMessage(::std::vector<std::string>& operationMessage, const char* str);
|
||||
bool CheckAndReadAPSetting(::std::vector<std::string>& operationMessage);
|
||||
|
||||
bool NeedsAcAdater()
|
||||
bool NeedsAcAdater(common::HardwareStateManager& manager)
|
||||
{
|
||||
return IsBatteryLower() && !IsAdapterConnected();
|
||||
return manager.IsBatteryLower() && !manager.IsAdapterConnected();
|
||||
}
|
||||
|
||||
typedef enum RestoreState
|
||||
@ -142,26 +142,26 @@ RestoreState s_RestoreState = STARTUP;
|
||||
// Restoreモード管理
|
||||
RestoreMode s_RestoreMode = RESTORE_MODE_RESTORE;
|
||||
|
||||
void CheckSdInserted(::std::vector<std::string>& message, bool& goNextStep);
|
||||
void CheckAcAdapter(::std::vector<std::string>& message, bool& goNextStep);
|
||||
void CheckSdWritable(::std::vector<std::string>& message, bool& goNextStep);
|
||||
void CheckApSetting(::std::vector<std::string>& message, bool& goNextStep);
|
||||
void CheckNupExecuted(::std::vector<std::string>& message, bool& goNextStep);
|
||||
void CheckDownloadIvs(::std::vector<std::string>& message, bool& goNextStep);
|
||||
void CheckAccountDeleted(::std::vector<std::string>& message, bool& goNextStep);
|
||||
void CheckWriteFinished(::std::vector<std::string>& message, bool& goNextStep);
|
||||
void CheckReadIvs(::std::vector<std::string>& message, bool& goNextStep);
|
||||
void CheckConsoleInitialized(::std::vector<std::string>& message, bool& goNextStep);
|
||||
void CheckExistsSerialNumber(::std::vector<std::string>& message, bool& goNextStep);
|
||||
void CheckIvsinSd(::std::vector<std::string>& message, bool& goNextStep);
|
||||
void CheckRegioinSd(::std::vector<std::string>& message, bool& goNextStep);
|
||||
void CheckSdInserted(common::HardwareStateManager& manager, ::std::vector<std::string>& message, bool& goNextStep);
|
||||
void CheckAcAdapter(common::HardwareStateManager& manager, ::std::vector<std::string>& message, bool& goNextStep);
|
||||
void CheckSdWritable(common::HardwareStateManager& manager, ::std::vector<std::string>& message, bool& goNextStep);
|
||||
void CheckApSetting(common::HardwareStateManager& manager, ::std::vector<std::string>& message, bool& goNextStep);
|
||||
void CheckNupExecuted(common::HardwareStateManager& manager, ::std::vector<std::string>& message, bool& goNextStep);
|
||||
void CheckDownloadIvs(common::HardwareStateManager& manager, ::std::vector<std::string>& message, bool& goNextStep);
|
||||
void CheckAccountDeleted(common::HardwareStateManager& manager, ::std::vector<std::string>& message, bool& goNextStep);
|
||||
void CheckWriteFinished(common::HardwareStateManager& manager, ::std::vector<std::string>& message, bool& goNextStep);
|
||||
void CheckReadIvs(common::HardwareStateManager& manager, ::std::vector<std::string>& message, bool& goNextStep);
|
||||
void CheckConsoleInitialized(common::HardwareStateManager& manager, ::std::vector<std::string>& message, bool& goNextStep);
|
||||
void CheckExistsSerialNumber(common::HardwareStateManager& manager, ::std::vector<std::string>& message, bool& goNextStep);
|
||||
void CheckIvsinSd(common::HardwareStateManager& manager, ::std::vector<std::string>& message, bool& goNextStep);
|
||||
void CheckRegioinSd(common::HardwareStateManager& manager, ::std::vector<std::string>& message, bool& goNextStep);
|
||||
|
||||
// SDカード挿入チェック
|
||||
void CheckSdInserted(::std::vector<std::string>& message, bool& goNextStep)
|
||||
void CheckSdInserted(common::HardwareStateManager& manager, ::std::vector<std::string>& message, bool& goNextStep)
|
||||
{
|
||||
if (nn::fs::IsSdmcInserted())
|
||||
{
|
||||
CheckAcAdapter(message, goNextStep);
|
||||
CheckAcAdapter(manager, message, goNextStep);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -171,27 +171,27 @@ void CheckSdInserted(::std::vector<std::string>& message, bool& goNextStep)
|
||||
}
|
||||
|
||||
// ACアダプタが必要かどうかチェック
|
||||
void CheckAcAdapter(::std::vector<std::string>& message, bool& goNextStep)
|
||||
void CheckAcAdapter(common::HardwareStateManager& manager, ::std::vector<std::string>& message, bool& goNextStep)
|
||||
{
|
||||
// ACアダプタが必要か?
|
||||
if (NeedsAcAdater())
|
||||
if (NeedsAcAdater(manager))
|
||||
{
|
||||
message.push_back(::std::string("Connect AC Adapter!!"));
|
||||
s_RestoreState = STARTUP;
|
||||
}
|
||||
else
|
||||
{
|
||||
CheckSdWritable(message, goNextStep);
|
||||
CheckSdWritable(manager, message, goNextStep);
|
||||
}
|
||||
}
|
||||
|
||||
// SDカード書き込みチェック
|
||||
void CheckSdWritable(::std::vector<std::string>& message, bool& goNextStep)
|
||||
void CheckSdWritable(common::HardwareStateManager& manager, ::std::vector<std::string>& message, bool& goNextStep)
|
||||
{
|
||||
// SDカードに書き込みできるか?
|
||||
if (nn::fs::IsSdmcWritable())
|
||||
{
|
||||
CheckApSetting(message, goNextStep);
|
||||
CheckApSetting(manager, message, goNextStep);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -207,11 +207,11 @@ void CheckSdWritable(::std::vector<std::string>& message, bool& goNextStep)
|
||||
|
||||
|
||||
// 設定ファイル書式チェック
|
||||
void CheckApSetting(::std::vector<std::string>& message, bool& goNextStep)
|
||||
void CheckApSetting(common::HardwareStateManager& manager, ::std::vector<std::string>& message, bool& goNextStep)
|
||||
{
|
||||
if (CheckAndReadAPSetting(message))
|
||||
{
|
||||
CheckNupExecuted(message, goNextStep);
|
||||
CheckNupExecuted(manager, message, goNextStep);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -220,13 +220,13 @@ void CheckApSetting(::std::vector<std::string>& message, bool& goNextStep)
|
||||
}
|
||||
|
||||
// NUP済みかどうかチェック
|
||||
void CheckNupExecuted(::std::vector<std::string>& message, bool& goNextStep)
|
||||
void CheckNupExecuted(common::HardwareStateManager& manager, ::std::vector<std::string>& message, bool& goNextStep)
|
||||
{
|
||||
if (common::ExistsUpdateCheckedFile())
|
||||
{
|
||||
if(s_GetIvsOnlyMode)
|
||||
{
|
||||
CheckDownloadIvs(message, goNextStep);
|
||||
CheckDownloadIvs(manager, message, goNextStep);
|
||||
}
|
||||
else if (s_NupOnlyMode)
|
||||
{
|
||||
@ -237,7 +237,7 @@ void CheckNupExecuted(::std::vector<std::string>& message, bool& goNextStep)
|
||||
}
|
||||
else
|
||||
{
|
||||
CheckAccountDeleted(message, goNextStep);
|
||||
CheckAccountDeleted(manager, message, goNextStep);
|
||||
}
|
||||
}
|
||||
else
|
||||
@ -266,7 +266,7 @@ void CheckNupExecuted(::std::vector<std::string>& message, bool& goNextStep)
|
||||
}
|
||||
|
||||
// インフラからIVS取得済みかチェック
|
||||
void CheckDownloadIvs(::std::vector<std::string>& message, bool& goNextStep)
|
||||
void CheckDownloadIvs(common::HardwareStateManager& manager, ::std::vector<std::string>& message, bool& goNextStep)
|
||||
{
|
||||
NN_UNUSED_VAR(message);
|
||||
NN_UNUSED_VAR(goNextStep);
|
||||
@ -280,7 +280,7 @@ void CheckDownloadIvs(::std::vector<std::string>& message, bool& goNextStep)
|
||||
}
|
||||
else
|
||||
{
|
||||
CheckWriteFinished(message, goNextStep);
|
||||
CheckWriteFinished(manager, message, goNextStep);
|
||||
}
|
||||
}
|
||||
else
|
||||
@ -291,20 +291,20 @@ void CheckDownloadIvs(::std::vector<std::string>& message, bool& goNextStep)
|
||||
}
|
||||
|
||||
// アカウント削除済みかチェック
|
||||
void CheckAccountDeleted(::std::vector<std::string>& message, bool& goNextStep)
|
||||
void CheckAccountDeleted(common::HardwareStateManager& manager, ::std::vector<std::string>& message, bool& goNextStep)
|
||||
{
|
||||
// アカウント削除確認ファイルがあるか?
|
||||
if (common::ExistsDeleteAccountChecked())
|
||||
{
|
||||
CheckDownloadIvs(message, goNextStep);
|
||||
CheckDownloadIvs(manager, message, goNextStep);
|
||||
}
|
||||
else
|
||||
{
|
||||
// 同一本体下記書き戻しの場合はアカウント削除しない
|
||||
if(EqualsDeviceIdFileandDeviceId().IsSuccess())
|
||||
if(EqualsDeviceIdFileandDeviceId(manager).IsSuccess())
|
||||
{
|
||||
CreateDeleteAccountFinishedFile();
|
||||
CheckDownloadIvs(message, goNextStep);
|
||||
CheckDownloadIvs(manager, message, goNextStep);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -314,7 +314,7 @@ void CheckAccountDeleted(::std::vector<std::string>& message, bool& goNextStep)
|
||||
}
|
||||
|
||||
// 書き込み完了かどうかチェック
|
||||
void CheckWriteFinished(::std::vector<std::string>& message, bool& goNextStep)
|
||||
void CheckWriteFinished(common::HardwareStateManager& manager, ::std::vector<std::string>& message, bool& goNextStep)
|
||||
{
|
||||
NN_UNUSED_VAR(goNextStep);
|
||||
|
||||
@ -341,17 +341,17 @@ void CheckWriteFinished(::std::vector<std::string>& message, bool& goNextStep)
|
||||
}
|
||||
else
|
||||
{
|
||||
CheckReadIvs(message, goNextStep);
|
||||
CheckReadIvs(manager, message, goNextStep);
|
||||
}
|
||||
}
|
||||
|
||||
// IVSを読めるかどうかチェック
|
||||
void CheckReadIvs(::std::vector<std::string>& message, bool& goNextStep)
|
||||
void CheckReadIvs(common::HardwareStateManager& manager, ::std::vector<std::string>& message, bool& goNextStep)
|
||||
{
|
||||
// IVSを読めるか?
|
||||
if (CanReadIVS())
|
||||
if (manager.CanReadIvs())
|
||||
{
|
||||
CheckConsoleInitialized(message, goNextStep);
|
||||
CheckConsoleInitialized(manager, message, goNextStep);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -361,22 +361,23 @@ void CheckReadIvs(::std::vector<std::string>& message, bool& goNextStep)
|
||||
}
|
||||
|
||||
// 本体初期化済みかどうかチェック
|
||||
void CheckConsoleInitialized(::std::vector<std::string>& message, bool& goNextStep)
|
||||
void CheckConsoleInitialized(common::HardwareStateManager& manager, ::std::vector<std::string>& message, bool& goNextStep)
|
||||
{
|
||||
// 本体初期化完了ファイルがあるか?
|
||||
if (common::ExistsConsoleInitializedFile())
|
||||
{
|
||||
CheckRegioinSd(message, goNextStep);
|
||||
CheckRegioinSd(manager, message, goNextStep);
|
||||
}
|
||||
else
|
||||
{
|
||||
CheckIvsinSd(message, goNextStep);
|
||||
CheckIvsinSd(manager, message, goNextStep);
|
||||
}
|
||||
}
|
||||
|
||||
// シリアルナンバーがあるかどうかチェック
|
||||
void CheckExistsSerialNumber(::std::vector<std::string>& message, bool& goNextStep)
|
||||
void CheckExistsSerialNumber(common::HardwareStateManager& manager, ::std::vector<std::string>& message, bool& goNextStep)
|
||||
{
|
||||
NN_UNUSED_VAR(manager);
|
||||
NN_UNUSED_VAR(message);
|
||||
NN_UNUSED_VAR(goNextStep);
|
||||
|
||||
@ -403,8 +404,9 @@ void CheckExistsSerialNumber(::std::vector<std::string>& message, bool& goNextSt
|
||||
}
|
||||
|
||||
// SDカードにIVSがあるかどうかチェック
|
||||
void CheckIvsinSd(::std::vector<std::string>& message, bool& goNextStep)
|
||||
void CheckIvsinSd(common::HardwareStateManager& manager, ::std::vector<std::string>& message, bool& goNextStep)
|
||||
{
|
||||
NN_UNUSED_VAR(manager);
|
||||
NN_UNUSED_VAR(message);
|
||||
NN_UNUSED_VAR(goNextStep);
|
||||
|
||||
@ -421,7 +423,7 @@ void CheckIvsinSd(::std::vector<std::string>& message, bool& goNextStep)
|
||||
}
|
||||
|
||||
// SDカードにリージョンデータがあるかどうかチェック
|
||||
void CheckRegioinSd(::std::vector<std::string>& message, bool& goNextStep)
|
||||
void CheckRegioinSd(common::HardwareStateManager& manager, ::std::vector<std::string>& message, bool& goNextStep)
|
||||
{
|
||||
NN_UNUSED_VAR(message);
|
||||
NN_UNUSED_VAR(goNextStep);
|
||||
@ -437,7 +439,7 @@ void CheckRegioinSd(::std::vector<std::string>& message, bool& goNextStep)
|
||||
}
|
||||
else
|
||||
{
|
||||
CheckExistsSerialNumber(message, goNextStep);
|
||||
CheckExistsSerialNumber(manager, message, goNextStep);
|
||||
}
|
||||
|
||||
}
|
||||
@ -466,6 +468,7 @@ void ShopOperationSuccess(ShopOperation op, const char* logMessage, RestoreState
|
||||
}
|
||||
|
||||
void ShopOperationSingleTemplate(
|
||||
common::HardwareStateManager& manager,
|
||||
std::vector<std::string>& message,
|
||||
ShopOperation op,
|
||||
const char* aliveMessage,
|
||||
@ -475,7 +478,7 @@ void ShopOperationSingleTemplate(
|
||||
)
|
||||
{
|
||||
// ACアダプタが必要か?
|
||||
if (NeedsAcAdater())
|
||||
if (NeedsAcAdater(manager))
|
||||
{
|
||||
message.push_back(::std::string("Connect AC Adapter!!"));
|
||||
}
|
||||
@ -542,10 +545,10 @@ void ShopOperationSingleTemplate(
|
||||
}
|
||||
}
|
||||
|
||||
void UpdateOperation(::std::vector<std::string>& message, RestoreState nextState)
|
||||
void UpdateOperation(common::HardwareStateManager& manager, ::std::vector<std::string>& message, RestoreState nextState)
|
||||
{
|
||||
// ACアダプタが必要か?
|
||||
if (NeedsAcAdater())
|
||||
if (NeedsAcAdater(manager))
|
||||
{
|
||||
message.push_back(::std::string("Connect AC Adapter!!"));
|
||||
}
|
||||
@ -689,12 +692,12 @@ void PutAliveMessage(::std::vector<std::string>& operationMessage, const char* s
|
||||
i += 4;
|
||||
}
|
||||
|
||||
nn::Result ExecSyncMcuRtc()
|
||||
nn::Result ExecSyncMcuRtc(common::HardwareStateManager& manager)
|
||||
{
|
||||
nn::Result result = nn::ResultSuccess();
|
||||
if(!common::ExistsRtcSyncFinishedFile())
|
||||
{
|
||||
result = ImportMcuRtc();
|
||||
result = ImportMcuRtc(manager);
|
||||
if(result.IsSuccess())
|
||||
{
|
||||
// RTCを同期完了ファイルを作る
|
||||
@ -707,7 +710,7 @@ nn::Result ExecSyncMcuRtc()
|
||||
|
||||
} // namespace <unnamed>
|
||||
|
||||
void ControlState(::std::vector<std::string>& operationMessage, bool& nextStep)
|
||||
void ControlState(common::HardwareStateManager& manager, ::std::vector<std::string>& operationMessage, bool& nextStep)
|
||||
{
|
||||
using namespace common;
|
||||
nn::Result result;
|
||||
@ -718,7 +721,7 @@ void ControlState(::std::vector<std::string>& operationMessage, bool& nextStep)
|
||||
// 起動時
|
||||
case STARTUP:
|
||||
{
|
||||
CheckSdInserted(operationMessage, nextStep);
|
||||
CheckSdInserted(manager, operationMessage, nextStep);
|
||||
}
|
||||
break;
|
||||
|
||||
@ -803,7 +806,7 @@ void ControlState(::std::vector<std::string>& operationMessage, bool& nextStep)
|
||||
|
||||
case IMPORT_RTC:
|
||||
{
|
||||
result = ExecSyncMcuRtc();
|
||||
result = ExecSyncMcuRtc(manager);
|
||||
if (result <= nn::fs::ResultVerificationFailed())
|
||||
{
|
||||
s_RestoreState = FAIL;
|
||||
@ -838,7 +841,7 @@ void ControlState(::std::vector<std::string>& operationMessage, bool& nextStep)
|
||||
// アップデート中
|
||||
case UPDATE_IN_PROGRESS:
|
||||
{
|
||||
UpdateOperation(operationMessage, UPDATE_DONE);
|
||||
UpdateOperation(manager, operationMessage, UPDATE_DONE);
|
||||
}
|
||||
break;
|
||||
|
||||
@ -863,7 +866,7 @@ void ControlState(::std::vector<std::string>& operationMessage, bool& nextStep)
|
||||
|
||||
case DOWNLOAD_IVS:
|
||||
{
|
||||
ShopOperationSingleTemplate(operationMessage, SHOP_OPERATION_GET_IVS, "Get Ivs",
|
||||
ShopOperationSingleTemplate(manager, operationMessage, SHOP_OPERATION_GET_IVS, "Get Ivs",
|
||||
"Get Ivs Finished.\n", "Get Ivs Failed. Retrying...", DOWNLOAD_IVS_DONE);
|
||||
}
|
||||
break;
|
||||
@ -909,7 +912,7 @@ void ControlState(::std::vector<std::string>& operationMessage, bool& nextStep)
|
||||
NN_LOG("Read User's SD Card\n");
|
||||
void* ivs;
|
||||
size_t size;
|
||||
GetIvs(&ivs, &size);
|
||||
manager.GetIvs(&ivs, &size);
|
||||
std::string sysSaveRoot;
|
||||
|
||||
common::Util::GetSaveDataDirectoryRoot(sysSaveRoot, ivs, size);
|
||||
@ -942,7 +945,7 @@ void ControlState(::std::vector<std::string>& operationMessage, bool& nextStep)
|
||||
|
||||
case DELETE_ACCOUNT:
|
||||
{
|
||||
ShopOperationSingleTemplate(operationMessage, SHOP_OPERATION_UNREGISTER, "Deleting Account",
|
||||
ShopOperationSingleTemplate(manager, operationMessage, SHOP_OPERATION_UNREGISTER, "Deleting Account",
|
||||
"Delete Account Finished.\n", "Delete Account Failed. Retrying...", DELETE_ACCOUNT_DONE);
|
||||
}
|
||||
break;
|
||||
@ -1035,7 +1038,7 @@ void ControlState(::std::vector<std::string>& operationMessage, bool& nextStep)
|
||||
case RESTORE_IN_PROGRESS:
|
||||
{
|
||||
// ACアダプタが必要か?
|
||||
if (NeedsAcAdater())
|
||||
if (NeedsAcAdater(manager))
|
||||
{
|
||||
operationMessage.push_back(::std::string("Connect AC Adapter!!"));
|
||||
}
|
||||
@ -1047,7 +1050,7 @@ void ControlState(::std::vector<std::string>& operationMessage, bool& nextStep)
|
||||
}
|
||||
|
||||
// 処理が完了した
|
||||
if (!NeedsAcAdater() && IsImportFinished())
|
||||
if (!NeedsAcAdater(manager) && IsImportFinished())
|
||||
{
|
||||
COMMON_LOGGER("Import NAND Data Finished.\n");
|
||||
|
||||
@ -1149,7 +1152,7 @@ void ControlState(::std::vector<std::string>& operationMessage, bool& nextStep)
|
||||
|
||||
case SYNC_TICKET:
|
||||
{
|
||||
ShopOperationSingleTemplate(operationMessage, SHOP_OPERATION_CONNECT_ONLY, "Shop Connect",
|
||||
ShopOperationSingleTemplate(manager, operationMessage, SHOP_OPERATION_CONNECT_ONLY, "Shop Connect",
|
||||
"Shop Connect Finished.\n", "Shop Connect Failed. Retrying...", UPLOAD_IVS);
|
||||
}
|
||||
break;
|
||||
@ -1158,7 +1161,7 @@ void ControlState(::std::vector<std::string>& operationMessage, bool& nextStep)
|
||||
// UPLOAD_IN_PROGRESSでのNUP実行後、サーバが更新されないという前提なので注意
|
||||
case UPLOAD_IVS:
|
||||
{
|
||||
UpdateOperation(operationMessage, DOWNLOAD_TWL);
|
||||
UpdateOperation(manager, operationMessage, DOWNLOAD_TWL);
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
@ -19,6 +19,7 @@
|
||||
#include <nn.h>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include "HardwareStateManager.h"
|
||||
|
||||
namespace ConsoleRestore
|
||||
{
|
||||
@ -32,7 +33,7 @@ typedef enum RestoreMode
|
||||
|
||||
const u32 RETRY_MAX = 3;
|
||||
|
||||
void ControlState(::std::vector<std::string>& operationMessage, bool& nextStep);
|
||||
void ControlState(common::HardwareStateManager& manager, ::std::vector<std::string>& operationMessage, bool& nextStep);
|
||||
bool InProgress();
|
||||
bool IsRestoreSucceeded();
|
||||
bool IsRestoreFailed();
|
||||
|
||||
@ -250,7 +250,7 @@ nn::Result ReadSerialNumber(u8* serial)
|
||||
return result;
|
||||
}
|
||||
|
||||
nn::Result EqualsDeviceIdFileandDeviceId()
|
||||
nn::Result EqualsDeviceIdFileandDeviceId(common::HardwareStateManager& manager)
|
||||
{
|
||||
static nn::Result result = nn::ResultSuccess();
|
||||
|
||||
@ -274,7 +274,7 @@ nn::Result EqualsDeviceIdFileandDeviceId()
|
||||
s_CheckedEqualsDeviceIdFileandDeviceId = true;
|
||||
std::memcpy(&sdDeviceId, buf, sizeof(sdDeviceId));
|
||||
|
||||
if (GetDeviceId() == sdDeviceId)
|
||||
if (manager.GetDeviceId() == sdDeviceId)
|
||||
{
|
||||
result = nn::ResultSuccess();
|
||||
}
|
||||
@ -469,11 +469,11 @@ inline u8 DecimalToBcd(u8 param)
|
||||
return (theTen << 4 | theOne);
|
||||
}
|
||||
|
||||
nn::Result ImportMcuRtc()
|
||||
nn::Result ImportMcuRtc(common::HardwareStateManager& manager)
|
||||
{
|
||||
COMMON_LOGGER("Import RTC Data.\n");
|
||||
nn::Result result = nn::ResultSuccess();
|
||||
nn::Handle handle = GetMcuHandle();
|
||||
nn::Handle handle = manager.GetMcuHandle();
|
||||
|
||||
if(handle.IsValid())
|
||||
{
|
||||
@ -851,7 +851,6 @@ bool ExistsIvsDirectory(std::string& ivsRoot)
|
||||
}
|
||||
if (numEntry == 0)
|
||||
{
|
||||
// ルートディレクトリを閉じる
|
||||
dir.Finalize();
|
||||
common::SdMountManager::Unmount();
|
||||
return false;
|
||||
|
||||
@ -20,11 +20,12 @@
|
||||
#include "FileName.h"
|
||||
#include <nn/ac/CTR/private/ac_NetworkSetting.h>
|
||||
#include <string>
|
||||
#include "HardwareStateManager.h"
|
||||
|
||||
namespace ConsoleRestore
|
||||
{
|
||||
|
||||
nn::Result EqualsDeviceIdFileandDeviceId();
|
||||
nn::Result EqualsDeviceIdFileandDeviceId(common::HardwareStateManager& manager);
|
||||
nn::Result EqualsRegionDataandRegion();
|
||||
nn::Result ReadSerialNumber(u8* serial);
|
||||
nn::Result SetupFileList();
|
||||
@ -79,7 +80,7 @@ struct CheckedNetworkSetting
|
||||
|
||||
CheckedNetworkSetting* GetTempNetworkSetting();
|
||||
nn::Result ImportCountryLanguageData();
|
||||
nn::Result ImportMcuRtc();
|
||||
nn::Result ImportMcuRtc(common::HardwareStateManager& manager);
|
||||
|
||||
// TWL写真領域を初期化してから本体初期化を行う
|
||||
void InitializeFileSystem();
|
||||
|
||||
@ -49,6 +49,7 @@ SOURCES[] =
|
||||
../common/PlayHistoryManager.cpp
|
||||
../common/VersionDetect.cpp
|
||||
../common/ResFont.cpp
|
||||
../common/HardwareStateManager.cpp
|
||||
|
||||
CTR_BANNER_SPEC = $(TARGET_PROGRAM).bsf
|
||||
|
||||
|
||||
@ -95,7 +95,10 @@ void DrawSystemState
|
||||
bool flip,
|
||||
std::string& adapterState,
|
||||
const char* toolVersion,
|
||||
common::VerDef* mVerData,
|
||||
u8 cupMajorVersion,
|
||||
u8 cupMinorVersion,
|
||||
u8 cupMicroVersion,
|
||||
u8 nupVersion,
|
||||
u8 batteryRemain,
|
||||
u64 deviceId,
|
||||
u64 friendCode,
|
||||
@ -110,10 +113,10 @@ void DrawSystemState
|
||||
{
|
||||
// パラメータ保存
|
||||
s_AdapterState = adapterState;
|
||||
s_CupMajor = mVerData->cup.majorVersion;
|
||||
s_CupMinor = mVerData->cup.minorVersion;
|
||||
s_CupMicro = mVerData->cup.microVersion;
|
||||
s_NupMajor = mVerData->nup.majorVersion;
|
||||
s_CupMajor = cupMajorVersion;
|
||||
s_CupMinor = cupMinorVersion;
|
||||
s_CupMicro = cupMicroVersion;
|
||||
s_NupMajor = nupVersion;
|
||||
s_BatteryRemain = batteryRemain;
|
||||
s_DeviceId = deviceId;
|
||||
s_FriendCode = friendCode;
|
||||
|
||||
@ -53,7 +53,10 @@ void DrawSystemState
|
||||
bool flip,
|
||||
std::string& adapterState,
|
||||
const char* toolVersion,
|
||||
common::VerDef* mVerData,
|
||||
u8 cupMajorVersion,
|
||||
u8 cupMinorVersion,
|
||||
u8 cupMicroVersion,
|
||||
u8 nupVersion,
|
||||
u8 batteryRemain,
|
||||
u64 deviceId,
|
||||
u64 friendCode,
|
||||
|
||||
@ -0,0 +1,81 @@
|
||||
/*---------------------------------------------------------------------------*
|
||||
Project: Horizon
|
||||
File: HardwareStateManager.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 "HardwareStateManager.h"
|
||||
|
||||
namespace common
|
||||
{
|
||||
|
||||
HardwareStateManager::HardwareStateManager(Util& hwUtility)
|
||||
{
|
||||
m_pUtil = &hwUtility;
|
||||
}
|
||||
|
||||
HardwareStateManager::~HardwareStateManager()
|
||||
{
|
||||
// TODO Auto-generated destructor stub
|
||||
}
|
||||
|
||||
void HardwareStateManager::Finalize()
|
||||
{
|
||||
m_pUtil->Finalize();
|
||||
}
|
||||
|
||||
bool HardwareStateManager::CanReadIvs()
|
||||
{
|
||||
return m_pUtil->CanReadIVS();
|
||||
}
|
||||
|
||||
bool HardwareStateManager::CanReadSerialNumber()
|
||||
{
|
||||
return m_pUtil->CanReadSerialNumber();
|
||||
}
|
||||
|
||||
bool HardwareStateManager::IsBatteryLower()
|
||||
{
|
||||
return m_pUtil->IsBatteryLower();
|
||||
}
|
||||
|
||||
bool HardwareStateManager::IsAdapterConnected()
|
||||
{
|
||||
return m_pUtil->IsAdapterConnected();
|
||||
}
|
||||
|
||||
bit32 HardwareStateManager::GetDeviceId()
|
||||
{
|
||||
return m_pUtil->GetDeviceId();
|
||||
}
|
||||
|
||||
void HardwareStateManager::GetIvs(void** ivs, size_t* size)
|
||||
{
|
||||
return m_pUtil->GetIvs(ivs, size);
|
||||
}
|
||||
|
||||
nn::Handle HardwareStateManager::GetMcuHandle()
|
||||
{
|
||||
return m_pUtil->GetMcuHandle();
|
||||
}
|
||||
|
||||
void HardwareStateManager::GetSerialNumber(u8** serial, size_t* size)
|
||||
{
|
||||
return m_pUtil->GetSerialNumber(serial, size);
|
||||
}
|
||||
|
||||
void HardwareStateManager::GetVersionData(common::VerDef* version)
|
||||
{
|
||||
return m_pUtil->GetVersionData(version);
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,50 @@
|
||||
/*---------------------------------------------------------------------------*
|
||||
Project: Horizon
|
||||
File: HardwareStateManager.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 HARDWARESTATEMANAGER_H_
|
||||
#define HARDWARESTATEMANAGER_H_
|
||||
|
||||
#include "Util.h"
|
||||
|
||||
|
||||
namespace common
|
||||
{
|
||||
|
||||
class HardwareStateManager
|
||||
{
|
||||
public:
|
||||
explicit HardwareStateManager(Util& hwUtility);
|
||||
virtual ~HardwareStateManager();
|
||||
|
||||
void Finalize();
|
||||
|
||||
bool CanReadIvs();
|
||||
bool CanReadSerialNumber();
|
||||
bool IsBatteryLower();
|
||||
bool IsAdapterConnected();
|
||||
bit32 GetDeviceId();
|
||||
void GetIvs(void** ivs, size_t* size);
|
||||
nn::Handle GetMcuHandle();
|
||||
void GetSerialNumber(u8** serial, size_t* size);
|
||||
void GetVersionData(common::VerDef* version);
|
||||
|
||||
private:
|
||||
Util* m_pUtil;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif /* HARDWARESTATEMANAGER_H_ */
|
||||
@ -13,15 +13,31 @@
|
||||
$Rev$
|
||||
*---------------------------------------------------------------------------*/
|
||||
|
||||
#include <nn.h>
|
||||
#include "Util.h"
|
||||
|
||||
#include <cctype>
|
||||
|
||||
#include <nn.h>
|
||||
#include <nn/ptm/CTR/ptm_ApiSysmenu.h>
|
||||
#include <nn/fs/CTR/fs_ArchiveTypesForSystem.h>
|
||||
#include <nn/fs/CTR/MPCore/fs_FileSystemBasePrivate.h>
|
||||
#include <nn/fs/fs_ApiSysSaveData.h>
|
||||
#include <nn/cfg/CTR/cfg_Api.h>
|
||||
#include <nn/cfg/CTR/cfg_ApiInit.h>
|
||||
#include <nn/cfg/CTR/cfg_ApiSys.h>
|
||||
#include <nn/friends.h>
|
||||
#include <nn/friends/CTR/friends_ApiPrivate.h>
|
||||
#include <nn/ps.h>
|
||||
|
||||
#include "Util.h"
|
||||
#include "FileName.h"
|
||||
#include "CommonLogger.h"
|
||||
#include "HeapManager.h"
|
||||
|
||||
|
||||
namespace common
|
||||
{
|
||||
|
||||
Util::Util()
|
||||
Util::Util() :
|
||||
m_BatteryRemain(100), m_CanReadSerialNumber(false), m_CanReadIvs(false)
|
||||
{
|
||||
// TODO 自動生成されたコンストラクター・スタブ
|
||||
|
||||
@ -32,6 +48,89 @@ Util::~Util()
|
||||
// TODO Auto-generated destructor stub
|
||||
}
|
||||
|
||||
void Util::Initialize()
|
||||
{
|
||||
// friendsの初期化
|
||||
nn::Result result = nn::friends::detail::Initialize();
|
||||
|
||||
// mcuの初期化
|
||||
nn::mcu::CTR::InitializeHwCheck(&m_McuSession);
|
||||
mp_Mcu = new nn::mcu::CTR::HwCheck(m_McuSession);
|
||||
|
||||
// 完全性検証SEEDの取得
|
||||
result = nn::fs::MountSpecialArchive(common::NAND_ARCHIVE_NAME, nn::fs::CTR::ARCHIVE_TYPE_CTR_NAND);
|
||||
if (result.IsSuccess())
|
||||
{
|
||||
nn::fs::FileInputStream fis;
|
||||
|
||||
result = fis.TryInitialize(common::IVS_NAND_PATHNAME);
|
||||
if (result.IsSuccess())
|
||||
{
|
||||
s64 fileSize = fis.GetSize();
|
||||
s32 ret;
|
||||
void* addr = NULL;
|
||||
addr = common::HeapManager::GetHeap()->Allocate(fileSize);
|
||||
if (addr != NULL)
|
||||
{
|
||||
mp_Ivs = addr;
|
||||
m_SizeofIvs = fileSize;
|
||||
result = fis.TryRead(&ret, addr, fileSize);
|
||||
if (result.IsSuccess())
|
||||
{
|
||||
m_CanReadIvs = true;
|
||||
}
|
||||
// 後でIVSを参照するのでFreeしない
|
||||
}
|
||||
}
|
||||
fis.Finalize();
|
||||
}
|
||||
// 一旦アンマウントしておく
|
||||
nn::fs::Unmount(common::NAND_ARCHIVE_NAME);
|
||||
|
||||
|
||||
// シリアルナンバーの取得
|
||||
std::memset(m_SerialNo, '\0',
|
||||
nn::cfg::CTR::CFG_SECURE_INFO_SERIAL_NO_LEN);
|
||||
result = nn::cfg::CTR::system::GetSerialNo(m_SerialNo);
|
||||
if(result.IsSuccess())
|
||||
{
|
||||
m_CanReadSerialNumber = true;
|
||||
}
|
||||
COMMON_LOGGER_RESULT_IF_FAILED_WITH_LINE(result);
|
||||
AddCheckDigit(reinterpret_cast<char*>(m_SerialNo));
|
||||
|
||||
|
||||
// デバイスIDの取得
|
||||
result = nn::ps::CTR::GetDeviceId(&m_DeviceId);
|
||||
COMMON_LOGGER_RESULT_IF_FAILED_WITH_LINE(result);
|
||||
|
||||
// リージョンの取得
|
||||
m_Region = nn::cfg::CTR::GetRegion();
|
||||
|
||||
// バージョンの取得
|
||||
common::GetSystemVersion(&m_VerData, m_Region);
|
||||
|
||||
// MACアドレスの取得
|
||||
nn::nwm::Mac mac;
|
||||
|
||||
result = nn::nwm::GetMacAddress(mac);
|
||||
COMMON_LOGGER_RESULT_IF_FAILED_WITH_LINE(result);
|
||||
mac.GetString(m_MacAddress);
|
||||
COMMON_LOGGER_RESULT_IF_FAILED_WITH_LINE(result);
|
||||
|
||||
// フレンドコードの取得
|
||||
nn::friends::CTR::FriendKey friendKey;
|
||||
result = nn::friends::CTR::GetMyFriendKey(&friendKey);
|
||||
COMMON_LOGGER_RESULT_IF_FAILED_WITH_LINE(result);
|
||||
m_FriendCode = nn::friends::CTR::FriendKeyToFriendCode(friendKey);
|
||||
}
|
||||
|
||||
void Util::Finalize()
|
||||
{
|
||||
nn::mcu::CTR::FinalizeHwCheck(&m_McuSession);
|
||||
nn::friends::detail::Finalize();
|
||||
}
|
||||
|
||||
// NULL終端されたシリアルナンバーを受け取る
|
||||
// NULL終端された場所にチェックデジットを付加して新たにNULL終端する
|
||||
void Util::AddCheckDigit(char* serial)
|
||||
@ -106,6 +205,111 @@ void Util::GetSaveDataDirectoryRoot(::std::string& sysSaveRoot, void* ivs, size_
|
||||
NN_LOG("%s\n", sysSaveRoot.c_str());
|
||||
}
|
||||
|
||||
bool Util::IsAdapterConnected()
|
||||
{
|
||||
return nn::ptm::CTR::GetAdapterState() == nn::ptm::CTR::ADAPTERSTATE_CONNECTED;
|
||||
}
|
||||
|
||||
bool Util::IsBatteryLower()
|
||||
{
|
||||
return m_BatteryRemain <= 10;
|
||||
}
|
||||
|
||||
bool Util::CanReadIVS()
|
||||
{
|
||||
return m_CanReadIvs;
|
||||
}
|
||||
|
||||
bool Util::CanReadSerialNumber()
|
||||
{
|
||||
return m_CanReadSerialNumber;
|
||||
}
|
||||
|
||||
void Util::GetSerialNumber(u8** serial, size_t* size)
|
||||
{
|
||||
*serial = m_SerialNo;
|
||||
*size = nn::cfg::CTR::CFG_SECURE_INFO_SERIAL_NO_LEN;
|
||||
}
|
||||
|
||||
u8* Util::GetSerialNumber()
|
||||
{
|
||||
return m_SerialNo;
|
||||
}
|
||||
|
||||
|
||||
void Util::GetIvs(void** ivs, size_t* size)
|
||||
{
|
||||
*ivs = mp_Ivs;
|
||||
*size = m_SizeofIvs;
|
||||
}
|
||||
|
||||
bit32 Util::GetDeviceId()
|
||||
{
|
||||
return m_DeviceId;
|
||||
}
|
||||
|
||||
u8 Util::GetCupMajorVersion()
|
||||
{
|
||||
return m_VerData.cup.majorVersion;
|
||||
}
|
||||
|
||||
u8 Util::GetCupMinorVersion()
|
||||
{
|
||||
return m_VerData.cup.minorVersion;
|
||||
}
|
||||
|
||||
u8 Util::GetCupMicroVersion()
|
||||
{
|
||||
return m_VerData.cup.microVersion;
|
||||
}
|
||||
|
||||
u8 Util::GetNupVersion()
|
||||
{
|
||||
return m_VerData.nup.majorVersion;
|
||||
}
|
||||
|
||||
nn::Handle Util::GetMcuHandle()
|
||||
{
|
||||
return m_McuSession;
|
||||
}
|
||||
|
||||
u32 Util::GetBatteryRemain()
|
||||
{
|
||||
u8 remain;
|
||||
mp_Mcu->GetBatteryRemain(&remain);
|
||||
return remain;
|
||||
}
|
||||
|
||||
u64 Util::GetInfraDeviceId()
|
||||
{
|
||||
bit64 infraDeviceId;
|
||||
infraDeviceId = m_DeviceId + common::INFRA_DEVICE_ID_OFFSET;
|
||||
return infraDeviceId;
|
||||
}
|
||||
|
||||
u64 Util::GetFriendcode()
|
||||
{
|
||||
return m_FriendCode;
|
||||
}
|
||||
|
||||
char8* Util::GetMacAddress()
|
||||
{
|
||||
return m_MacAddress;
|
||||
}
|
||||
|
||||
nn::cfg::CTR::CfgRegionCode Util::GetRegion()
|
||||
{
|
||||
return m_Region;
|
||||
}
|
||||
|
||||
const char* Util::GetRegionCodeA3()
|
||||
{
|
||||
return nn::cfg::GetRegionCodeA3(m_Region);
|
||||
}
|
||||
|
||||
void Util::GetVersionData(common::VerDef* version)
|
||||
{
|
||||
*version = m_VerData;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -17,6 +17,12 @@
|
||||
#define UTIL_H_
|
||||
|
||||
#include <string>
|
||||
#include <nn.h>
|
||||
#include <nn/cfg/CTR/cfg_ApiSys.h>
|
||||
#include <nn/mcu.h>
|
||||
#include <nn/nwm.h>
|
||||
|
||||
#include "VersionDetect.h"
|
||||
|
||||
namespace common
|
||||
{
|
||||
@ -27,8 +33,76 @@ public:
|
||||
Util();
|
||||
virtual ~Util();
|
||||
|
||||
void Initialize();
|
||||
void Finalize();
|
||||
|
||||
static void AddCheckDigit(char* serial);
|
||||
static void GetSaveDataDirectoryRoot(::std::string& sysSaveRoot, void* ivs, size_t size);
|
||||
|
||||
bool IsAdapterConnected();
|
||||
bool IsBatteryLower();
|
||||
bool CanReadIVS();
|
||||
bool CanReadSerialNumber();
|
||||
void GetSerialNumber(u8** serial, size_t* size);
|
||||
u8* GetSerialNumber();
|
||||
void GetIvs(void** ivs, size_t* size);
|
||||
bit32 GetDeviceId();
|
||||
u8 GetCupMajorVersion();
|
||||
u8 GetCupMinorVersion();
|
||||
u8 GetCupMicroVersion();
|
||||
u8 GetNupVersion();
|
||||
nn::Handle GetMcuHandle();
|
||||
u32 GetBatteryRemain();
|
||||
u64 GetInfraDeviceId();
|
||||
u64 GetFriendcode();
|
||||
char8* GetMacAddress();
|
||||
nn::cfg::CTR::CfgRegionCode GetRegion();
|
||||
const char* GetRegionCodeA3();
|
||||
void GetVersionData(common::VerDef* version);
|
||||
|
||||
|
||||
private:
|
||||
NN_PADDING4;
|
||||
// フレンドコード
|
||||
u64 m_FriendCode;
|
||||
|
||||
// バージョン情報
|
||||
common::VerDef m_VerData;
|
||||
|
||||
// mcu接続のためのハンドル
|
||||
nn::Handle m_McuSession;
|
||||
|
||||
// デバイスID
|
||||
bit32 m_DeviceId;
|
||||
|
||||
// IVSへのポインタ
|
||||
void* mp_Ivs;
|
||||
|
||||
// IVSのサイズ
|
||||
size_t m_SizeofIvs;
|
||||
NN_PADDING4;
|
||||
|
||||
// MCUへのポインタ
|
||||
nn::mcu::CTR::HwCheck* mp_Mcu;
|
||||
|
||||
// リージョン
|
||||
nn::cfg::CTR::CfgRegionCode m_Region;
|
||||
|
||||
// バッテリ残量
|
||||
u8 m_BatteryRemain;
|
||||
|
||||
// シリアルナンバーが読めるかどうか
|
||||
bool m_CanReadSerialNumber;
|
||||
|
||||
// IVSが読めるかどうか
|
||||
bool m_CanReadIvs;
|
||||
|
||||
// シリアルナンバー
|
||||
u8 m_SerialNo[nn::cfg::CTR::CFG_SECURE_INFO_SERIAL_NO_LEN];
|
||||
|
||||
// MACアドレス
|
||||
char8 m_MacAddress[nn::nwm::Mac::MAC_STRING_SIZE];
|
||||
NN_PADDING3;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user