summaryrefslogtreecommitdiff
path: root/src/textfile_gui.cpp
diff options
context:
space:
mode:
authormatthijs <matthijs@openttd.org>2014-10-23 10:49:14 +0000
committermatthijs <matthijs@openttd.org>2014-10-23 10:49:14 +0000
commit815567c39b34f9b72292f8701e5a108105e74db8 (patch)
treeb0131e75fbec69b50d1cc8387dbc59b17b8ba302 /src/textfile_gui.cpp
parente3791822b2c38ffd18770e524a75d2c7e8cf0832 (diff)
downloadopenttd-815567c39b34f9b72292f8701e5a108105e74db8.tar.xz
(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.
Diffstat (limited to 'src/textfile_gui.cpp')
-rw-r--r--src/textfile_gui.cpp19
1 files changed, 13 insertions, 6 deletions
diff --git a/src/textfile_gui.cpp b/src/textfile_gui.cpp
index ad6215af5..46bbc009a 100644
--- a/src/textfile_gui.cpp
+++ b/src/textfile_gui.cpp
@@ -264,12 +264,19 @@ const char *GetTextfile(TextfileType type, Subdirectory dir, const char *filenam
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;
}