diff --git a/Common/CommonPaths.h b/Common/CommonPaths.h index 0fdf5f887c..949c8d390b 100644 --- a/Common/CommonPaths.h +++ b/Common/CommonPaths.h @@ -100,7 +100,7 @@ #define LOGGER_CONFIG "Logger.ini" // Files in the directory returned by GetUserPath(D_LOGS_IDX) -#define MAIN_LOG "dolphin.log" +#define MAIN_LOG "ppsspp.log" // Sys files #define TOTALDB "totaldb.dsy" diff --git a/Common/LogManager.cpp b/Common/LogManager.cpp index 0918cebf9d..64da7ff032 100644 --- a/Common/LogManager.cpp +++ b/Common/LogManager.cpp @@ -68,6 +68,8 @@ LogManager::LogManager() m_fileLog = new FileLogListener(File::GetUserPath(F_MAINLOG_IDX).c_str()); m_consoleLog = new ConsoleListener(); m_debuggerLog = new DebuggerLogListener(); +#else + m_fileLog = NULL; #endif for (int i = 0; i < LogTypes::NUMBER_OF_LOGS; ++i) @@ -88,8 +90,9 @@ LogManager::~LogManager() { for (int i = 0; i < LogTypes::NUMBER_OF_LOGS; ++i) { + if (m_fileLog != NULL) + m_logManager->RemoveListener((LogTypes::LOG_TYPE)i, m_fileLog); #if !defined(ANDROID) && !defined(IOS) && !defined(BLACKBERRY) - m_logManager->RemoveListener((LogTypes::LOG_TYPE)i, m_fileLog); m_logManager->RemoveListener((LogTypes::LOG_TYPE)i, m_consoleLog); m_logManager->RemoveListener((LogTypes::LOG_TYPE)i, m_debuggerLog); #endif @@ -97,12 +100,30 @@ LogManager::~LogManager() for (int i = 0; i < LogTypes::NUMBER_OF_LOGS; ++i) delete m_Log[i]; + if (m_fileLog != NULL) + delete m_fileLog; #if !defined(ANDROID) && !defined(IOS) && !defined(BLACKBERRY) - delete m_fileLog; delete m_consoleLog; #endif } +void LogManager::ChangeFileLog(const char *filename) +{ + if (m_fileLog != NULL) + { + for (int i = 0; i < LogTypes::NUMBER_OF_LOGS; ++i) + m_logManager->RemoveListener((LogTypes::LOG_TYPE)i, m_fileLog); + delete m_fileLog; + } + + if (filename != NULL) + { + m_fileLog = new FileLogListener(filename); + for (int i = 0; i < LogTypes::NUMBER_OF_LOGS; ++i) + m_Log[i]->AddListener(m_fileLog); + } +} + void LogManager::SaveConfig(IniFile::Section *section) { for (int i = 0; i < LogTypes::NUMBER_OF_LOGS; i++) diff --git a/Common/LogManager.h b/Common/LogManager.h index 9b6614e696..faef623276 100644 --- a/Common/LogManager.h +++ b/Common/LogManager.h @@ -179,6 +179,8 @@ public: static void Init(); static void Shutdown(); + void ChangeFileLog(const char *filename); + void SaveConfig(IniFile::Section *section); void LoadConfig(IniFile::Section *section); }; diff --git a/Windows/main.cpp b/Windows/main.cpp index 0facb4845b..c840312467 100644 --- a/Windows/main.cpp +++ b/Windows/main.cpp @@ -52,6 +52,7 @@ int WINAPI WinMain(HINSTANCE _hInstance, HINSTANCE hPrevInstance, LPSTR szCmdLin Common::EnableCrashingOnCrashes(); const char *fileToStart = NULL; + const char *fileToLog = NULL; bool showLog = false; bool autoRun = true; @@ -59,14 +60,14 @@ int WINAPI WinMain(HINSTANCE _hInstance, HINSTANCE hPrevInstance, LPSTR szCmdLin VFSRegister("", new DirectoryAssetReader("assets/")); VFSRegister("", new DirectoryAssetReader("")); - for (int i = 1; i < __argc; i++) + for (int i = 1; i < __argc; ++i) { - if (__targv[i][0] == '\0') + if (__argv[i][0] == '\0') continue; - if (__targv[i][0] == '-') + if (__argv[i][0] == '-') { - switch (__targv[i][1]) + switch (__argv[i][1]) { case 'j': g_Config.iCpuCore = CPU_JIT; @@ -80,11 +81,17 @@ int WINAPI WinMain(HINSTANCE _hInstance, HINSTANCE hPrevInstance, LPSTR szCmdLin case 's': autoRun = false; break; + case '-': + if (!strcmp(__argv[i], "--log") && i < __argc - 1) + fileToLog = __argv[++i]; + if (!strncmp(__argv[i], "--log=", strlen("--log=")) && strlen(__argv[i]) > strlen("--log=")) + fileToLog = __argv[i] + strlen("--log="); + break; } } else if (fileToStart == NULL) { - fileToStart = __targv[i]; + fileToStart = __argv[i]; if (!File::Exists(fileToStart)) { fprintf(stderr, "File not found: %s\n", fileToStart); @@ -127,6 +134,8 @@ int WINAPI WinMain(HINSTANCE _hInstance, HINSTANCE hPrevInstance, LPSTR szCmdLin MainWindow::UpdateMenus(); LogManager::Init(); + if (fileToLog != NULL) + LogManager::GetInstance()->ChangeFileLog(fileToLog); bool hidden = false; #ifndef _DEBUG hidden = true;