Codechange: move misc settings to std::string
This commit is contained in:
		| @@ -24,7 +24,7 @@ | |||||||
|  |  | ||||||
| #include "safeguards.h" | #include "safeguards.h" | ||||||
|  |  | ||||||
| char _keyboard_opt[2][OSK_KEYBOARD_ENTRIES * 4 + 1]; | std::string _keyboard_opt[2]; | ||||||
| static WChar _keyboard[2][OSK_KEYBOARD_ENTRIES]; | static WChar _keyboard[2][OSK_KEYBOARD_ENTRIES]; | ||||||
|  |  | ||||||
| enum KeyStateBits { | enum KeyStateBits { | ||||||
| @@ -356,16 +356,16 @@ void GetKeyboardLayout() | |||||||
| 	char errormark[2][OSK_KEYBOARD_ENTRIES + 1]; // used for marking invalid chars | 	char errormark[2][OSK_KEYBOARD_ENTRIES + 1]; // used for marking invalid chars | ||||||
| 	bool has_error = false; // true when an invalid char is detected | 	bool has_error = false; // true when an invalid char is detected | ||||||
|  |  | ||||||
| 	if (StrEmpty(_keyboard_opt[0])) { | 	if (_keyboard_opt[0].empty()) { | ||||||
| 		GetString(keyboard[0], STR_OSK_KEYBOARD_LAYOUT, lastof(keyboard[0])); | 		GetString(keyboard[0], STR_OSK_KEYBOARD_LAYOUT, lastof(keyboard[0])); | ||||||
| 	} else { | 	} else { | ||||||
| 		strecpy(keyboard[0], _keyboard_opt[0], lastof(keyboard[0])); | 		strecpy(keyboard[0], _keyboard_opt[0].c_str(), lastof(keyboard[0])); | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	if (StrEmpty(_keyboard_opt[1])) { | 	if (_keyboard_opt[1].empty()) { | ||||||
| 		GetString(keyboard[1], STR_OSK_KEYBOARD_LAYOUT_CAPS, lastof(keyboard[1])); | 		GetString(keyboard[1], STR_OSK_KEYBOARD_LAYOUT_CAPS, lastof(keyboard[1])); | ||||||
| 	} else { | 	} else { | ||||||
| 		strecpy(keyboard[1], _keyboard_opt[1], lastof(keyboard[1])); | 		strecpy(keyboard[1], _keyboard_opt[1].c_str(), lastof(keyboard[1])); | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	for (uint j = 0; j < 2; j++) { | 	for (uint j = 0; j < 2; j++) { | ||||||
|   | |||||||
| @@ -64,7 +64,7 @@ FileToSaveLoad _file_to_saveload; ///< File to save or load in the openttd loop. | |||||||
| uint32 _ttdp_version;         ///< version of TTDP savegame (if applicable) | uint32 _ttdp_version;         ///< version of TTDP savegame (if applicable) | ||||||
| SaveLoadVersion _sl_version;  ///< the major savegame version identifier | SaveLoadVersion _sl_version;  ///< the major savegame version identifier | ||||||
| byte   _sl_minor_version;     ///< the minor savegame version, DO NOT USE! | byte   _sl_minor_version;     ///< the minor savegame version, DO NOT USE! | ||||||
| char _savegame_format[8];    ///< how to compress savegames | std::string _savegame_format; ///< how to compress savegames | ||||||
| bool _do_autosave;            ///< are we doing an autosave at the moment? | bool _do_autosave;            ///< are we doing an autosave at the moment? | ||||||
|  |  | ||||||
| /** What are we currently doing? */ | /** What are we currently doing? */ | ||||||
| @@ -2351,36 +2351,33 @@ static const SaveLoadFormat _saveload_formats[] = { | |||||||
| /** | /** | ||||||
|  * Return the savegameformat of the game. Whether it was created with ZLIB compression |  * Return the savegameformat of the game. Whether it was created with ZLIB compression | ||||||
|  * uncompressed, or another type |  * uncompressed, or another type | ||||||
|  * @param s Name of the savegame format. If nullptr it picks the first available one |  * @param full_name Name of the savegame format. If empty it picks the first available one | ||||||
|  * @param compression_level Output for telling what compression level we want. |  * @param compression_level Output for telling what compression level we want. | ||||||
|  * @return Pointer to SaveLoadFormat struct giving all characteristics of this type of savegame |  * @return Pointer to SaveLoadFormat struct giving all characteristics of this type of savegame | ||||||
|  */ |  */ | ||||||
| static const SaveLoadFormat *GetSavegameFormat(char *s, byte *compression_level) | static const SaveLoadFormat *GetSavegameFormat(const std::string &full_name, byte *compression_level) | ||||||
| { | { | ||||||
| 	const SaveLoadFormat *def = lastof(_saveload_formats); | 	const SaveLoadFormat *def = lastof(_saveload_formats); | ||||||
|  |  | ||||||
| 	/* find default savegame format, the highest one with which files can be written */ | 	/* find default savegame format, the highest one with which files can be written */ | ||||||
| 	while (!def->init_write) def--; | 	while (!def->init_write) def--; | ||||||
|  |  | ||||||
| 	if (!StrEmpty(s)) { | 	if (!full_name.empty()) { | ||||||
| 		/* Get the ":..." of the compression level out of the way */ | 		/* Get the ":..." of the compression level out of the way */ | ||||||
| 		char *complevel = strrchr(s, ':'); | 		size_t separator = full_name.find(':'); | ||||||
| 		if (complevel != nullptr) *complevel = '\0'; | 		bool has_comp_level = separator != std::string::npos; | ||||||
|  | 		const std::string name(full_name, 0, has_comp_level ? separator : full_name.size()); | ||||||
|  |  | ||||||
| 		for (const SaveLoadFormat *slf = &_saveload_formats[0]; slf != endof(_saveload_formats); slf++) { | 		for (const SaveLoadFormat *slf = &_saveload_formats[0]; slf != endof(_saveload_formats); slf++) { | ||||||
| 			if (slf->init_write != nullptr && strcmp(s, slf->name) == 0) { | 			if (slf->init_write != nullptr && name.compare(slf->name) == 0) { | ||||||
| 				*compression_level = slf->default_compression; | 				*compression_level = slf->default_compression; | ||||||
| 				if (complevel != nullptr) { | 				if (has_comp_level) { | ||||||
| 					/* There is a compression level in the string. | 					const std::string complevel(full_name, separator + 1); | ||||||
| 					 * First restore the : we removed to do proper name matching, |  | ||||||
| 					 * then move the the begin of the actual version. */ |  | ||||||
| 					*complevel = ':'; |  | ||||||
| 					complevel++; |  | ||||||
|  |  | ||||||
| 					/* Get the version and determine whether all went fine. */ | 					/* Get the level and determine whether all went fine. */ | ||||||
| 					char *end; | 					size_t processed; | ||||||
| 					long level = strtol(complevel, &end, 10); | 					long level = std::stol(complevel, &processed, 10); | ||||||
| 					if (end == complevel || level != Clamp(level, slf->min_compression, slf->max_compression)) { | 					if (processed == 0 || level != Clamp(level, slf->min_compression, slf->max_compression)) { | ||||||
| 						SetDParamStr(0, complevel); | 						SetDParamStr(0, complevel); | ||||||
| 						ShowErrorMessage(STR_CONFIG_ERROR, STR_CONFIG_ERROR_INVALID_SAVEGAME_COMPRESSION_LEVEL, WL_CRITICAL); | 						ShowErrorMessage(STR_CONFIG_ERROR, STR_CONFIG_ERROR_INVALID_SAVEGAME_COMPRESSION_LEVEL, WL_CRITICAL); | ||||||
| 					} else { | 					} else { | ||||||
| @@ -2391,12 +2388,9 @@ static const SaveLoadFormat *GetSavegameFormat(char *s, byte *compression_level) | |||||||
| 			} | 			} | ||||||
| 		} | 		} | ||||||
|  |  | ||||||
| 		SetDParamStr(0, s); | 		SetDParamStr(0, name); | ||||||
| 		SetDParamStr(1, def->name); | 		SetDParamStr(1, def->name); | ||||||
| 		ShowErrorMessage(STR_CONFIG_ERROR, STR_CONFIG_ERROR_INVALID_SAVEGAME_COMPRESSION_ALGORITHM, WL_CRITICAL); | 		ShowErrorMessage(STR_CONFIG_ERROR, STR_CONFIG_ERROR_INVALID_SAVEGAME_COMPRESSION_ALGORITHM, WL_CRITICAL); | ||||||
|  |  | ||||||
| 		/* Restore the string by adding the : back */ |  | ||||||
| 		if (complevel != nullptr) *complevel = ':'; |  | ||||||
| 	} | 	} | ||||||
| 	*compression_level = def->default_compression; | 	*compression_level = def->default_compression; | ||||||
| 	return def; | 	return def; | ||||||
|   | |||||||
| @@ -934,7 +934,7 @@ static inline void SlSkipBytes(size_t length) | |||||||
| 	for (; length != 0; length--) SlReadByte(); | 	for (; length != 0; length--) SlReadByte(); | ||||||
| } | } | ||||||
|  |  | ||||||
| extern char _savegame_format[8]; | extern std::string _savegame_format; | ||||||
| extern bool _do_autosave; | extern bool _do_autosave; | ||||||
|  |  | ||||||
| #endif /* SAVELOAD_H */ | #endif /* SAVELOAD_H */ | ||||||
|   | |||||||
| @@ -34,7 +34,7 @@ | |||||||
| static const char * const SCREENSHOT_NAME = "screenshot"; ///< Default filename of a saved screenshot. | static const char * const SCREENSHOT_NAME = "screenshot"; ///< Default filename of a saved screenshot. | ||||||
| static const char * const HEIGHTMAP_NAME  = "heightmap";  ///< Default filename of a saved heightmap. | static const char * const HEIGHTMAP_NAME  = "heightmap";  ///< Default filename of a saved heightmap. | ||||||
|  |  | ||||||
| char _screenshot_format_name[8];      ///< Extension of the current screenshot format (corresponds with #_cur_screenshot_format). | std::string _screenshot_format_name;  ///< Extension of the current screenshot format (corresponds with #_cur_screenshot_format). | ||||||
| uint _num_screenshot_formats;         ///< Number of available screenshot formats. | uint _num_screenshot_formats;         ///< Number of available screenshot formats. | ||||||
| uint _cur_screenshot_format;          ///< Index of the currently selected screenshot format in #_screenshot_formats. | uint _cur_screenshot_format;          ///< Index of the currently selected screenshot format in #_screenshot_formats. | ||||||
| static char _screenshot_name[128];    ///< Filename of the screenshot file. | static char _screenshot_name[128];    ///< Filename of the screenshot file. | ||||||
| @@ -584,7 +584,7 @@ void InitializeScreenshotFormats() | |||||||
| { | { | ||||||
| 	uint j = 0; | 	uint j = 0; | ||||||
| 	for (uint i = 0; i < lengthof(_screenshot_formats); i++) { | 	for (uint i = 0; i < lengthof(_screenshot_formats); i++) { | ||||||
| 		if (!strcmp(_screenshot_format_name, _screenshot_formats[i].extension)) { | 		if (_screenshot_format_name.compare(_screenshot_formats[i].extension) != 0) { | ||||||
| 			j = i; | 			j = i; | ||||||
| 			break; | 			break; | ||||||
| 		} | 		} | ||||||
|   | |||||||
| @@ -31,7 +31,7 @@ void MakeScreenshotWithConfirm(ScreenshotType t); | |||||||
| bool MakeScreenshot(ScreenshotType t, std::string name, uint32 width = 0, uint32 height = 0); | bool MakeScreenshot(ScreenshotType t, std::string name, uint32 width = 0, uint32 height = 0); | ||||||
| bool MakeMinimapWorldScreenshot(); | bool MakeMinimapWorldScreenshot(); | ||||||
|  |  | ||||||
| extern char _screenshot_format_name[8]; | extern std::string _screenshot_format_name; | ||||||
| extern uint _num_screenshot_formats; | extern uint _num_screenshot_formats; | ||||||
| extern uint _cur_screenshot_format; | extern uint _cur_screenshot_format; | ||||||
| extern char _full_screenshot_name[MAX_PATH]; | extern char _full_screenshot_name[MAX_PATH]; | ||||||
|   | |||||||
| @@ -23,7 +23,6 @@ static const SettingDescGlobVarList _misc_settings[] = { | |||||||
| SDTG_LIST  =  SDTG_LIST($name, $type, $length, $flags, $guiflags, $var, $def,                               $str, $strhelp, $strval, $proc, $from, $to, $cat, $extra, $startup), | SDTG_LIST  =  SDTG_LIST($name, $type, $length, $flags, $guiflags, $var, $def,                               $str, $strhelp, $strval, $proc, $from, $to, $cat, $extra, $startup), | ||||||
| SDTG_MMANY = SDTG_MMANY($name, $type,          $flags, $guiflags, $var, $def,                        $full, $str, $strhelp, $strval, $proc, $from, $to, $cat, $extra, $startup), | SDTG_MMANY = SDTG_MMANY($name, $type,          $flags, $guiflags, $var, $def,                        $full, $str, $strhelp, $strval, $proc, $from, $to, $cat, $extra, $startup), | ||||||
| SDTG_OMANY = SDTG_OMANY($name, $type,          $flags, $guiflags, $var, $def,       $max,            $full, $str, $strhelp, $strval, $proc, $from, $to, $cat, $extra, $startup), | SDTG_OMANY = SDTG_OMANY($name, $type,          $flags, $guiflags, $var, $def,       $max,            $full, $str, $strhelp, $strval, $proc, $from, $to, $cat, $extra, $startup), | ||||||
| SDTG_STR   =   SDTG_STR($name, $type,          $flags, $guiflags, $var, $def,                               $str, $strhelp, $strval, $proc, $from, $to, $cat, $extra, $startup), |  | ||||||
| SDTG_SSTR  =  SDTG_SSTR($name, $type,          $flags, $guiflags, $var, $def,                               $str, $strhelp, $strval, $proc, $from, $to, $cat, $extra, $startup), | SDTG_SSTR  =  SDTG_SSTR($name, $type,          $flags, $guiflags, $var, $def,                               $str, $strhelp, $strval, $proc, $from, $to, $cat, $extra, $startup), | ||||||
| SDTG_BOOL  =  SDTG_BOOL($name,                 $flags, $guiflags, $var, $def,                               $str, $strhelp, $strval, $proc, $from, $to, $cat, $extra, $startup), | SDTG_BOOL  =  SDTG_BOOL($name,                 $flags, $guiflags, $var, $def,                               $str, $strhelp, $strval, $proc, $from, $to, $cat, $extra, $startup), | ||||||
| SDTG_VAR   =   SDTG_VAR($name, $type,          $flags, $guiflags, $var, $def, $min, $max, $interval,        $str, $strhelp, $strval, $proc, $from, $to, $cat, $extra, $startup), | SDTG_VAR   =   SDTG_VAR($name, $type,          $flags, $guiflags, $var, $def, $min, $max, $interval,        $str, $strhelp, $strval, $proc, $from, $to, $cat, $extra, $startup), | ||||||
| @@ -156,16 +155,16 @@ var      = _cur_resolution | |||||||
| def      = ""0,0"" | def      = ""0,0"" | ||||||
| cat      = SC_BASIC | cat      = SC_BASIC | ||||||
|  |  | ||||||
| [SDTG_STR] | [SDTG_SSTR] | ||||||
| name     = ""screenshot_format"" | name     = ""screenshot_format"" | ||||||
| type     = SLE_STRB | type     = SLE_STR | ||||||
| var      = _screenshot_format_name | var      = _screenshot_format_name | ||||||
| def      = nullptr | def      = nullptr | ||||||
| cat      = SC_EXPERT | cat      = SC_EXPERT | ||||||
|  |  | ||||||
| [SDTG_STR] | [SDTG_SSTR] | ||||||
| name     = ""savegame_format"" | name     = ""savegame_format"" | ||||||
| type     = SLE_STRB | type     = SLE_STR | ||||||
| var      = _savegame_format | var      = _savegame_format | ||||||
| def      = nullptr | def      = nullptr | ||||||
| cat      = SC_EXPERT | cat      = SC_EXPERT | ||||||
| @@ -308,16 +307,16 @@ min      = 0 | |||||||
| max      = 0xFF | max      = 0xFF | ||||||
| cat      = SC_BASIC | cat      = SC_BASIC | ||||||
|  |  | ||||||
| [SDTG_STR] | [SDTG_SSTR] | ||||||
| name     = ""keyboard"" | name     = ""keyboard"" | ||||||
| type     = SLE_STRB | type     = SLE_STR | ||||||
| var      = _keyboard_opt[0] | var      = _keyboard_opt[0] | ||||||
| def      = nullptr | def      = nullptr | ||||||
| cat      = SC_EXPERT | cat      = SC_EXPERT | ||||||
|  |  | ||||||
| [SDTG_STR] | [SDTG_SSTR] | ||||||
| name     = ""keyboard_caps"" | name     = ""keyboard_caps"" | ||||||
| type     = SLE_STRB | type     = SLE_STR | ||||||
| var      = _keyboard_opt[1] | var      = _keyboard_opt[1] | ||||||
| def      = nullptr | def      = nullptr | ||||||
| cat      = SC_EXPERT | cat      = SC_EXPERT | ||||||
|   | |||||||
| @@ -37,8 +37,7 @@ static const uint OSK_KEYBOARD_ENTRIES = 50; | |||||||
| /** | /** | ||||||
|  * The number of characters has to be OSK_KEYBOARD_ENTRIES. However, these |  * The number of characters has to be OSK_KEYBOARD_ENTRIES. However, these | ||||||
|  * have to be UTF-8 encoded, which means up to 4 bytes per character. |  * have to be UTF-8 encoded, which means up to 4 bytes per character. | ||||||
|  * Furthermore the string needs to be '\0'-terminated. |  | ||||||
|  */ |  */ | ||||||
| extern char _keyboard_opt[2][OSK_KEYBOARD_ENTRIES * 4 + 1]; | extern std::string _keyboard_opt[2]; | ||||||
|  |  | ||||||
| #endif /* TEXTBUF_GUI_H */ | #endif /* TEXTBUF_GUI_H */ | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 rubidium42
					rubidium42