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@731 385bec56-5757-e545-9c3a-d8741f4650f1
320 lines
9.8 KiB
C++
320 lines
9.8 KiB
C++
/*---------------------------------------------------------------------------*
|
|
Project: Horizon
|
|
File: ConsoleBackup.cpp
|
|
|
|
Copyright (C)2009 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.h>
|
|
#include <nn/version.h>
|
|
#include <nn/ptm/CTR/ptm_ApiSysmenu.h>
|
|
#include <nn/mcu.h>
|
|
#include <nn/cfg/CTR/cfg_Api.h>
|
|
#include <nn/cfg/CTR/cfg_ApiInit.h>
|
|
#include <nn/cfg/CTR/cfg_ApiSys.h>
|
|
#include <nn/ps.h>
|
|
#include <nn/nwm.h>
|
|
#include <nn/ac.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_ApiNor.h>
|
|
#include <nn/os/os_SharedInfo.h>
|
|
#include <nn/pl/CTR/pl_Version.h>
|
|
#include <nn/fs/fs_ApiSharedExtSaveData.h>
|
|
#include <nn/nim.h>
|
|
#include <nn/ndm.h>
|
|
#include <nn/am.h>
|
|
|
|
#include "demo.h"
|
|
|
|
#include <vector>
|
|
#include <string>
|
|
|
|
#include "DrawSystemState.h"
|
|
#include "FileName.h"
|
|
#include "Controller.h"
|
|
#include "SimplePlayer.h"
|
|
#include "Exporter.h"
|
|
#include "CommonLogger.h"
|
|
#include "SDMountManager.h"
|
|
#include "HeapManager.h"
|
|
#include "common_Types.h"
|
|
#include "VersionDetect.h"
|
|
#include "Util.h"
|
|
#include "ResFont.h"
|
|
#include "HardwareStateManager.h"
|
|
#include "OperationMessage.h"
|
|
|
|
// バージョン表示用
|
|
#include "version.h"
|
|
|
|
namespace {
|
|
|
|
// グラフィックスに割り当てるメモリ
|
|
const size_t s_GxHeapSize = 0x800000;
|
|
|
|
common::Util s_HwUtility;
|
|
|
|
} // namespace <unnamed>
|
|
|
|
extern "C" void nninitSetupDaemons(void)
|
|
{
|
|
}
|
|
|
|
namespace ConsoleBackup{
|
|
|
|
|
|
extern "C" void nnMain(void)
|
|
{
|
|
nn::Result result;
|
|
|
|
// os の初期化
|
|
nn::os::Initialize();
|
|
|
|
// fs の初期化
|
|
nn::fs::Initialize();
|
|
|
|
// appletの初期化
|
|
nn::applet::Enable( false );
|
|
|
|
// hid の初期化
|
|
result = nn::hid::Initialize();
|
|
COMMON_LOGGER_RESULT_IF_FAILED(result);
|
|
|
|
// ndmの初期化
|
|
result = nn::ndm::Initialize();
|
|
COMMON_LOGGER_RESULT_IF_FAILED(result);
|
|
|
|
// 全デーモンの自律動作をacの自動接続も含めて止める
|
|
result = nn::ndm::SuspendScheduler();
|
|
COMMON_LOGGER_RESULT_IF_FAILED(result);
|
|
|
|
// cfg の初期化
|
|
nn::cfg::CTR::init::Initialize();
|
|
nn::cfg::CTR::system::Initialize();
|
|
|
|
// 時計設定用ptm初期化
|
|
nn::ptm::CTR::InitializeForSystemMenu();
|
|
|
|
// ps の初期化
|
|
nn::ps::Initialize();
|
|
|
|
// amの初期化
|
|
nn::am::InitializeForLocalImporter();
|
|
|
|
// ヒープの確保
|
|
common::InitializeHeap();
|
|
|
|
// RenderSystem の準備
|
|
common::HeapManager gxHeapManager(s_GxHeapSize);
|
|
uptr heapForGx = reinterpret_cast<uptr>(gxHeapManager.GetAddr());
|
|
demo::RenderSystemDrawing renderSystem;
|
|
renderSystem.Initialize(heapForGx, s_GxHeapSize);
|
|
|
|
// ResFontの初期化
|
|
common::InitializeResFont();
|
|
|
|
// サウンドスレッドの起動
|
|
common::InitializeSimplePlayer();
|
|
|
|
// ログ描画の初期化
|
|
common::Logger::GetLoggerInstance()->Initialize(common::CONSOLE_WIDTH, common::CONSOLE_HEIGHT,
|
|
common::CONSOLE_MAX_LINE, &renderSystem);
|
|
|
|
// RenderSystemを作ってからログが出せる
|
|
common::Logger::InitializeEjectThread();
|
|
common::Logger::SetEjectHandler(OnSdEjected);
|
|
common::Logger::SetInsertHandler(OnSdInserted);
|
|
// 起動時に削除
|
|
common::Logger::GetLoggerInstance()->ClearSdLog();
|
|
|
|
COMMON_LOGGER("\n");
|
|
COMMON_LOGGER("CTR Console Backup start\n");
|
|
|
|
// ボタン入力
|
|
nn::hid::PadReader s_PadReader;
|
|
nn::hid::PadStatus padStatus;
|
|
|
|
// データの準備
|
|
s_HwUtility.InitializeForBackup();
|
|
common::HardwareStateManager manager(s_HwUtility);
|
|
|
|
// 情報出力
|
|
COMMON_LOGGER("CTR Console Backup %s-%s-%s\n", CONSOLE_REPAIR_VERSION_MAJOR, CONSOLE_REPAIR_VERSION_MINOR, CONSOLE_REPAIR_VERSION_MICRO);
|
|
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());
|
|
|
|
bool flip = false;
|
|
bool continueBackup = false;
|
|
bool forceDelete = false;
|
|
|
|
for(;;)
|
|
{
|
|
bool nextStep = false;
|
|
s_PadReader.ReadLatest(&padStatus);
|
|
|
|
// AまたはSTARTボタンで進行
|
|
if(padStatus.trigger & nn::hid::BUTTON_A ||
|
|
padStatus.trigger & nn::hid::BUTTON_START)
|
|
{
|
|
nextStep = true;
|
|
if(padStatus.hold & nn::hid::BUTTON_LEFT)
|
|
{
|
|
forceDelete = true;
|
|
}
|
|
}
|
|
|
|
// LまたはRボタンで上下画面フリップ
|
|
if(padStatus.trigger & nn::hid::BUTTON_R ||
|
|
padStatus.trigger & nn::hid::BUTTON_L)
|
|
{
|
|
flip = !flip;
|
|
}
|
|
|
|
// XボタンでWiFi On/Off
|
|
if(padStatus.trigger & nn::hid::BUTTON_X)
|
|
{
|
|
s_HwUtility.ToggleWifiStatus();
|
|
}
|
|
|
|
// コンソールスクロール
|
|
if(padStatus.hold & nn::hid::BUTTON_UP)
|
|
{
|
|
common::Logger::GetLoggerInstance()->ScrollUp();
|
|
}
|
|
|
|
// コンソールスクロール
|
|
if(padStatus.hold & nn::hid::BUTTON_DOWN)
|
|
{
|
|
common::Logger::GetLoggerInstance()->ScrollDown();
|
|
}
|
|
|
|
// 情報更新
|
|
// ACアダプタ
|
|
std::string adapterState;
|
|
if(manager.IsAdapterConnected())
|
|
{
|
|
adapterState += ::std::string("Connected");
|
|
}
|
|
else
|
|
{
|
|
adapterState += ::std::string("Not Connected");
|
|
}
|
|
|
|
// 操作用メッセージ
|
|
// 進捗確認メッセージを兼ねる?
|
|
common::OperationMessage operationMessage;
|
|
|
|
ControlState(manager, operationMessage, nextStep, continueBackup, forceDelete);
|
|
|
|
nn::util::FloatColor titleColor;
|
|
|
|
titleColor.r = 0.3f;
|
|
titleColor.g = 0.f;
|
|
titleColor.b = 0.2f;
|
|
|
|
// 上画面表示
|
|
common::DrawSystemState("CTR Console Backup",
|
|
renderSystem,
|
|
titleColor,
|
|
flip,
|
|
adapterState,
|
|
s_HwUtility.GetCupMajorVersion(),
|
|
s_HwUtility.GetCupMinorVersion(),
|
|
s_HwUtility.GetCupMicroVersion(),
|
|
s_HwUtility.GetNupVersion(),
|
|
s_HwUtility.GetBatteryRemain(),
|
|
s_HwUtility.GetInfraDeviceId(),
|
|
s_HwUtility.GetFriendcode(),
|
|
GetProgress(),
|
|
IsBackupFailed(),
|
|
IsBackupSucceeded(),
|
|
IsBackupWarning(),
|
|
s_HwUtility.GetMacAddress(),
|
|
operationMessage,
|
|
s_HwUtility.GetRegion(),
|
|
s_HwUtility.GetSerialNumber(),
|
|
s_HwUtility.HasReadFriendCode(),
|
|
s_HwUtility.IsWifiOn()
|
|
);
|
|
|
|
if (GetBackupMode() == BACKUP_MODE_DELETE_IF_FAILED)
|
|
{
|
|
const u8 spaceSize = 10;
|
|
const u8 lineBottom = 23;
|
|
const u32 screenWidth = 400;
|
|
|
|
renderSystem.SetColor(1.f, 1.f, 1.f);
|
|
renderSystem.DrawText(0, lineBottom * spaceSize, "Delete Error File Mode");
|
|
|
|
renderSystem.SetColor(titleColor.r, titleColor.g, titleColor.b);
|
|
renderSystem.FillRectangle(0, lineBottom * spaceSize, screenWidth, spaceSize);
|
|
renderSystem.SetColor(1.f, 1.f, 1.f);
|
|
}
|
|
|
|
renderSystem.SwapBuffers();
|
|
|
|
// デフォルトで下画面に描画するもの
|
|
renderSystem.SetRenderTarget(common::Util::GetRenderTarget(NN_GX_DISPLAY1, flip));
|
|
if(IsBackupSucceeded())
|
|
{
|
|
renderSystem.SetClearColor(common::Util::GetRenderTarget(NN_GX_DISPLAY1, flip), SUCCESS_COLOR);
|
|
}
|
|
if(IsBackupWarning())
|
|
{
|
|
renderSystem.SetClearColor(common::Util::GetRenderTarget(NN_GX_DISPLAY1, flip), WARN_COLOR);
|
|
}
|
|
else if(IsBackupFailed())
|
|
{
|
|
renderSystem.SetClearColor(common::Util::GetRenderTarget(NN_GX_DISPLAY1, flip), FAIL_COLOR);
|
|
}
|
|
renderSystem.Clear();
|
|
renderSystem.SetColor(1.f, 1.f, 1.f);
|
|
|
|
common::Logger::GetLoggerInstance()->DrawConsole();
|
|
renderSystem.SwapBuffers();
|
|
|
|
|
|
renderSystem.WaitVsync(NN_GX_DISPLAY_BOTH);
|
|
|
|
// 電源長押しで終了
|
|
if ( nn::applet::IsExpectedToCloseApplication())
|
|
{
|
|
common::Logger::GetLoggerInstance()->Finalize();
|
|
// アンマウント
|
|
nn::fs::Unmount(common::NAND_ARCHIVE_NAME);
|
|
nn::fs::Unmount(common::SDMC_ARCHIVE_NAME);
|
|
renderSystem.Finalize();
|
|
|
|
nn::ps::Finalize();
|
|
nn::ptm::CTR::FinalizeForSystemMenu();
|
|
nn::cfg::CTR::system::Finalize();
|
|
nn::cfg::CTR::init::Finalize();
|
|
nn::hid::Finalize();
|
|
nn::fs::Finalize();
|
|
|
|
nn::applet::PrepareToCloseApplication();
|
|
nn::applet::CloseApplication();
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
}
|