mirror of
https://github.com/rvtr/ctr_Repair.git
synced 2025-10-31 13:51:08 -04:00
CUP不要時にもNUPバージョンをチェックして必要なら強制的にCUPするように
NUPバージョンをromfsから読み出すように アプリ名の変更 git-svn-id: file:///Volumes/Transfer/gigaleak_20231201/2020-05-23%20-%20ctr.7z%20+%20svn_v1.068.zip/ctr/svn/ctr_Repair@355 385bec56-5757-e545-9c3a-d8741f4650f1
This commit is contained in:
parent
52efc9fe1e
commit
6b864c9c80
59
trunk/CardCup/HeapManager.cpp
Normal file
59
trunk/CardCup/HeapManager.cpp
Normal file
@ -0,0 +1,59 @@
|
|||||||
|
/*---------------------------------------------------------------------------*
|
||||||
|
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"
|
||||||
|
|
||||||
|
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(), 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
46
trunk/CardCup/HeapManager.h
Normal file
46
trunk/CardCup/HeapManager.h
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
/*---------------------------------------------------------------------------*
|
||||||
|
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>
|
||||||
|
|
||||||
|
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);
|
||||||
|
|
||||||
|
#endif /* HEAPMANAGER_H_ */
|
||||||
@ -23,19 +23,22 @@ INCLUDES += $(SAMPLED_DEMOS_COMMON_INCLUDE_DIR)
|
|||||||
SOURCES[] =
|
SOURCES[] =
|
||||||
main.cpp
|
main.cpp
|
||||||
scrollBuffer.cpp
|
scrollBuffer.cpp
|
||||||
|
VersionDetect.cpp
|
||||||
|
HeapManager.cpp
|
||||||
|
|
||||||
LIBS += lib_demo \
|
LIBS += lib_demo \
|
||||||
libnn_am \
|
libnn_am \
|
||||||
libnn_cup \
|
libnn_cup \
|
||||||
libnn_ns \
|
libnn_ns \
|
||||||
|
|
||||||
|
ROMFS_ROOT = romfiles
|
||||||
|
|
||||||
DESCRIPTOR = $(HORIZON_ROOT)/resources/specfiles/SelfCup.desc
|
DESCRIPTOR = $(HORIZON_ROOT)/resources/specfiles/SelfCup.desc
|
||||||
|
|
||||||
TARGET_PROGRAM = CardCup
|
TARGET_PROGRAM = SelfCupTool
|
||||||
|
|
||||||
TITLE = CardCup
|
TITLE = SelfCupTool
|
||||||
ROM_SPEC_FILE = CardCup.rsf
|
ROM_SPEC_FILE = SelfCupTool.rsf
|
||||||
|
|
||||||
CTR_BANNER_SPEC = $(TARGET_PROGRAM).bsf
|
CTR_BANNER_SPEC = $(TARGET_PROGRAM).bsf
|
||||||
|
|
||||||
|
|||||||
Binary file not shown.
@ -1,5 +1,6 @@
|
|||||||
BasicInfo:
|
BasicInfo:
|
||||||
Title: SelfCup
|
Title: SelfCupTool
|
||||||
|
ProductCode: CTR-P-234A
|
||||||
BackupMemoryType: None
|
BackupMemoryType: None
|
||||||
Logo: Nintendo
|
Logo: Nintendo
|
||||||
|
|
||||||
@ -13,6 +14,7 @@ TitleInfo:
|
|||||||
|
|
||||||
SystemControlInfo:
|
SystemControlInfo:
|
||||||
AppType : Application
|
AppType : Application
|
||||||
|
StackSize : 65536
|
||||||
Dependency:
|
Dependency:
|
||||||
- nwm
|
- nwm
|
||||||
- socket
|
- socket
|
||||||
@ -26,202 +26,224 @@
|
|||||||
#include <nn/am.h>
|
#include <nn/am.h>
|
||||||
#include <nn/ndm.h>
|
#include <nn/ndm.h>
|
||||||
#include <nn/cfg.h>
|
#include <nn/cfg.h>
|
||||||
|
#include <nn/ptm_Private.h>
|
||||||
|
|
||||||
#include <nn/cup.h>
|
#include <nn/cup.h>
|
||||||
|
|
||||||
#include "demo.h"
|
#include "demo.h"
|
||||||
#include "scrollBuffer.h"
|
#include "scrollBuffer.h"
|
||||||
|
#include "VersionDetect.h"
|
||||||
|
#include "HeapManager.h"
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
const int s_GxHeapSize=0x800000;
|
const s32 s_GxHeapSize = 0x800000;
|
||||||
nn::fnd::ExpHeap s_appHeap;
|
uptr s_GxHeap;
|
||||||
uptr s_GxHeap;
|
|
||||||
|
|
||||||
demo::RenderSystemDrawing s_RenderSystem;
|
demo::RenderSystemDrawing s_RenderSystem;
|
||||||
ScrollBuffer s_scrollBufferInstance;
|
ScrollBuffer s_scrollBufferInstance;
|
||||||
ScrollBuffer *s_scrollBuffer;
|
ScrollBuffer *s_scrollBuffer;
|
||||||
|
|
||||||
char s_updaterBuffer[1<<20] NN_ATTRIBUTE_ALIGN(4096);
|
char s_updaterBuffer[1 << 20] NN_ATTRIBUTE_ALIGN(4096);
|
||||||
|
|
||||||
// デモの初期化
|
// デモの初期化
|
||||||
void Initialize()
|
void Initialize()
|
||||||
|
{
|
||||||
|
// NuiShellの初期化 (CUPに必須)
|
||||||
|
NN_UTIL_PANIC_IF_FAILED(nn::ns::CTR::InitializeForShell());
|
||||||
|
|
||||||
|
// ndmの初期化
|
||||||
|
nn::ndm::Initialize();
|
||||||
|
|
||||||
|
// 全デーモンの自律動作をacの自動接続も含めて止める
|
||||||
|
nn::ndm::SuspendScheduler();
|
||||||
|
|
||||||
|
// amの初期化
|
||||||
|
nn::am::InitializeForSystemMenu();
|
||||||
|
|
||||||
|
// fsの初期化 (カード確認用)
|
||||||
|
nn::fs::Initialize();
|
||||||
|
|
||||||
|
// appletの初期化
|
||||||
|
//nn::applet::InitializeForSystem( nn::applet::PHOME_MENU_APPLET_ID, nn::applet::TYPE_SYS );
|
||||||
|
//nn::applet::Initialize( nn::applet::TEST2_APPLET_ID);
|
||||||
|
//nn::applet::SetAppletMode();
|
||||||
|
nn::applet::Enable();
|
||||||
|
|
||||||
|
nn::cfg::Initialize();
|
||||||
|
|
||||||
|
// デバイスメモリの設定
|
||||||
|
const s32 DEVICE_MEMORY_SIZE = 32 * 1024 * 1024;
|
||||||
|
NN_UTIL_PANIC_IF_FAILED(nn::os::SetDeviceMemorySize(DEVICE_MEMORY_SIZE));
|
||||||
|
|
||||||
|
// ヒープの初期化
|
||||||
|
InitializeHeap();
|
||||||
|
|
||||||
|
// 描画インスタンスの初期化
|
||||||
|
s_GxHeap = reinterpret_cast<uptr>(ForceAllocate(s_GxHeapSize));s_RenderSystem
|
||||||
|
.Initialize(s_GxHeap, s_GxHeapSize);
|
||||||
|
|
||||||
|
// 描画インスタンスの初期化
|
||||||
|
s_scrollBufferInstance.Initialize(&s_RenderSystem);
|
||||||
|
s_scrollBuffer = &s_scrollBufferInstance;
|
||||||
|
|
||||||
|
// GPU利用宣言
|
||||||
|
nn::applet::AssignGpuRight();
|
||||||
|
}
|
||||||
|
|
||||||
|
// 消費時間取得用関数群
|
||||||
|
s64 s_StartTick;
|
||||||
|
void SetTick()
|
||||||
|
{
|
||||||
|
s_StartTick = nn::os::Tick::GetSystemCurrent();
|
||||||
|
}
|
||||||
|
s64 GetConsumedMillisec()
|
||||||
|
{
|
||||||
|
s64 endTick = nn::os::Tick::GetSystemCurrent();
|
||||||
|
nn::os::Tick consumed(endTick - s_StartTick);
|
||||||
|
return ((nn::fnd::TimeSpan) consumed).GetMilliSeconds();
|
||||||
|
}
|
||||||
|
|
||||||
|
// 動いていることを知らせるための、くるくる画面表示取得用メソッド
|
||||||
|
const char s_progress[] = "-\\|/";
|
||||||
|
s32 s_progressIndex = 0;
|
||||||
|
char GetProgressChar()
|
||||||
|
{
|
||||||
|
s_progressIndex = (s_progressIndex + 1) % (sizeof(s_progress) - 1);
|
||||||
|
return s_progress[s_progressIndex];
|
||||||
|
}
|
||||||
|
|
||||||
|
nn::Result UpdateCore()
|
||||||
|
{
|
||||||
|
nn::Result result;
|
||||||
|
nn::cup::ProgressInfo info;
|
||||||
|
|
||||||
|
/********************** アップデート*******************/
|
||||||
|
SetTick();
|
||||||
|
s_scrollBuffer->AppendText("Start Card Update")->Render();
|
||||||
|
NN_UTIL_RETURN_IF_FAILED(nn::cup::CTR::DoUpdate());
|
||||||
|
|
||||||
|
// ステータスがStartedになるまで、プログレスは取得できない
|
||||||
|
s_scrollBuffer->AppendText("");
|
||||||
|
do
|
||||||
{
|
{
|
||||||
// os の初期化
|
s_scrollBuffer->ReplaceText(" %c Initializing", GetProgressChar())->Render();
|
||||||
nn::os::Initialize();
|
result = nn::cup::CTR::GetProgressInfo(&info);
|
||||||
|
|
||||||
// NuiShellの初期化 (CUPに必須)
|
|
||||||
NN_UTIL_PANIC_IF_FAILED(nn::ns::CTR::InitializeForShell());
|
|
||||||
|
|
||||||
// ndmの初期化
|
|
||||||
nn::ndm::Initialize();
|
|
||||||
|
|
||||||
// 全デーモンの自律動作をacの自動接続も含めて止める
|
|
||||||
nn::ndm::SuspendScheduler();
|
|
||||||
|
|
||||||
// amの初期化
|
|
||||||
nn::am::InitializeForSystemMenu();
|
|
||||||
|
|
||||||
// fsの初期化 (カード確認用)
|
|
||||||
nn::fs::Initialize();
|
|
||||||
|
|
||||||
// appletの初期化
|
|
||||||
//nn::applet::InitializeForSystem( nn::applet::PHOME_MENU_APPLET_ID, nn::applet::TYPE_SYS );
|
|
||||||
//nn::applet::Initialize( nn::applet::TEST2_APPLET_ID);
|
|
||||||
//nn::applet::SetAppletMode();
|
|
||||||
nn::applet::Enable();
|
|
||||||
|
|
||||||
nn::cfg::Initialize();
|
|
||||||
|
|
||||||
// デバイスメモリの設定
|
|
||||||
const int DEVICE_MEMORY_SIZE = 12*1024 * 1024;
|
|
||||||
NN_UTIL_PANIC_IF_FAILED(nn::os::SetDeviceMemorySize(DEVICE_MEMORY_SIZE));
|
|
||||||
|
|
||||||
// ヒープの初期化
|
|
||||||
s_appHeap.Initialize(nn::os::GetDeviceMemoryAddress(), nn::os::GetDeviceMemorySize(), nn::os::ALLOCATE_OPTION_LINEAR);
|
|
||||||
|
|
||||||
// 描画インスタンスの初期化
|
|
||||||
s_GxHeap = reinterpret_cast<uptr>(s_appHeap.Allocate(s_GxHeapSize));
|
|
||||||
s_RenderSystem.Initialize(s_GxHeap, s_GxHeapSize);
|
|
||||||
|
|
||||||
// 描画インスタンスの初期化
|
|
||||||
s_scrollBufferInstance.Initialize(&s_RenderSystem);
|
|
||||||
s_scrollBuffer=&s_scrollBufferInstance;
|
|
||||||
|
|
||||||
// GPU利用宣言
|
|
||||||
nn::applet::AssignGpuRight();
|
|
||||||
}
|
|
||||||
|
|
||||||
// 消費時間取得用関数群
|
|
||||||
s64 s_StartTick;
|
|
||||||
void SetTick()
|
|
||||||
{
|
|
||||||
s_StartTick=nn::os::Tick::GetSystemCurrent();
|
|
||||||
}
|
|
||||||
s64 GetConsumedMillisec()
|
|
||||||
{
|
|
||||||
s64 endTick=nn::os::Tick::GetSystemCurrent();
|
|
||||||
nn::os::Tick consumed(endTick-s_StartTick);
|
|
||||||
return ((nn::fnd::TimeSpan)consumed).GetMilliSeconds();
|
|
||||||
}
|
|
||||||
|
|
||||||
// 動いていることを知らせるための、くるくる画面表示取得用メソッド
|
|
||||||
const char s_progress[]="-\\|/";
|
|
||||||
int s_progressIndex=0;
|
|
||||||
char GetProgressChar()
|
|
||||||
{
|
|
||||||
s_progressIndex=(s_progressIndex+1)%(sizeof(s_progress)-1);
|
|
||||||
return s_progress[s_progressIndex];
|
|
||||||
}
|
|
||||||
|
|
||||||
nn::Result UpdateCore()
|
|
||||||
{
|
|
||||||
nn::Result result;
|
|
||||||
nn::cup::ProgressInfo info;
|
|
||||||
|
|
||||||
/********************** アップデート*******************/
|
|
||||||
SetTick();
|
|
||||||
s_scrollBuffer->AppendText("Start Card Update")->Render();
|
|
||||||
NN_UTIL_RETURN_IF_FAILED(nn::cup::CTR::DoUpdate());
|
|
||||||
|
|
||||||
// ステータスがStartedになるまで、プログレスは取得できない
|
|
||||||
s_scrollBuffer->AppendText("");
|
|
||||||
do{
|
|
||||||
s_scrollBuffer->ReplaceText(" %c Initializing", GetProgressChar())->Render();
|
|
||||||
result = nn::cup::CTR::GetProgressInfo(&info);
|
|
||||||
NN_UTIL_RETURN_IF_FAILED(result);
|
|
||||||
nn::os::Thread::Sleep(nn::fnd::TimeSpan::FromMilliSeconds(40));
|
|
||||||
}while(info.state==nn::cup::CTR::UPDATE_STATE_INITIALIZING);
|
|
||||||
|
|
||||||
// 抜けた際のstateがFAILEDかどうか確認
|
|
||||||
if(info.state==nn::cup::CTR::UPDATE_STATE_FAILED){
|
|
||||||
NN_UTIL_RETURN_IF_FAILED(info.lastResult);
|
|
||||||
}
|
|
||||||
s_scrollBuffer->ReplaceText(" - Initialized (%lldmsec)", GetConsumedMillisec());
|
|
||||||
|
|
||||||
/********************* アップデート中 ******************/
|
|
||||||
SetTick();
|
|
||||||
s_scrollBuffer->AppendText("")->Render();
|
|
||||||
do{
|
|
||||||
result = nn::cup::CTR::GetProgressInfo(&info);
|
|
||||||
NN_UTIL_RETURN_IF_FAILED(result);
|
|
||||||
s_scrollBuffer->ReplaceText(" %c Title %d/%d, size %lld/%lld",
|
|
||||||
GetProgressChar(),
|
|
||||||
info.numImportedTitles, info.numTotalTitles,
|
|
||||||
info.importedSize, info.totalSize)->Render();
|
|
||||||
nn::os::Thread::Sleep(nn::fnd::TimeSpan::FromMilliSeconds(40));
|
|
||||||
|
|
||||||
}while(info.state==nn::cup::CTR::UPDATE_STATE_STARTED);
|
|
||||||
// 抜けた際のstateがFAILEDかどうか確認
|
|
||||||
if(info.state==nn::cup::CTR::UPDATE_STATE_FAILED){
|
|
||||||
NN_UTIL_RETURN_IF_FAILED(info.lastResult);
|
|
||||||
}
|
|
||||||
s_scrollBuffer->AppendText(" - Imported (%lldmsec)", GetConsumedMillisec())->Render();
|
|
||||||
|
|
||||||
/***************** アップデート終了中 ******************/
|
|
||||||
SetTick();
|
|
||||||
s_scrollBuffer->AppendText("")->Render();
|
|
||||||
do{
|
|
||||||
result = nn::cup::CTR::GetProgressInfo(&info);
|
|
||||||
NN_UTIL_RETURN_IF_FAILED(result);
|
|
||||||
s_scrollBuffer->ReplaceText(" %c Update Finalizing", GetProgressChar())->Render();
|
|
||||||
nn::os::Thread::Sleep(nn::fnd::TimeSpan::FromMilliSeconds(40));
|
|
||||||
}while(info.state==nn::cup::CTR::UPDATE_STATE_FINALIZING);
|
|
||||||
// 抜けた際のstateがFAILEDかどうか確認
|
|
||||||
if(info.state==nn::cup::CTR::UPDATE_STATE_FAILED){
|
|
||||||
NN_UTIL_RETURN_IF_FAILED(info.lastResult);
|
|
||||||
}
|
|
||||||
|
|
||||||
/******************* アップデート終了 *******************/
|
|
||||||
s_scrollBuffer->AppendText(" - Finalized (%lldmsec)", GetConsumedMillisec())->Render();
|
|
||||||
s_scrollBuffer->AppendText("");
|
|
||||||
|
|
||||||
return nn::ResultSuccess();
|
|
||||||
}
|
|
||||||
|
|
||||||
nn::Result UpdateSequence(bool *isHandledError)
|
|
||||||
{
|
|
||||||
nn::Result result;
|
|
||||||
nn::Result lastResult=nn::ResultSuccess();
|
|
||||||
|
|
||||||
/********************* CUPの初期化 *******************/
|
|
||||||
s_scrollBuffer->AppendText("Initializing Cup Library")->Render();
|
|
||||||
SetTick(); // 初期化開始前の時間をセット
|
|
||||||
result=nn::cup::CTR::Initialize(s_updaterBuffer,sizeof(s_updaterBuffer));
|
|
||||||
if(result==nn::cup::CTR::ResultUpdatePartitionNotFound()){
|
|
||||||
s_scrollBuffer->AppendText(" - Update Partition Not Found (%lldmsec)", GetConsumedMillisec())->Render();
|
|
||||||
s_scrollBuffer->AppendText("")->Render();
|
|
||||||
*isHandledError=true;
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
if(result==nn::cup::CTR::ResultUpdateNotRequired()){
|
|
||||||
s_scrollBuffer->AppendText(" - Already Updated (%lldmsec)", GetConsumedMillisec())->Render();
|
|
||||||
s_scrollBuffer->AppendText("")->Render();
|
|
||||||
*isHandledError=true;
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
if(result==nn::cup::CTR::ResultInvalidUpdatePartitionFormat()){
|
|
||||||
s_scrollBuffer->AppendText(" - Invalid Update Partition (%lldmsec)", GetConsumedMillisec())->Render();
|
|
||||||
s_scrollBuffer->AppendText("")->Render();
|
|
||||||
*isHandledError=true;
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
NN_UTIL_RETURN_IF_FAILED(result);
|
NN_UTIL_RETURN_IF_FAILED(result);
|
||||||
|
nn::os::Thread::Sleep(nn::fnd::TimeSpan::FromMilliSeconds(40));
|
||||||
|
} while (info.state == nn::cup::CTR::UPDATE_STATE_INITIALIZING);
|
||||||
|
|
||||||
s_scrollBuffer->AppendText(" - Need Update (%lldmsec)", GetConsumedMillisec())->Render();
|
// 抜けた際のstateがFAILEDかどうか確認
|
||||||
s_scrollBuffer->AppendText("")->Render();
|
if (info.state == nn::cup::CTR::UPDATE_STATE_FAILED)
|
||||||
|
{
|
||||||
lastResult=UpdateCore();
|
NN_UTIL_RETURN_IF_FAILED(info.lastResult);
|
||||||
|
|
||||||
// Initializeに成功した場合のみ、再びInitializeするためにFinalizeが必要
|
|
||||||
SetTick();
|
|
||||||
s_scrollBuffer->AppendText("Finalizing Cup Library")->Render();
|
|
||||||
NN_UTIL_RETURN_IF_FAILED(nn::cup::CTR::Finalize());
|
|
||||||
s_scrollBuffer->AppendText(" - Complete (%lldmsec)", GetConsumedMillisec())->Render();
|
|
||||||
s_scrollBuffer->AppendText("")->Render();
|
|
||||||
|
|
||||||
return lastResult;
|
|
||||||
}
|
}
|
||||||
|
s_scrollBuffer->ReplaceText(" - Initialized (%lldmsec)", GetConsumedMillisec());
|
||||||
|
|
||||||
|
/********************* アップデート中 ******************/
|
||||||
|
SetTick();
|
||||||
|
s_scrollBuffer->AppendText("")->Render();
|
||||||
|
do
|
||||||
|
{
|
||||||
|
result = nn::cup::CTR::GetProgressInfo(&info);
|
||||||
|
NN_UTIL_RETURN_IF_FAILED(result);
|
||||||
|
s_scrollBuffer->ReplaceText(" %c Title %d/%d, size %lld/%lld", GetProgressChar(), info.numImportedTitles,
|
||||||
|
info.numTotalTitles, info.importedSize, info.totalSize)->Render();
|
||||||
|
nn::os::Thread::Sleep(nn::fnd::TimeSpan::FromMilliSeconds(40));
|
||||||
|
|
||||||
|
} while (info.state == nn::cup::CTR::UPDATE_STATE_STARTED);
|
||||||
|
// 抜けた際のstateがFAILEDかどうか確認
|
||||||
|
if (info.state == nn::cup::CTR::UPDATE_STATE_FAILED)
|
||||||
|
{
|
||||||
|
NN_UTIL_RETURN_IF_FAILED(info.lastResult);
|
||||||
|
}
|
||||||
|
s_scrollBuffer->AppendText(" - Imported (%lldmsec)", GetConsumedMillisec())->Render();
|
||||||
|
|
||||||
|
/***************** アップデート終了中 ******************/
|
||||||
|
SetTick();
|
||||||
|
s_scrollBuffer->AppendText("")->Render();
|
||||||
|
do
|
||||||
|
{
|
||||||
|
result = nn::cup::CTR::GetProgressInfo(&info);
|
||||||
|
NN_UTIL_RETURN_IF_FAILED(result);
|
||||||
|
s_scrollBuffer->ReplaceText(" %c Update Finalizing", GetProgressChar())->Render();
|
||||||
|
nn::os::Thread::Sleep(nn::fnd::TimeSpan::FromMilliSeconds(40));
|
||||||
|
} while (info.state == nn::cup::CTR::UPDATE_STATE_FINALIZING);
|
||||||
|
// 抜けた際のstateがFAILEDかどうか確認
|
||||||
|
if (info.state == nn::cup::CTR::UPDATE_STATE_FAILED)
|
||||||
|
{
|
||||||
|
NN_UTIL_RETURN_IF_FAILED(info.lastResult);
|
||||||
|
}
|
||||||
|
|
||||||
|
/******************* アップデート終了 *******************/
|
||||||
|
s_scrollBuffer->AppendText(" - Finalized (%lldmsec)", GetConsumedMillisec())->Render();
|
||||||
|
s_scrollBuffer->AppendText("");
|
||||||
|
|
||||||
|
return nn::ResultSuccess();
|
||||||
|
}
|
||||||
|
|
||||||
|
nn::Result UpdateSequence(bool *isHandledError)
|
||||||
|
{
|
||||||
|
nn::Result result;
|
||||||
|
nn::Result lastResult = nn::ResultSuccess();
|
||||||
|
|
||||||
|
/********************* CUPの初期化 *******************/
|
||||||
|
s_scrollBuffer->AppendText("Initializing Cup Library")->Render();
|
||||||
|
SetTick(); // 初期化開始前の時間をセット
|
||||||
|
result = nn::cup::CTR::Initialize(s_updaterBuffer, sizeof(s_updaterBuffer));
|
||||||
|
if (result == nn::cup::CTR::ResultUpdatePartitionNotFound())
|
||||||
|
{
|
||||||
|
s_scrollBuffer->AppendText(" - Update Partition Not Found (%lldmsec)", GetConsumedMillisec())->Render();
|
||||||
|
s_scrollBuffer->AppendText("")->Render();
|
||||||
|
*isHandledError = true;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
if (result == nn::cup::CTR::ResultUpdateNotRequired())
|
||||||
|
{
|
||||||
|
s_scrollBuffer->AppendText(" - Already Updated (%lldmsec)", GetConsumedMillisec())->Render();
|
||||||
|
s_scrollBuffer->AppendText("")->Render();
|
||||||
|
*isHandledError = true;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
if (result == nn::cup::CTR::ResultInvalidUpdatePartitionFormat())
|
||||||
|
{
|
||||||
|
s_scrollBuffer->AppendText(" - Invalid Update Partition (%lldmsec)", GetConsumedMillisec())->Render();
|
||||||
|
s_scrollBuffer->AppendText("")->Render();
|
||||||
|
*isHandledError = true;
|
||||||
|
return result;
|
||||||
|
}NN_UTIL_RETURN_IF_FAILED(result);
|
||||||
|
|
||||||
|
s_scrollBuffer->AppendText(" - Need Update (%lldmsec)", GetConsumedMillisec())->Render();
|
||||||
|
s_scrollBuffer->AppendText("")->Render();
|
||||||
|
|
||||||
|
lastResult = UpdateCore();
|
||||||
|
|
||||||
|
// Initializeに成功した場合のみ、再びInitializeするためにFinalizeが必要
|
||||||
|
SetTick();
|
||||||
|
s_scrollBuffer->AppendText("Finalizing Cup Library")->Render();
|
||||||
|
NN_UTIL_RETURN_IF_FAILED(nn::cup::CTR::Finalize());
|
||||||
|
s_scrollBuffer->AppendText(" - Complete (%lldmsec)", GetConsumedMillisec())->Render();
|
||||||
|
s_scrollBuffer->AppendText("")->Render();
|
||||||
|
|
||||||
|
return lastResult;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
nn::Result ExecuteCup(ScrollBuffer* scrollBuf)
|
||||||
|
{
|
||||||
|
nn::Result result;
|
||||||
|
bool isHandledError = false;
|
||||||
|
result = UpdateSequence(&isHandledError);
|
||||||
|
if (isHandledError == false && result.IsFailure())
|
||||||
|
{
|
||||||
|
{
|
||||||
|
// それ以外の場合は、Resultを表示
|
||||||
|
scrollBuf->AppendText(" - Unhandled Error: 0x%08x", result.GetPrintableBits());
|
||||||
|
scrollBuf->AppendText("")->Render();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
extern "C" void nnMain()
|
extern "C" void nnMain()
|
||||||
@ -233,7 +255,7 @@ extern "C" void nnMain()
|
|||||||
nn::ProgramId MMEN_PROGRAM_ID = 0x0004003000008202;
|
nn::ProgramId MMEN_PROGRAM_ID = 0x0004003000008202;
|
||||||
|
|
||||||
nn::cfg::CfgRegionCode region = nn::cfg::GetRegion();
|
nn::cfg::CfgRegionCode region = nn::cfg::GetRegion();
|
||||||
switch(region)
|
switch (region)
|
||||||
{
|
{
|
||||||
case nn::cfg::CFG_REGION_AMERICA:
|
case nn::cfg::CFG_REGION_AMERICA:
|
||||||
{
|
{
|
||||||
@ -255,35 +277,57 @@ extern "C" void nnMain()
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
nn::am::ProgramInfo outInfos;
|
nn::am::ProgramInfo outInfos;
|
||||||
result = nn::am::GetProgramInfos(&outInfos, nn::fs::MEDIA_TYPE_NAND, &MMEN_PROGRAM_ID, 1);
|
result = nn::am::GetProgramInfos(&outInfos, nn::fs::MEDIA_TYPE_NAND, &MMEN_PROGRAM_ID, 1);
|
||||||
if (result.IsSuccess())
|
if (result.IsSuccess())
|
||||||
{
|
{
|
||||||
|
result = ExecuteCup(s_scrollBuffer);
|
||||||
/******************** CUPの実行 *******************/
|
// CUP不要だがNUPバージョンのほうが新しかったら強制的に実行
|
||||||
bool isHandledError = false;
|
if (result == nn::cup::CTR::ResultUpdateNotRequired())
|
||||||
result = UpdateSequence(&isHandledError);
|
|
||||||
if (isHandledError == false && result.IsFailure())
|
|
||||||
{
|
{
|
||||||
|
// バージョンの取得
|
||||||
|
VerDef versionData;
|
||||||
|
GetSystemVersion(&versionData, region);
|
||||||
|
|
||||||
|
const size_t ROMFS_BUFFER_SIZE = 1024 * 32;
|
||||||
|
u8 buffer[ROMFS_BUFFER_SIZE];
|
||||||
|
result = nn::fs::MountRom(16, 16, buffer, ROMFS_BUFFER_SIZE);
|
||||||
|
if (result.IsSuccess())
|
||||||
{
|
{
|
||||||
// それ以外の場合は、Resultを表示
|
nn::fs::FileReader fileReader;
|
||||||
s_scrollBuffer->AppendText(" - Unhandled Error: 0x%08x", result.GetPrintableBits());
|
result = fileReader.TryInitialize("rom:/nup_version.bin");
|
||||||
s_scrollBuffer->AppendText("")->Render();
|
if (result.IsSuccess())
|
||||||
|
{
|
||||||
|
u8 buf[1024];
|
||||||
|
s32 readSize;
|
||||||
|
result = fileReader.TryRead(&readSize, buf, sizeof(buf));
|
||||||
|
if (result.IsSuccess())
|
||||||
|
{
|
||||||
|
if (versionData.nup.majorVersion < *reinterpret_cast<u8*>(buf))
|
||||||
|
{
|
||||||
|
// CUPバージョンを削除
|
||||||
|
result = nn::am::DeleteProgram(nn::fs::MEDIA_TYPE_NAND, cCupVerId[region]);
|
||||||
|
if (result.IsSuccess())
|
||||||
|
{
|
||||||
|
result = ExecuteCup(s_scrollBuffer);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if(result == nn::am::ResultNotFound())
|
else if (result == nn::am::ResultNotFound())
|
||||||
{
|
{
|
||||||
s_scrollBuffer->AppendText("Cannot find Home Menu");
|
s_scrollBuffer->AppendText("Cannot find Home Menu");
|
||||||
}
|
}
|
||||||
|
|
||||||
s_scrollBuffer->AppendText("")->Render();
|
s_scrollBuffer->AppendText("")->Render();
|
||||||
|
|
||||||
for(;;)
|
for (;;)
|
||||||
{
|
{
|
||||||
s_RenderSystem.SetRenderTarget(NN_GX_DISPLAY0);
|
s_RenderSystem.SetRenderTarget(NN_GX_DISPLAY0);
|
||||||
if(result.IsSuccess() || result == nn::cup::CTR::ResultUpdateNotRequired())
|
if (result.IsSuccess() || result == nn::cup::CTR::ResultUpdateNotRequired())
|
||||||
{
|
{
|
||||||
s_RenderSystem.SetClearColor(NN_GX_DISPLAY0, 0, 1, 0, 1);
|
s_RenderSystem.SetClearColor(NN_GX_DISPLAY0, 0, 1, 0, 1);
|
||||||
}
|
}
|
||||||
@ -294,7 +338,7 @@ extern "C" void nnMain()
|
|||||||
s_RenderSystem.Clear();
|
s_RenderSystem.Clear();
|
||||||
s_RenderSystem.SwapBuffers();
|
s_RenderSystem.SwapBuffers();
|
||||||
s_RenderSystem.SetRenderTarget(NN_GX_DISPLAY1);
|
s_RenderSystem.SetRenderTarget(NN_GX_DISPLAY1);
|
||||||
if(result.IsSuccess() || result == nn::cup::CTR::ResultUpdateNotRequired())
|
if (result.IsSuccess() || result == nn::cup::CTR::ResultUpdateNotRequired())
|
||||||
{
|
{
|
||||||
s_RenderSystem.SetClearColor(NN_GX_DISPLAY1, 0, 1, 0, 1);
|
s_RenderSystem.SetClearColor(NN_GX_DISPLAY1, 0, 1, 0, 1);
|
||||||
}
|
}
|
||||||
@ -304,7 +348,7 @@ extern "C" void nnMain()
|
|||||||
}
|
}
|
||||||
s_scrollBuffer->ReplaceText("%c Finished", GetProgressChar())->Render();
|
s_scrollBuffer->ReplaceText("%c Finished", GetProgressChar())->Render();
|
||||||
|
|
||||||
if ( nn::applet::IsExpectedToCloseApplication() )
|
if (nn::applet::IsExpectedToCloseApplication())
|
||||||
{
|
{
|
||||||
nn::applet::PrepareToCloseApplication();
|
nn::applet::PrepareToCloseApplication();
|
||||||
nn::applet::CloseApplication();
|
nn::applet::CloseApplication();
|
||||||
|
|||||||
1
trunk/CardCup/romfiles/nup_version.bin
Normal file
1
trunk/CardCup/romfiles/nup_version.bin
Normal file
@ -0,0 +1 @@
|
|||||||
|
|
||||||
Loading…
Reference in New Issue
Block a user