changeset 18633:b99ace5e6811 draft

(svn r23480) -Fix [FS#4594]: replace OS error messages with internal error messages when that's possible
author rubidium <rubidium@openttd.org>
date Sat, 10 Dec 2011 16:05:26 +0000
parents eb93faa96b65
children 45e8cda75fba
files src/genworld.cpp src/lang/english.txt src/saveload/saveload.cpp src/settings.cpp
diffstat 4 files changed, 53 insertions(+), 17 deletions(-) [+]
line wrap: on
line diff
--- a/src/genworld.cpp
+++ b/src/genworld.cpp
@@ -32,6 +32,7 @@
 #include "core/random_func.hpp"
 #include "core/backup_type.hpp"
 #include "progress.h"
+#include "error.h"
 
 #include "table/sprites.h"
 
@@ -83,6 +84,7 @@
 	_gw.threaded = false;
 
 	DeleteWindowById(WC_MODAL_PROGRESS, 0);
+	ShowFirstError();
 	MarkWholeScreenDirty();
 }
 
@@ -317,6 +319,7 @@
 		return;
 	}
 
+	UnshowCriticalError();
 	/* Remove any open window */
 	DeleteAllNonVitalWindows();
 	/* Hide vital windows, because we don't allow to use them */
--- a/src/lang/english.txt
+++ b/src/lang/english.txt
@@ -1371,6 +1371,21 @@
 
 STR_CONFIG_SETTING_QUERY_CAPTION                                :{WHITE}Change setting value
 
+# Config errors
+STR_CONFIG_ERROR                                                :{WHITE}Error with the configuration file...
+STR_CONFIG_ERROR_ARRAY                                          :{WHITE}... error in array '{RAW_STRING}'
+STR_CONFIG_ERROR_INVALID_VALUE                                  :{WHITE}... invalid value '{RAW_STRING}' for '{RAW_STRING}'
+STR_CONFIG_ERROR_TRAILING_CHARACTERS                            :{WHITE}... trailing characters at end of setting '{RAW_STRING}'
+STR_CONFIG_ERROR_DUPLICATE_GRFID                                :{WHITE}... ignoring NewGRF '{RAW_STRING}': duplicate GRF ID with '{RAW_STRING}'
+STR_CONFIG_ERROR_INVALID_GRF                                    :{WHITE}... ignoring invalid NewGRF '{RAW_STRING}': {STRING}
+STR_CONFIG_ERROR_INVALID_GRF_NOT_FOUND                          :not found
+STR_CONFIG_ERROR_INVALID_GRF_UNSAFE                             :unsafe for static use
+STR_CONFIG_ERROR_INVALID_GRF_SYSTEM                             :system NewGRF
+STR_CONFIG_ERROR_INVALID_GRF_INCOMPATIBLE                       :incompatible to this version of OpenTTD
+STR_CONFIG_ERROR_INVALID_GRF_UNKNOWN                            :unknown
+STR_CONFIG_ERROR_INVALID_SAVEGAME_COMPRESSION_LEVEL             :{WHITE}... compression level '{RAW_STRING}' is not valid
+STR_CONFIG_ERROR_INVALID_SAVEGAME_COMPRESSION_ALGORITHM         :{WHITE}... savegame format '{RAW_STRING}' is not available. Reverting to '{RAW_STRING}'
+
 # Intro window
 STR_INTRO_CAPTION                                               :{WHITE}OpenTTD {REV}
 
--- a/src/saveload/saveload.cpp
+++ b/src/saveload/saveload.cpp
@@ -2285,7 +2285,8 @@
 					char *end;
 					long level = strtol(complevel, &end, 10);
 					if (end == complevel || level != Clamp(level, slf->min_compression, slf->max_compression)) {
-						ShowInfoF("Compression level '%s' is not valid.", complevel);
+						SetDParamStr(0, complevel);
+						ShowErrorMessage(STR_CONFIG_ERROR, STR_CONFIG_ERROR_INVALID_SAVEGAME_COMPRESSION_LEVEL, WL_CRITICAL);
 					} else {
 						*compression_level = level;
 					}
@@ -2294,7 +2295,9 @@
 			}
 		}
 
-		ShowInfoF("Savegame format '%s' is not available. Reverting to '%s'.", s, def->name);
+		SetDParamStr(0, s);
+		SetDParamStr(1, def->name);
+		ShowErrorMessage(STR_CONFIG_ERROR, STR_CONFIG_ERROR_INVALID_SAVEGAME_COMPRESSION_ALGORITHM, WL_CRITICAL);
 
 		/* Restore the string by adding the : back */
 		if (complevel != NULL) *complevel = ':';
--- a/src/settings.cpp
+++ b/src/settings.cpp
@@ -61,6 +61,7 @@
 #include "smallmap_gui.h"
 #include "roadveh.h"
 #include "fios.h"
+#include "strings_func.h"
 
 #include "void_map.h"
 #include "station_base.h"
@@ -340,7 +341,10 @@
 	case SDT_NUMX: {
 		char *end;
 		size_t val = strtoul(str, &end, 0);
-		if (*end != '\0') ShowInfoF("ini: trailing characters at end of setting '%s'", desc->name);
+		if (*end != '\0') {
+			SetDParamStr(0, desc->name);
+			ShowErrorMessage(STR_CONFIG_ERROR, STR_CONFIG_ERROR_TRAILING_CHARACTERS, WL_CRITICAL);
+		}
 		return (void*)val;
 	}
 	case SDT_ONEOFMANY: {
@@ -349,19 +353,27 @@
 		 * look if we have defined a converter from old value to new value. */
 		if (r == (size_t)-1 && desc->proc_cnvt != NULL) r = desc->proc_cnvt(str);
 		if (r != (size_t)-1) return (void*)r; // and here goes converted value
-		ShowInfoF("ini: invalid value '%s' for '%s'", str, desc->name); // sorry, we failed
+
+		SetDParamStr(0, str);
+		SetDParamStr(1, desc->name);
+		ShowErrorMessage(STR_CONFIG_ERROR, STR_CONFIG_ERROR_INVALID_VALUE, WL_CRITICAL);
 		return 0;
 	}
 	case SDT_MANYOFMANY: {
 		size_t r = LookupManyOfMany(desc->many, str);
 		if (r != (size_t)-1) return (void*)r;
-		ShowInfoF("ini: invalid value '%s' for '%s'", str, desc->name);
+		SetDParamStr(0, str);
+		SetDParamStr(1, desc->name);
+		ShowErrorMessage(STR_CONFIG_ERROR, STR_CONFIG_ERROR_INVALID_VALUE, WL_CRITICAL);
 		return NULL;
 	}
 	case SDT_BOOLX:
 		if (strcmp(str, "true")  == 0 || strcmp(str, "on")  == 0 || strcmp(str, "1") == 0) return (void*)true;
 		if (strcmp(str, "false") == 0 || strcmp(str, "off") == 0 || strcmp(str, "0") == 0) return (void*)false;
-		ShowInfoF("ini: invalid setting value '%s' for '%s'", str, desc->name);
+
+		SetDParamStr(0, str);
+		SetDParamStr(1, desc->name);
+		ShowErrorMessage(STR_CONFIG_ERROR, STR_CONFIG_ERROR_INVALID_VALUE, WL_CRITICAL);
 		break;
 
 	case SDT_STRING: return orig_str;
@@ -500,7 +512,8 @@
 
 		case SDT_INTLIST: {
 			if (!LoadIntList((const char*)p, ptr, sld->length, GetVarMemType(sld->conv))) {
-				ShowInfoF("ini: error in array '%s'", sdb->name);
+				SetDParamStr(0, sdb->name);
+				ShowErrorMessage(STR_CONFIG_ERROR, STR_CONFIG_ERROR_ARRAY, WL_CRITICAL);
 			} else if (sd->desc.proc_cnvt != NULL) {
 				sd->desc.proc_cnvt((const char*)p);
 			}
@@ -1371,28 +1384,28 @@
 		if (!StrEmpty(item->value)) {
 			c->num_params = ParseIntList(item->value, (int*)c->param, lengthof(c->param));
 			if (c->num_params == (byte)-1) {
-				ShowInfoF("ini: error in array '%s'", item->name);
+				SetDParamStr(0, item->name);
+				ShowErrorMessage(STR_CONFIG_ERROR, STR_CONFIG_ERROR_ARRAY, WL_CRITICAL);
 				c->num_params = 0;
 			}
 		}
 
 		/* Check if item is valid */
 		if (!FillGRFDetails(c, is_static) || HasBit(c->flags, GCF_INVALID)) {
-			const char *msg;
-
 			if (c->status == GCS_NOT_FOUND) {
-				msg = "not found";
+				SetDParam(1, STR_CONFIG_ERROR_INVALID_GRF_NOT_FOUND);
 			} else if (HasBit(c->flags, GCF_UNSAFE)) {
-				msg = "unsafe for static use";
+				SetDParam(1, STR_CONFIG_ERROR_INVALID_GRF_UNSAFE);
 			} else if (HasBit(c->flags, GCF_SYSTEM)) {
-				msg = "system NewGRF";
+				SetDParam(1, STR_CONFIG_ERROR_INVALID_GRF_SYSTEM);
 			} else if (HasBit(c->flags, GCF_INVALID)) {
-				msg = "incompatible to this version of OpenTTD";
+				SetDParam(1, STR_CONFIG_ERROR_INVALID_GRF_INCOMPATIBLE);
 			} else {
-				msg = "unknown";
+				SetDParam(1, STR_CONFIG_ERROR_INVALID_GRF_UNKNOWN);
 			}
 
-			ShowInfoF("ini: ignoring invalid NewGRF '%s': %s", item->name, msg);
+			SetDParamStr(0, item->name);
+			ShowErrorMessage(STR_CONFIG_ERROR, STR_CONFIG_ERROR_INVALID_GRF, WL_CRITICAL);
 			delete c;
 			continue;
 		}
@@ -1401,7 +1414,9 @@
 		bool duplicate = false;
 		for (const GRFConfig *gc = first; gc != NULL; gc = gc->next) {
 			if (gc->ident.grfid == c->ident.grfid) {
-				ShowInfoF("ini: ignoring  NewGRF '%s': duplicate GRF ID with '%s'", item->name, gc->filename);
+				SetDParamStr(0, item->name);
+				SetDParamStr(1, gc->filename);
+				ShowErrorMessage(STR_CONFIG_ERROR, STR_CONFIG_ERROR_DUPLICATE_GRFID, WL_CRITICAL);
 				duplicate = true;
 				break;
 			}