[ghex] Figure out datadir at runtime on Windows



commit 51cd6108571962891d7b404f3d5357a5714f0885
Author: Kalev Lember <kalevlember gmail com>
Date:   Sat Feb 18 21:29:26 2012 +0200

    Figure out datadir at runtime on Windows
    
    Apps on Windows are supposed to be relocatable.

 src/ghex-window.c |   22 +++++++++++++++++++++-
 1 files changed, 21 insertions(+), 1 deletions(-)
---
diff --git a/src/ghex-window.c b/src/ghex-window.c
index c457627..c4cc3c2 100644
--- a/src/ghex-window.c
+++ b/src/ghex-window.c
@@ -510,6 +510,23 @@ ghex_window_destroy_contents (GHexWindow *win)
     win->contents = NULL;
 }
 
+static gchar *
+ghex_datadir (void)
+{
+    gchar *datadir;
+#ifdef G_OS_WIN32
+    gchar *dir;
+
+    dir = g_win32_get_package_installation_directory_of_module (NULL);
+    datadir = g_build_filename (dir, "share", "ghex", NULL);
+    g_free (dir);
+#else
+    datadir = g_strdup (GHEXDATADIR);
+#endif
+
+    return datadir;
+}
+
 static GObject *
 ghex_window_constructor (GType                  type,
                          guint                  n_construct_properties,
@@ -519,6 +536,7 @@ ghex_window_constructor (GType                  type,
     GHexWindow *window;
     GtkWidget  *menubar;
     GError     *error = NULL;
+    gchar      *datadir;
     gchar      *ui_path;
 
     object = G_OBJECT_CLASS (ghex_window_parent_class)->constructor (type,
@@ -559,12 +577,14 @@ ghex_window_constructor (GType                  type,
                                         window->doc_list_action_group, 0);
 
     /* Load menu description from file */
-    ui_path = g_build_filename (GHEXDATADIR, "ghex-ui.xml", NULL);
+    datadir = ghex_datadir ();
+    ui_path = g_build_filename (datadir, "ghex-ui.xml", NULL);
     if (!gtk_ui_manager_add_ui_from_file (window->ui_manager, ui_path, &error)) {
         g_warning ("Failed to load ui: %s", error->message);
         g_error_free (error);
     }
     g_free (ui_path);
+    g_free (datadir);
 
     window->vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
 



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