Changeset - r6935:a7744b917c21
[Not reviewed]
master
0 4 0
rubidium - 17 years ago 2007-06-17 20:09:05
rubidium@openttd.org
(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>
4 files changed with 12 insertions and 6 deletions:
0 comments (0 inline, 0 general)
src/fileio.cpp
Show inline comments
 
@@ -276,13 +276,13 @@ FILE *FioFOpenFileSp(const char *filenam
 
	wchar_t Lmode[5];
 
	MultiByteToWideChar(CP_ACP, 0, mode, -1, Lmode, lengthof(Lmode));
 
#endif
 
	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);
 
	}
 

	
 
	f = fopen(buf, mode);
 
@@ -298,17 +298,17 @@ FILE *FioFOpenFileSp(const char *filenam
 
/** Opens OpenTTD files somewhere in a personal or global directory */
 
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;
 
}
 

	
 
/**
src/fileio.h
Show inline comments
 
@@ -30,12 +30,13 @@ enum Subdirectory {
 
	SCENARIO_DIR,  ///< Base directory for all scenarios
 
	HEIGHTMAP_DIR, ///< Subdirectory of scenario for heightmaps
 
	GM_DIR,        ///< Subdirectory for all music
 
	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
 
};
 

	
 
/**
 
 * Types of searchpaths OpenTTD might use
 
 */
 
enum Searchpath {
src/openttd.cpp
Show inline comments
 
@@ -857,13 +857,13 @@ void SwitchMode(int new_mode)
 
		break;
 

	
 
	case SM_LOAD: { /* Load game, Play Scenario */
 
		_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 {
 
			/* Update the local player for a loaded game. It is either always
 
			 * player #1 (eg 0) or in the case of a dedicated server a spectator */
 
			SetLocalPlayer(_network_dedicated ? PLAYER_SPECTATOR : PLAYER_FIRST);
 
@@ -891,13 +891,13 @@ void SwitchMode(int new_mode)
 

	
 
		GenerateWorld(GW_HEIGHTMAP, 1 << _patches.map_x, 1 << _patches.map_y);
 
		MarkWholeScreenDirty();
 
		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);
 
			_patches_newgame.starting_year = _cur_year;
 
		} else {
 
			ShowErrorMessage(INVALID_STRING_ID, STR_4009_GAME_LOAD_FAILED, 0, 0);
 
@@ -907,13 +907,13 @@ void SwitchMode(int new_mode)
 

	
 
	case SM_MENU: /* Switch to game intro menu */
 
		LoadIntroGame();
 
		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);
 
		}
 
		break;
 

	
src/saveload.cpp
Show inline comments
 
@@ -1581,12 +1581,17 @@ SaveOrLoadResult SaveOrLoad(const char *
 
		_sl_version = 0;
 
		AfterLoadGame();
 
		return SL_OK;
 
	}
 

	
 
	_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;
 
	}
 

	
 
	_sl.bufe = _sl.bufp = NULL;
0 comments (0 inline, 0 general)