From 9ec70dabc502e9cc7e00b1dfd4e1cc4149c7dda0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Rosen?= Date: Mon, 5 Mar 2012 22:36:26 +0000 Subject: [PATCH] patch #3092 : Allow to specify default system-wide preferences by lipk --- CMakeLists.txt | 10 ++++++++++ SConstruct | 1 + data/core/about.cfg | 3 +++ src/SConscript | 8 ++++++++ src/filesystem.cpp | 9 +++++++++ src/filesystem.hpp | 1 + src/game_config.cpp | 6 ++++++ src/game_config.hpp | 1 + src/preferences.cpp | 11 +++++++++++ 9 files changed, 50 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 14b6aa10292..253274caa7d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -60,6 +60,7 @@ set(DATADIRNAME "wesnoth" CACHE STRING "change the name of the directory for the set(EXECUTABLE_OUTPUT_PATH "${CMAKE_BINARY_DIR}" CACHE STRING "change the dir where binaries are placed right at compile time") set(LOCALEDIR "translations" CACHE STRING "change the name of the locale data directory to a non-default name") set(PREFERENCES_DIR "" CACHE STRING "Use a non-default preferences directory (.wesnoth on unix)") +set(DEFAULT_PREFS_FILE "" CACHE STRING "Set system wide preferences file") #Game options option(ENABLE_FRIBIDI "Enable FriBIDi support" ON) @@ -171,6 +172,15 @@ if(PREFERENCES_DIR) add_definitions(-DPREFERENCES_DIR=\\\"${PREFERENCES_DIR}\\\") endif(PREFERENCES_DIR) + +if(DEFAULT_PREFS_FILE) + add_definitions(-DDEFAULT_PREFS_PATH=\\\"${DEFAULT_PREFS_FILE}\\\") + + if(NOT DEFAULT_PREFS_FILE MATCHES "^/") + add_definitions(-DHAS_RELATIVE_DEFPREF) + endif(NOT DEFAULT_PREFS_FILE MATCHES "^/") +endif(DEFAULT_PREFS_FILE) + if(ENABLE_LOW_MEM) add_definitions(-DLOW_MEM) endif(ENABLE_LOW_MEM) diff --git a/SConstruct b/SConstruct index 9280409f6d6..255ad1559a8 100755 --- a/SConstruct +++ b/SConstruct @@ -73,6 +73,7 @@ opts.AddVariables( BoolVariable('nls','enable compile/install of gettext message catalogs',True), PathVariable('prefix', 'autotools-style installation prefix', "/usr/local", PathVariable.PathAccept), PathVariable('prefsdir', 'user preferences directory', "", PathVariable.PathAccept), + PathVariable('default_prefs_file', 'default preferences file name', "", PathVariable.PathAccept), PathVariable('destdir', 'prefix to add to all installation paths.', "/", PathVariable.PathAccept), BoolVariable('prereqs','abort if prerequisites cannot be detected',True), ('program_suffix', 'suffix to append to names of installed programs',"$version_suffix"), diff --git a/data/core/about.cfg b/data/core/about.cfg index a5d3860400f..4da722c6b79 100644 --- a/data/core/about.cfg +++ b/data/core/about.cfg @@ -898,6 +898,9 @@ name = "Ben Anderman (crimson_penguin)" comment = "unit list" [/entry] + [entry] + name = "Boldizsár Lipka (lipk)" + [/entry] [entry] name = "Brilliand" [/entry] diff --git a/src/SConscript b/src/SConscript index f7f9941db45..0c3326a6466 100644 --- a/src/SConscript +++ b/src/SConscript @@ -60,6 +60,14 @@ if env["PLATFORM"] != "win32": if filesystem_env['prefsdir']: filesystem_env.Append(CPPDEFINES = "PREFERENCES_DIR='\"$prefsdir\"'") +if env['default_prefs_file']: + client_env.Append(CPPDEFINES = "DEFAULT_PREFS_PATH='\"$default_prefs_file\"'") + + game_config_env['default_prefs_file'] = env['default_prefs_file'] + game_config_env.Append(CPPDEFINES = "DEFAULT_PREFS_PATH='\"$default_prefs_file\"'") + if not os.path.isabs(env['default_prefs_file']): + filesystem_env.Append(CPPDEFINES = "HAS_RELATIVE_DEFPREF") + libwesnoth_core_sources.extend([ game_config_env.Object("game_config.cpp"), filesystem_env.Object("filesystem.cpp") diff --git a/src/filesystem.cpp b/src/filesystem.cpp index 5dfa694057b..07ecdfdbd58 100644 --- a/src/filesystem.cpp +++ b/src/filesystem.cpp @@ -287,6 +287,15 @@ std::string get_prefs_file() return get_user_config_dir() + "/preferences"; } +std::string get_default_prefs_file() +{ +#ifdef HAS_RELATIVE_DEFPREF + return game_config::path + "/" + game_config::default_preferences_path; +#else + return game_config::default_preferences_path; +#endif +} + std::string get_save_index_file() { return get_user_data_dir() + "/save_index"; diff --git a/src/filesystem.hpp b/src/filesystem.hpp index 5f396d69cc6..63f9355c345 100644 --- a/src/filesystem.hpp +++ b/src/filesystem.hpp @@ -63,6 +63,7 @@ std::string get_dir(const std::string &dir); // The location of various important files: std::string get_prefs_file(); +std::string get_default_prefs_file(); std::string get_save_index_file(); std::string get_saves_dir(); std::string get_intl_dir(); diff --git a/src/game_config.cpp b/src/game_config.cpp index fa3eb925354..9763bb20753 100644 --- a/src/game_config.cpp +++ b/src/game_config.cpp @@ -160,6 +160,12 @@ namespace game_config #endif #endif +#ifdef DEFAULT_PREFS_PATH + std::string default_preferences_path = DEFAULT_PREFS_PATH; +#else + std::string default_preferences_path = ""; +#endif + std::string preferences_dir = ""; std::vector server_list; diff --git a/src/game_config.hpp b/src/game_config.hpp index bb8f4b75a6e..72f7e1b9719 100644 --- a/src/game_config.hpp +++ b/src/game_config.hpp @@ -56,6 +56,7 @@ namespace game_config extern std::string path; extern std::string preferences_dir; + extern std::string default_preferences_path; struct server_info { server_info() : name(""), address("") { } diff --git a/src/preferences.cpp b/src/preferences.cpp index d5a7873b90c..31c7cc7aec1 100644 --- a/src/preferences.cpp +++ b/src/preferences.cpp @@ -55,8 +55,19 @@ namespace preferences { base_manager::base_manager() { +#ifdef DEFAULT_PREFS_PATH + scoped_istream stream = istream_file(get_default_prefs_file()); + read(prefs, *stream); + + config user_prefs; + stream = istream_file(get_prefs_file()); + read(user_prefs, *stream); + + prefs.merge_with(user_prefs); +#else scoped_istream stream = istream_file(get_prefs_file()); read(prefs, *stream); +#endif } base_manager::~base_manager()