Changeset - r20928:e6a1e0b8d890
[Not reviewed]
master
0 6 0
rubidium - 11 years ago 2013-11-13 19:32:37
rubidium@openttd.org
(svn r25975) -Feature [FS#5385]: XDG base directory support
6 files changed with 122 insertions and 17 deletions:
0 comments (0 inline, 0 general)
config.lib
Show inline comments
 
@@ -69,12 +69,13 @@ set_default() {
 
	with_allegro="1"
 
	with_sdl="1"
 
	with_cocoa="1"
 
	with_zlib="1"
 
	with_lzma="1"
 
	with_lzo2="1"
 
	with_xdg_basedir="1"
 
	with_png="1"
 
	enable_builtin_depend="1"
 
	with_makedepend="0"
 
	with_direct_music="1"
 
	with_sort="1"
 
	with_iconv="1"
 
@@ -142,12 +143,13 @@ set_default() {
 
		with_allegro
 
		with_sdl
 
		with_cocoa
 
		with_zlib
 
		with_lzma
 
		with_lzo2
 
		with_xdg_basedir
 
		with_png
 
		enable_builtin_depend
 
		with_makedepend
 
		with_direct_music
 
		with_sort
 
		with_iconv
 
@@ -344,12 +346,19 @@ detect_params() {
 
			--without-lzo2)               with_lzo2="0";;
 
			--with-lzo2=*)                with_lzo2="$optarg";;
 
			--with-liblzo2)               with_lzo2="2";;
 
			--without-liblzo2)            with_lzo2="0";;
 
			--with-liblzo2=*)             with_lzo2="$optarg";;
 

	
 
			--with-xdg-basedir)           with_xdg_basedir="2";;
 
			--without-xdg-basedir)        with_xdg_basedir="0";;
 
			--with-xdg-basedir=*)         with_xdg_basedir="$optarg";;
 
			--with-libxdg-basedir)        with_xdg_basedir="2";;
 
			--without-libxdg-basedir)     with_xdg_basedir="0";;
 
			--with-libxdg-basedir=*)      with_xdg_basedir="$optarg";;
 

	
 
			--with-png)                   with_png="2";;
 
			--without-png)                with_png="0";;
 
			--with-png=*)                 with_png="$optarg";;
 
			--with-libpng)                with_png="2";;
 
			--without-libpng)             with_png="0";;
 
			--with-libpng=*)              with_png="$optarg";;
 
@@ -815,12 +824,13 @@ check_params() {
 
			log 1 "configure: error: no liblzo2 detected"
 
			log 1 " If you want to compile without liblzo2 use --without-liblzo2 as parameter"
 
			exit
 
		fi
 
	fi
 

	
 
	detect_xdg_basedir
 
	detect_png
 
	detect_freetype
 
	detect_fontconfig
 
	detect_icu
 
	detect_pspconfig
 
	detect_libtimidity
 
@@ -1658,12 +1668,23 @@ make_cflags_and_ldflags() {
 
		else
 
			LIBS="$LIBS -llzo2"
 
		fi
 
		CFLAGS="$CFLAGS -DWITH_LZO"
 
	fi
 

	
 
	if [ -n "$xdg_basedir_config" ]; then
 
		CFLAGS="$CFLAGS -DWITH_XDG_BASEDIR"
 
		CFLAGS="$CFLAGS `$xdg_basedir_config --cflags | tr '\n\r' '  '`"
 

	
 
		if [ "$enable_static" != "0" ]; then
 
			LIBS="$LIBS `$xdg_basedir_config --libs --static | tr '\n\r' '  '`"
 
		else
 
			LIBS="$LIBS `$xdg_basedir_config --libs | tr '\n\r' '  '`"
 
		fi
 
	fi
 

	
 
	# 64bit machines need -D_SQ64
 
	if [ "$cpu_type" = "64" ] && [ "$enable_universal" = "0" ]; then
 
		CFLAGS="$CFLAGS -D_SQ64"
 
	fi
 
	CFLAGS="$CFLAGS -I$SCRIPT_SRC_DIR"
 

	
 
@@ -2719,12 +2740,50 @@ detect_lzma() {
 
		return 0
 
	fi
 

	
 
	log 1 "checking liblzma... found"
 
}
 

	
 
detect_xdg_basedir() {
 
	# 0 means no, 1 is auto-detect, 2 is force
 
	if [ "$with_xdg_basedir" = "0" ]; then
 
		log 1 "checking libxdg_basedir... disabled"
 

	
 
		xdg_basedir_config=""
 
		return 0
 
	fi
 

	
 
	if [ "$with_xdg_basedir" = "1" ] || [ "$with_xdg_basedir" = "" ] || [ "$with_xdg_basedir" = "2" ]; then
 
		xdg_basedir_config="pkg-config libxdg-basedir"
 
	else
 
		xdg_basedir_config="$with_xdg_basedir"
 
	fi
 

	
 
	version=`$xdg_basedir_config --modversion 2>/dev/null`
 
	ret=$?
 
	log 2 "executing $xdg_basedir_config --modversion"
 
	log 2 "  returned $version"
 
	log 2 "  exit code $ret"
 

	
 
	if [ -z "$version" ] || [ "$ret" != "0" ]; then
 
		log 1 "checking libxdg_basedir... not found"
 

	
 
		# It was forced, so it should be found.
 
		if [ "$with_xdg_basedir" != "1" ]; then
 
			log 1 "configure: error: pkg-config libxdg_basedir couldn't be found"
 
			log 1 "configure: error: you supplied '$with_xdg_basedir', but it seems invalid"
 
			exit 1
 
		fi
 

	
 
		xdg_basedir_config=""
 
		return 0
 
	fi
 

	
 
	log 1 "checking libxdg_basedir... found"
 
}
 

	
 
detect_png() {
 
	# 0 means no, 1 is auto-detect, 2 is force
 
	if [ "$with_png" = "0" ]; then
 
		log 1 "checking libpng... disabled"
 

	
 
		png_config=""
 
@@ -3639,12 +3698,14 @@ showhelp() {
 
	echo "  --with-liblzo2[=liblzo2.a]     enables liblzo2 support"
 
	echo "  --with-png[=libpng-config]     enables libpng support"
 
	echo "  --with-freetype[=freetype-config]"
 
	echo "                                 enables libfreetype support"
 
	echo "  --with-fontconfig[=pkg-config fontconfig]"
 
	echo "                                 enables fontconfig support"
 
	echo "  --with-xdg-basedir[=pkg-config libxdg-basedir]"
 
	echo "                                 enables fontconfig support"
 
	echo "  --with-icu[=icu-config]        enables icu (used for right-to-left support)"
 
	echo "  --static-icu                   try to link statically (libsicu instead of"
 
	echo "                                 libicu; can fail as the new name is guessed)"
 
	echo "  --with-iconv[=iconv-path]      enables iconv support"
 
	echo "  --with-psp-config[=psp-config] enables psp-config support (PSP ONLY)"
 
	echo "  --disable-builtin-depend       disable use of builtin deps finder"
os/debian/control
Show inline comments
 
Source: openttd
 
Section: games
 
Priority: optional
 
Maintainer: Matthijs Kooijman <matthijs@stdin.nl>
 
Uploaders: Jordi Mallach <jordi@debian.org>
 
DM-Upload-Allowed: yes
 
Build-Depends: debhelper (>= 7.0.50), libsdl-dev, zlib1g-dev, libpng-dev, libfreetype6-dev, libfontconfig-dev, libicu-dev, liblzma-dev, liblzo2-dev
 
Build-Depends: debhelper (>= 7.0.50), libsdl-dev, zlib1g-dev, libpng-dev, libfreetype6-dev, libfontconfig-dev, libicu-dev, liblzma-dev, liblzo2-dev, libxdg-basedir-dev
 
Standards-Version: 3.8.4
 
Vcs-Browser: http://git.debian.org/?p=collab-maint/openttd.git
 
Vcs-Git: git://git.debian.org/collab-maint/openttd.git
 
Homepage: http://www.openttd.org/
 

	
 
Package: openttd
os/debian/rules
Show inline comments
 
@@ -14,13 +14,13 @@ endif
 

	
 
# Pass custom options to configure. Since it's not autoconf but a custom
 
# script, some of the option names are slightly different. We also need
 
# to be explicit about the dependencies, in case we're not running in a
 
# clean build root.
 
override_dh_auto_configure:
 
	./configure $(CROSS) --prefix-dir=/usr --install-dir=debian/openttd --without-allegro --with-zlib --with-sdl --with-png --with-freetype --with-fontconfig --with-icu --with-liblzo2 --with-lzma --without-iconv --disable-strip CFLAGS="$(CFLAGS) -g" LDFLAGS="$(LDFLAGS) -Wl,-as-needed"
 
	./configure $(CROSS) --prefix-dir=/usr --install-dir=debian/openttd --without-allegro --with-zlib --with-sdl --with-png --with-freetype --with-fontconfig --with-icu --with-liblzo2 --with-lzma --with-xdg-basedir --without-iconv --disable-strip CFLAGS="$(CFLAGS) -g" LDFLAGS="$(LDFLAGS) -Wl,-as-needed"
 

	
 
# Do some extra installation
 
override_dh_auto_install:
 
	$(MAKE) install DO_NOT_INSTALL_CHANGELOG=1 DO_NOT_INSTALL_LICENSE=1
 

	
 
	# Install the wrapper and make it executable
readme.txt
Show inline comments
 
@@ -279,13 +279,14 @@ your operating system:
 
		root directory, i.e. '/'.
 
	2. Your personal directory
 
		Windows: C:\My Documents\OpenTTD (95, 98, ME)
 
		         C:\Documents and Settings\<username>\My Documents\OpenTTD (2000, XP)
 
		         C:\Users\<username>\Documents\OpenTTD (Vista, 7)
 
		Mac OSX: ~/Documents/OpenTTD
 
		Linux:   ~/.openttd
 
		Linux:   $XDG_DATA_HOME/openttd which is usually ~/.local/share/openttd when
 
		         built with XDG base directory support, otherwise ~/.openttd
 
	3. The shared directory
 
		Windows: C:\Documents and Settings\All Users\Shared Documents\OpenTTD (2000, XP)
 
		         C:\Users\Public\Documents\OpenTTD (Vista, 7)
 
		Mac OSX: /Library/Application Support/OpenTTD
 
		Linux:   not available
 
	4. The binary directory (where the OpenTTD executable is)
 
@@ -319,16 +320,19 @@ use and no files should be added to it o
 

	
 
Notes:
 
	- Linux in the previous list means .deb, but most paths should be similar for
 
	  others.
 
	- The previous search order is also used for NewGRFs and openttd.cfg.
 
	- If openttd.cfg is not found, then it will be created using the 2, 4, 1, 3,
 
	  5 order.
 
	  5 order. When built with XDG base directory support, openttd.cfg will be
 
	  created in $XDG_CONFIG_HOME/openttd which is usually ~/.config/openttd.
 
	- Savegames will be relative to the config file only if there is no save/
 
	  directory in paths with higher priority than the config file path, but
 
	  autosaves and screenshots will always be relative to the config file.
 
	  Unless the configuration file is in $XDG_CONFIG_HOME/openttd, then all
 
	  other files will be saved under $XDG_DATA_HOME/openttd.
 

	
 
The preferred setup:
 
Place 3rd party files in shared directory (or in personal directory if you do
 
not have write access on shared directory) and have your openttd.cfg config
 
file in personal directory (where the game will then also place savegames and
 
screenshots).
src/fileio.cpp
Show inline comments
 
@@ -25,12 +25,16 @@
 
#include <unistd.h>
 
#include <pwd.h>
 
#endif
 
#include <sys/stat.h>
 
#include <algorithm>
 

	
 
#ifdef WITH_XDG_BASEDIR
 
#include "basedir.h"
 
#endif
 

	
 
/** Size of the #Fio data buffer. */
 
#define FIO_BUFFER_SIZE 512
 

	
 
/** Structure for keeping several open files with just one data buffer. */
 
struct Fio {
 
	byte *buffer, *buffer_end;             ///< position pointer in local buffer and last valid byte of buffer
 
@@ -1068,12 +1072,18 @@ bool DoScanWorkingDirectory()
 
 * Determine the base (personal dir and game data dir) paths
 
 * @param exe the path to the executable
 
 */
 
void DetermineBasePaths(const char *exe)
 
{
 
	char tmp[MAX_PATH];
 
#if defined(WITH_XDG_BASEDIR) && defined(WITH_PERSONAL_DIR)
 
	snprintf(tmp, MAX_PATH, "%s" PATHSEP "%s", xdgDataHome(NULL),
 
			PERSONAL_DIR[0] == '.' ? &PERSONAL_DIR[1] : PERSONAL_DIR);
 
	AppendPathSeparator(tmp, MAX_PATH);
 
	_searchpaths[SP_PERSONAL_DIR_XDG] = strdup(tmp);
 
#endif
 
#if defined(__MORPHOS__) || defined(__AMIGA__) || defined(DOS) || defined(OS2) || !defined(WITH_PERSONAL_DIR)
 
	_searchpaths[SP_PERSONAL_DIR] = NULL;
 
#else
 
#ifdef __HAIKU__
 
	BPath path;
 
	find_directory(B_USER_SETTINGS_DIRECTORY, &path);
 
@@ -1152,62 +1162,89 @@ const char *_personal_dir;
 
 * @param exe the path from the current path to the executable
 
 */
 
void DeterminePaths(const char *exe)
 
{
 
	DetermineBasePaths(exe);
 

	
 
#if defined(WITH_XDG_BASEDIR) && defined(WITH_PERSONAL_DIR)
 
	char config_home[MAX_PATH];
 
	snprintf(config_home, MAX_PATH, "%s" PATHSEP "%s", xdgConfigHome(NULL),
 
			PERSONAL_DIR[0] == '.' ? &PERSONAL_DIR[1] : PERSONAL_DIR);
 
	AppendPathSeparator(config_home, MAX_PATH);
 
#endif
 

	
 
	Searchpath sp;
 
	FOR_ALL_SEARCHPATHS(sp) {
 
		if (sp == SP_WORKING_DIR && !_do_scan_working_directory) continue;
 
		DEBUG(misc, 4, "%s added as search path", _searchpaths[sp]);
 
	}
 

	
 
	char *config_dir;
 
	if (_config_file != NULL) {
 
		char *dir = strdup(_config_file);
 
		char *end = strrchr(dir, PATHSEPCHAR);
 
		config_dir = strdup(_config_file);
 
		char *end = strrchr(config_dir, PATHSEPCHAR);
 
		if (end == NULL) {
 
			dir[0] = '\0';
 
			config_dir[0] = '\0';
 
		} else {
 
			end[1] = '\0';
 
		}
 
		_personal_dir = dir;
 
	} else {
 
		char personal_dir[MAX_PATH];
 
		if (FioFindFullPath(personal_dir, lengthof(personal_dir), BASE_DIR, "openttd.cfg") != NULL) {
 
			char *end = strrchr(personal_dir, PATHSEPCHAR);
 
			if (end != NULL) end[1] = '\0';
 
			_personal_dir = strdup(personal_dir);
 
			_config_file = str_fmt("%sopenttd.cfg", _personal_dir);
 
			config_dir = strdup(personal_dir);
 
			_config_file = str_fmt("%sopenttd.cfg", config_dir);
 
		} else {
 
#if defined(WITH_XDG_BASEDIR) && defined(WITH_PERSONAL_DIR)
 
			/* No previous configuration file found. Use the configuration folder from XDG. */
 
			config_dir = config_home;
 
#else
 
			static const Searchpath new_openttd_cfg_order[] = {
 
					SP_PERSONAL_DIR, SP_BINARY_DIR, SP_WORKING_DIR, SP_SHARED_DIR, SP_INSTALLATION_DIR
 
				};
 

	
 
			for (uint i = 0; i < lengthof(new_openttd_cfg_order); i++) {
 
				if (IsValidSearchPath(new_openttd_cfg_order[i])) {
 
					_personal_dir = strdup(_searchpaths[new_openttd_cfg_order[i]]);
 
					_config_file = str_fmt("%sopenttd.cfg", _personal_dir);
 
					config_dir = strdup(_searchpaths[new_openttd_cfg_order[i]]);
 
					break;
 
				}
 
			}
 
#endif
 
			_config_file = str_fmt("%sopenttd.cfg", config_dir);
 
		}
 
	}
 

	
 
	DEBUG(misc, 3, "%s found as personal directory", _personal_dir);
 
	DEBUG(misc, 3, "%s found as config directory", config_dir);
 

	
 
	_highscore_file = str_fmt("%shs.dat", _personal_dir);
 
	_highscore_file = str_fmt("%shs.dat", config_dir);
 
	extern char *_hotkeys_file;
 
	_hotkeys_file = str_fmt("%shotkeys.cfg", _personal_dir);
 
	_hotkeys_file = str_fmt("%shotkeys.cfg", config_dir);
 
	extern char *_windows_file;
 
	_windows_file = str_fmt("%swindows.cfg", _personal_dir);
 
	_windows_file = str_fmt("%swindows.cfg", config_dir);
 

	
 
#if defined(WITH_XDG_BASEDIR) && defined(WITH_PERSONAL_DIR)
 
	if (config_dir == config_home) {
 
		/* We are using the XDG configuration home for the config file,
 
		 * then store the rest in the XDG data home folder. */
 
		_personal_dir = _searchpaths[SP_PERSONAL_DIR_XDG];
 
		FioCreateDirectory(_personal_dir);
 
	} else
 
#endif
 
	{
 
		_personal_dir = config_dir;
 
	}
 

	
 
	/* Make the necessary folders */
 
#if !defined(__MORPHOS__) && !defined(__AMIGA__) && defined(WITH_PERSONAL_DIR)
 
	FioCreateDirectory(_personal_dir);
 
	FioCreateDirectory(config_dir);
 
	if (config_dir != _personal_dir) FioCreateDirectory(_personal_dir);
 
#endif
 

	
 
	DEBUG(misc, 3, "%s found as personal directory", _personal_dir);
 

	
 
	static const Subdirectory default_subdirs[] = {
 
		SAVE_DIR, AUTOSAVE_DIR, SCENARIO_DIR, HEIGHTMAP_DIR, BASESET_DIR, NEWGRF_DIR, AI_DIR, AI_LIBRARY_DIR, GAME_DIR, GAME_LIBRARY_DIR, SCREENSHOT_DIR
 
	};
 

	
 
	for (uint i = 0; i < lengthof(default_subdirs); i++) {
 
		char *dir = str_fmt("%s%s", _personal_dir, _subdirs[default_subdirs[i]]);
src/fileio_type.h
Show inline comments
 
@@ -40,12 +40,15 @@ enum Subdirectory {
 
/**
 
 * Types of searchpaths OpenTTD might use
 
 */
 
enum Searchpath {
 
	SP_FIRST_DIR,
 
	SP_WORKING_DIR = SP_FIRST_DIR, ///< Search in the working directory
 
#if defined(WITH_XDG_BASEDIR) && defined(WITH_PERSONAL_DIR)
 
	SP_PERSONAL_DIR_XDG,           ///< Search in the personal directory from the XDG specification
 
#endif
 
	SP_PERSONAL_DIR,               ///< Search in the personal directory
 
	SP_SHARED_DIR,                 ///< Search in the shared directory, like 'Shared Files' under Windows
 
	SP_BINARY_DIR,                 ///< Search in the directory where the binary resides
 
	SP_INSTALLATION_DIR,           ///< Search in the installation directory
 
	SP_APPLICATION_BUNDLE_DIR,     ///< Search within the application bundle
 
	SP_AUTODOWNLOAD_DIR,           ///< Search within the autodownload directory
0 comments (0 inline, 0 general)