(svn r27650) -Codechange: Replace SaveOrLoadMode by FileOperation and DetailedFileType.
This commit is contained in:
@@ -2778,10 +2778,10 @@ SaveOrLoadResult LoadWithFilter(LoadFilter *reader)
|
||||
* @param threaded True when threaded saving is allowed
|
||||
* @return Return the result of the action. #SL_OK, #SL_ERROR, or #SL_REINIT ("unload" the game)
|
||||
*/
|
||||
SaveOrLoadResult SaveOrLoad(const char *filename, int mode, Subdirectory sb, bool threaded)
|
||||
SaveOrLoadResult SaveOrLoad(const char *filename, FileOperation fop, DetailedFileType dft, Subdirectory sb, bool threaded)
|
||||
{
|
||||
/* An instance of saving is already active, so don't go saving again */
|
||||
if (_sl.saveinprogress && mode == SL_SAVE && threaded) {
|
||||
if (_sl.saveinprogress && fop == FOP_SAVE && dft == DFT_GAME_FILE && threaded) {
|
||||
/* if not an autosave, but a user action, show error message */
|
||||
if (!_do_autosave) ShowErrorMessage(STR_ERROR_SAVE_STILL_IN_PROGRESS, INVALID_STRING_ID, WL_ERROR);
|
||||
return SL_OK;
|
||||
@@ -2790,7 +2790,7 @@ SaveOrLoadResult SaveOrLoad(const char *filename, int mode, Subdirectory sb, boo
|
||||
|
||||
try {
|
||||
/* Load a TTDLX or TTDPatch game */
|
||||
if (mode == SL_OLD_LOAD) {
|
||||
if (fop == FOP_LOAD && dft == DFT_OLD_GAME_FILE) {
|
||||
InitializeGame(256, 256, true, true); // set a mapsize of 256x256 for TTDPatch games or it might get confused
|
||||
|
||||
/* TTD/TTO savegames have no NewGRFs, TTDP savegame have them
|
||||
@@ -2811,25 +2811,35 @@ SaveOrLoadResult SaveOrLoad(const char *filename, int mode, Subdirectory sb, boo
|
||||
return SL_OK;
|
||||
}
|
||||
|
||||
switch (mode) {
|
||||
case SL_LOAD_CHECK: _sl.action = SLA_LOAD_CHECK; break;
|
||||
case SL_LOAD: _sl.action = SLA_LOAD; break;
|
||||
case SL_SAVE: _sl.action = SLA_SAVE; break;
|
||||
assert(dft == DFT_GAME_FILE);
|
||||
switch (dft) {
|
||||
case FOP_CHECK:
|
||||
_sl.action = SLA_LOAD_CHECK;
|
||||
break;
|
||||
|
||||
case FOP_LOAD:
|
||||
_sl.action = SLA_LOAD;
|
||||
break;
|
||||
|
||||
case FOP_SAVE:
|
||||
_sl.action = SLA_SAVE;
|
||||
break;
|
||||
|
||||
default: NOT_REACHED();
|
||||
}
|
||||
|
||||
FILE *fh = (mode == SL_SAVE) ? FioFOpenFile(filename, "wb", sb) : FioFOpenFile(filename, "rb", sb);
|
||||
FILE *fh = (fop == FOP_SAVE) ? FioFOpenFile(filename, "wb", sb) : FioFOpenFile(filename, "rb", sb);
|
||||
|
||||
/* Make it a little easier to load savegames from the console */
|
||||
if (fh == NULL && mode != SL_SAVE) fh = FioFOpenFile(filename, "rb", SAVE_DIR);
|
||||
if (fh == NULL && mode != SL_SAVE) fh = FioFOpenFile(filename, "rb", BASE_DIR);
|
||||
if (fh == NULL && mode != SL_SAVE) fh = FioFOpenFile(filename, "rb", SCENARIO_DIR);
|
||||
if (fh == NULL && fop != FOP_SAVE) fh = FioFOpenFile(filename, "rb", SAVE_DIR);
|
||||
if (fh == NULL && fop != FOP_SAVE) fh = FioFOpenFile(filename, "rb", BASE_DIR);
|
||||
if (fh == NULL && fop != FOP_SAVE) fh = FioFOpenFile(filename, "rb", SCENARIO_DIR);
|
||||
|
||||
if (fh == NULL) {
|
||||
SlError(mode == SL_SAVE ? STR_GAME_SAVELOAD_ERROR_FILE_NOT_WRITEABLE : STR_GAME_SAVELOAD_ERROR_FILE_NOT_READABLE);
|
||||
SlError(fop == FOP_SAVE ? STR_GAME_SAVELOAD_ERROR_FILE_NOT_WRITEABLE : STR_GAME_SAVELOAD_ERROR_FILE_NOT_READABLE);
|
||||
}
|
||||
|
||||
if (mode == SL_SAVE) { // SAVE game
|
||||
if (fop == FOP_SAVE) { // SAVE game
|
||||
DEBUG(desync, 1, "save: %08x; %02x; %s", _date, _date_fract, filename);
|
||||
if (_network_server || !_settings_client.gui.threaded_saves) threaded = false;
|
||||
|
||||
@@ -2837,24 +2847,25 @@ SaveOrLoadResult SaveOrLoad(const char *filename, int mode, Subdirectory sb, boo
|
||||
}
|
||||
|
||||
/* LOAD game */
|
||||
assert(mode == SL_LOAD || mode == SL_LOAD_CHECK);
|
||||
assert(fop == FOP_LOAD || fop == FOP_CHECK);
|
||||
DEBUG(desync, 1, "load: %s", filename);
|
||||
return DoLoad(new FileReader(fh), mode == SL_LOAD_CHECK);
|
||||
return DoLoad(new FileReader(fh), fop == FOP_CHECK);
|
||||
} catch (...) {
|
||||
/* This code may be executed both for old and new save games. */
|
||||
ClearSaveLoadState();
|
||||
|
||||
/* Skip the "colour" character */
|
||||
if (mode != SL_LOAD_CHECK) DEBUG(sl, 0, "%s", GetSaveLoadErrorString() + 3);
|
||||
if (fop != FOP_CHECK) DEBUG(sl, 0, "%s", GetSaveLoadErrorString() + 3);
|
||||
|
||||
/* A saver/loader exception!! reinitialize all variables to prevent crash! */
|
||||
return (mode == SL_LOAD || mode == SL_OLD_LOAD) ? SL_REINIT : SL_ERROR;
|
||||
return (fop == FOP_LOAD) ? SL_REINIT : SL_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
/** Do a save when exiting the game (_settings_client.gui.autosave_on_exit) */
|
||||
void DoExitSave()
|
||||
{
|
||||
SaveOrLoad("exit.sav", SL_SAVE, AUTOSAVE_DIR);
|
||||
SaveOrLoad("exit.sav", FOP_SAVE, DFT_GAME_FILE, AUTOSAVE_DIR);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -2898,34 +2909,27 @@ void GenerateDefaultSaveName(char *buf, const char *last)
|
||||
*/
|
||||
void FileToSaveLoad::SetMode(FiosType ft)
|
||||
{
|
||||
switch (ft) {
|
||||
case FIOS_TYPE_FILE:
|
||||
case FIOS_TYPE_SCENARIO:
|
||||
this->mode = SL_LOAD;
|
||||
break;
|
||||
this->SetMode(FOP_LOAD, GetAbstractFileType(ft), GetDetailedFileType(ft));
|
||||
}
|
||||
|
||||
case FIOS_TYPE_OLDFILE:
|
||||
case FIOS_TYPE_OLD_SCENARIO:
|
||||
this->mode = SL_OLD_LOAD;
|
||||
break;
|
||||
|
||||
#ifdef WITH_PNG
|
||||
case FIOS_TYPE_PNG:
|
||||
this->mode = SL_PNG;
|
||||
break;
|
||||
#endif /* WITH_PNG */
|
||||
|
||||
case FIOS_TYPE_BMP:
|
||||
this->mode = SL_BMP;
|
||||
break;
|
||||
|
||||
default:
|
||||
this->mode = SL_INVALID;
|
||||
break;
|
||||
/**
|
||||
* Set the mode and file type of the file to save or load.
|
||||
* @param fop File operation being performed.
|
||||
* @param aft Abstract file type.
|
||||
* @param dft Detailed file type.
|
||||
*/
|
||||
void FileToSaveLoad::SetMode(FileOperation fop, AbstractFileType aft, DetailedFileType dft)
|
||||
{
|
||||
if (aft == FT_INVALID || aft == FT_NONE) {
|
||||
this->file_op = FOP_INVALID;
|
||||
this->detail_ftype = DFT_INVALID;
|
||||
this->abstract_ftype = FT_INVALID;
|
||||
return;
|
||||
}
|
||||
|
||||
this->filetype = GetAbstractFileType(ft);
|
||||
if (this->filetype == FT_NONE) this->filetype = FT_INVALID;
|
||||
this->file_op = fop;
|
||||
this->detail_ftype = dft;
|
||||
this->abstract_ftype = aft;
|
||||
}
|
||||
|
||||
#if 0
|
||||
|
Reference in New Issue
Block a user