追加忘れ

git-svn-id: file:///Volumes/Transfer/gigaleak_20231201/2020-05-23%20-%20ctr.7z%20+%20svn_v1.068.zip/ctr/svn/ctr_Repair@25 385bec56-5757-e545-9c3a-d8741f4650f1
This commit is contained in:
N2614 2011-02-07 09:17:24 +00:00
parent 822ecb5fc0
commit 46a0dea8a9
3 changed files with 293 additions and 0 deletions

View File

@ -0,0 +1,220 @@
/*---------------------------------------------------------------------------*
Project: Horizon
File: PlayHistoryManager.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 <nn/pl.h>
#include <nn/pl/CTR/pl_PlayHistoryApiSysmenu.h>
#include "PlayHistoryManager.h"
#include "HeapManager.h"
#include "SdMountManager.h"
#include "SdReaderWriter.h"
#include "CommonLogger.h"
#include "FileName.h"
#include "ProgramId.h"
namespace common
{
PlayHistoryManager::PlayHistoryManager()
{
// TODO 自動生成されたコンストラクター・スタブ
}
PlayHistoryManager::~PlayHistoryManager()
{
// TODO Auto-generated destructor stub
}
void PlayHistoryManager::Export()
{
nn::Result result;
SdMountManager::Mount();
SdReaderWriter sd;
size_t historyNum = nn::pl::CTR::GetPlayHistoryLength();
if ( historyNum == 0)
{
NN_LOG("No Play Event\n");
return;
}
// SDに書き込む
result = sd.WriteBuf(common::PLAYHISTORY_COUNT_PATHNAME, reinterpret_cast<void*>(&historyNum),
sizeof(historyNum));
COMMON_LOGGER_RESULT_IF_FAILED_WITH_LINE(result);
nn::pl::CTR::PlayEvent* pEvent;
pEvent = reinterpret_cast<nn::pl::CTR::PlayEvent*> (HeapManager::GetHeap()->Allocate(
sizeof(nn::pl::CTR::PlayEvent) * historyNum));
if ( pEvent == NULL )
{
NN_LOG("Failed to Allocate Heap\n");
return;
}
// 一番古いデータから素直に全部読み込む
nn::pl::CTR::GetPlayHistory(pEvent, 0, historyNum);
// SDに書き込む
result = sd.WriteBuf(common::PLAYHISTORY_PATHNAME, reinterpret_cast<void*>(pEvent),
sizeof(nn::pl::CTR::PlayEvent) * historyNum);
COMMON_LOGGER_RESULT_IF_FAILED_WITH_LINE(result);
HeapManager::GetHeap()->Free(pEvent);
SdMountManager::Unmount();
}
void PlayHistoryManager::GetPlayHistoryNums(size_t* nums)
{
nn::Result result;
size_t bufSize = common::HeapManager::GetHeap()->GetAllocatableSize();
void* buf = common::HeapManager::GetHeap()->Allocate(bufSize);
if (buf != NULL)
{
common::SdReaderWriter sdReader;
size_t readSize;
result = sdReader.ReadBuf(common::PLAYHISTORY_COUNT_PATHNAME, buf, bufSize, &readSize);
if (result.IsSuccess())
{
*nums = *reinterpret_cast<size_t*> (buf);
}
}
HeapManager::GetHeap()->Free(buf);
}
void PlayHistoryManager::Import()
{
nn::Result result;
SdMountManager::Mount();
SdReaderWriter sd;
SdMountManager::Mount();
// プレイ履歴の件数を取得する
size_t historyNum = 0;
GetPlayHistoryNums(&historyNum);
if(historyNum == 0)
{
NN_LOG("No PlayHistory found\n");
return;
}
size_t bufSize = common::HeapManager::GetHeap()->GetAllocatableSize();
void* buf = common::HeapManager::GetHeap()->Allocate(bufSize);
if (buf != NULL)
{
common::SdReaderWriter sdReader;
size_t readSize;
result = sdReader.ReadBuf(common::PLAYHISTORY_PATHNAME, buf, bufSize, &readSize);
if(result.IsSuccess())
{
nn::pl::CTR::PlayEvent* pEvent = reinterpret_cast<nn::pl::CTR::PlayEvent*>(buf);
NN_LOG("history num = %d\n", historyNum);
// プレイ履歴を無効化する
nn::pl::CTR::ClearPlayHistory();
// データ移行ツールを無視して書き込む
for(u32 i = 0; i < historyNum; i++)
{
COMMON_LOGGER("Importing PlayHistory %d/%d", i, historyNum);
if ((pEvent[i].GetProgramId() & WITHOUT_VALIATION_MASK) != CONSOLE_BACKUP_PROGRAM_ID
&& (pEvent[i].GetProgramId() & WITHOUT_VALIATION_MASK) != CONSOLE_RESTORE_PROGRAM_ID)
{
NN_LOG("%05d 0x%16llx : %X : %d\n", i, pEvent[i].GetProgramId(), pEvent[i].GetEventType(),
pEvent[i].minutes);
nn::pl::CTR::NotifyPlayEvent(pEvent[i].GetEventType(), pEvent[i].GetProgramId(),
pEvent[i].GetEventTime());
}
else
{
NN_LOG("Skipped\n");
}
}
}
else
{
COMMON_LOGGER_RESULT_WITH_LINE(result , __LINE__);
}
common::HeapManager::GetHeap()->Free(buf);
}
else
{
NN_LOG("Failed Allocate Heap!! %s, %d", __FILE__, __LINE__);
return;
}
SdMountManager::Unmount();
}
void PlayHistoryManager::Dump()
{
nn::Result result;
s32 playEventLength = nn::pl::CTR::GetPlayHistoryLength();
if ( playEventLength == 0 )
{
NN_LOG("No Play Event\n");
return;
}
nn::pl::CTR::PlayEvent* playEvent = reinterpret_cast<nn::pl::CTR::PlayEvent*> (HeapManager::GetHeap()->Allocate(
sizeof(nn::pl::CTR::PlayEvent) * playEventLength));
if ( playEvent == NULL )
{
NN_LOG("Failed to Allocate Heap\n");
return;
}
// 一番古いデータから素直に全部読み込む
(void)nn::pl::CTR::GetPlayHistory(playEvent, 0, playEventLength);
// 取得したデータを順番にすべて表示していく
s32 restPlayEventLength = playEventLength;
s32 displayCount = 0;
nn::pl::CTR::PlayEvent* pEvent;
while ( restPlayEventLength > 0 )
{
// 一気に表示できるところまで表示する
int line;
for ( line = 0; line < 24; line++ )
{
pEvent = &playEvent[displayCount];
NN_LOG("0x%16llx : %X : %d\n", pEvent->GetProgramId(), pEvent->eventType, pEvent->minutes);
restPlayEventLength--;
displayCount++;
if(restPlayEventLength <= 0)
{
break;
}
}
}
HeapManager::GetHeap()->Free(playEvent);
return;
}
}

View File

@ -0,0 +1,45 @@
/*---------------------------------------------------------------------------*
Project: Horizon
File: PlayHistoryManager.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 PLAYHISTORYMANAGER_H_
#define PLAYHISTORYMANAGER_H_
namespace common
{
//! @brief データ移行ツールの履歴を消しながらプレイ履歴を移行するためのクラスです。
class PlayHistoryManager
{
public:
PlayHistoryManager();
virtual ~PlayHistoryManager();
//! @brief SDカードに出力します。
void Export();
//! @brief SDカードからプレイ履歴に書き込みます
void Import();
//! @brief デバッグ用。プレイ履歴をデバッグ出力します。
void Dump();
private:
void GetPlayHistoryNums(size_t* nums);
};
}
#endif /* PLAYHISTORYMANAGER_H_ */

View File

@ -0,0 +1,28 @@
/*---------------------------------------------------------------------------*
Project: Horizon
File: ProgramId.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 PROGRAMID_H_
#define PROGRAMID_H_
namespace common
{
const u64 CONSOLE_BACKUP_PROGRAM_ID = 0x000400000f802200L;
const u64 CONSOLE_RESTORE_PROGRAM_ID = 0x000400000f802300L;
const u64 WITHOUT_VALIATION_MASK = 0xffffffffffffff00L;
}
#endif /* PROGRAMID_H_ */