diff --git a/trunk/ConsoleDataMigration/ConsoleBackup/Controller.cpp b/trunk/ConsoleDataMigration/ConsoleBackup/Controller.cpp index 5c0c148..e27eb3d 100644 --- a/trunk/ConsoleDataMigration/ConsoleBackup/Controller.cpp +++ b/trunk/ConsoleDataMigration/ConsoleBackup/Controller.cpp @@ -14,6 +14,7 @@ *---------------------------------------------------------------------------*/ #include "Controller.h" +#include "FileChecker.h" #include "ConsoleBackup.h" #include "Exporter.h" #include "SimplePlayer.h" @@ -37,6 +38,9 @@ typedef enum BackupState } BackupState; +// APSettingの書式が無い警告サウンドを鳴らしたかどうか +bool s_ExistAPSettingAnnotation = false; + BackupState s_BackupState = STARTUP; bool s_PlayedFinishedSound = false; bool s_PlayedFailSound = false; @@ -64,26 +68,40 @@ void ControlState(::std::vector& operationMessage, bool& nextStep, // SDカードが挿入されているか? if (nn::fs::IsSdmcInserted()) { - // 書き込み中に抜かないように - if (nextStep) + // 無線設定ファイルがあるか? + if (common::ExistsAPSetting()) { - // SDカードに書き込みできるか? - if (nn::fs::IsSdmcWritable()) + // 書き込み中に抜かないように + if (nextStep) { - // シリアルナンバーを読み取れるか? - if (!CanReadSerialNumber()) + // SDカードに書き込みできるか? + if (nn::fs::IsSdmcWritable()) { - common::PlaySound(common::SOUND_ANNOTATION); - COMMON_LOGGER("Can't Read Serial Number\n"); + // シリアルナンバーを読み取れるか? + 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; - 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("APSetting.txt does not exist!")); } } else @@ -211,6 +229,7 @@ void OnSdEjected() } else { + common::InitializeFileCheck(); InitializeState(); } } @@ -220,6 +239,7 @@ void InitializeState() s_BackupState = STARTUP; s_PlayedFailSound = false; s_PlayedFinishedSound = false; + s_ExistAPSettingAnnotation = false; } } // namespace ConsoleBackup diff --git a/trunk/ConsoleDataMigration/ConsoleBackup/OMakefile b/trunk/ConsoleDataMigration/ConsoleBackup/OMakefile index aa6ce6d..b8feb6e 100644 --- a/trunk/ConsoleDataMigration/ConsoleBackup/OMakefile +++ b/trunk/ConsoleDataMigration/ConsoleBackup/OMakefile @@ -31,6 +31,7 @@ SOURCES[] = Exporter.cpp ../common/DrawSystemState.cpp ../common/FileTransfer.cpp + ../common/FileChecker.cpp ../common/SdReaderWriter.cpp ../common/HeapManager.cpp ../common/SdLogger.cpp diff --git a/trunk/ConsoleDataMigration/ConsoleRestore/Controller.cpp b/trunk/ConsoleDataMigration/ConsoleRestore/Controller.cpp index dad1a6e..e7604b7 100644 --- a/trunk/ConsoleDataMigration/ConsoleRestore/Controller.cpp +++ b/trunk/ConsoleDataMigration/ConsoleRestore/Controller.cpp @@ -20,6 +20,7 @@ #include #include "Controller.h" +#include "FileChecker.h" #include "ConsoleRestore.h" #include "SimplePlayer.h" #include "CommonLogger.h" @@ -83,6 +84,8 @@ bool NeedsAcAdater() bool CheckAndReadAPSetting(::std::vector& operationMessage) { + using namespace common; + if (!ExistsAPSetting()) { if(!s_ExistAPSettingAnnotation) @@ -140,7 +143,7 @@ void PutAliveMessage(::std::vector& operationMessage, const char* s void ExecSyncMcuRtc() { - if(!ExistsRtcSyncFinishedFile()) + if(!common::ExistsRtcSyncFinishedFile()) { ImportMcuRtc(); // 時計を無効化する @@ -150,6 +153,8 @@ void ExecSyncMcuRtc() void ControlState(::std::vector& operationMessage, bool& nextStep, bool& continueRestore) { + using namespace common; + // 状態遷移Controller switch (s_RestoreState) { @@ -212,7 +217,7 @@ void ControlState(::std::vector& operationMessage, bool& nextStep, if (nextStep && !nn::fs::IsSdmcWritable()) { error = true; - common::PlaySound(common::SOUND_ANNOTATION); + PlaySound(SOUND_ANNOTATION); COMMON_LOGGER("Can't Write SD Card!!\n"); } } @@ -303,19 +308,19 @@ void ControlState(::std::vector& operationMessage, bool& nextStep, ExecSyncMcuRtc(); s_RestoreState = UPDATE_IN_PROGRESS; - common::PlaySound(common::SOUND_CURSOR); + PlaySound(SOUND_CURSOR); } else if(needsErase) { COMMON_LOGGER("Erase Trash\n"); s_RestoreState = ERASE; - common::PlaySound(common::SOUND_CURSOR); + PlaySound(SOUND_CURSOR); } else { COMMON_LOGGER("Start Import Data\n"); s_RestoreState = RESTORE_IN_PROGRESS; - common::PlaySound(common::SOUND_CURSOR); + PlaySound(SOUND_CURSOR); } } } @@ -331,7 +336,7 @@ void ControlState(::std::vector& operationMessage, bool& nextStep, if (!s_SerialNumberAnnotation) { s_SerialNumberAnnotation = true; - common::PlaySound(common::SOUND_ANNOTATION); + PlaySound(SOUND_ANNOTATION); } if (nextStep) @@ -543,7 +548,7 @@ void ControlState(::std::vector& operationMessage, bool& nextStep, static bool init = true; if (init) { - common::PlaySound(common::SOUND_OK); + PlaySound(SOUND_OK); init = false; } } @@ -555,7 +560,7 @@ void ControlState(::std::vector& operationMessage, bool& nextStep, operationMessage.push_back(::std::string("Failed.")); if (!s_PlayedFailSound) { - common::PlaySound(common::SOUND_NG); + PlaySound(SOUND_NG); s_PlayedFailSound = true; } } @@ -588,6 +593,7 @@ void OnSdEjected() else { InitializeState(); + ClearFileReadReslt(); } } @@ -595,7 +601,7 @@ void InitializeState() { s_RestoreState = STARTUP; - InitializeFileCheck(); + common::InitializeFileCheck(); s_ExistAPSettingAnnotation = false; s_ReadSettingDone = false; diff --git a/trunk/ConsoleDataMigration/ConsoleRestore/Importer.cpp b/trunk/ConsoleDataMigration/ConsoleRestore/Importer.cpp index 772e768..8c30f57 100644 --- a/trunk/ConsoleDataMigration/ConsoleRestore/Importer.cpp +++ b/trunk/ConsoleDataMigration/ConsoleRestore/Importer.cpp @@ -63,12 +63,6 @@ TimeZone s_TimeZone; const size_t NTP_SERVER_NAME_LENGTH = 256; char s_NtpServerName[NTP_SERVER_NAME_LENGTH]; -// ファイルの存在確認 -bool CheckFileExists(const wchar_t* path); - -bool s_FileExistsChecked[EXISTS_MAX]; -bool s_FileExistsCheckeResult[EXISTS_MAX]; - bool s_CheckedEqualsIVSFileandIVS = false; bool s_ReadSerialNumber = false; @@ -177,30 +171,6 @@ void ConvertTimeZoneString(const char* str) namespace { -bool CheckFileExists(const wchar_t* path) -{ - nn::Result result; - bool exist = false; - result = common::SdMountManager::Mount(); - - if (result.IsSuccess()) - { - nn::fs::FileInputStream fis; - - result = fis.TryInitialize(path); - if(result.IsSuccess()) - { - exist = true; - } - fis.Finalize(); - } - - common::SdMountManager::Unmount(); - - - return exist; -} - bool CreateEmptyFile(const wchar_t* path) { nn::Result result; @@ -225,50 +195,6 @@ bool CreateEmptyFile(const wchar_t* path) return create; } -bool ExistsFile(FileExistsCheck index) -{ - if(index > EXISTS_MAX) - { - NN_LOG("Invalid File index!!\n"); - return false; - } - - if(s_FileExistsChecked[index]) - { - return s_FileExistsCheckeResult[index]; - } - - s_FileExistsChecked[index] = true; - s_FileExistsCheckeResult[index] = CheckFileExists(FILENAME_TABLE[index]); - return s_FileExistsCheckeResult[index]; -} - -} - -bool ExistsUpdateCheckedFile() -{ - return ExistsFile(EXISTS_UPDATE_FINISHED); -} - -bool ExistsSerialNumberFile() -{ - return ExistsFile(EXISTS_SERIAL_NUMBER); -} - -bool ExistsIVSFile() -{ - return ExistsFile(EXISTS_IVS); -} - -void InitializeFileCheck() -{ - for(u32 i = 0; i < EXISTS_MAX; i++) - { - s_FileExistsChecked[i] = false; - } - - s_CheckedEqualsIVSFileandIVS = false; - s_ReadSerialNumber = false; } u8* ReadSerialNumber() @@ -287,21 +213,6 @@ u8* ReadSerialNumber() s_ReadSerialNumber = true; return s_SerialNo; } -bool ExistsWriteFinishedFile() -{ - return ExistsFile(EXISTS_WRITE_FINISHED); -} - -bool ExistsAPSetting() -{ - return ExistsFile(EXISTS_AP_SETTING); -} - -bool ExistsRtcSyncFinishedFile() -{ - return ExistsFile(EXISTS_RTC_SYNC_FINISHED); -} - bool EqualsIVSFileandIVS() { nn::Result result; @@ -372,11 +283,6 @@ bool EqualsIVSFileandIVS() return retval; } -bool ExistsConsoleInitializedFile() -{ - return ExistsFile(EXISTS_CONSOLE_INTIALIZED); -} - void SetCountry(nn::cfg::CTR::CfgCountryCode countryCode) { using namespace nn::cfg::CTR; @@ -1263,6 +1169,11 @@ void ImportTwlSoundData() ImportTwlData(common::TWL_SOUND); } +void ClearFileReadReslt() +{ + s_CheckedEqualsIVSFileandIVS = false; + s_ReadSerialNumber = false; +} void ImportData() { diff --git a/trunk/ConsoleDataMigration/ConsoleRestore/Importer.h b/trunk/ConsoleDataMigration/ConsoleRestore/Importer.h index 757f772..70dbb8a 100644 --- a/trunk/ConsoleDataMigration/ConsoleRestore/Importer.h +++ b/trunk/ConsoleDataMigration/ConsoleRestore/Importer.h @@ -23,39 +23,8 @@ namespace ConsoleRestore { -typedef enum FILE_EXISTS_CHECK -{ - EXISTS_UPDATE_FINISHED, - EXISTS_SERIAL_NUMBER, - EXISTS_IVS, - EXISTS_CONSOLE_INTIALIZED, - EXISTS_WRITE_FINISHED, - EXISTS_AP_SETTING, - EXISTS_RTC_SYNC_FINISHED, - EXISTS_MAX -} FileExistsCheck; - -const wchar_t* const FILENAME_TABLE[EXISTS_MAX] = -{ - common::UPDATE_CHECK_PATHNAME, - common::SERIAL_PATHNAME, - common::IVS_PATHNAME, - common::INITIALIZED_CHECK_PATHNAME, - common::WRITE_FINISHED_PATHNAME, - common::AP_SETTING_PATHNAME, - common::RTC_SYNC_CHECK_PATHNAME -}; - -bool ExistsUpdateCheckedFile(); -bool ExistsSerialNumberFile(); -bool ExistsIVSFile(); bool EqualsIVSFileandIVS(); -bool ExistsConsoleInitializedFile(); -void InitializeFileCheck(); u8* ReadSerialNumber(); -bool ExistsWriteFinishedFile(); -bool ExistsAPSetting(); -bool ExistsRtcSyncFinishedFile(); bool IsImportFinished(); void ImportData(); @@ -96,6 +65,7 @@ void ImportMcuRtc(); // TWL写真領域を初期化してから本体初期化を行う void InitializeFileSystem(); +void ClearFileReadReslt(); } #endif /* IMPORTER_H_ */ diff --git a/trunk/ConsoleDataMigration/ConsoleRestore/OMakefile b/trunk/ConsoleDataMigration/ConsoleRestore/OMakefile index d9ee94a..9c2097b 100644 --- a/trunk/ConsoleDataMigration/ConsoleRestore/OMakefile +++ b/trunk/ConsoleDataMigration/ConsoleRestore/OMakefile @@ -33,6 +33,7 @@ SOURCES[] = Ntpclient.cpp ../common/DrawSystemState.cpp ../common/FileTransfer.cpp + ../common/FileChecker.cpp ../common/SdReaderWriter.cpp ../common/HeapManager.cpp ../common/SdLogger.cpp diff --git a/trunk/ConsoleDataMigration/common/FileChecker.cpp b/trunk/ConsoleDataMigration/common/FileChecker.cpp new file mode 100644 index 0000000..037df01 --- /dev/null +++ b/trunk/ConsoleDataMigration/common/FileChecker.cpp @@ -0,0 +1,113 @@ +/*---------------------------------------------------------------------------* + Project: Horizon + File: FileChecker.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 "FileChecker.h" +#include "SdMountManager.h" + +namespace common +{ + +bool s_FileExistsChecked[EXISTS_MAX]; +bool s_FileExistsCheckeResult[EXISTS_MAX]; + +bool CheckFileExists(const wchar_t* path) +{ + nn::Result result; + bool exist = false; + result = common::SdMountManager::Mount(); + + if (result.IsSuccess()) + { + nn::fs::FileInputStream fis; + + result = fis.TryInitialize(path); + if(result.IsSuccess()) + { + exist = true; + } + fis.Finalize(); + } + + common::SdMountManager::Unmount(); + + + return exist; +} + +bool ExistsFile(FileExistsCheck index) +{ + if(index > EXISTS_MAX) + { + NN_LOG("Invalid File index!!\n"); + return false; + } + + if(s_FileExistsChecked[index]) + { + return s_FileExistsCheckeResult[index]; + } + + s_FileExistsChecked[index] = true; + s_FileExistsCheckeResult[index] = CheckFileExists(FILENAME_TABLE[index]); + return s_FileExistsCheckeResult[index]; +} + +bool ExistsUpdateCheckedFile() +{ + return ExistsFile(EXISTS_UPDATE_FINISHED); +} + +bool ExistsSerialNumberFile() +{ + return ExistsFile(EXISTS_SERIAL_NUMBER); +} + +bool ExistsIVSFile() +{ + return ExistsFile(EXISTS_IVS); +} + +bool ExistsConsoleInitializedFile() +{ + return ExistsFile(EXISTS_CONSOLE_INTIALIZED); +} + +bool ExistsWriteFinishedFile() +{ + return ExistsFile(EXISTS_WRITE_FINISHED); +} + +bool ExistsAPSetting() +{ + return ExistsFile(EXISTS_AP_SETTING); +} + +bool ExistsRtcSyncFinishedFile() +{ + return ExistsFile(EXISTS_RTC_SYNC_FINISHED); +} + + +void InitializeFileCheck() +{ + for(u32 i = 0; i < EXISTS_MAX; i++) + { + s_FileExistsChecked[i] = false; + } +} + + +} diff --git a/trunk/ConsoleDataMigration/common/FileChecker.h b/trunk/ConsoleDataMigration/common/FileChecker.h new file mode 100644 index 0000000..f959105 --- /dev/null +++ b/trunk/ConsoleDataMigration/common/FileChecker.h @@ -0,0 +1,60 @@ +/*---------------------------------------------------------------------------* + Project: Horizon + File: FileChecker.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 FILECHECKER_H_ +#define FILECHECKER_H_ + +#include "FileName.h" + +namespace common +{ + +typedef enum FILE_EXISTS_CHECK +{ + EXISTS_UPDATE_FINISHED, + EXISTS_SERIAL_NUMBER, + EXISTS_IVS, + EXISTS_CONSOLE_INTIALIZED, + EXISTS_WRITE_FINISHED, + EXISTS_AP_SETTING, + EXISTS_RTC_SYNC_FINISHED, + EXISTS_MAX +} FileExistsCheck; + +const wchar_t* const FILENAME_TABLE[EXISTS_MAX] = +{ + common::UPDATE_CHECK_PATHNAME, + common::SERIAL_PATHNAME, + common::IVS_PATHNAME, + common::INITIALIZED_CHECK_PATHNAME, + common::WRITE_FINISHED_PATHNAME, + common::AP_SETTING_PATHNAME, + common::RTC_SYNC_CHECK_PATHNAME +}; + + +bool ExistsUpdateCheckedFile(); +bool ExistsSerialNumberFile(); +bool ExistsIVSFile(); +bool ExistsConsoleInitializedFile(); +bool ExistsWriteFinishedFile(); +bool ExistsAPSetting(); +bool ExistsRtcSyncFinishedFile(); + +void InitializeFileCheck(); + +} + +#endif /* FILECHECKER_H_ */