mirror of
https://github.com/open-goal/jak-project
synced 2026-08-02 08:42:11 -04:00
game: allow overriding the config directory location
This commit is contained in:
+51
-20
@@ -57,6 +57,14 @@ fs::path get_user_home_dir() {
|
||||
#endif
|
||||
}
|
||||
|
||||
struct {
|
||||
bool initialized = false;
|
||||
fs::path path_to_data_folder;
|
||||
fs::path user_config_dir_override = "";
|
||||
// by default - if the config dir is overridden, we don't use the default save location
|
||||
bool use_overridden_config_dir_for_saves = true;
|
||||
} g_file_path_info;
|
||||
|
||||
fs::path get_user_config_dir() {
|
||||
fs::path config_base_path;
|
||||
#ifdef _WIN32
|
||||
@@ -80,36 +88,52 @@ fs::path get_user_config_dir() {
|
||||
|
||||
fs::path get_user_settings_dir(GameVersion game_version) {
|
||||
auto game_version_name = game_version_names[game_version];
|
||||
return get_user_config_dir() / game_version_name / "settings";
|
||||
auto config_dir = get_user_config_dir();
|
||||
if (!g_file_path_info.user_config_dir_override.empty()) {
|
||||
config_dir = g_file_path_info.user_config_dir_override;
|
||||
}
|
||||
return config_dir / game_version_name / "settings";
|
||||
}
|
||||
|
||||
fs::path get_user_memcard_dir(GameVersion game_version) {
|
||||
auto game_version_name = game_version_names[game_version];
|
||||
return get_user_config_dir() / game_version_name / "saves";
|
||||
auto config_dir = get_user_config_dir();
|
||||
if (!g_file_path_info.user_config_dir_override.empty() &&
|
||||
g_file_path_info.use_overridden_config_dir_for_saves) {
|
||||
config_dir = g_file_path_info.user_config_dir_override;
|
||||
}
|
||||
return config_dir / game_version_name / "saves";
|
||||
}
|
||||
|
||||
fs::path get_user_screenshots_dir(GameVersion game_version) {
|
||||
auto game_version_name = game_version_names[game_version];
|
||||
return get_user_config_dir() / game_version_name / "screenshots";
|
||||
auto config_dir = get_user_config_dir();
|
||||
if (!g_file_path_info.user_config_dir_override.empty()) {
|
||||
config_dir = g_file_path_info.user_config_dir_override;
|
||||
}
|
||||
return config_dir / game_version_name / "screenshots";
|
||||
}
|
||||
|
||||
fs::path get_user_misc_dir(GameVersion game_version) {
|
||||
auto game_version_name = game_version_names[game_version];
|
||||
return get_user_config_dir() / game_version_name / "misc";
|
||||
auto config_dir = get_user_config_dir();
|
||||
if (!g_file_path_info.user_config_dir_override.empty()) {
|
||||
config_dir = g_file_path_info.user_config_dir_override;
|
||||
}
|
||||
return config_dir / game_version_name / "misc";
|
||||
}
|
||||
|
||||
fs::path get_user_features_dir(GameVersion game_version) {
|
||||
auto game_version_name = game_version_names[game_version];
|
||||
auto path = get_user_config_dir() / game_version_name / "features";
|
||||
auto config_dir = get_user_config_dir();
|
||||
if (!g_file_path_info.user_config_dir_override.empty()) {
|
||||
config_dir = g_file_path_info.user_config_dir_override;
|
||||
}
|
||||
auto path = config_dir / game_version_name / "features";
|
||||
file_util::create_dir_if_needed(path);
|
||||
return path;
|
||||
}
|
||||
|
||||
struct {
|
||||
bool initialized = false;
|
||||
fs::path path_to_data;
|
||||
} gFilePathInfo;
|
||||
|
||||
/*!
|
||||
* Get the path to the current executable.
|
||||
*/
|
||||
@@ -171,29 +195,30 @@ std::optional<fs::path> try_get_data_dir() {
|
||||
}
|
||||
|
||||
bool setup_project_path(std::optional<fs::path> project_path_override) {
|
||||
if (gFilePathInfo.initialized) {
|
||||
if (g_file_path_info.initialized) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (project_path_override) {
|
||||
gFilePathInfo.path_to_data = fs::absolute(project_path_override.value());
|
||||
gFilePathInfo.initialized = true;
|
||||
lg::info("Using explicitly set project path: {}", gFilePathInfo.path_to_data.string());
|
||||
g_file_path_info.path_to_data_folder = fs::absolute(project_path_override.value());
|
||||
g_file_path_info.initialized = true;
|
||||
lg::info("Using explicitly set project path: {}",
|
||||
g_file_path_info.path_to_data_folder.string());
|
||||
return true;
|
||||
}
|
||||
|
||||
auto data_path = try_get_data_dir();
|
||||
if (data_path) {
|
||||
gFilePathInfo.path_to_data = *data_path;
|
||||
gFilePathInfo.initialized = true;
|
||||
g_file_path_info.path_to_data_folder = *data_path;
|
||||
g_file_path_info.initialized = true;
|
||||
lg::info("Using data path: {}", data_path->string());
|
||||
return true;
|
||||
}
|
||||
|
||||
auto development_repo_path = try_get_jak_project_path();
|
||||
if (development_repo_path) {
|
||||
gFilePathInfo.path_to_data = *development_repo_path;
|
||||
gFilePathInfo.initialized = true;
|
||||
g_file_path_info.path_to_data_folder = *development_repo_path;
|
||||
g_file_path_info.initialized = true;
|
||||
lg::info("Using development repo path: {}", *development_repo_path);
|
||||
return true;
|
||||
}
|
||||
@@ -202,9 +227,15 @@ bool setup_project_path(std::optional<fs::path> project_path_override) {
|
||||
return false;
|
||||
}
|
||||
|
||||
void override_user_config_dir(fs::path user_config_dir_override,
|
||||
bool use_overridden_config_dir_for_saves) {
|
||||
g_file_path_info.user_config_dir_override = user_config_dir_override;
|
||||
g_file_path_info.use_overridden_config_dir_for_saves = use_overridden_config_dir_for_saves;
|
||||
}
|
||||
|
||||
fs::path get_jak_project_dir() {
|
||||
ASSERT(gFilePathInfo.initialized);
|
||||
return gFilePathInfo.path_to_data;
|
||||
ASSERT(g_file_path_info.initialized);
|
||||
return g_file_path_info.path_to_data_folder;
|
||||
}
|
||||
|
||||
std::string get_file_path(const std::vector<std::string>& input) {
|
||||
|
||||
@@ -39,8 +39,11 @@ fs::path get_jak_project_dir();
|
||||
bool create_dir_if_needed(const fs::path& path);
|
||||
bool create_dir_if_needed_for_file(const std::string& path);
|
||||
bool create_dir_if_needed_for_file(const fs::path& path);
|
||||
std::string get_current_executable_path();
|
||||
std::optional<std::string> try_get_project_path_from_path(const std::string& path);
|
||||
bool setup_project_path(std::optional<fs::path> project_path_override);
|
||||
void override_user_config_dir(fs::path user_config_dir_override,
|
||||
bool use_overridden_config_dir_for_saves);
|
||||
std::string get_file_path(const std::vector<std::string>& path);
|
||||
void write_binary_file(const std::string& name, const void* data, size_t size);
|
||||
void write_binary_file(const fs::path& name, const void* data, size_t size);
|
||||
|
||||
@@ -2,12 +2,12 @@
|
||||
|
||||
#include "TP_Type.h"
|
||||
|
||||
#include "common/goos/Printer.h"
|
||||
#include "common/goos/Reader.h"
|
||||
#include "common/log/log.h"
|
||||
#include "common/type_system/defenum.h"
|
||||
#include "common/type_system/deftype.h"
|
||||
#include "common/util/string_util.h"
|
||||
#include <common/goos/Printer.h>
|
||||
|
||||
#include "decompiler/Disasm/Register.h"
|
||||
|
||||
|
||||
@@ -96,11 +96,14 @@ int main(int argc, char** argv) {
|
||||
bool disable_avx2 = false;
|
||||
bool disable_display = false;
|
||||
bool enable_profiling = false;
|
||||
bool enable_portable = false;
|
||||
bool disable_save_location_override = false;
|
||||
std::string profile_until_event = "";
|
||||
std::string gpu_test = "";
|
||||
std::string gpu_test_out_path = "";
|
||||
int port_number = -1;
|
||||
fs::path project_path_override;
|
||||
fs::path user_config_dir_override;
|
||||
std::vector<std::string> game_args;
|
||||
CLI::App app{"OpenGOAL Game Runtime"};
|
||||
app.add_flag("--version", show_version, "Display the built revision");
|
||||
@@ -112,6 +115,12 @@ int main(int argc, char** argv) {
|
||||
app.add_flag("--no-avx2", disable_avx2, "Disable AVX2 for testing");
|
||||
app.add_flag("--no-display", disable_display, "Disable video display");
|
||||
app.add_flag("--profile", enable_profiling, "Enables profiling immediately from startup");
|
||||
app.add_flag("--portable", enable_portable,
|
||||
"Save settings and saves relative to the game's executable, takes precedence over "
|
||||
"--config-path");
|
||||
app.add_flag("--disable_save_location_override", disable_save_location_override,
|
||||
"If --config-path is provided along with this flag, saves will still be loaded and "
|
||||
"stored to the default location");
|
||||
app.add_option("--profile-until-event", profile_until_event,
|
||||
"Stops recording profile events once an event with this name is seen");
|
||||
app.add_option("--gpu-test", gpu_test,
|
||||
@@ -120,6 +129,8 @@ int main(int argc, char** argv) {
|
||||
"Where to store the gpu test result file");
|
||||
app.add_option("--proj-path", project_path_override,
|
||||
"Specify the location of the 'data/' folder");
|
||||
app.add_option("--config-path", user_config_dir_override,
|
||||
"Override the location where all user configuration and saves are saved");
|
||||
app.footer(game_arg_documentation());
|
||||
app.add_option("Game Args", game_args,
|
||||
"Remaining arguments (after '--') that are passed-through to the game itself");
|
||||
@@ -127,6 +138,15 @@ int main(int argc, char** argv) {
|
||||
app.allow_extras();
|
||||
CLI11_PARSE(app, argc, argv);
|
||||
|
||||
// Override the user's config dir, potentially (either because it was explicitly provided
|
||||
// or because it's portable mode)
|
||||
if (enable_portable) {
|
||||
user_config_dir_override = file_util::get_current_executable_path();
|
||||
}
|
||||
if (!user_config_dir_override.empty()) {
|
||||
file_util::override_user_config_dir(user_config_dir_override, !disable_save_location_override);
|
||||
}
|
||||
|
||||
if (show_version) {
|
||||
lg::print("{}", build_revision());
|
||||
return 0;
|
||||
|
||||
@@ -31,8 +31,8 @@ class KeyboardDevice : public InputDevice {
|
||||
const CommandBindingGroups& commands,
|
||||
std::shared_ptr<PadData> data,
|
||||
std::optional<InputBindAssignmentMeta>& bind_assignment) override;
|
||||
void close_device() override{
|
||||
// there is nothing to close
|
||||
void close_device() override {
|
||||
// there is nothing to close
|
||||
};
|
||||
|
||||
private:
|
||||
|
||||
@@ -31,8 +31,8 @@ class MouseDevice : public InputDevice {
|
||||
const CommandBindingGroups& commands,
|
||||
std::shared_ptr<PadData> data,
|
||||
std::optional<InputBindAssignmentMeta>& bind_assignment) override;
|
||||
void close_device() override{
|
||||
// there is nothing to close
|
||||
void close_device() override {
|
||||
// there is nothing to close
|
||||
};
|
||||
|
||||
void enable_relative_mode(const bool enable);
|
||||
|
||||
@@ -379,8 +379,8 @@ void Workspace::tracked_file_will_save(const LSPSpec::DocumentUri& file_uri) {
|
||||
}
|
||||
}
|
||||
|
||||
void Workspace::update_global_index(const GameVersion game_version){
|
||||
// TODO - project wide indexing potentially (ie. finding references)
|
||||
void Workspace::update_global_index(const GameVersion game_version) {
|
||||
// TODO - project wide indexing potentially (ie. finding references)
|
||||
};
|
||||
|
||||
void Workspace::stop_tracking_file(const LSPSpec::DocumentUri& file_uri) {
|
||||
|
||||
Reference in New Issue
Block a user