ctr_Repair/trunk/ConsoleDataMigration/sources/tools/PreinstallListUp/main.cpp
N2614 a24e80d2e2 [PreinstallListUp]電源ボタン長押しで終了するように
git-svn-id: file:///Volumes/Transfer/gigaleak_20231201/2020-05-23%20-%20ctr.7z%20+%20svn_v1.068.zip/ctr/svn/ctr_Repair@625 385bec56-5757-e545-9c3a-d8741f4650f1
2012-02-08 06:19:26 +00:00

233 lines
6.3 KiB
C++

/*---------------------------------------------------------------------------*
Project: Horizon
File: main.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.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/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>
#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/am_ApiSystemMenu.h>
#include <nn/am.h>
#include "Aes_define.h"
#include "FileTransfer.h"
#include "CommonLogger.h"
#include "demo.h"
#include <vector>
#include <string>
#include "DrawSystemState.h"
#include "FileName.h"
#include "SimplePlayer.h"
#include "CommonLogger.h"
#include "SDMountManager.h"
#include "HeapManager.h"
#include "common_Types.h"
#include "VersionDetect.h"
#include "Util.h"
#include "CommonLogger.h"
#include "SdReaderWriter.h"
#include "../ConsoleRestore/PreinstallImporter.h"
namespace
{
// グラフィックスに割り当てるメモリ
const size_t s_GxHeapSize = 0x800000;
const u32 CONSOLE_WIDTH = 38;
const u32 CONSOLE_HEIGHT = 24;
const u32 CONSOLE_MAX_LINE = 1000;
const size_t THREAD_STACK_SIZE = 0x2000;
nn::os::Thread s_Thread;
nn::os::StackBuffer<THREAD_STACK_SIZE> s_ThreadStack;
demo::RenderSystemDrawing s_RenderSystem;
}
namespace PreinstallListUp
{
void ThreadFunc()
{
COMMON_LOGGER("GetPreinstalledInfo\n");
nn::Result result;
// シリアルナンバーの取得
u8 serialNo[nn::cfg::CTR::CFG_SECURE_INFO_SERIAL_NO_LEN];
std::memset(serialNo, '\0',
nn::cfg::CTR::CFG_SECURE_INFO_SERIAL_NO_LEN);
result = nn::cfg::CTR::system::GetSerialNo(serialNo);
COMMON_LOGGER_RETURN_VOID_IF_FAILED(result);
// デバイスIDの取得
bit32 deviceId;
result = nn::ps::CTR::GetDeviceId(&deviceId);
COMMON_LOGGER_RETURN_VOID_IF_FAILED(result);
const bit64 infraDeviceId = deviceId + common::INFRA_DEVICE_ID_OFFSET;
ConsoleRestore::PreinstallImporter importer;
size_t num;
nn::ProgramId list[256];
result = importer.ListTitles(list, &num, infraDeviceId, serialNo);
if(result == nn::MakePermanentResult(nn::Result::SUMMARY_NOT_FOUND,
nn::Result::MODULE_APPLICATION, nn::Result::DESCRIPTION_NOT_FOUND))
{
COMMON_LOGGER("No PreInstalled Application found\n");
}
else
{
COMMON_LOGGER("Preinstalled num = %d\n", num);
for (u32 i = 0; i < num; i++)
{
COMMON_LOGGER("%016llx\n", list[i]);
}
}
COMMON_LOGGER_RETURN_VOID_IF_FAILED(result);
}
void FinalizeAll()
{
common::Logger::GetLoggerInstance()->Finalize();
// アンマウント
nn::fs::Unmount("nand:");
nn::fs::Unmount("sdmc:");
s_RenderSystem.Finalize();
nn::ps::Finalize();
nn::cfg::CTR::system::Finalize();
nn::cfg::CTR::init::Finalize();
nn::hid::Finalize();
nn::fs::Finalize();
nn::applet::PrepareToCloseApplication();
nn::applet::CloseApplication();
}
extern "C" void nninitSetupDaemons(void)
{
}
extern "C" void nnMain(void)
{
nn::Result result;
// os の初期化
nn::os::Initialize();
// fs の初期化
nn::fs::Initialize();
// appletの初期化
nn::applet::Enable( false );
// cfgの初期化
nn::cfg::CTR::init::Initialize();
nn::cfg::CTR::system::Initialize();
// hid の初期化
result = nn::hid::Initialize();
NN_ERR_THROW_FATAL_IF_FATAL_ONLY(result);
// ps の初期化
nn::ps::Initialize();
// ヒープの確保
common::InitializeHeap();
// RenderSystem の準備
common::HeapManager gxHeap(s_GxHeapSize);
uptr heapForGx = reinterpret_cast<uptr>(gxHeap.GetAddr());
s_RenderSystem.Initialize(heapForGx, s_GxHeapSize);
// ログ描画の初期化
common::Logger::GetLoggerInstance()->Initialize(CONSOLE_WIDTH, CONSOLE_HEIGHT, CONSOLE_MAX_LINE, &s_RenderSystem);
// RenderSystemを作ってからログが出せる
common::Logger::InitializeEjectThread();
s_Thread.Start(ThreadFunc, s_ThreadStack);
// ボタン入力
nn::hid::PadReader s_PadReader;
nn::hid::PadStatus padStatus;
for(;;)
{
s_PadReader.ReadLatest(&padStatus);
// コンソールスクロール
if(padStatus.hold & nn::hid::BUTTON_UP)
{
common::Logger::GetLoggerInstance()->ScrollUp();
}
// コンソールスクロール
if(padStatus.hold & nn::hid::BUTTON_DOWN)
{
common::Logger::GetLoggerInstance()->ScrollDown();
}
if(padStatus.hold & nn::hid::BUTTON_LEFT)
{
common::Logger::GetLoggerInstance()->ScrollToBegin();
}
if(padStatus.hold & nn::hid::BUTTON_RIGHT)
{
common::Logger::GetLoggerInstance()->ScrollToEnd();
}
s_RenderSystem.SetRenderTarget(NN_GX_DISPLAY0);
s_RenderSystem.Clear();
s_RenderSystem.SetColor(1.f, 1.f, 1.f);
common::Logger::GetLoggerInstance()->DrawConsole();
s_RenderSystem.SwapBuffers();
s_RenderSystem.WaitVsync(NN_GX_DISPLAY_BOTH);
// 電源長押しで終了
if ( nn::applet::IsExpectedToCloseApplication())
{
FinalizeAll();
}
}
}
}