From a7edfa221e1853be823fc6949fe32c7d1b88b1f6 Mon Sep 17 00:00:00 2001 From: Megamouse Date: Thu, 2 Jan 2025 17:42:05 +0100 Subject: [PATCH] windows: move logs to log dir --- Utilities/File.cpp | 10 ++++++ Utilities/File.h | 3 ++ rpcs3/Emu/System.cpp | 64 ++++++++++++++++++----------------- rpcs3/main.cpp | 2 +- rpcs3/rpcs3qt/log_frame.cpp | 2 +- rpcs3/rpcs3qt/main_window.cpp | 4 +-- 6 files changed, 50 insertions(+), 35 deletions(-) diff --git a/Utilities/File.cpp b/Utilities/File.cpp index 3753c68271..ec0f49c89e 100644 --- a/Utilities/File.cpp +++ b/Utilities/File.cpp @@ -2152,6 +2152,16 @@ const std::string& fs::get_cache_dir() return s_dir; } +const std::string& fs::get_log_dir() +{ +#ifdef _WIN32 + static const std::string s_dir = fs::get_config_dir() + "log/"; + return s_dir; +#else + return fs::get_cache_dir(); +#endif +} + const std::string& fs::get_temp_dir() { static const std::string s_dir = [] diff --git a/Utilities/File.h b/Utilities/File.h index 7773eb8db0..f3adaa15d4 100644 --- a/Utilities/File.h +++ b/Utilities/File.h @@ -605,6 +605,9 @@ namespace fs // Get common cache directory const std::string& get_cache_dir(); + // Get common log directory + const std::string& get_log_dir(); + // Temporary directory const std::string& get_temp_dir(); diff --git a/rpcs3/Emu/System.cpp b/rpcs3/Emu/System.cpp index 4ddf0df692..179eb7f1ad 100644 --- a/rpcs3/Emu/System.cpp +++ b/rpcs3/Emu/System.cpp @@ -347,9 +347,40 @@ void Emulator::Init() { jit_runtime::initialize(); + const std::string emu_dir = rpcs3::utils::get_emu_dir(); + auto make_path_verbose = [&](const std::string& path, bool must_exist_outside_emu_dir) + { + if (fs::is_dir(path)) + { + return true; + } + + if (must_exist_outside_emu_dir) + { + const std::string parent = fs::get_parent_dir(path); + const std::string emu_dir_no_delim = emu_dir.substr(0, emu_dir.find_last_not_of(fs::delim) + 1); + + if (parent != emu_dir_no_delim && GetCallbacks().resolve_path(parent) != GetCallbacks().resolve_path(emu_dir_no_delim)) + { + sys_log.fatal("Cannot use '%s' for Virtual File System because it does not exist.\nPlease specify an existing and writable directory path in Toolbar -> Manage -> Virtual File System.", path); + return false; + } + } + + if (!fs::create_path(path)) + { + sys_log.fatal("Failed to create path: %s (%s)", path, fs::g_tls_error); + return false; + } + + return true; + }; + if (!g_tty) { - const auto tty_path = fs::get_cache_dir() + "TTY.log"; + make_path_verbose(fs::get_log_dir(), true); + + const auto tty_path = fs::get_log_dir() + "TTY.log"; g_tty.open(tty_path, fs::rewrite + fs::append); if (!g_tty) @@ -402,7 +433,6 @@ void Emulator::Init() sys_log.notice("Using VFS config:\n%s", g_cfg_vfs.to_string()); // Mount all devices - const std::string emu_dir = rpcs3::utils::get_emu_dir(); const std::string elf_dir = fs::get_parent_dir(m_path); const std::string dev_bdvd = g_cfg_vfs.get(g_cfg_vfs.dev_bdvd, emu_dir); // Only used for make_path const std::string dev_hdd0 = g_cfg_vfs.get(g_cfg_vfs.dev_hdd0, emu_dir); @@ -502,34 +532,6 @@ void Emulator::Init() g_backup_cfg.from_string(g_cfg.to_string()); // Create directories (can be disabled if necessary) - auto make_path_verbose = [&](const std::string& path, bool must_exist_outside_emu_dir) - { - if (fs::is_dir(path)) - { - return true; - } - - if (must_exist_outside_emu_dir) - { - const std::string parent = fs::get_parent_dir(path); - const std::string emu_dir_no_delim = emu_dir.substr(0, emu_dir.find_last_not_of(fs::delim) + 1); - - if (parent != emu_dir_no_delim && GetCallbacks().resolve_path(parent) != GetCallbacks().resolve_path(emu_dir_no_delim)) - { - sys_log.fatal("Cannot use '%s' for Virtual File System because it does not exist.\nPlease specify an existing and writable directory path in Toolbar -> Manage -> Virtual File System.", path); - return false; - } - } - - if (!fs::create_path(path)) - { - sys_log.fatal("Failed to create path: %s (%s)", path, fs::g_tls_error); - return false; - } - - return true; - }; - const std::string save_path = dev_hdd0 + "home/" + m_usr + "/savedata/"; const std::string user_path = dev_hdd0 + "home/" + m_usr + "/localusername"; @@ -3636,7 +3638,7 @@ void Emulator::Kill(bool allow_autoexit, bool savestate, savestate_stage* save_s if (usz attempted_read_size = utils::sub_saturate(g_tty.pos(), m_tty_file_init_pos)) { - if (fs::file tty_read_fd{fs::get_cache_dir() + "TTY.log"}) + if (fs::file tty_read_fd{fs::get_log_dir() + "TTY.log"}) { // Enforce an arbitrary limit for now to avoid OOM in case the guest code has bombarded TTY // 3MB, this should be enough diff --git a/rpcs3/main.cpp b/rpcs3/main.cpp index f67670ccc9..82002913d4 100644 --- a/rpcs3/main.cpp +++ b/rpcs3/main.cpp @@ -569,7 +569,7 @@ int main(int argc, char** argv) } const std::string lock_name = fs::get_cache_dir() + "RPCS3.buf"; - const std::string log_name = fs::get_cache_dir() + "RPCS3.log"; + const std::string log_name = fs::get_log_dir() + "RPCS3.log"; static fs::file instance_lock; diff --git a/rpcs3/rpcs3qt/log_frame.cpp b/rpcs3/rpcs3qt/log_frame.cpp index cde2803a30..a318a9c03d 100644 --- a/rpcs3/rpcs3qt/log_frame.cpp +++ b/rpcs3/rpcs3qt/log_frame.cpp @@ -157,7 +157,7 @@ log_frame::log_frame(std::shared_ptr _gui_settings, QWidget* paren setWidget(m_tabWidget); // Open or create TTY.log - m_tty_file.open(fs::get_cache_dir() + "TTY.log", fs::read + fs::create); + m_tty_file.open(fs::get_log_dir() + "TTY.log", fs::read + fs::create); CreateAndConnectActions(); LoadSettings(); diff --git a/rpcs3/rpcs3qt/main_window.cpp b/rpcs3/rpcs3qt/main_window.cpp index b4bc2af5d6..e23d9b32bc 100644 --- a/rpcs3/rpcs3qt/main_window.cpp +++ b/rpcs3/rpcs3qt/main_window.cpp @@ -2676,8 +2676,8 @@ void main_window::CreateConnects() return; } - const std::string archived_path = fs::get_cache_dir() + "RPCS3.log.gz"; - const std::string raw_file_path = fs::get_cache_dir() + "RPCS3.log"; + const std::string archived_path = fs::get_log_dir() + "RPCS3.log.gz"; + const std::string raw_file_path = fs::get_log_dir() + "RPCS3.log"; fs::stat_t raw_stat{}; fs::stat_t archived_stat{};