From 46a0dea8a99475afb8ca84afeaf0add3d4cbcc19 Mon Sep 17 00:00:00 2001 From: N2614 Date: Mon, 7 Feb 2011 09:17:24 +0000 Subject: [PATCH] =?UTF-8?q?=E8=BF=BD=E5=8A=A0=E5=BF=98=E3=82=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- .../common/PlayHistoryManager.cpp | 220 ++++++++++++++++++ .../common/PlayHistoryManager.h | 45 ++++ trunk/ConsoleDataMigration/common/ProgramId.h | 28 +++ 3 files changed, 293 insertions(+) create mode 100644 trunk/ConsoleDataMigration/common/PlayHistoryManager.cpp create mode 100644 trunk/ConsoleDataMigration/common/PlayHistoryManager.h create mode 100644 trunk/ConsoleDataMigration/common/ProgramId.h diff --git a/trunk/ConsoleDataMigration/common/PlayHistoryManager.cpp b/trunk/ConsoleDataMigration/common/PlayHistoryManager.cpp new file mode 100644 index 0000000..1818264 --- /dev/null +++ b/trunk/ConsoleDataMigration/common/PlayHistoryManager.cpp @@ -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 +#include + +#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(&historyNum), + sizeof(historyNum)); + COMMON_LOGGER_RESULT_IF_FAILED_WITH_LINE(result); + + nn::pl::CTR::PlayEvent* pEvent; + pEvent = reinterpret_cast (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(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 (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(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 (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; +} + +} diff --git a/trunk/ConsoleDataMigration/common/PlayHistoryManager.h b/trunk/ConsoleDataMigration/common/PlayHistoryManager.h new file mode 100644 index 0000000..916741b --- /dev/null +++ b/trunk/ConsoleDataMigration/common/PlayHistoryManager.h @@ -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_ */ diff --git a/trunk/ConsoleDataMigration/common/ProgramId.h b/trunk/ConsoleDataMigration/common/ProgramId.h new file mode 100644 index 0000000..c565f11 --- /dev/null +++ b/trunk/ConsoleDataMigration/common/ProgramId.h @@ -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_ */