Skip to content

Commit

Permalink
Merge pull request scp-fs2open#6387 from Shivansps/custom-preferences…
Browse files Browse the repository at this point in the history
…-path

Support custom preferences path
  • Loading branch information
Goober5000 authored Nov 29, 2024
2 parents fa30b46 + aadd55e commit d21fb62
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
11 changes: 6 additions & 5 deletions code/cmdline/cmdline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1586,6 +1586,12 @@ bool SetCmdlineParams()
{
//getcwd(FreeSpace_Directory, 256); // set the directory to our fs2 root

// DO THIS BEFORE get_flags, as portable_mode can change the value of pref_path printed in the json
if (portable_mode.found())
{
Cmdline_portable_mode = true;
}

// DO THIS FIRST to avoid unrecognized flag warnings when just getting flag file
if ( get_flags_arg.found() ) {
write_flags();
Expand Down Expand Up @@ -2087,11 +2093,6 @@ bool SetCmdlineParams()
Cmdline_noshadercache = true;
}

if (portable_mode.found())
{
Cmdline_portable_mode = true;
}

if (lang_arg.found())
{
Cmdline_lang = lang_arg.str();
Expand Down
11 changes: 9 additions & 2 deletions code/osapi/osapi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,15 @@ namespace
{
// Lazily initialize the preferences path
if (!preferencesPath) {
preferencesPath = SDL_GetPrefPath(ORGANIZATION_NAME, APPLICATION_NAME);

//Check for a custom path set by env variable
auto envPreferencesPath = getenv("FSO_PREFERENCES_PATH");
if (envPreferencesPath != nullptr && strlen(envPreferencesPath) > 0) {
preferencesPath = envPreferencesPath;
}
else {
preferencesPath = SDL_GetPrefPath(ORGANIZATION_NAME, APPLICATION_NAME);
}

// this section will at least tell the user if something is seriously wrong instead of just crashing without a message or debug log.
// It may crash later, especially when trying to load sound. But let's let it *try* to run in the current directory at least.
if (preferencesPath == nullptr) {
Expand Down

0 comments on commit d21fb62

Please sign in to comment.