mirror of https://github.com/OpenTTD/OpenTTD
(svn r10188) -Codechange: make it a little easier to load a savegame from the console:
-g <absolute path> -g <relative path from current working directory> -g <relative path from within the savegame directory>release/0.6
parent
6d9393cb60
commit
b2799961bc
|
@ -279,7 +279,7 @@ FILE *FioFOpenFileSp(const char *filename, const char *mode, Searchpath sp, Subd
|
|||
FILE *f = NULL;
|
||||
char buf[MAX_PATH];
|
||||
|
||||
if (subdir == BASE_DIR) {
|
||||
if (subdir == NO_DIRECTORY) {
|
||||
ttd_strlcpy(buf, filename, lengthof(buf));
|
||||
} else {
|
||||
snprintf(buf, lengthof(buf), "%s%s%s", _searchpaths[sp], _subdirs[subdir], filename);
|
||||
|
@ -301,11 +301,11 @@ FILE *FioFOpenFile(const char *filename, const char *mode, Subdirectory subdir)
|
|||
FILE *f = NULL;
|
||||
Searchpath sp;
|
||||
|
||||
assert(subdir < NUM_SUBDIRS);
|
||||
assert(subdir < NUM_SUBDIRS || subdir == NO_DIRECTORY);
|
||||
|
||||
FOR_ALL_SEARCHPATHS(sp) {
|
||||
f = FioFOpenFileSp(filename, mode, sp, subdir);
|
||||
if (f != NULL || subdir == 0) break;
|
||||
if (f != NULL || subdir == NO_DIRECTORY) break;
|
||||
}
|
||||
|
||||
return f;
|
||||
|
|
|
@ -33,6 +33,7 @@ enum Subdirectory {
|
|||
DATA_DIR, ///< Subdirectory for all data (GRFs, sample.cat, intro game)
|
||||
LANG_DIR, ///< Subdirectory for all translation files
|
||||
NUM_SUBDIRS, ///< Number of subdirectories
|
||||
NO_DIRECTORY, ///< A path without any base directory
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
@ -860,7 +860,7 @@ void SwitchMode(int new_mode)
|
|||
_opt_ptr = &_opt;
|
||||
ResetGRFConfig(true);
|
||||
|
||||
if (!SafeSaveOrLoad(_file_to_saveload.name, _file_to_saveload.mode, GM_NORMAL, BASE_DIR)) {
|
||||
if (!SafeSaveOrLoad(_file_to_saveload.name, _file_to_saveload.mode, GM_NORMAL, NO_DIRECTORY)) {
|
||||
LoadIntroGame();
|
||||
ShowErrorMessage(INVALID_STRING_ID, STR_4009_GAME_LOAD_FAILED, 0, 0);
|
||||
} else {
|
||||
|
@ -894,7 +894,7 @@ void SwitchMode(int new_mode)
|
|||
break;
|
||||
|
||||
case SM_LOAD_SCENARIO: { /* Load scenario from scenario editor */
|
||||
if (SafeSaveOrLoad(_file_to_saveload.name, _file_to_saveload.mode, GM_EDITOR, BASE_DIR)) {
|
||||
if (SafeSaveOrLoad(_file_to_saveload.name, _file_to_saveload.mode, GM_EDITOR, NO_DIRECTORY)) {
|
||||
_opt_ptr = &_opt;
|
||||
|
||||
SetLocalPlayer(OWNER_NONE);
|
||||
|
@ -910,7 +910,7 @@ void SwitchMode(int new_mode)
|
|||
break;
|
||||
|
||||
case SM_SAVE: /* Save game */
|
||||
if (SaveOrLoad(_file_to_saveload.name, SL_SAVE, BASE_DIR) != SL_OK) {
|
||||
if (SaveOrLoad(_file_to_saveload.name, SL_SAVE, NO_DIRECTORY) != SL_OK) {
|
||||
ShowErrorMessage(INVALID_STRING_ID, STR_4007_GAME_SAVE_FAILED, 0, 0);
|
||||
} else {
|
||||
DeleteWindowById(WC_SAVELOAD, 0);
|
||||
|
|
|
@ -1584,6 +1584,11 @@ SaveOrLoadResult SaveOrLoad(const char *filename, int mode, Subdirectory sb)
|
|||
}
|
||||
|
||||
_sl.fh = (mode == SL_SAVE) ? FioFOpenFile(filename, "wb", sb) : FioFOpenFile(filename, "rb", sb);
|
||||
|
||||
/* Make it a little easier to load savegames from the console */
|
||||
if (_sl.fh == NULL && mode == SL_LOAD) _sl.fh = FioFOpenFile(filename, "rb", SAVE_DIR);
|
||||
if (_sl.fh == NULL && mode == SL_LOAD) _sl.fh = FioFOpenFile(filename, "rb", BASE_DIR);
|
||||
|
||||
if (_sl.fh == NULL) {
|
||||
DEBUG(sl, 0, "Cannot open savegame '%s' for saving/loading.", filename);
|
||||
return SL_ERROR;
|
||||
|
|
Loading…
Reference in New Issue