Changeset - r27434:07a7eae56362
[Not reviewed]
master
0 1 0
Rubidium - 13 months ago 2023-05-24 20:40:12
rubidium@openttd.org
Codechange: use std::string to create error message about external files
1 file changed with 8 insertions and 17 deletions:
0 comments (0 inline, 0 general)
src/gfxinit.cpp
Show inline comments
 
@@ -121,38 +121,29 @@ void CheckExternalFiles()
 

	
 
	Debug(grf, 1, "Using the {} base graphics set", used_set->name);
 

	
 
	static const size_t ERROR_MESSAGE_LENGTH = 256;
 
	static const size_t MISSING_FILE_MESSAGE_LENGTH = 128;
 

	
 
	/* Allocate for a message for each missing file and for one error
 
	 * message per set.
 
	 */
 
	char error_msg[MISSING_FILE_MESSAGE_LENGTH * (GraphicsSet::NUM_FILES + SoundsSet::NUM_FILES) + 2 * ERROR_MESSAGE_LENGTH];
 
	error_msg[0] = '\0';
 
	char *add_pos = error_msg;
 
	const char *last = lastof(error_msg);
 

	
 
	std::string error_msg;
 
	auto output_iterator = std::back_inserter(error_msg);
 
	if (used_set->GetNumInvalid() != 0) {
 
		/* Not all files were loaded successfully, see which ones */
 
		add_pos += seprintf(add_pos, last, "Trying to load graphics set '%s', but it is incomplete. The game will probably not run correctly until you properly install this set or select another one. See section 4.1 of README.md.\n\nThe following files are corrupted or missing:\n", used_set->name.c_str());
 
		fmt::format_to(output_iterator, "Trying to load graphics set '{}', but it is incomplete. The game will probably not run correctly until you properly install this set or select another one. See section 4.1 of README.md.\n\nThe following files are corrupted or missing:\n", used_set->name);
 
		for (uint i = 0; i < GraphicsSet::NUM_FILES; i++) {
 
			MD5File::ChecksumResult res = GraphicsSet::CheckMD5(&used_set->files[i], BASESET_DIR);
 
			if (res != MD5File::CR_MATCH) add_pos += seprintf(add_pos, last, "\t%s is %s (%s)\n", used_set->files[i].filename.c_str(), res == MD5File::CR_MISMATCH ? "corrupt" : "missing", used_set->files[i].missing_warning.c_str());
 
			if (res != MD5File::CR_MATCH) fmt::format_to(output_iterator, "\t{} is {} ({})\n", used_set->files[i].filename, res == MD5File::CR_MISMATCH ? "corrupt" : "missing", used_set->files[i].missing_warning);
 
		}
 
		add_pos += seprintf(add_pos, last, "\n");
 
		fmt::format_to(output_iterator, "\n");
 
	}
 

	
 
	const SoundsSet *sounds_set = BaseSounds::GetUsedSet();
 
	if (sounds_set->GetNumInvalid() != 0) {
 
		add_pos += seprintf(add_pos, last, "Trying to load sound set '%s', but it is incomplete. The game will probably not run correctly until you properly install this set or select another one. See section 4.1 of README.md.\n\nThe following files are corrupted or missing:\n", sounds_set->name.c_str());
 
		fmt::format_to(output_iterator, "Trying to load sound set '{}', but it is incomplete. The game will probably not run correctly until you properly install this set or select another one. See section 4.1 of README.md.\n\nThe following files are corrupted or missing:\n", sounds_set->name);
 

	
 
		static_assert(SoundsSet::NUM_FILES == 1);
 
		/* No need to loop each file, as long as there is only a single
 
		 * sound file. */
 
		add_pos += seprintf(add_pos, last, "\t%s is %s (%s)\n", sounds_set->files->filename.c_str(), SoundsSet::CheckMD5(sounds_set->files, BASESET_DIR) == MD5File::CR_MISMATCH ? "corrupt" : "missing", sounds_set->files->missing_warning.c_str());
 
		fmt::format_to(output_iterator, "\t{} is {} ({})\n", sounds_set->files->filename, SoundsSet::CheckMD5(sounds_set->files, BASESET_DIR) == MD5File::CR_MISMATCH ? "corrupt" : "missing", sounds_set->files->missing_warning);
 
	}
 

	
 
	if (add_pos != error_msg) ShowInfoI(error_msg);
 
	if (!error_msg.empty()) ShowInfoI(error_msg);
 
}
 

	
 
/** Actually load the sprite tables. */
0 comments (0 inline, 0 general)