Skip to content

Commit

Permalink
windows: move logs to log dir
Browse files Browse the repository at this point in the history
  • Loading branch information
Megamouse committed Jan 3, 2025
1 parent 5903d6e commit 2dfe694
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 35 deletions.
10 changes: 10 additions & 0 deletions Utilities/File.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
Expand Down
3 changes: 3 additions & 0 deletions Utilities/File.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
64 changes: 33 additions & 31 deletions rpcs3/Emu/System.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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";

Expand Down Expand Up @@ -3595,7 +3597,7 @@ void Emulator::Kill(bool allow_autoexit, bool savestate, savestate_stage* save_s

if (usz attempted_read_size = utils::sub_saturate<usz>(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
Expand Down
2 changes: 1 addition & 1 deletion rpcs3/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,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;

Expand Down
2 changes: 1 addition & 1 deletion rpcs3/rpcs3qt/log_frame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ log_frame::log_frame(std::shared_ptr<gui_settings> _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();
Expand Down
4 changes: 2 additions & 2 deletions rpcs3/rpcs3qt/main_window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2673,8 +2673,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{};
Expand Down

0 comments on commit 2dfe694

Please sign in to comment.