patch #3092 : Allow to specify default system-wide preferences by lipk

This commit is contained in:
Jérémy Rosen 2012-03-05 22:36:26 +00:00
parent 1e2ab67f73
commit 9ec70dabc5
9 changed files with 50 additions and 0 deletions

View file

@ -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)

View file

@ -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"),

View file

@ -898,6 +898,9 @@
name = "Ben Anderman (crimson_penguin)"
comment = "unit list"
[/entry]
[entry]
name = "Boldizsár Lipka (lipk)"
[/entry]
[entry]
name = "Brilliand"
[/entry]

View file

@ -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")

View file

@ -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";

View file

@ -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();

View file

@ -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_info> server_list;

View file

@ -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("") { }

View file

@ -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()