(svn r13859) -Fix: loading of TTD(Patch) savegames from the command line didn't work
authorsmatz
Mon, 28 Jul 2008 15:31:11 +0000
changeset 9730 ae89a033cf1f
parent 9729 9f30f91062c6
child 9731 4332cbaf5bd4
(svn r13859) -Fix: loading of TTD(Patch) savegames from the command line didn't work
src/fios.cpp
src/fios.h
src/openttd.cpp
--- a/src/fios.cpp	Mon Jul 28 15:17:47 2008 +0000
+++ b/src/fios.cpp	Mon Jul 28 15:31:11 2008 +0000
@@ -297,12 +297,12 @@
  * @param mode Save/load mode.
  * @param file Name of the file to check.
  * @param ext A pointer to the extension identifier inside file
- * @param title Buffer if a callback wants to lookup the title of the file
+ * @param title Buffer if a callback wants to lookup the title of the file; NULL to skip the lookup
  * @return a FIOS_TYPE_* type of the found file, FIOS_TYPE_INVALID if not a savegame
  * @see FiosGetFileList
  * @see FiosGetSavegameList
  */
-static FiosType FiosGetSavegameListCallback(SaveLoadDialogMode mode, const char *file, const char *ext, char *title)
+FiosType FiosGetSavegameListCallback(SaveLoadDialogMode mode, const char *file, const char *ext, char *title)
 {
 	/* Show savegame files
 	 * .SAV OpenTTD saved game
@@ -314,7 +314,7 @@
 	if (mode == SLD_LOAD_GAME || mode == SLD_LOAD_SCENARIO) {
 		if (strcasecmp(ext, ".ss1") == 0 || strcasecmp(ext, ".sv1") == 0 ||
 				strcasecmp(ext, ".sv2") == 0) {
-			GetOldSaveGameName(title, _fios_path, file);
+			if (title != NULL) GetOldSaveGameName(title, _fios_path, file);
 			return FIOS_TYPE_OLDFILE;
 		}
 	}
--- a/src/fios.h	Mon Jul 28 15:17:47 2008 +0000
+++ b/src/fios.h	Mon Jul 28 15:31:11 2008 +0000
@@ -105,6 +105,8 @@
 bool FiosDelete(const char *name);
 /* Make a filename from a name */
 void FiosMakeSavegameName(char *buf, const char *name, size_t size);
+/* Determines type of savegame (or tells it is not a savegame) */
+FiosType FiosGetSavegameListCallback(SaveLoadDialogMode mode, const char *file, const char *ext, char *title);
 
 int CDECL compare_FiosItems(const void *a, const void *b);
 
--- a/src/openttd.cpp	Mon Jul 28 15:17:47 2008 +0000
+++ b/src/openttd.cpp	Mon Jul 28 15:31:11 2008 +0000
@@ -460,11 +460,21 @@
 			if (mgo.opt != NULL) {
 				ttd_strlcpy(_file_to_saveload.name, mgo.opt, sizeof(_file_to_saveload.name));
 				_switch_mode = SM_LOAD;
-			} else {
-				_switch_mode = SM_NEWGAME;
-				/* Give a random map */
-				generation_seed = InteractiveRandom();
+				_file_to_saveload.mode = SL_LOAD;
+
+				/* if the file doesn't exist or it is not a valid savegame, let the saveload code show an error */
+				const char *t = strrchr(_file_to_saveload.name, '.');
+				if (t != NULL) {
+					FiosType ft = FiosGetSavegameListCallback(SLD_LOAD_GAME, _file_to_saveload.name, t, NULL);
+					if (ft != FIOS_TYPE_INVALID) SetFiosType(ft);
+				}
+
+				break;
 			}
+
+			_switch_mode = SM_NEWGAME;
+			/* Give a random map */
+			generation_seed = InteractiveRandom();
 			break;
 		case 'G': generation_seed = atoi(mgo.opt); break;
 		case 'c': _config_file = strdup(mgo.opt); break;