summaryrefslogtreecommitdiff
path: root/src/textfile_gui.cpp
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2012-02-12 10:51:43 +0000
committerrubidium <rubidium@openttd.org>2012-02-12 10:51:43 +0000
commit58269b7ad2a70b94de104ede2c69e126b58be534 (patch)
treed926e442ee19aed1792cdcada332e91ae5512a18 /src/textfile_gui.cpp
parent2a6e23263af057018ce1e90818467aded3dcd55f (diff)
downloadopenttd-58269b7ad2a70b94de104ede2c69e126b58be534.tar.xz
(svn r23935) -Codechange: generalise GetTextfile
Diffstat (limited to 'src/textfile_gui.cpp')
-rw-r--r--src/textfile_gui.cpp36
1 files changed, 36 insertions, 0 deletions
diff --git a/src/textfile_gui.cpp b/src/textfile_gui.cpp
index 93138eac3..3a4954323 100644
--- a/src/textfile_gui.cpp
+++ b/src/textfile_gui.cpp
@@ -192,3 +192,39 @@ TextfileWindow::TextfileWindow(TextfileType file_type) : Window(), file_type(fil
this->hscroll->SetCount(this->max_length + WD_FRAMETEXT_LEFT + WD_FRAMETEXT_RIGHT);
this->hscroll->SetStepSize(10); // Speed up horizontal scrollbar
}
+
+/**
+ * Search a textfile file next to the given content.
+ * @param type The type of the textfile to search for.
+ * @param dir The subdirectory to search in.
+ * @param filename The filename of the content to look for.
+ * @return The path to the textfile, \c NULL otherwise.
+ */
+const char *GetTextfile(TextfileType type, Subdirectory dir, const char *filename)
+{
+ static const char * const prefixes[] = {
+ "readme",
+ "changelog",
+ "license",
+ };
+ assert_compile(lengthof(prefixes) == TFT_END);
+
+ const char *prefix = prefixes[type];
+
+ if (filename == NULL) return NULL;
+
+ static char file_path[MAX_PATH];
+ strecpy(file_path, filename, lastof(file_path));
+
+ 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;
+
+ 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.txt", prefix);
+ return FioCheckFileExists(file_path, dir) ? file_path : NULL;
+}