Support custom preferences path#6387
Conversation
…cesPath() It is a better place for it, it enables the regular path checks and warnings
Goober5000
left a comment
There was a problem hiding this comment.
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.
fs2open.github.com/code/cmdline/cmdline.cpp Line 1591 in 3e055ec 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" 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) |
This comment may date from a time when the command-line was parsed in that function, rather than just checked. The intent of
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
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 |
Because -get_flags prints the value of pref_path, and this changes depending if portable_mode is also set.
Goober5000
left a comment
There was a problem hiding this comment.
This looks good now, but we should resolve the "./" question before completing this PR.
|
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. |
|
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 Anything before json flags is irrelevant anyway as pref_path is not exported to flags.ich 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 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). |
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. |
|
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. |
|
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. |
|
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. |
|
I tested this on Linux. This creates an unexpected file: It works as expected with a trailing slash ( This creates an expected file: |
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()? |
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.