mirror of
https://github.com/open-goal/jak-project
synced 2026-06-24 09:51:29 -04:00
config: change linux and windows config directories (#1582)
This commit is contained in:
@@ -54,18 +54,20 @@ void ReplWrapper::add_to_history(const std::string& line) {
|
||||
}
|
||||
|
||||
void ReplWrapper::save_history() {
|
||||
// NOTE - library doesn't seem unicode safe on windows
|
||||
std::filesystem::path path = file_util::get_user_home_dir();
|
||||
if (std::filesystem::exists(path)) {
|
||||
std::filesystem::path path = file_util::get_user_config_dir();
|
||||
if (file_util::create_dir_if_needed(path)) {
|
||||
repl.history_save((path / ".opengoal.repl.history").string());
|
||||
} else {
|
||||
fmt::print("Couldn't save REPL history file to '{}'", path.string());
|
||||
}
|
||||
}
|
||||
|
||||
void ReplWrapper::load_history() {
|
||||
// NOTE - library doesn't seem unicode safe on windows
|
||||
std::filesystem::path path = file_util::get_user_home_dir();
|
||||
std::filesystem::path path = file_util::get_user_config_dir() / ".opengoal.repl.history";
|
||||
if (std::filesystem::exists(path)) {
|
||||
repl.history_load((path / ".opengoal.repl.history").string());
|
||||
repl.history_load(path.string());
|
||||
} else {
|
||||
fmt::print("Couldn't locate REPL history file at '{}'", path.string());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -48,17 +48,32 @@ std::filesystem::path get_user_home_dir() {
|
||||
#endif
|
||||
}
|
||||
|
||||
std::filesystem::path get_user_game_dir() {
|
||||
// TODO - i anticipate UTF-8 problems on windows with our current FS api
|
||||
return get_user_home_dir() / "OpenGOAL";
|
||||
std::filesystem::path get_user_config_dir() {
|
||||
std::filesystem::path config_base_path;
|
||||
#ifdef _WIN32
|
||||
auto config_base_dir = std::getenv("APPDATA");
|
||||
config_base_path = std::filesystem::path(std::string(config_base_dir));
|
||||
#elif __linux
|
||||
// Docs - https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html
|
||||
// Prefer XDG_CONFIG_HOME if available
|
||||
auto config_base_dir = std::getenv("XDG_CONFIG_HOME");
|
||||
if (!config_base_dir) {
|
||||
config_base_path = get_user_home_dir() / ".config";
|
||||
} else {
|
||||
config_base_path = std::string(config_base_dir);
|
||||
}
|
||||
#endif
|
||||
return config_base_path / "OpenGOAL";
|
||||
}
|
||||
|
||||
std::filesystem::path get_user_settings_dir() {
|
||||
return get_user_game_dir() / "jak1" / "settings";
|
||||
// TODO - jak2
|
||||
return get_user_config_dir() / "jak1" / "settings";
|
||||
}
|
||||
|
||||
std::filesystem::path get_user_memcard_dir() {
|
||||
return get_user_game_dir() / "jak1" / "saves";
|
||||
// TODO - jak2
|
||||
return get_user_config_dir() / "jak1" / "saves";
|
||||
}
|
||||
|
||||
struct {
|
||||
@@ -171,8 +186,7 @@ std::string get_file_path(const std::vector<std::string>& input) {
|
||||
|
||||
bool create_dir_if_needed(const std::filesystem::path& path) {
|
||||
if (!std::filesystem::is_directory(path)) {
|
||||
std::filesystem::create_directories(path);
|
||||
return true;
|
||||
return std::filesystem::create_directories(path);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ namespace fs = std::filesystem;
|
||||
|
||||
namespace file_util {
|
||||
std::filesystem::path get_user_home_dir();
|
||||
std::filesystem::path get_user_game_dir();
|
||||
std::filesystem::path get_user_config_dir();
|
||||
std::filesystem::path get_user_settings_dir();
|
||||
std::filesystem::path get_user_memcard_dir();
|
||||
std::filesystem::path get_jak_project_dir();
|
||||
|
||||
@@ -637,7 +637,7 @@ void InitMachine_PCPort() {
|
||||
}
|
||||
|
||||
// setup string constants
|
||||
auto user_dir_path = file_util::get_user_game_dir();
|
||||
auto user_dir_path = file_util::get_user_config_dir();
|
||||
intern_from_c("*pc-user-dir-base-path*")->value =
|
||||
make_string_from_c(user_dir_path.string().c_str());
|
||||
// TODO - we will eventually need a better way to know what game we are playing
|
||||
@@ -720,4 +720,4 @@ void InitMachineScheme() {
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace jak1
|
||||
} // namespace jak1
|
||||
|
||||
@@ -519,7 +519,7 @@ void InitMachine_PCPort() {
|
||||
}
|
||||
|
||||
// setup string constants
|
||||
auto user_dir_path = file_util::get_user_game_dir();
|
||||
auto user_dir_path = file_util::get_user_config_dir();
|
||||
intern_from_c("*pc-user-dir-base-path*")->value() =
|
||||
make_string_from_c(user_dir_path.string().c_str());
|
||||
// TODO - we will eventually need a better way to know what game we are playing
|
||||
@@ -621,4 +621,4 @@ void InitMachineScheme() {
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace jak2
|
||||
} // namespace jak2
|
||||
|
||||
Reference in New Issue
Block a user