1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2025-12-24 00:03:11 +01:00

Merge pull request #3997 from SijmenSchoon/develop

Remember previous save/load location
This commit is contained in:
Ted John
2016-07-06 20:52:50 +01:00
6 changed files with 63 additions and 10 deletions

View File

@@ -26,7 +26,7 @@ Includes all git commit authors. Aliases are GitHub user names.
* (vanderkleij) - Misc.
* Ben Pye (benpye) - Misc.
* (JeroenSack) - Misc.
* (Vijfhoek) - Misc.
* Sijmen Schoon (SijmenSchoon) - Misc.
* (wolfreak99) - Misc.
* Inseok Lee (dlunch) - Original command line
* Lewis Fox (LRFLEW) - Misc.
@@ -93,7 +93,7 @@ Includes all git commit authors. Aliases are GitHub user names.
* English (UK) - Ted John (IntelOrca), (Tinytimrob)
* English (US) - Ted John (IntelOrca), Michael Steenbeek (Gymnasiast); small fixes: (LRFLEW), (mike-koch), Harry Lam (daihakken)
* Czech - Martin Černáč (octaroot), (Clonewayx), Tomáš Pazdiora (Aroidzap)
* Dutch - Michael Steenbeek (Gymnasiast), Yannic Geurts (xzbobzx), (mrtnptrs), Thomas den Hollander (ThomasdenH), (hostbrute), Marijn van de Werf (marijnvdwerf); reviewing and discussion: Aaron van Geffen (AaronVanGeffen), (Balletie) and Sijmen Schoon (Vijfhoek).
* Dutch - Michael Steenbeek (Gymnasiast), Yannic Geurts (xzbobzx), (mrtnptrs), Thomas den Hollander (ThomasdenH), (hostbrute), Marijn van de Werf (marijnvdwerf); reviewing and discussion: Aaron van Geffen (AaronVanGeffen), (Balletie) and Sijmen Schoon (SijmenSchoon).
* Finnish - (DJHasis), (Zode), (TheWing)
* French - (fbourigault), Joël Troch (JoelTroch), Michael Steenbeek (Gymnasiast), Romain Vigier (rvgr), (AziasYur), Hugo Courtial (s0r00t), David Delobel (incyclum)
* German - (danidoedel), (atmaxinger), (Yepoleb), Daniel Kessel (dkessel), Leon (AllGoodNamesAreTaken), (raidcookie)

View File

@@ -222,7 +222,10 @@ config_property_definition _generalDefinitions[] = {
{ offsetof(general_configuration, scenario_select_mode), "scenario_select_mode", CONFIG_VALUE_TYPE_UINT8, SCENARIO_SELECT_MODE_ORIGIN, NULL },
{ offsetof(general_configuration, scenario_unlocking_enabled), "scenario_unlocking_enabled", CONFIG_VALUE_TYPE_BOOLEAN, true, NULL },
{ offsetof(general_configuration, scenario_hide_mega_park), "scenario_hide_mega_park", CONFIG_VALUE_TYPE_BOOLEAN, true, NULL },
{ offsetof(general_configuration, last_save_game_directory), "last_game_directory", CONFIG_VALUE_TYPE_STRING, { .value_string = NULL }, NULL },
{ offsetof(general_configuration, last_save_landscape_directory), "last_landscape_directory", CONFIG_VALUE_TYPE_STRING, { .value_string = NULL }, NULL },
{ offsetof(general_configuration, last_save_scenario_directory), "last_scenario_directory", CONFIG_VALUE_TYPE_STRING, { .value_string = NULL }, NULL },
{ offsetof(general_configuration, last_save_track_directory), "last_track_directory", CONFIG_VALUE_TYPE_STRING, { .value_string = NULL }, NULL },
};
config_property_definition _interfaceDefinitions[] = {

View File

@@ -192,6 +192,10 @@ typedef struct general_configuration {
uint8 scenario_select_mode;
uint8 scenario_unlocking_enabled;
uint8 scenario_hide_mega_park;
utf8string last_save_game_directory;
utf8string last_save_landscape_directory;
utf8string last_save_scenario_directory;
utf8string last_save_track_directory;
} general_configuration;
typedef struct interface_configuration {

View File

@@ -62,6 +62,21 @@ bool filename_valid_characters(const utf8 *filename)
return true;
}
utf8 *path_get_directory(const utf8 *path)
{
// Find the last slash or backslash in the path
char *filename = strrchr(path, platform_get_path_separator());
// If the path is invalid (e.g. just a file name), return NULL
if (filename == NULL)
return NULL;
char *directory = _strdup(path);
safe_strtrunc(directory, strlen(path) - strlen(filename) + 2);
return directory;
}
const char *path_get_filename(const utf8 *path)
{
// Find last slash or backslash in the path

View File

@@ -28,6 +28,7 @@ int mph_to_dmps(int mph);
bool filename_valid_characters(const utf8 *filename);
char *path_get_directory(const utf8 *path);
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);

View File

@@ -196,7 +196,11 @@ rct_window *window_loadsave_open(int type, char *defaultName)
includeNewItem = (type & 0x01) == LOADSAVETYPE_SAVE;
switch (type & 0x0E) {
case LOADSAVETYPE_GAME:
platform_get_user_directory(path, "save");
if (gConfigGeneral.last_save_game_directory && platform_ensure_directory_exists(gConfigGeneral.last_save_game_directory))
safe_strcpy(path, gConfigGeneral.last_save_game_directory, MAX_PATH);
else
platform_get_user_directory(path, "save");
if (!platform_ensure_directory_exists(path)) {
log_error("Unable to create save directory.");
window_close(w);
@@ -206,7 +210,11 @@ rct_window *window_loadsave_open(int type, char *defaultName)
window_loadsave_populate_list(w, includeNewItem, path, ".sv6");
break;
case LOADSAVETYPE_LANDSCAPE:
platform_get_user_directory(path, "landscape");
if (gConfigGeneral.last_save_landscape_directory && platform_ensure_directory_exists(gConfigGeneral.last_save_landscape_directory))
safe_strcpy(path, gConfigGeneral.last_save_landscape_directory, MAX_PATH);
else
platform_get_user_directory(path, "landscape");
if (!platform_ensure_directory_exists(path)) {
log_error("Unable to create landscapes directory.");
window_close(w);
@@ -216,7 +224,11 @@ rct_window *window_loadsave_open(int type, char *defaultName)
window_loadsave_populate_list(w, includeNewItem, path, ".sc6");
break;
case LOADSAVETYPE_SCENARIO:
platform_get_user_directory(path, "scenario");
if (gConfigGeneral.last_save_scenario_directory && platform_ensure_directory_exists(gConfigGeneral.last_save_scenario_directory))
safe_strcpy(path, gConfigGeneral.last_save_scenario_directory, MAX_PATH);
else
platform_get_user_directory(path, "scenario");
if (!platform_ensure_directory_exists(path)) {
log_error("Unable to create scenarios directory.");
window_close(w);
@@ -229,11 +241,15 @@ rct_window *window_loadsave_open(int type, char *defaultName)
/*
Uncomment when user tracks are separated
platform_get_user_directory(path, "tracks");
if (gConfigGeneral.last_save_track_directory && platform_ensure_directory_exists(gConfigGeneral.last_save_track_directory))
save_strcpy(path, gConfigGeneral.last_save_track_directory, MAX_PATH);
else
platform_get_user_directory(path, "tracks");
if (!platform_ensure_directory_exists(path)) {
log_error("Unable to create tracks directory.");
window_close(w);
return NULL;
log_error("Unable to create tracks directory.");
window_close(w);
return NULL;
}
*/
@@ -705,11 +721,20 @@ static void window_loadsave_invoke_callback(int result)
}
}
static void save_path(utf8 **config_str, const char *path)
{
if (*config_str != NULL)
free(*config_str);
*config_str = path_get_directory(path);
config_save_default();
}
static void window_loadsave_select(rct_window *w, const char *path)
{
SDL_RWops* rw;
switch (_loadsaveType & 0x0F) {
case (LOADSAVETYPE_LOAD | LOADSAVETYPE_GAME) :
save_path(&gConfigGeneral.last_save_game_directory, path);
if (gLoadSaveTitleSequenceSave) {
utf8 newName[MAX_PATH];
char *extension = (char*)path_get_extension(path);
@@ -739,6 +764,7 @@ static void window_loadsave_select(rct_window *w, const char *path)
}
break;
case (LOADSAVETYPE_SAVE | LOADSAVETYPE_GAME) :
save_path(&gConfigGeneral.last_save_game_directory, path);
rw = SDL_RWFromFile(path, "wb+");
if (rw != NULL) {
int success = scenario_save(rw, gConfigGeneral.save_plugin_data ? 1 : 0);
@@ -761,6 +787,7 @@ static void window_loadsave_select(rct_window *w, const char *path)
}
break;
case (LOADSAVETYPE_LOAD | LOADSAVETYPE_LANDSCAPE) :
save_path(&gConfigGeneral.last_save_landscape_directory, path);
if (editor_load_landscape(path)) {
gfx_invalidate_screen();
window_loadsave_invoke_callback(MODAL_RESULT_OK);
@@ -771,6 +798,7 @@ static void window_loadsave_select(rct_window *w, const char *path)
}
break;
case (LOADSAVETYPE_SAVE | LOADSAVETYPE_LANDSCAPE) :
save_path(&gConfigGeneral.last_save_landscape_directory, path);
rw = SDL_RWFromFile(path, "wb+");
if (rw != NULL) {
scenario_set_filename(path);
@@ -791,6 +819,7 @@ static void window_loadsave_select(rct_window *w, const char *path)
break;
case (LOADSAVETYPE_SAVE | LOADSAVETYPE_SCENARIO) :
{
save_path(&gConfigGeneral.last_save_scenario_directory, path);
int parkFlagsBackup = gParkFlags;
gParkFlags &= ~PARK_FLAGS_18;
gS6Info->editor_step = 255;
@@ -815,6 +844,7 @@ static void window_loadsave_select(rct_window *w, const char *path)
break;
}
case (LOADSAVETYPE_LOAD | LOADSAVETYPE_TRACK) :
save_path(&gConfigGeneral.last_save_track_directory, path);
window_install_track_open(path);
window_close_by_class(WC_LOADSAVE);
window_loadsave_invoke_callback(MODAL_RESULT_OK);