+ if (insert_location_sorted (source.location) || source.location != last_location) {
+ var config_dir = Path.build_filename (Environment.get_user_config_dir (), "cinaest");
+ var config_file = Path.build_filename (config_dir, "cinaest.cfg");
+
+ // Make sure the directory is available
+ DirUtils.create_with_parents (config_dir, 0770);
+
+ var keyfile = new KeyFile ();
+ try {
+ keyfile.load_from_file (config_file, KeyFileFlags.NONE);
+ } catch (Error e) {
+ if (!(e is KeyFileError.NOT_FOUND))
+ stdout.printf ("Error loading configuration: %s\n", e.message);
+ }
+ var l = new string[locations.length ()];
+ for (int i = 0; i < l.length; i++) {
+ l[i] = locations.nth_data (i);
+ }
+ keyfile.set_string_list ("GooglePlugin", "KnownLocations", l);
+ keyfile.set_string ("GooglePlugin", "LastLocation", source.location);
+ last_location = source.location;
+
+ try {
+ var file = File.new_for_path (config_file + ".part");
+ var stream = file.create (FileCreateFlags.REPLACE_DESTINATION, null);
+ var data = keyfile.to_data ();
+
+ stream.write (data, data.length, null);
+ FileUtils.rename (config_file + ".part", config_file);
+ } catch (Error e) {
+ stdout.printf ("Failed to store configuration: %s\n", e.message);
+ }
+ }