changeset 11532:3e68dda0f8af draft

(svn r15893) -Add: watermark crash.sav and don't generate crash information if a loaded crash.sav causes a crash
author glx <glx@openttd.org>
date Mon, 30 Mar 2009 00:21:43 +0000
parents 23734bd05e51
children 80379bc12cb3
files src/gamelog.cpp src/gamelog.h src/gamelog_internal.h src/saveload/gamelog_sl.cpp src/saveload/saveload.cpp src/win32.cpp
diffstat 6 files changed, 51 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/src/gamelog.cpp
+++ b/src/gamelog.cpp
@@ -135,6 +135,7 @@
 	"cheat was used",
 	"settings changed",
 	"GRF bug triggered",
+	"emergency savegame",
 };
 
 assert_compile(lengthof(la_text) == GLAT_END);
@@ -249,6 +250,9 @@
 							PrintGrfFilename(buf, lc->grfbug.grfid);
 							break;
 					}
+
+				case GLCT_EMERGENCY:
+					break;
 			}
 
 			proc(buf);
@@ -317,6 +321,31 @@
 }
 
 
+/** Logs a emergency savegame
+ */
+void GamelogEmergency()
+{
+	assert(_gamelog_action_type == GLAT_EMERGENCY);
+	GamelogChange(GLCT_EMERGENCY);
+}
+
+/** Finds out if current game is a loaded emergency savegame.
+ */
+bool GamelogTestEmergency()
+{
+	const LoggedChange *emergency = NULL;
+
+	const LoggedAction *laend = &_gamelog_action[_gamelog_actions];
+	for (const LoggedAction *la = _gamelog_action; la != laend; la++) {
+		const LoggedChange *lcend = &la->change[la->changes];
+		for (const LoggedChange *lc = la->change; lc != lcend; lc++) {
+			if (lc->ct == GLCT_EMERGENCY) emergency = lc;
+		}
+	}
+
+	return (emergency != NULL);
+}
+
 /** Logs a change in game revision
  * @param revision new revision string
  */
--- a/src/gamelog.h
+++ b/src/gamelog.h
@@ -14,6 +14,7 @@
 	GLAT_CHEAT,        ///< Cheat was used
 	GLAT_SETTING,      ///< Setting changed
 	GLAT_GRFBUG,       ///< GRF bug was triggered
+	GLAT_EMERGENCY,    ///< Emergency savegame
 	GLAT_END,          ///< So we know how many GLATs are there
 	GLAT_NONE  = 0xFF, ///< No logging active; in savegames, end of list
 };
@@ -29,6 +30,9 @@
 void GamelogPrintDebug(int level);
 void GamelogPrintConsole();
 
+void GamelogEmergency();
+bool GamelogTestEmergency();
+
 void GamelogRevision();
 void GamelogMode();
 void GamelogOldver();
--- a/src/gamelog_internal.h
+++ b/src/gamelog_internal.h
@@ -19,6 +19,7 @@
 	GLCT_GRFPARAM,    ///< GRF parameter changed
 	GLCT_GRFMOVE,     ///< GRF order changed
 	GLCT_GRFBUG,      ///< GRF bug triggered
+	GLCT_EMERGENCY,   ///< Emergency savegame
 	GLCT_END,         ///< So we know how many GLCTs are there
 	GLCT_NONE = 0xFF, ///< In savegames, end of list
 };
--- a/src/saveload/gamelog_sl.cpp
+++ b/src/saveload/gamelog_sl.cpp
@@ -76,6 +76,10 @@
 	SLE_END()
 };
 
+static const SaveLoad _glog_emergency_desc[] = {
+	SLE_END()
+};
+
 static const SaveLoad *_glog_desc[] = {
 	_glog_mode_desc,
 	_glog_revision_desc,
@@ -87,6 +91,7 @@
 	_glog_grfparam_desc,
 	_glog_grfmove_desc,
 	_glog_grfbug_desc,
+	_glog_emergency_desc,
 };
 
 assert_compile(lengthof(_glog_desc) == GLCT_END);
--- a/src/saveload/saveload.cpp
+++ b/src/saveload/saveload.cpp
@@ -40,7 +40,7 @@
 
 #include "saveload_internal.h"
 
-extern const uint16 SAVEGAME_VERSION = 115;
+extern const uint16 SAVEGAME_VERSION = 116;
 
 SavegameType _savegame_type; ///< type of savegame we are loading
 
--- a/src/win32.cpp
+++ b/src/win32.cpp
@@ -234,8 +234,15 @@
 	_T("Be aware that critical parts of the internal game state may have become ")
 	_T("corrupted. The saved game is not guaranteed to work.");
 
+static const TCHAR _emergency_crash[] =
+	_T("A serious fault condition occured in the game. The game will shut down.\n")
+	_T("As you loaded an emergency savegame no crash information will be generated.\n");
+
 static bool EmergencySave()
 {
+	GamelogStartAction(GLAT_EMERGENCY);
+	GamelogEmergency();
+	GamelogStopAction();
 	SaveOrLoad("crash.sav", SL_SAVE, BASE_DIR);
 	return true;
 }
@@ -471,6 +478,10 @@
 	static bool had_exception = false;
 
 	if (had_exception) ExitProcess(0);
+	if (GamelogTestEmergency()) {
+		MessageBox(NULL, _emergency_crash, _T("Fatal Application Failure"), MB_ICONERROR);
+		ExitProcess(0);
+	}
 	had_exception = true;
 
 	_ident = GetTickCount(); // something pretty unique