[snappy] Make snappy relocatable



commit 722d975f388f6e8da68fc34cc5756ead085c0633
Author: Andoni Morales Alastruey <ylatuya gmail com>
Date:   Thu Jun 7 15:31:57 2012 +0200

    Make snappy relocatable
    
    Signed-off-by: Luis de Bethencourt <luis debethencourt com>

 src/snappy.c         |   28 ++++++++++++++++++++++++++++
 src/user_interface.c |   16 ++++++++--------
 src/user_interface.h |    1 +
 3 files changed, 37 insertions(+), 8 deletions(-)
---
diff --git a/src/snappy.c b/src/snappy.c
index 51811ea..d8d499c 100644
--- a/src/snappy.c
+++ b/src/snappy.c
@@ -166,11 +166,38 @@ main (int argc, char *argv[])
   gchar *version_str;
   GList *uri_list;
   GOptionContext *context;
+  gchar *data_dir;
 
 #ifdef ENABLE_DBUS
   SnappyMP *mp_obj = NULL;
 #endif
 
+
+  /* Try to find the path for our resources in case snappy was relocated */
+  data_dir = g_strdup(SNAPPY_DATA_DIR);
+  if (!g_file_test(data_dir, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR)) {
+    gchar *root_dir;
+
+#ifdef G_OS_WIN32
+    root_dir = g_win32_get_package_installation_directory_of_module(NULL);
+#elif !defined(G_OS_UNIX)
+    gchar *exec_path;
+    gchar *bin_dir;
+
+    exec_path = g_file_read_link("/proc/self/exe", NULL);
+    bin_dir = g_path_get_dirname(exec_path);
+    root_dir = g_build_filename(bin_dir, "..", NULL);
+    g_free(exec_path);
+    g_free(bin_dir);
+#else
+    root_dir = NULL;
+#endif
+    if (root_dir != NULL) {
+      data_dir = g_build_filename(root_dir, "share", "snappy", NULL);
+      g_free(root_dir);
+    }
+  }
+
   if (!g_thread_supported ())
     g_thread_init (NULL);
 
@@ -189,6 +216,7 @@ main (int argc, char *argv[])
   ui->fullscreen = fullscreen;
   ui->hide = hide;
   ui->tags = tags;
+  ui->data_dir = data_dir;
   interface_init (ui);
   video_texture = clutter_texture_new ();
 
diff --git a/src/user_interface.c b/src/user_interface.c
index 99f064b..1dba97f 100644
--- a/src/user_interface.c
+++ b/src/user_interface.c
@@ -402,20 +402,20 @@ load_controls (UserInterface * ui)
   ClutterActor *vol_int_box = NULL;
   GError *error = NULL;
 
-  vid_panel_png = g_build_filename (SNAPPY_DATA_DIR, "vid-panel.png", NULL);
-  ui->play_png = g_build_filename (SNAPPY_DATA_DIR, "media-actions-start.png",
+  vid_panel_png = g_build_filename (ui->data_dir, "vid-panel.png", NULL);
+  ui->play_png = g_build_filename (ui->data_dir, "media-actions-start.png",
       NULL);
-  ui->pause_png = g_build_filename (SNAPPY_DATA_DIR, "media-actions-pause.png",
+  ui->pause_png = g_build_filename (ui->data_dir, "media-actions-pause.png",
       NULL);
-  ui->volume_low_png = g_build_filename (SNAPPY_DATA_DIR,
+  ui->volume_low_png = g_build_filename (ui->data_dir,
       "audio-volume-low.png", NULL);
-  ui->volume_high_png = g_build_filename (SNAPPY_DATA_DIR,
+  ui->volume_high_png = g_build_filename (ui->data_dir,
       "audio-volume-high.png", NULL);
-  ui->subtitle_toggle_png = g_build_filename (SNAPPY_DATA_DIR,
+  ui->subtitle_toggle_png = g_build_filename (ui->data_dir,
       "subtitle-toggle.png", NULL);
-  ui->video_stream_toggle_png = g_build_filename (SNAPPY_DATA_DIR,
+  ui->video_stream_toggle_png = g_build_filename (ui->data_dir,
       "video-stream-toggle.png", NULL);
-  ui->audio_stream_toggle_png = g_build_filename (SNAPPY_DATA_DIR,
+  ui->audio_stream_toggle_png = g_build_filename (ui->data_dir,
       "audio-stream-toggle.png", NULL);
 
   icon_files[0] = vid_panel_png;
diff --git a/src/user_interface.h b/src/user_interface.h
index b7f7a28..6264141 100644
--- a/src/user_interface.h
+++ b/src/user_interface.h
@@ -91,6 +91,7 @@ struct _UserInterface
   gchar *volume_low_png, *volume_high_png;
   gchar *subtitle_toggle_png;
   gchar *video_stream_toggle_png, *audio_stream_toggle_png;
+  gchar *data_dir;
   gchar *duration_str;
 
   GList *uri_list;



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