From 99af5bbe4c655655c56d009d0a77ea70371275ad Mon Sep 17 00:00:00 2001 From: Andrey Filipenkov Date: Sat, 17 Sep 2022 16:56:01 +0300 Subject: [PATCH] add dedicated method to get logs path --- client/CMT.cpp | 2 +- client/CServerHandler.cpp | 2 +- launcher/mainwindow_moc.cpp | 2 +- lib/VCMIDirs.cpp | 4 ++++ lib/VCMIDirs.h | 3 +++ server/CVCMIServer.cpp | 2 +- 6 files changed, 11 insertions(+), 4 deletions(-) diff --git a/client/CMT.cpp b/client/CMT.cpp index 00d7615f5..ebc5274f4 100644 --- a/client/CMT.cpp +++ b/client/CMT.cpp @@ -232,7 +232,7 @@ int main(int argc, char * argv[]) *console->cb = processCommand; console->start(); - const bfs::path logPath = VCMIDirs::get().userCachePath() / "VCMI_Client_log.txt"; + const bfs::path logPath = VCMIDirs::get().userLogsPath() / "VCMI_Client_log.txt"; logConfig = new CBasicLogConfigurator(logPath, console); logConfig->configureDefault(); logGlobal->info(NAME); diff --git a/client/CServerHandler.cpp b/client/CServerHandler.cpp index e0193efdc..40bb64ce1 100644 --- a/client/CServerHandler.cpp +++ b/client/CServerHandler.cpp @@ -685,7 +685,7 @@ void CServerHandler::threadRunServer() { #ifndef VCMI_ANDROID setThreadName("CServerHandler::threadRunServer"); - const std::string logName = (VCMIDirs::get().userCachePath() / "server_log.txt").string(); + const std::string logName = (VCMIDirs::get().userLogsPath() / "server_log.txt").string(); std::string comm = VCMIDirs::get().serverPath().string() + " --port=" + getDefaultPortStr() + " --run-by-client" diff --git a/launcher/mainwindow_moc.cpp b/launcher/mainwindow_moc.cpp index 8aa817664..4aca35f9a 100644 --- a/launcher/mainwindow_moc.cpp +++ b/launcher/mainwindow_moc.cpp @@ -28,7 +28,7 @@ void MainWindow::load() QDir::setCurrent(QApplication::applicationDirPath()); console = new CConsoleHandler(); - CBasicLogConfigurator logConfig(VCMIDirs::get().userCachePath() / "VCMI_Launcher_log.txt", console); + CBasicLogConfigurator logConfig(VCMIDirs::get().userLogsPath() / "VCMI_Launcher_log.txt", console); logConfig.configureDefault(); CResourceHandler::initialize(); diff --git a/lib/VCMIDirs.cpp b/lib/VCMIDirs.cpp index a5114863e..82cb903b9 100644 --- a/lib/VCMIDirs.cpp +++ b/lib/VCMIDirs.cpp @@ -13,6 +13,8 @@ namespace bfs = boost::filesystem; +bfs::path IVCMIDirs::userLogsPath() const { return userCachePath(); } + bfs::path IVCMIDirs::userSavePath() const { return userDataPath() / "Saves"; } bfs::path IVCMIDirs::fullLibraryPath(const std::string &desiredFolder, const std::string &baseLibName) const @@ -35,6 +37,7 @@ std::string IVCMIDirs::genHelpString() const " user data: " + userDataPath().string() + "\n" " user cache: " + userCachePath().string() + "\n" " user config: " + userConfigPath().string() + "\n" + " user logs: " + userLogsPath().string() + "\n" " user saves: " + userSavePath().string() + "\n"; // Should end without new-line? } @@ -44,6 +47,7 @@ void IVCMIDirs::init() bfs::create_directories(userDataPath()); bfs::create_directories(userCachePath()); bfs::create_directories(userConfigPath()); + bfs::create_directories(userLogsPath()); bfs::create_directories(userSavePath()); } diff --git a/lib/VCMIDirs.h b/lib/VCMIDirs.h index b6558f0a5..deaa263ab 100644 --- a/lib/VCMIDirs.h +++ b/lib/VCMIDirs.h @@ -21,6 +21,9 @@ public: // Path to writeable directory with user configs virtual boost::filesystem::path userConfigPath() const = 0; + // Path to writeable directory to store log files + virtual boost::filesystem::path userLogsPath() const; + // Path to saved games virtual boost::filesystem::path userSavePath() const; diff --git a/server/CVCMIServer.cpp b/server/CVCMIServer.cpp index 837b0ee32..5cef5f553 100644 --- a/server/CVCMIServer.cpp +++ b/server/CVCMIServer.cpp @@ -915,7 +915,7 @@ int main(int argc, char * argv[]) #endif console = new CConsoleHandler(); - CBasicLogConfigurator logConfig(VCMIDirs::get().userCachePath() / "VCMI_Server_log.txt", console); + CBasicLogConfigurator logConfig(VCMIDirs::get().userLogsPath() / "VCMI_Server_log.txt", console); logConfig.configureDefault(); logGlobal->info(NAME);