mirror of https://github.com/OpenTTD/OpenTTD
(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.release/1.5
parent
e3791822b2
commit
815567c39b
|
@ -264,12 +264,19 @@ const char *GetTextfile(TextfileType type, Subdirectory dir, const char *filenam
|
||||||
char *slash = strrchr(file_path, PATHSEPCHAR);
|
char *slash = strrchr(file_path, PATHSEPCHAR);
|
||||||
if (slash == NULL) return NULL;
|
if (slash == NULL) return NULL;
|
||||||
|
|
||||||
seprintf(slash + 1, lastof(file_path), "%s_%s.txt", prefix, GetCurrentLanguageIsoCode());
|
static const char * const exts[] = {
|
||||||
if (FioCheckFileExists(file_path, dir)) return file_path;
|
"txt",
|
||||||
|
};
|
||||||
|
|
||||||
seprintf(slash + 1, lastof(file_path), "%s_%.2s.txt", prefix, GetCurrentLanguageIsoCode());
|
for (size_t i = 0; i < lengthof(exts); i++) {
|
||||||
if (FioCheckFileExists(file_path, dir)) return file_path;
|
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.txt", prefix);
|
seprintf(slash + 1, lastof(file_path), "%s_%.2s.%s", prefix, GetCurrentLanguageIsoCode(), exts[i]);
|
||||||
return FioCheckFileExists(file_path, dir) ? file_path : NULL;
|
if (FioCheckFileExists(file_path, dir)) return file_path;
|
||||||
|
|
||||||
|
seprintf(slash + 1, lastof(file_path), "%s.%s", prefix, exts[i]);
|
||||||
|
if (FioCheckFileExists(file_path, dir)) return file_path;
|
||||||
|
}
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue