[rhythmbox] mpid: try loading from resources as well as files



commit 48c6c3c539e5a343294fc965807fe4e618a001c3
Author: Jonathan Matthew <jonathan d14n org>
Date:   Mon Jul 18 20:36:57 2016 +1000

    mpid: try loading from resources as well as files

 lib/libmediaplayerid/mpid-files.c |   46 +++++++++++++++++++++++++++---------
 1 files changed, 34 insertions(+), 12 deletions(-)
---
diff --git a/lib/libmediaplayerid/mpid-files.c b/lib/libmediaplayerid/mpid-files.c
index d476a03..53054e9 100644
--- a/lib/libmediaplayerid/mpid-files.c
+++ b/lib/libmediaplayerid/mpid-files.c
@@ -16,23 +16,15 @@
  */
 
 #include <glib.h>
+#include <gio/gio.h>
 
 #include "mediaplayerid.h"
 #include "mpid-private.h"
 
-void
-mpid_read_device_file (MPIDDevice *device, const char *device_info_path)
+static void
+mpid_read_keyfile (MPIDDevice *device, GKeyFile *keyfile)
 {
        GError *error = NULL;
-       GKeyFile *keyfile;
-
-       keyfile = g_key_file_new ();
-       if (g_key_file_load_from_file (keyfile, device_info_path, G_KEY_FILE_NONE, &error) == FALSE) {
-               mpid_debug ("unable to read device info file %s: %s\n", device_info_path, error->message);
-               g_clear_error (&error);
-               device->error = MPID_ERROR_DEVICE_INFO_MISSING;
-               return;
-       }
 
        mpid_override_strv_from_keyfile (&device->access_protocols, keyfile, "Device", "AccessProtocol");
 
@@ -63,6 +55,37 @@ mpid_read_device_file (MPIDDevice *device, const char *device_info_path)
                }
        }
 
+}
+
+void
+mpid_read_device_file (MPIDDevice *device, const char *device_info_path)
+{
+       GError *error = NULL;
+       GKeyFile *keyfile;
+       GBytes *bytes;
+       gsize len;
+       const void *data;
+
+       keyfile = g_key_file_new ();
+       bytes = g_resources_lookup_data (device_info_path, G_RESOURCE_LOOKUP_FLAGS_NONE, &error);
+       if (bytes != NULL) {
+               data = g_bytes_get_data (bytes, &len);
+
+               if (g_key_file_load_from_data (keyfile, data, len, G_KEY_FILE_NONE, &error) == FALSE) {
+                       mpid_debug ("unable to read device info resource %s: %s\n", device_info_path, 
error->message);
+                       g_clear_error (&error);
+                       device->error = MPID_ERROR_DEVICE_INFO_MISSING;
+                       g_bytes_unref (bytes);
+                       return;
+               }
+       } else if (g_key_file_load_from_file (keyfile, device_info_path, G_KEY_FILE_NONE, &error) == FALSE) {
+               mpid_debug ("unable to read device info file %s: %s\n", device_info_path, error->message);
+               g_clear_error (&error);
+               device->error = MPID_ERROR_DEVICE_INFO_MISSING;
+               return;
+       }
+
+       mpid_read_keyfile (device, keyfile);
        g_key_file_free (keyfile);
 }
 
@@ -94,4 +117,3 @@ mpid_find_and_read_device_file (MPIDDevice *device, const char *device_file)
        device->error = MPID_ERROR_DEVICE_INFO_MISSING;
 }
 
-


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