Changeset - r19067:8b759022e9ee
[Not reviewed]
master
0 3 0
rubidium - 13 years ago 2012-02-12 10:51:43
rubidium@openttd.org
(svn r23935) -Codechange: generalise GetTextfile
3 files changed with 40 insertions and 25 deletions:
0 comments (0 inline, 0 general)
src/newgrf_config.cpp
Show inline comments
 
@@ -20,6 +20,7 @@
 
#include "progress.h"
 
#include "video/video_driver.hpp"
 
#include "strings_func.h"
 
#include "textfile_gui.h"
 

	
 
#include "fileio_func.h"
 
#include "fios.h"
 
@@ -878,29 +879,5 @@ bool GRFConfig::IsOpenTTDBaseGRF() const
 
 */
 
const char *GRFConfig::GetTextfile(TextfileType type) const
 
{
 
	static const char * const prefixes[] = {
 
		"readme",
 
		"changelog",
 
		"license",
 
	};
 
	assert_compile(lengthof(prefixes) == TFT_END);
 

	
 
	const char *prefix = prefixes[type];
 

	
 
	if (this->filename == NULL) return NULL;
 

	
 
	static char file_path[MAX_PATH];
 
	strecpy(file_path, this->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, NEWGRF_DIR)) return file_path;
 

	
 
	seprintf(slash + 1, lastof(file_path), "%s_%.2s.txt", prefix, GetCurrentLanguageIsoCode());
 
	if (FioCheckFileExists(file_path, NEWGRF_DIR)) return file_path;
 

	
 
	seprintf(slash + 1, lastof(file_path), "%s.txt", prefix);
 
	return FioCheckFileExists(file_path, NEWGRF_DIR) ? file_path : NULL;
 
	return ::GetTextfile(type, NEWGRF_DIR, this->filename);
 
}
src/textfile_gui.cpp
Show inline comments
 
@@ -192,3 +192,39 @@ TextfileWindow::TextfileWindow(TextfileT
 
	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;
 
}
src/textfile_gui.h
Show inline comments
 
@@ -16,6 +16,8 @@
 
#include "textfile_type.h"
 
#include "window_gui.h"
 

	
 
const char *GetTextfile(TextfileType type, Subdirectory dir, const char *filename);
 

	
 
/** Window for displaying a textfile */
 
struct TextfileWindow : public Window, MissingGlyphSearcher {
 
	TextfileType file_type;              ///< Type of textfile to view.
0 comments (0 inline, 0 general)