private static UserConfig config;
protected KeyFile key_file;
+ protected KeyFile sys_key_file;
public bool get_upnp_enabled () throws GLib.Error {
return this.get_bool ("general", ENABLED_KEY);
public UserConfig () throws Error {
this.key_file = new KeyFile ();
+ this.sys_key_file = new KeyFile ();
- var dirs = new string[2];
- dirs[0] = Environment.get_user_config_dir ();
- dirs[1] = BuildConfig.SYS_CONFIG_DIR;
+ var path = Path.build_filename (BuildConfig.SYS_CONFIG_DIR,
+ CONFIG_FILE);
- string path;
- this.key_file.load_from_dirs (CONFIG_FILE,
- dirs,
- out path,
- KeyFileFlags.KEEP_COMMENTS |
- KeyFileFlags.KEEP_TRANSLATIONS);
- debug ("Loaded user configuration from file '%s'", path);
+ this.sys_key_file.load_from_file (path,
+ KeyFileFlags.KEEP_COMMENTS |
+ KeyFileFlags.KEEP_TRANSLATIONS);
+ debug ("Loaded system configuration from file '%s'", path);
+
+ try {
+ path = Path.build_filename (Environment.get_user_config_dir (),
+ CONFIG_FILE);
+
+ this.key_file.load_from_file (path,
+ KeyFileFlags.KEEP_COMMENTS |
+ KeyFileFlags.KEEP_TRANSLATIONS);
+
+ debug ("Loaded user configuration from file '%s'", path);
+ } catch (Error error) {
+ debug ("Failed to load user configuration from file '%s': %s",
+ path,
+ error.message);
+ }
}
public bool get_enabled (string section) throws GLib.Error {
public string get_string (string section,
string key) throws GLib.Error {
- var val = this.key_file.get_string (section, key);
+ string val;
+
+ try {
+ val = this.key_file.get_string (section, key);
+ } catch (KeyFileError error) {
+ if (error is KeyFileError.KEY_NOT_FOUND ||
+ error is KeyFileError.GROUP_NOT_FOUND) {
+ val = this.sys_key_file.get_string (section, key);
+ } else {
+ throw error;
+ }
+ }
if (val == null || val == "") {
throw new ConfigurationError.NO_VALUE_SET
string key)
throws GLib.Error {
var str_list = new Gee.ArrayList<string> ();
- var strings = this.key_file.get_string_list (section, key);
+ string[] strings;
+
+ try {
+ strings = this.key_file.get_string_list (section, key);
+ } catch (KeyFileError error) {
+ if (error is KeyFileError.KEY_NOT_FOUND ||
+ error is KeyFileError.GROUP_NOT_FOUND) {
+ strings = this.sys_key_file.get_string_list (section, key);
+ } else {
+ throw error;
+ }
+ }
foreach (var str in strings) {
str_list.add (str);
int min,
int max)
throws GLib.Error {
- int val = this.key_file.get_integer (section, key);
+ int val;
+
+ try {
+ val = this.key_file.get_integer (section, key);
+ } catch (KeyFileError error) {
+ if (error is KeyFileError.KEY_NOT_FOUND ||
+ error is KeyFileError.GROUP_NOT_FOUND) {
+ val = this.sys_key_file.get_integer (section, key);
+ } else {
+ throw error;
+ }
+ }
if (val == 0 || val < min || val > max) {
throw new ConfigurationError.VALUE_OUT_OF_RANGE
string key)
throws GLib.Error {
var int_list = new Gee.ArrayList<int> ();
- var ints = this.key_file.get_integer_list (section, key);
+ int[] ints;
+
+ try {
+ ints = this.key_file.get_integer_list (section, key);
+ } catch (KeyFileError error) {
+ if (error is KeyFileError.KEY_NOT_FOUND ||
+ error is KeyFileError.GROUP_NOT_FOUND) {
+ ints = this.sys_key_file.get_integer_list (section, key);
+ } else {
+ throw error;
+ }
+ }
foreach (var num in ints) {
int_list.add (num);
public bool get_bool (string section,
string key)
throws GLib.Error {
- return this.key_file.get_boolean (section, key);
+ bool val;
+
+ try {
+ val = this.key_file.get_boolean (section, key);
+ } catch (KeyFileError error) {
+ if (error is KeyFileError.KEY_NOT_FOUND ||
+ error is KeyFileError.GROUP_NOT_FOUND) {
+ val = this.sys_key_file.get_boolean (section, key);
+ } else {
+ throw error;
+ }
+ }
+
+ return val;
}
}