mirror of https://github.com/OpenRCT2/OpenRCT2.git
More consistent use between name and paths. Improved path_get_* functions.
This commit is contained in:
parent
02349d2463
commit
5b1d93805d
17
src/config.c
17
src/config.c
|
@ -1440,16 +1440,13 @@ static void title_sequence_open(const char *path, const char *customName)
|
|||
gConfigTitleSequences.presets = realloc(gConfigTitleSequences.presets, sizeof(title_sequence) * (size_t)gConfigTitleSequences.num_presets);
|
||||
|
||||
if (customName == NULL) {
|
||||
char nameBuffer[MAX_PATH], *name;
|
||||
char nameBuffer[MAX_PATH];
|
||||
safe_strncpy(nameBuffer, path, MAX_PATH);
|
||||
name = nameBuffer + strlen(nameBuffer) - 1;
|
||||
while (*name == '\\' || *name == '/') {
|
||||
*name = 0;
|
||||
name--;
|
||||
}
|
||||
while (*(name - 1) != '\\' && *(name - 1) != '/') {
|
||||
name--;
|
||||
}
|
||||
// Get folder name
|
||||
// First strip off the last folder separator
|
||||
*strrchr(nameBuffer, platform_get_path_separator()) = '\0';
|
||||
// Then find the name of the folder
|
||||
char *name = strrchr(nameBuffer, platform_get_path_separator()) + 1;
|
||||
safe_strncpy(gConfigTitleSequences.presets[preset].name, name, TITLE_SEQUENCE_NAME_SIZE);
|
||||
gConfigTitleSequences.presets[preset].path[0] = 0;
|
||||
}
|
||||
|
@ -1548,7 +1545,7 @@ void title_sequence_save_preset_script(int preset)
|
|||
|
||||
|
||||
platform_get_user_directory(path, "title sequences");
|
||||
strcat(path, path_get_filename(gConfigTitleSequences.presets[preset].name));
|
||||
strcat(path, gConfigTitleSequences.presets[preset].name);
|
||||
strncat(path, &separator, 1);
|
||||
strcat(path, "script.txt");
|
||||
|
||||
|
|
|
@ -1050,7 +1050,7 @@ void save_game()
|
|||
}
|
||||
void save_game_as()
|
||||
{
|
||||
window_loadsave_open(LOADSAVETYPE_SAVE | LOADSAVETYPE_GAME, gScenarioSavePath);
|
||||
window_loadsave_open(LOADSAVETYPE_SAVE | LOADSAVETYPE_GAME, path_get_filename(gScenarioSavePath));
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -58,7 +58,13 @@ const char *path_get_filename(const utf8 *path)
|
|||
// Find last slash or backslash in the path
|
||||
char *filename = strrchr(path, platform_get_path_separator());
|
||||
|
||||
assert(filename != NULL);
|
||||
// Checks if the path is valid (e.g. not just a file name)
|
||||
if (filename == NULL)
|
||||
{
|
||||
log_warning("Invalid path given: %s", path);
|
||||
// Return the input string to keep things working
|
||||
return path;
|
||||
}
|
||||
|
||||
// Increase pointer by one, to get rid of the slashes
|
||||
filename++;
|
||||
|
@ -68,12 +74,15 @@ const char *path_get_filename(const utf8 *path)
|
|||
|
||||
const char *path_get_extension(const utf8 *path)
|
||||
{
|
||||
// Try to find the most-right dot in the path
|
||||
char *extension = strrchr(path, '.');
|
||||
// Get the filename from the path
|
||||
char *filename = path_get_filename(path);
|
||||
|
||||
// When NULL was returned, return a pointer to the null-terminator
|
||||
// Try to find the most-right dot in the filename
|
||||
char *extension = strrchr(filename, '.');
|
||||
|
||||
// When no dot was found, return a pointer to the null-terminator
|
||||
if (extension == NULL)
|
||||
extension = strrchr(path, '\0');
|
||||
extension = strrchr(filename, '\0');
|
||||
|
||||
return extension;
|
||||
}
|
||||
|
|
|
@ -137,9 +137,7 @@ void window_install_track_open(const char* path)
|
|||
strncpy(track_path, path, MAX_PATH);
|
||||
track_path[MAX_PATH - 1] = '\0';
|
||||
|
||||
char* track_name_pointer = track_path;
|
||||
while (*track_name_pointer++ != '\0');
|
||||
while (*--track_name_pointer != '\\');
|
||||
char* track_name_pointer = strrchr(track_path, platform_get_path_separator());
|
||||
track_name_pointer++;
|
||||
|
||||
strncpy(track_dest_name, track_name_pointer, MAX_PATH);
|
||||
|
|
|
@ -159,7 +159,7 @@ rct_window *window_loadsave_open(int type, char *defaultName)
|
|||
_defaultName[0] = 0;
|
||||
|
||||
if (!str_is_null_or_empty(defaultName)) {
|
||||
safe_strncpy(_defaultName, path_get_filename(defaultName), sizeof(_defaultName));
|
||||
safe_strncpy(_defaultName, defaultName, sizeof(_defaultName));
|
||||
path_remove_extension(_defaultName);
|
||||
}
|
||||
|
||||
|
@ -745,7 +745,7 @@ static void window_loadsave_select(rct_window *w, const char *path)
|
|||
case (LOADSAVETYPE_LOAD | LOADSAVETYPE_GAME) :
|
||||
if (gLoadSaveTitleSequenceSave) {
|
||||
utf8 newName[MAX_PATH];
|
||||
char *extension = (char*)path_get_extension(path_get_filename(path));
|
||||
char *extension = (char*)path_get_extension(path);
|
||||
safe_strncpy(newName, path_get_filename(path), MAX_PATH);
|
||||
if (_stricmp(extension, ".sv6") != 0 && _stricmp(extension, ".sc6") != 0)
|
||||
strcat(newName, ".sv6");
|
||||
|
|
Loading…
Reference in New Issue