mirror of
https://github.com/OpenRCT2/OpenRCT2
synced 2026-01-15 19:13:07 +01:00
Split extension setter into two functions
This commit is contained in:
@@ -3116,7 +3116,7 @@ int save_track_design(uint8 rideIndex){
|
||||
return 1;
|
||||
}
|
||||
|
||||
path_set_extension(path, "TD6", false);
|
||||
path_append_extension(path, "TD6");
|
||||
|
||||
save_track_to_file(RCT2_ADDRESS(0x009D8178, rct_track_td6), path);
|
||||
|
||||
|
||||
@@ -94,12 +94,17 @@ const char *path_get_extension(const utf8 *path)
|
||||
return extension;
|
||||
}
|
||||
|
||||
void path_set_extension(utf8 *path, const utf8 *newExtension, bool replaceExistingExtension)
|
||||
void path_set_extension(utf8 *path, const utf8 *newExtension)
|
||||
{
|
||||
// First remove the current extension
|
||||
if (replaceExistingExtension)
|
||||
// Remove existing extension (check first if there is one)
|
||||
if (path_get_extension(path) < strrchr(path, '\0'))
|
||||
path_remove_extension(path);
|
||||
// Append new extension
|
||||
path_append_extension(path, newExtension);
|
||||
}
|
||||
|
||||
void path_append_extension(utf8 *path, const utf8 *newExtension)
|
||||
{
|
||||
// Append a dot to the filename if the new extension doesn't start with it
|
||||
char *endOfString = strrchr(path, '\0');
|
||||
if (newExtension[0] != '.')
|
||||
@@ -113,9 +118,10 @@ void path_remove_extension(utf8 *path)
|
||||
{
|
||||
// Find last dot in filename, and replace it with a null-terminator
|
||||
char *lastDot = strrchr(path_get_filename(path), '.');
|
||||
if (lastDot != NULL) {
|
||||
if (lastDot != NULL)
|
||||
*lastDot = '\0';
|
||||
}
|
||||
else
|
||||
log_warning("No extension found. (path = %s)", path);
|
||||
}
|
||||
|
||||
bool readentirefile(const utf8 *path, void **outBuffer, int *outLength)
|
||||
|
||||
@@ -32,7 +32,8 @@ bool filename_valid_characters(const utf8 *filename);
|
||||
|
||||
const char *path_get_filename(const utf8 *path);
|
||||
const char *path_get_extension(const utf8 *path);
|
||||
void path_set_extension(utf8 *path, const utf8 *newExtension, bool replaceExistingExtension);
|
||||
void path_set_extension(utf8 *path, const utf8 *newExtension);
|
||||
void path_append_extension(utf8 *path, const utf8 *newExtension);
|
||||
void path_remove_extension(utf8 *path);
|
||||
bool readentirefile(const utf8 *path, void **outBuffer, int *outLength);
|
||||
|
||||
|
||||
@@ -375,7 +375,7 @@ void window_editor_bottom_toolbar_jump_forward_to_save_scenario()
|
||||
s6Info->editor_step = 255;
|
||||
|
||||
// Ensure path has .SC6 extension
|
||||
path_set_extension(path, ".SC6", false);
|
||||
path_append_extension(path, ".SC6");
|
||||
|
||||
// Save the scenario
|
||||
parkFlagsBackup = RCT2_GLOBAL(RCT2_ADDRESS_PARK_FLAGS, uint32);
|
||||
|
||||
Reference in New Issue
Block a user