Changeset - r21879:caf71a58a412
[Not reviewed]
master
0 1 0
matthijs - 10 years ago 2014-10-23 10:49:14
matthijs@openttd.org
(svn r27033) -Codechange: Generalize GetTextfile for multiple extensions
- Instead of hardcoding the .txt extension in a printf string, it is
now stored in an array of possible extensions. This array still only
contains .txt, so behaviour is unchanged, but this makes it easier
to add other extensions later.
1 file changed with 13 insertions and 6 deletions:
0 comments (0 inline, 0 general)
src/textfile_gui.cpp
Show inline comments
 
@@ -264,12 +264,19 @@ const char *GetTextfile(TextfileType typ
 
	char *slash = strrchr(file_path, PATHSEPCHAR);
 
	if (slash == NULL) return NULL;
 

	
 
	seprintf(slash + 1, lastof(file_path), "%s_%s.txt", prefix, GetCurrentLanguageIsoCode());
 
	if (FioCheckFileExists(file_path, dir)) return file_path;
 
	static const char * const exts[] = {
 
		"txt",
 
	};
 

	
 
	for (size_t i = 0; i < lengthof(exts); i++) {
 
		seprintf(slash + 1, lastof(file_path), "%s_%s.%s", prefix, GetCurrentLanguageIsoCode(), exts[i]);
 
		if (FioCheckFileExists(file_path, dir)) return file_path;
 

	
 
	seprintf(slash + 1, lastof(file_path), "%s_%.2s.txt", prefix, GetCurrentLanguageIsoCode());
 
	if (FioCheckFileExists(file_path, dir)) return file_path;
 
		seprintf(slash + 1, lastof(file_path), "%s_%.2s.%s", prefix, GetCurrentLanguageIsoCode(), exts[i]);
 
		if (FioCheckFileExists(file_path, dir)) return file_path;
 

	
 
	seprintf(slash + 1, lastof(file_path), "%s.txt", prefix);
 
	return FioCheckFileExists(file_path, dir) ? file_path : NULL;
 
		seprintf(slash + 1, lastof(file_path), "%s.%s", prefix, exts[i]);
 
		if (FioCheckFileExists(file_path, dir)) return file_path;
 
	}
 
	return NULL;
 
}
0 comments (0 inline, 0 general)