ctr_Repair/trunk/ConsoleDataMigration/ConsoleBackup/Controller.cpp
N2614 ffe18679f3 出力用ディレクトリを毎回生成するように
ログメッセージをファイル名変更に追従
APが見つからないログメッセージを出力するように

git-svn-id: file:///Volumes/Transfer/gigaleak_20231201/2020-05-23%20-%20ctr.7z%20+%20svn_v1.068.zip/ctr/svn/ctr_Repair@23 385bec56-5757-e545-9c3a-d8741f4650f1
2011-02-07 02:32:32 +00:00

246 lines
6.4 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*---------------------------------------------------------------------------*
Project: Horizon
File: Controller.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 "Controller.h"
#include "FileChecker.h"
#include "ConsoleBackup.h"
#include "Exporter.h"
#include "SimplePlayer.h"
#include "CommonLogger.h"
#include <nn.h>
namespace ConsoleBackup
{
namespace
{
typedef enum BackupState
{
STARTUP, // 初期値
IN_PROGRESS, // 吸出し中
DONE, // 吸出し完了
FINISHED, // SDカード抜き完了
FAIL // 失敗
} BackupState;
// APSettingの書式が無い警告サウンドを鳴らしたかどうか
bool s_ExistAPSettingAnnotation = false;
BackupState s_BackupState = STARTUP;
bool s_PlayedFinishedSound = false;
bool s_PlayedFailSound = false;
} // namespace <unnamed>
bool NeedsAcAdateper()
{
return IsBatteryLower() && !IsAdapterConnected();
}
void ControlState(::std::vector<std::string>& operationMessage, bool& nextStep, bool& continueBackup)
{
// 状態遷移Controller
switch (s_BackupState)
{
// 起動時
case STARTUP:
{
bool error = false;
// 完全性検証SEEDを読めるか
if (CanReadIVS())
{
// SDカードが挿入されているか
if (nn::fs::IsSdmcInserted())
{
// 無線設定ファイルがあるか?
if (common::ExistsAPSetting())
{
// 書き込み中に抜かないように
if (nextStep)
{
// SDカードに書き込みできるか
if (nn::fs::IsSdmcWritable())
{
// シリアルナンバーを読み取れるか?
if (!CanReadSerialNumber())
{
common::PlaySound(common::SOUND_ANNOTATION);
COMMON_LOGGER("Can't Read Serial Number\n");
}
}
else
{
error = true;
common::PlaySound(common::SOUND_ANNOTATION);
COMMON_LOGGER("Can't Write SD Card!!\n");
}
}
}
else
{
error = true;
if (!s_ExistAPSettingAnnotation)
{
s_ExistAPSettingAnnotation = true;
common::PlaySound(common::SOUND_ANNOTATION);
}
operationMessage.push_back(::std::string("Accsess_Point_Setting does not exist!"));
}
}
else
{
error = true;
operationMessage.push_back(::std::string("Insert SD Card!!"));
}
}
else
{
error = true;
operationMessage.push_back(::std::string("Can't Read IVS!!"));
}
// ACアダプタが必要か
if (NeedsAcAdateper())
{
error = true;
operationMessage.push_back(::std::string("Connect AC Adapter!!"));
}
// エラーが無ければ進行用メッセージ表示
if(!error)
{
operationMessage.push_back(::std::string("Push A or START Button"));
}
if (nextStep && !error)
{
COMMON_LOGGER("Start Export Data\n");
s_BackupState = IN_PROGRESS;
common::PlaySound(common::SOUND_CURSOR);
}
}
break;
// 吸出し中
case IN_PROGRESS:
{
continueBackup = true;
// ACアダプタが必要か
if (NeedsAcAdateper())
{
continueBackup = false;
operationMessage.push_back(::std::string("Connect AC Adapter!!"));
}
// データを書き込む
ExportData();
// 処理が完了した
if (continueBackup && IsExportFinished())
{
FinalizeExportThread();
COMMON_LOGGER("Export NAND Data Finished.\n");
if(GetProgress() > 99)
{
s_BackupState = DONE;
}
else
{
s_BackupState = FAIL;
}
}
}
break;
// 吸出し完了
case DONE:
{
operationMessage.push_back(::std::string("Backup Done. Pull Out SD Card."));
}
break;
// SDカード抜き完了
case FINISHED:
{
operationMessage.push_back(::std::string("Backup Succeeded!!\n"));
if(!s_PlayedFinishedSound)
{
common::PlaySound(common::SOUND_OK);
s_PlayedFinishedSound = true;
}
}
break;
// 吸出し失敗
case FAIL:
{
operationMessage.push_back(::std::string("Backup Failed."));
if(!s_PlayedFailSound)
{
common::PlaySound(common::SOUND_NG);
s_PlayedFailSound = true;
}
}
break;
}
}
bool InProgress()
{
return s_BackupState == IN_PROGRESS;
}
bool IsBackupSucceeded()
{
return s_BackupState == FINISHED;
}
bool IsBackupFailed()
{
return s_BackupState == FAIL;
}
void OnSdEjected()
{
if(s_BackupState == DONE || s_BackupState == FINISHED)
{
s_BackupState = FINISHED;
}
else
{
common::InitializeFileCheck();
InitializeState();
}
}
void InitializeState()
{
s_BackupState = STARTUP;
s_PlayedFailSound = false;
s_PlayedFinishedSound = false;
s_ExistAPSettingAnnotation = false;
}
} // namespace ConsoleBackup