Update of /cvsroot/gtkpod/libgpod/src
In directory sc8-pr-cvs2.sourceforge.net:/tmp/cvs-serv18826/src

Modified Files:
        itdb.h itdb_device.c itdb_device.h itdb_itunesdb.c 
        itdb_photoalbum.c 
Log Message:
        * src/itdb.h
          src/itdb_device.c:
          Added itdb_device_write_sysinfo() and itdb_device_set_sysinfo().

        * src/itdb_itunesdb.c (itdb_create_directories):
          Use functions introduced above.

          (itdb_write): Write SynsInfo file when writing the iTunesDB if
          SysInfo hash has been changed by application.

        * src/itdb_device.[ch]: mark sysinfo hash as changed/unchanged.

        * src/itdb_photoalbum.c (itdb_photodb_write): Write SynsInfo file
          when writing the iTunesDB if SysInfo hash has been changed by
          application.



Index: itdb.h
===================================================================
RCS file: /cvsroot/gtkpod/libgpod/src/itdb.h,v
retrieving revision 1.37
retrieving revision 1.38
diff -u -d -r1.37 -r1.38
--- itdb.h      5 Jun 2006 15:14:14 -0000       1.37
+++ itdb.h      7 Jun 2006 15:41:50 -0000       1.38
@@ -1,4 +1,4 @@
-/* Time-stamp: <2006-06-06 00:13:08 jcs>
+/* Time-stamp: <2006-06-07 00:56:08 jcs>
 |
 |  Copyright (C) 2002-2005 Jorg Schuler <jcsjcs at users sourceforge net>
 |  Part of the gtkpod project.
@@ -862,7 +862,10 @@
 void itdb_device_free (Itdb_Device *device);
 void itdb_device_set_mountpoint (Itdb_Device *device, const gchar *mp);
 gboolean itdb_device_read_sysinfo (Itdb_Device *device);
+gboolean itdb_device_write_sysinfo (Itdb_Device *device, GError **error);
 gchar *itdb_device_get_sysinfo (Itdb_Device *device, const gchar *field);
+void itdb_device_set_sysinfo (Itdb_Device *device,
+                             const gchar *field, const gchar *value);
 const Itdb_IpodInfo *itdb_device_get_ipod_info (Itdb_Device *device);
 const Itdb_IpodInfo *itdb_info_get_ipod_info_table (void);
 const gchar *itdb_info_get_ipod_model_name_string (Itdb_IpodModel model);

Index: itdb_device.c
===================================================================
RCS file: /cvsroot/gtkpod/libgpod/src/itdb_device.c,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- itdb_device.c       5 Jun 2006 15:14:15 -0000       1.7
+++ itdb_device.c       7 Jun 2006 15:41:50 -0000       1.8
@@ -1,4 +1,4 @@
-/* Time-stamp: <2006-06-06 00:13:09 jcs>
+/* Time-stamp: <2006-06-07 23:49:33 jcs>
 |
 |  Copyright (C) 2002-2005 Jorg Schuler <jcsjcs at users sourceforge net>
 |  Part of the gtkpod project.
@@ -237,6 +237,7 @@
        g_hash_table_destroy (device->sysinfo);
     device->sysinfo = g_hash_table_new_full (g_str_hash, g_str_equal,
                                             g_free, g_free);
+    device->sysinfo_changed = FALSE;
 }
 
 
@@ -343,13 +344,10 @@
                ptr = strchr (buf, ':');
                if (ptr && (ptr!=buf))
                {
-                   gchar *key, *value;
                    *ptr = 0;
                    ++ptr;
-                   key = g_strdup (buf);
-                   g_strstrip (ptr);
-                   value = g_strdup (ptr);
-                   g_hash_table_insert (device->sysinfo, key, value);
+                   itdb_device_set_sysinfo (device,
+                                            buf, g_strstrip(ptr));
                }
            }
            fclose (fd);
@@ -357,10 +355,78 @@
        g_free (sysinfo_path);
     }
     g_free (dev_path);
+    /* indicate that sysinfo is identical to what is on the iPod */
+    device->sysinfo_changed = FALSE;
     return result;
 }
 
 
+
+/* used by itdb_device_write_sysinfo() */
+static void write_sysinfo_entry (const gchar *key,
+                                const gchar *value,
+                                FILE *file)
+{
+    fprintf (file, "%s: %s\n", key, value);
+}
+
+
+
+/** 
+ * itdb_device_write_sysinfo:
+ * @device: an #Itdb_Device
+ *
+ * Fills the SysInfo file with information in device->sysinfo. Note:
+ * no directories are created if not already existent.
+ *
+ * Return value: TRUE if file could be read, FALSE otherwise 
+ **/
+gboolean itdb_device_write_sysinfo (Itdb_Device *device, GError **error)
+{
+    gchar *devicedir;
+    gboolean success = FALSE;
+
+    g_return_val_if_fail (device, FALSE);
+    g_return_val_if_fail (device->mountpoint, FALSE);
+
+    devicedir = itdb_get_device_dir (device->mountpoint);
+    if (devicedir)
+    {
+       gchar *sysfile = g_build_filename (devicedir, "SysInfo", NULL);
+       FILE *sysinfo = fopen (sysfile, "w");
+       if (sysinfo)
+       {
+           if (device->sysinfo)
+           {
+               g_hash_table_foreach (device->sysinfo,
+                                     (GHFunc)write_sysinfo_entry,
+                                     sysinfo);
+           }
+           fclose (sysinfo);
+           success = TRUE;
+       }
+       else
+       {
+           g_set_error (error, 0, -1,
+                        _("Could not open '%s' for writing."),
+                        sysfile);
+       }
+       g_free (sysfile);
+       g_free (devicedir);
+    }
+    else
+    {
+       g_set_error (error, 0, -1,
+                    _("Device directory does not exist."));
+    }
+
+    if (success)
+       device->sysinfo_changed = FALSE;
+
+    return success;
+}
+
+
 /**
  * itdb_device_get_sysinfo:
  * @device: an #Itdb_Device
@@ -380,6 +446,35 @@
     return g_strdup (g_hash_table_lookup (device->sysinfo, field));
 }
 
+/**
+ * itdb_device_set_sysinfo:
+ * @device: an #Itdb_Device
+ * @field: field to set
+ * @value: value to set (or NULL to remove the field).
+ *
+ * Set specified field. It can later be written to the iPod using
+ * itdb_device_read_sysinfo
+ *
+ **/
+void itdb_device_set_sysinfo (Itdb_Device *device,
+                             const gchar *field, const gchar *value)
+{
+    g_return_if_fail (device);
+    g_return_if_fail (device->sysinfo);
+    g_return_if_fail (field);
+
+    if (field)
+    {
+       g_hash_table_insert (device->sysinfo,
+                            g_strdup (field), g_strdup (value));
+    }
+    else
+    {
+       g_hash_table_remove (device->sysinfo, field);
+    }
+    device->sysinfo_changed = TRUE;
+}
+
 
 /**
  * itdb_device_get_ipod_info:

Index: itdb_device.h
===================================================================
RCS file: /cvsroot/gtkpod/libgpod/src/itdb_device.h,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- itdb_device.h       4 Jun 2006 16:24:44 -0000       1.5
+++ itdb_device.h       7 Jun 2006 15:41:50 -0000       1.6
@@ -1,4 +1,4 @@
-/* Time-stamp: <2006-06-04 18:44:50 jcs>
+/* Time-stamp: <2006-06-07 23:48:37 jcs>
 |
 |  Copyright (C) 2002-2005 Jorg Schuler <jcsjcs at users sourceforge net>
 |  Part of the gtkpod project.
@@ -57,7 +57,9 @@
                           * phone iTunesDBs)
                           */
     GHashTable *sysinfo;  /* hash with value/key pairs of all entries
-                            in Device/SysInfo */
+                          * in Device/SysInfo */
+    gboolean sysinfo_changed; /* Has the sysinfo hash been changed by
+                                the user (itdb_set_sysinfo) */
 };
 
 struct _Itdb_ArtworkFormat

Index: itdb_itunesdb.c
===================================================================
RCS file: /cvsroot/gtkpod/libgpod/src/itdb_itunesdb.c,v
retrieving revision 1.62
retrieving revision 1.63
diff -u -d -r1.62 -r1.63
--- itdb_itunesdb.c     5 Jun 2006 15:45:56 -0000       1.62
+++ itdb_itunesdb.c     7 Jun 2006 15:41:50 -0000       1.63
@@ -1,4 +1,4 @@
-/* Time-stamp: <2006-06-06 00:44:28 jcs>
+/* Time-stamp: <2006-06-08 00:35:09 jcs>
 |
 |  Copyright (C) 2002-2005 Jorg Schuler <jcsjcs at users sourceforge net>
 |  Part of the gtkpod project.
@@ -4259,6 +4259,7 @@
        g_free (itdb->filename);
        itdb->filename = fn;
     }
+
     /* make sure all buffers are flushed as some people tend to
        disconnect as soon as gtkpod returns */
     sync ();
@@ -4314,6 +4315,12 @@
     if (result == TRUE)
        result = itdb_rename_files (itdb_get_mountpoint (itdb), error);
 
+    /* Write SysInfo file if it has changed */
+    if (!(*error) && itdb->device->sysinfo_changed)
+    {
+       itdb_device_write_sysinfo (itdb->device, error);
+    }
+
     /* make sure all buffers are flushed as some people tend to
        disconnect as soon as gtkpod returns */
     sync ();
@@ -5306,7 +5313,7 @@
  * itdb_get_artwork_dir:
  * @mountpoint: the iPod mountpoint
  *
- * Retrieve the Artwork directory (containing the SysInfo file) by
+ * Retrieve the Artwork directory (containing the ArtworDB) by
  * first calling itdb_get_control_dir() and then adding 'Artwork'
  *
  * Return value: path to the Artwork directory or NULL of
@@ -5462,8 +5469,8 @@
        /* Assign iPod device reference to new database */
        itdb_set_mountpoint(itdb, mountpoint);
        
-       /* Rather than reread sysinfo file (that may not exist if
-        * shuffle, use parameter to load into the sysinfo hash.
+
+       /* Insert model_number into sysinfo file if present
         * The model number can be extracted in a couple of ways:
         *              - use the read_sysinfo_file function
         *              - use libipoddevice and hal to get the model
@@ -5471,9 +5478,11 @@
          *                read the sysinfo file, complemented by some
         *                guessing).
         */
-       g_hash_table_insert (itdb->device->sysinfo,
-                            g_strdup ("ModelNumStr"),
-                            g_strdup (model_number));
+       if (model_number)
+       {
+           itdb_device_set_sysinfo (itdb->device,
+                                    "ModelNumStr", model_number);
+       }
        
        /* Create the remaining directories resident on blank ipod */
        writeok = itdb_create_directories(itdb->device, error);
@@ -5657,7 +5666,6 @@
     gboolean result;
     gchar *pbuf;
     gint i, dirnum;
-    FILE *sysinfo = NULL;
     Itdb_IpodInfo const *info = NULL;
     gboolean calconnotes, devicefile;
     gchar *podpath;
@@ -5830,6 +5838,8 @@
     /* Construct a Device directory file for special models */
     if (devicefile)
     {
+       gchar *model_number;
+
        pbuf = g_build_filename (mp, podpath, "Device", NULL);
        if (!g_file_test (pbuf, G_FILE_TEST_EXISTS))
        {
@@ -5840,23 +5850,18 @@
        }
        g_free (pbuf);
 
+       model_number = itdb_device_get_sysinfo (device, "ModelNumStr");
        /* Construct a SysInfo file */
-       pbuf = g_build_filename (mp, podpath, "Device", "SysInfo", NULL);
-       if (!g_file_test (pbuf, G_FILE_TEST_EXISTS))
+       if (model_number && (strlen (model_number) != 0))
        {
-           sysinfo = fopen(pbuf, "w");
-           if(sysinfo != NULL)
-           {
-               fprintf(sysinfo, "ModelNumStr: %s", 
-                       info->model_number);
-               fclose(sysinfo);
-           }
-           else
+           pbuf = NULL;
+           if (!itdb_device_write_sysinfo (device, error))
            {
+               g_free (model_number);
                goto error_dir;
            }
        }
-       g_free (pbuf);
+       g_free (model_number);
     }
     pbuf = NULL;
 

Index: itdb_photoalbum.c
===================================================================
RCS file: /cvsroot/gtkpod/libgpod/src/itdb_photoalbum.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- itdb_photoalbum.c   4 Jun 2006 16:24:45 -0000       1.3
+++ itdb_photoalbum.c   7 Jun 2006 15:41:50 -0000       1.4
@@ -368,6 +368,12 @@
 
     result = ipod_write_photo_db (photodb);
 
+    /* Write SysInfo file if it has changed */
+    if (!(*error) && photodb->device->sysinfo_changed)
+    {
+       itdb_device_write_sysinfo (photodb->device, error);
+    }
+
     if (result == -1)
        return FALSE;
     else



_______________________________________________
gtkpod-cvs2 mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/gtkpod-cvs2

Reply via email to