[vinagre] Use g_get_system_data_dirs() to find data files



commit 3f96d292f3a2d1cbcf899b7774149437d00ad4be
Author: David King <amigadave amigadave com>
Date:   Thu Jun 30 17:41:33 2011 +0200

    Use g_get_system_data_dirs() to find data files
    
    In Vinagre.Dirs.get_package_data_file(), use g_get_system_data_dirs() to
    loop through the data directories and return the path to the first data
    file that exists. Check the path that was set when Vinagre was compiled
    first, followed by those obtained from the system. In this way, it is
    sufficient to set XDG_DATA_DIRS to make Vinagre relocatable, solving bug
    653722.

 vinagre/vinagre-dirs.vala |   33 ++++++++++++++++++++++-----------
 1 files changed, 22 insertions(+), 11 deletions(-)
---
diff --git a/vinagre/vinagre-dirs.vala b/vinagre/vinagre-dirs.vala
index f9bf03d..e9fbd80 100644
--- a/vinagre/vinagre-dirs.vala
+++ b/vinagre/vinagre-dirs.vala
@@ -27,19 +27,30 @@ namespace Vinagre.Dirs {
             Config.PACKAGE_TARNAME);
     }
 
-    // Only used by get_package_data_file ().
-    private string get_vinagre_data_dir () {
-#if ! G_OS_WIN32
-        // TODO: const string[] data_dirs = Environment.get_system_data_dirs ();
-        return Path.build_filename (Config.DATADIR, Config.PACKAGE_TARNAME);
-#else
+    public string get_package_data_file (string filename) {
+#if G_OS_WIN32
         return Path.build_filename (
             Win32.get_package_installation_directory_of_module (null), "share",
-            Config.PACKAGE_TARNAME);
-#endif
-    }
+            Config.PACKAGE_TARNAME, filename);
+#else
+        /* Check the compiled-in path first, so that if Vinagre is installed in
+         * a custom prefix and the standard prefix, the custom prefix is
+         * checked first. */
+        var system_data_dirs = Environment.get_system_data_dirs ();
+        string[] data_dirs = {};
+        data_dirs += Config.DATADIR;
+        foreach (var dir in system_data_dirs) { data_dirs += dir; };
 
-    public string get_package_data_file (string filename) {
-        return Path.build_filename (get_vinagre_data_dir (), filename);
+        foreach (var dir in data_dirs) {
+            var absolute_path = Path.build_filename (dir,
+                Config.PACKAGE_TARNAME, filename);
+            if (FileUtils.test (absolute_path, FileTest.EXISTS))
+                return absolute_path;
+        };
+
+        // Filename could not be found!
+        error ("Data file â%sâ could not be found in system data directories.",
+            filename);
+#endif
     }
 }



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]