diff --git a/branches/1stNUP_for_2ndNUP/sources/ConsoleBackup/ConsoleBackup.cpp b/branches/1stNUP_for_2ndNUP/sources/ConsoleBackup/ConsoleBackup.cpp index d37a148..cd94f6c 100644 --- a/branches/1stNUP_for_2ndNUP/sources/ConsoleBackup/ConsoleBackup.cpp +++ b/branches/1stNUP_for_2ndNUP/sources/ConsoleBackup/ConsoleBackup.cpp @@ -127,6 +127,7 @@ extern "C" void nnMain(void) // RenderSystemを作ってからログが出せる common::Logger::InitializeEjectThread(); common::Logger::SetEjectHandler(OnSdEjected); + common::Logger::SetInsertHandler(OnSdInserted); // 起動時に削除 common::Logger::GetLoggerInstance()->ClearSdLog(); diff --git a/branches/1stNUP_for_2ndNUP/sources/ConsoleBackup/Controller.cpp b/branches/1stNUP_for_2ndNUP/sources/ConsoleBackup/Controller.cpp index 9eb2c89..b201e96 100644 --- a/branches/1stNUP_for_2ndNUP/sources/ConsoleBackup/Controller.cpp +++ b/branches/1stNUP_for_2ndNUP/sources/ConsoleBackup/Controller.cpp @@ -506,6 +506,11 @@ void OnSdEjected() } } +void OnSdInserted() +{ + common::Logger::GetLoggerInstance()->ClearSdLog(); +} + void InitializeState() { s_BackupState = STARTUP; diff --git a/branches/1stNUP_for_2ndNUP/sources/ConsoleBackup/Controller.h b/branches/1stNUP_for_2ndNUP/sources/ConsoleBackup/Controller.h index 0308307..ef10878 100644 --- a/branches/1stNUP_for_2ndNUP/sources/ConsoleBackup/Controller.h +++ b/branches/1stNUP_for_2ndNUP/sources/ConsoleBackup/Controller.h @@ -54,6 +54,9 @@ bool IsBackupWarning(); // SDカードが抜き出されたときに実行したい関数 void OnSdEjected(); +// SDカードが挿し込まれたときに実行する処理 +void OnSdInserted(); + // 状態を初期化する void InitializeState(); diff --git a/branches/1stNUP_for_2ndNUP/sources/common/SdLogger.cpp b/branches/1stNUP_for_2ndNUP/sources/common/SdLogger.cpp index 9851395..5ce9d4b 100644 --- a/branches/1stNUP_for_2ndNUP/sources/common/SdLogger.cpp +++ b/branches/1stNUP_for_2ndNUP/sources/common/SdLogger.cpp @@ -82,6 +82,7 @@ void SdmcInsertedEventThreadFunc() { s_SdInsertedEventFunc(); } + SdMountManager::ForceUnmount(); s_SdInsertedEvent.ClearSignal(); s_SdLogger.Inactivate(); } @@ -124,12 +125,6 @@ SdLogger* GetSdInstance() void SdLogger::Print(const char* fmt, ::std::va_list arg) { Activate(); - if(!m_Permitted) - { - NN_LOG("SD Write Not Permitted\n"); - return; - } - nn::Result result; result = SdMountManager::Mount(); if (result.IsFailure()) @@ -143,6 +138,29 @@ void SdLogger::Print(const char* fmt, ::std::va_list arg) stringSize = nn::nstd::TVSNPrintf(str, sizeof(str), fmt, arg); + // 書き込み不可であればバッファリングのみ行う + if(!m_Permitted) + { + NN_LOG("SD Write Not Permitted\n"); + m_Buffer.push_back(std::string(str)); + return; + } + + // バッファリング済みならまず吐き出す + for(std::vector::iterator it = m_Buffer.begin(); it != m_Buffer.end(); it++) + { + PrintCore(it->c_str(), it->size()); + } + m_Buffer.clear(); + + PrintCore(str, stringSize); + + SdMountManager::Unmount(); +} + +nn::Result SdLogger::PrintCore(const char* str, size_t size) +{ + nn::Result result; ::std::wstring log(common::SDMC_ROOT_DIRECTORY_PATH); log += common::LOG_PATHNAME; @@ -168,7 +186,7 @@ void SdLogger::Print(const char* fmt, ::std::va_list arg) if (result.IsSuccess()) { s32 writeSize; - result = sd.TryWrite(&writeSize, str, stringSize, true); + result = sd.TryWrite(&writeSize, str, size, true); if (result.IsSuccess()) { result = sd.TryFlush(); @@ -204,7 +222,8 @@ void SdLogger::Print(const char* fmt, ::std::va_list arg) dir.Finalize(); sd.Finalize(); - SdMountManager::Unmount(); + + return nn::ResultSuccess(); } void SdLogger::Clear() diff --git a/branches/1stNUP_for_2ndNUP/sources/common/SdLogger.h b/branches/1stNUP_for_2ndNUP/sources/common/SdLogger.h index 6d543f2..103c5fc 100644 --- a/branches/1stNUP_for_2ndNUP/sources/common/SdLogger.h +++ b/branches/1stNUP_for_2ndNUP/sources/common/SdLogger.h @@ -17,6 +17,8 @@ #define SDLOGGER_H_ #include +#include +#include namespace common { @@ -42,7 +44,10 @@ public: private: void Activate(); + nn::Result PrintCore(const char* str, size_t size); + nn::fs::FileOutputStream sd; + std::vector m_Buffer; bool m_TryActivate; bool m_Permitted; NN_PADDING2;