Ensure custom preferences path ends with path separator#6480
Conversation
db5038b to
2d841c0
Compare
|
I force pushed a different take on this PR. Originally, I merely added a path separator to the end of the path, if there wasn't one on The following code was trying to void os_deinit() {
if (preferencesPath) {
SDL_free(preferencesPath);
preferencesPath = nullptr;
}
}I decided to rewrite this PR to address that at the same time. I changed the type of Of note, there's a |
Example: Given: FSO_PREFERENCES_PATH='./config' fs2_open Path becomes: './config/'
2d841c0 to
440eed6
Compare
|
yeah i was thinking about do it myself as well. That said, i think the problem was actually caused because some internal part of the code is calling getPreferencesPath() directly when it should be done via os_get_config_path() fs2open.github.com/code/osapi/osapi.cpp Line 815 in 440eed6 Because if you do this and pass the path without the ending directory separator the pilots profiles are actually writen correctly, its the fs2_open.inis that are not. But since there is no coment or indicator that you cant use getPreferencesPath() directly, i think this is the right thing to do. Also, i might be wrong, i didnt do enoght testing in this case. |
|
Yeah there are several places in the code that call Also keep in mind that |
|
Just to clarify, are there any changes that I need to make? |
|
Then i think checking for the ending directory terminator on getPreferencesPath() is the right thing to do. |
Mainly to resolve this question: Regarding @Shivansps 's comment:
Is this actually the case? The only places in the code where If EDIT: I just looked over the PR. In other respects, the changes look good. |
|
Just leaving some notes here for future reference. The pilot files get saved in the correct location regardless if the preferences path has a trailing slash, because the trailing slash is added if it's not present. // - pilotfile::save_player(...)
// - cfopen(filename, ..., CF_TYPE_PLAYERS, ...)
// - _cfopen(filename, ..., CF_TYPE_PLAYERS, ...)
// - cf_create_default_path_string(..., pathtype, filename, ...)
////////////////////////////////////////////////////////////////////////////
// Don't add slash for root directory
if (Pathtypes[pathtype].path[0] != '\0') {
if (path.back() != DIR_SEPARATOR_CHAR) {
path += DIR_SEPARATOR_CHAR;
}
}
// add filename
if (filename) {
path += filename;
}The // - os_init_registry_stuff(...)
// - profile_read(Osreg_config_file_name /* "fs2_open.ini" */)
// - os_get_config_path(...)
////////////////////////////////////////////////////////////////////////////
ss << getPreferencesPath() << compatiblePath; |
To clarify, what i meant to say is that getPrefencesPath() is not meant to be called from outside "osapi.cpp", looking back at the initial PRs i think it is just meant as a optimization so SDL_GetPrefPath() is not called multiples times because its slow. daftmurgi is correct i got confused because of this line fs2open.github.com/code/osapi/osapi.cpp Line 840 in 440eed6 os_get_config_path() does not add the dir char separator unless it is in legacy mode, as i mistakely belived. |
If the user launches FSO with a
FSO_PREFERENCES_PATHvalue that does not end with a path separator (Linux/, Windows\), FSO will create afs2_open.inifile in the wrong location.Example:
Given:
FSO_PREFERENCES_PATH='./config' fs2_openPath is:
'./config'INI file path becomes:
./configfs2_open.iniThis PR ensures that the custom preferences path ends with a path separator, resulting in the
fs2_open.inifile being created in the expected location.Example with PR:
Given:
FSO_PREFERENCES_PATH='./config' fs2_openPath becomes:
'./config/'INI file path becomes:
./config/fs2_open.iniExtends #6387.