Skip to content

Comments

Support custom preferences path#6387

Merged
Goober5000 merged 4 commits intoscp-fs2open:masterfrom
Shivansps:custom-preferences-path
Nov 29, 2024
Merged

Support custom preferences path#6387
Goober5000 merged 4 commits intoscp-fs2open:masterfrom
Shivansps:custom-preferences-path

Conversation

@Shivansps
Copy link
Contributor

@Shivansps Shivansps commented Oct 9, 2024

The idea is to truly allow FSO to be portable along with Knet launcher, with being able to set a custom folder for the pilots and settings it is possible to have a folder stucture where the knossos library is portable along with the the knossos executable and still reading the pilots and saving settings to a portable location inside the library itself instead of the appdata folder.

The older portable mode is not enoght for this (i was wrong, it still works, it just that due to the argument parsing order the wrong pref_path is printed on "-get_flags json_v1", but this should not affect functionallity).
But it is not adecuate for this as the old portable mode will use the current working folder to save pilots, settings and pickup the inis, so it dosent work in the same way as the appdata folder.

I did test it by setting a env variable in windows FSO_PREFERENCES_PATH to "D:\test dir\ " (without quotes), and the data folder was succesfully saved inside that folder along with graphical settings and new pilots.

I would like advise on the env variable name, if it feels right, and offcourse, anything i need to change to add.

Note: this does not overrides portable mode, if -portable_mode is set the executable location will be used instead.

Note2: There is a bug on os_is_legacy_mode() line 523 as auto old_config_exists = true; defaults to true and it is never changed anywhere, FSO never searchs for the old file or registry settings on windows, resulting in defaulting the legacy mode to ON if the fs2_open.ini is not present on the preferences path, overriding it to ".//".

This also needs to be investigated on linux as i seem to remember the message of legacy mode being printed all the time there.

I belive this should be addresed on a separated PR if thats not the intended behaviour.

…cesPath()

It is a better place for it, it enables the regular path checks and warnings
@Shivansps Shivansps marked this pull request as ready for review October 10, 2024 22:12
@wookieejedi wookieejedi added the enhancement A new feature or upgrade of an existing feature to add additional functionality. label Oct 16, 2024
Copy link
Contributor

@Goober5000 Goober5000 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a pretty simple PR - it looks good and that's a good environment variable name - but I had a question about this:

it just that due to the argument parsing order the wrong pref_path is printed on "-get_flags json_v1",

Can you elaborate on this? If this is a bug, we should fix it.

@Goober5000 Goober5000 added this to the Release 25.0 milestone Nov 20, 2024
@Shivansps
Copy link
Contributor Author

Shivansps commented Nov 21, 2024

This is a pretty simple PR - it looks good and that's a good environment variable name - but I had a question about this:

it just that due to the argument parsing order the wrong pref_path is printed on "-get_flags json_v1",

Can you elaborate on this? If this is a bug, we should fix it.

if ( get_flags_arg.found() ) {

Due to the parsing order of flags, -get_flags is always parsed first, what is good, but if you use -get_flags json_v1 AND -portable_mode the SDL env pref path is printed on the json instead of "./" indicating it is on the same location as the executable as what happens with legacy mode.

-get_flags is not intended to be used along other flags, it just happens that the portable mode flag actually changes the output, so i dont know if this should be considered a bug or not. It does not affect the functionality of the -portable_mode function itself.

Also i dont know what this means exactly "// DO THIS FIRST to avoid unrecognized flag warnings when just getting flag file"
How checking if a flag is present can give you a unrecognized flag warning?

For the record, before anyone do any changes here, i belive printing "./" as the value of the pref_path in the flags json for when FSO is in legacy mode or while using -portable_mode is not completely ok here, as that is a relative path, and the SDL path printed in normal operation is an absolute path. So any launcher reading the json flags will have to interpret "./" as the executable path instead. But changing this is risky as it might break old launchers (or do nothing)

@Goober5000
Copy link
Contributor

Also i dont know what this means exactly "// DO THIS FIRST to avoid unrecognized flag warnings when just getting flag file"
How checking if a flag is present can give you a unrecognized flag warning?

This comment may date from a time when the command-line was parsed in that function, rather than just checked. The intent of -get_flags is that the engine should create the flags file and then immediately exit. It should not throw any Warning or Error dialogs, otherwise these could interfere with wxLauncher and now Knossos. So, anything that produces a dialog should be avoided, whether it is applying a command-line parameter or even parsing a command-line parameter.

-get_flags is not intended to be used along other flags, it just happens that the portable mode flag actually changes the output, so i dont know if this should be considered a bug or not. It does not affect the functionality of the -portable_mode function itself.

After some consideration, I think that yes, this is a bug. The portable mode flag is relevant to the core functionality of the engine, and it is also relevant to -get_flags. So, I think -portable_mode should be moved above -get_flags and given an appropriate comment, something like "DO THIS FIRST FIRST" or "DO THIS ZEROETH". You can make this change as part of this PR.

For the record, before anyone do any changes here, i belive printing "./" as the value of the pref_path in the flags json for when FSO is in legacy mode or while using -portable_mode is not completely ok here, as that is a relative path, and the SDL path printed in normal operation is an absolute path. So any launcher reading the json flags will have to interpret "./" as the executable path instead. But changing this is risky as it might break old launchers (or do nothing)

Hmm. Good question.

Well, first we should double check our assumptions. Find an old build of FSO, from before the SDL upgrade, and check the output of -get_flags. See if the pref_path was "./" back then.

Because -get_flags prints the value of pref_path, and this changes depending if portable_mode is also set.
Copy link
Contributor

@Goober5000 Goober5000 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good now, but we should resolve the "./" question before completing this PR.

@Shivansps
Copy link
Contributor Author

ill try with old builds, but there is a limit of how much i can go back, i think json flags is around 3.8.0.
mmmm
thinking about it, i think only knossos and knet uses the json flags...

@Shivansps
Copy link
Contributor Author

Shivansps commented Nov 24, 2024

ok, this is impossible to test directly on old builds. But ive looked at the code and 3.8.0 (before json flags) should report "./" for legacy/portable/fallback and the full sdl path for normal operation
https://github.com/scp-fs2open/fs2open.github.com/blob/release_3_8_0/code/osapi/osapi.cpp#L562

Anything before json flags is irrelevant anyway as pref_path is not exported to flags.ich
https://github.com/scp-fs2open/fs2open.github.com/blob/release_3_8_0/code/cmdline/cmdline.cpp#L1250

So, what i think i could do is to modify a build to export the executable path when "./" is set as the current preferences path. (This should only be for the json export and not to be used internally)
And then test if this breaks old-knossos normal operation (not sure if it supported portable executable mode) but i could try.
Knet is irrelevant if something breaks i can fix it, but im petty sure it should work.

And then report back, what im not sure if that should be done on this pr or not, or how soon should i try it.

Alternatively, i could define a "json_v2" for the get_flags that will now change "./" to current executable path, leaving v1 alone and any potential to break stuff on old launcher (i still petty sure knossos is the only to use json flags).
What im not sure if making a "-get_flags json_v2" is worth it for such change, it is small but it does have a small chance to break something, somewhere.

@Goober5000
Copy link
Contributor

Goober5000 commented Nov 27, 2024

So, what i think i could do is to modify a build to export the executable path when "./" is set as the current preferences path. (This should only be for the json export and not to be used internally)
And then test if this breaks old-knossos normal operation (not sure if it supported portable executable mode) but i could try.
Knet is irrelevant if something breaks i can fix it, but im petty sure it should work.

And then report back, what im not sure if that should be done on this pr or not, or how soon should i try it.

Yes this is a good plan. Short, quick, and if it works that will be a very good thing.

This should be done before we close out this PR. If it works, we can make that change right now. If it doesn't work, we can tie that change to the json_v2 format.

EDIT: I'm also almost certain that the json format is only used for old-Knossos and Knossos.NET. I can confirm that Launcher 5.5g and wxLauncher both used flags.lch.

@Shivansps
Copy link
Contributor Author

i havent realised that getting the path to the current executable directory (or executable) is non standart in C++ and needs a utility function with a OS specific implementation. This feels like a bit complicated, it is worth it? And i have no idea of how to do it for mac.

@Goober5000
Copy link
Contributor

Hmm. It's an important issue that you pointed out, so I think it should be fixed, but it sounds like it's outside the scope of this PR. So I'll approve this one, and then that can be done separately. I'll also ask taylor what the best strategy is.

@Shivansps
Copy link
Contributor Author

Thank you goober. Ill give it a try anyway when i can to test if the knossos and knet have a problem with that change, in case that is needed later.

@Goober5000 Goober5000 merged commit d21fb62 into scp-fs2open:master Nov 29, 2024
@daftmugi
Copy link
Contributor

daftmugi commented Dec 2, 2024

I tested this on Linux.

export FSO_PREFERENCES_PATH=/home/user/fs/config
./fs2_open

This creates an unexpected file: ./configfs2_open.ini.

It works as expected with a trailing slash (/):

export FSO_PREFERENCES_PATH=/home/user/fs/config/
./fs2_open

This creates an expected file: ./config/fs2_open.ini.

@Shivansps
Copy link
Contributor Author

Shivansps commented Dec 2, 2024

I tested this on Linux.

export FSO_PREFERENCES_PATH=/home/user/fs/config
./fs2_open

This creates an unexpected file: ./configfs2_open.ini.

It works as expected with a trailing slash (/):

export FSO_PREFERENCES_PATH=/home/user/fs/config/
./fs2_open

This creates an expected file: ./config/fs2_open.ini.

this is correct, it is because the normal SDL path also have a trailing directory separator character, so if you set your own to override it, it should have it.

EDIT: That said, os_get_config_path() should be able to deal with that. Is the config system getting the path directly from getPreferencesPath()?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement A new feature or upgrade of an existing feature to add additional functionality.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants