Patch: View base textfiles

Forum for technical discussions regarding development. If you have a general suggestion, problem or comment, please use one of the other forums.

Moderator: OpenTTD Developers

Post Reply
User avatar
Lord Aro
Tycoon
Tycoon
Posts: 2369
Joined: 25 Jun 2009 16:42
Location: Location, Location
Contact:

Patch: View base textfiles

Post by Lord Aro »

Hey all

I've been working on a patch that gives the ability to view OTTD textfiles (readme, changelog and license) ingame

It's functional, but due to the OS specific code, it probably only works on my computer (debian unstable)

therefore, i enclose the patch(es) and ask you to give me some hints as to adding some more (working) OS specific code

Code: Select all

/**
 * Get the location of the executable, e.g. openttd.exe
 * @return the location of the executable, as a string.
 */
const char *GetExecutableLocation()
{
	const char *path;
	char buf[1024];
	
	#if defined (WIN32) || defined (WIN64)
		GetModuleFileName(path, &size);
	#elif defined (__APPLE__)
		_NSGetExecutablePath(path, &size);
	#elif defined(UNIX)
		if (readlink("/proc/self/exe", buf, sizeof(buf)) == -1) path = buf;
	#elif defined(__FreeBSD__)
		int mib[4];
		mib[0] = CTL_KERN;
		mib[1] = KERN_PROC;
		mib[2] = KERN_PROC_PATHNAME;
		mib[3] = -1;
		sysctl(mib, 4, buf, sizeof(buf), NULL, 0); 
		path = buf;
	#elif defined(SUNOS)
		path = getexecname();
	#endif
	return path;
}
Attachments
03_also_look_for_COPYING_textfile.diff
(598 Bytes) Downloaded 152 times
04_add_executable_location_function.diff
(1.47 KiB) Downloaded 116 times
05_view_base_textfile.diff
(6.33 KiB) Downloaded 121 times
AroAI - A really feeble attempt at an AI

It is practically impossible to teach good programming to students that have had a prior exposure to BASIC: as potential programmers they are mentally mutilated beyond hope of regeneration. --Edsger Dijkstra
Eddi
Tycoon
Tycoon
Posts: 8271
Joined: 17 Jan 2007 00:14

Re: Patch: View base textfiles

Post by Eddi »

you should probably use the same mechanism as the search for the config file
frosch
OpenTTD Developer
OpenTTD Developer
Posts: 988
Joined: 20 Dec 2006 13:31
Location: Aschaffenburg

Re: Patch: View base textfiles

Post by frosch »

If you install OpenTTD on a *nix system, the location of the readme has no relation to the binary. The path to the documentation files is specified by the distributor using the "--prefix-dir" and "--doc-dir" arguments to "configure". You would have to pass these to the preprocessor using the "-D" compiler option or similar (maybe like the revision number if passer or whatever).
Usually this is something like "/usr/share/doc/openttd".
⢇⡸⢸⠢⡇⡇⢎⡁⢎⡱⢸⡱⢸⣭⠀⢸⢜⢸⢸⣀⢸⣀⢸⣭⢸⡱⠀⢰⠭⡆⣫⠰⣉⢸⢸⠀⢰⠭⡆⡯⡆⢹⠁⠀⢐⠰⡁
User avatar
ffpp
Engineer
Engineer
Posts: 125
Joined: 29 Jan 2010 12:56

Re: Patch: View base textfiles

Post by ffpp »

Or make an additional game option to set the standard path for the text files.
Preset by default in relation to the default install directory.
User avatar
Lord Aro
Tycoon
Tycoon
Posts: 2369
Joined: 25 Jun 2009 16:42
Location: Location, Location
Contact:

Re: Patch: View base textfiles

Post by Lord Aro »

ok, ok my idea of readme.txt always being next the binary was presumptuous. How would you recommend i do it? ;)
AroAI - A really feeble attempt at an AI

It is practically impossible to teach good programming to students that have had a prior exposure to BASIC: as potential programmers they are mentally mutilated beyond hope of regeneration. --Edsger Dijkstra
Rubidium
OpenTTD Developer
OpenTTD Developer
Posts: 3815
Joined: 09 Feb 2006 19:15

Re: Patch: View base textfiles

Post by Rubidium »

Lets add the next step of complexity to this equation: Debian also compresses the changelog/readme/known-bugs etc., and even renames some somewhat (no .txt in changelog.gz, but readme.txt.gz). Whether and how it happens for other non-Debian derived distributions I'm not sure, though it'll probably be safe to assume they use some sort of compression as well.
User avatar
Lord Aro
Tycoon
Tycoon
Posts: 2369
Joined: 25 Jun 2009 16:42
Location: Location, Location
Contact:

Re: Patch: View base textfiles

Post by Lord Aro »

Umm... ignore those? :D
AroAI - A really feeble attempt at an AI

It is practically impossible to teach good programming to students that have had a prior exposure to BASIC: as potential programmers they are mentally mutilated beyond hope of regeneration. --Edsger Dijkstra
Post Reply

Return to “OpenTTD Development”

Who is online

Users browsing this forum: No registered users and 23 guests