diff options
author | Jorg Schuler <jcsjcs@users.sourceforge.net> | 2006-06-07 15:41:50 +0000 |
---|---|---|
committer | Jorg Schuler <jcsjcs@users.sourceforge.net> | 2006-06-07 15:41:50 +0000 |
commit | 7650d7d53fdc1e7767573f09fcaf9689d7583562 (patch) | |
tree | 2b8204d9d37a11e3316321c23fe4767797461bc0 | |
parent | 38afffa77609ade96535f707032722691610f30e (diff) | |
download | libgpod-7650d7d53fdc1e7767573f09fcaf9689d7583562.tar.gz libgpod-7650d7d53fdc1e7767573f09fcaf9689d7583562.tar.xz libgpod-7650d7d53fdc1e7767573f09fcaf9689d7583562.zip |
* 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.
git-svn-id: https://gtkpod.svn.sf.net/svnroot/gtkpod/libgpod/trunk@1302 f01d2545-417e-4e96-918e-98f8d0dbbcb6
-rw-r--r-- | ChangeLog | 23 | ||||
-rw-r--r-- | docs/reference/tmpl/device.sgml | 1 | ||||
-rw-r--r-- | src/itdb.h | 5 | ||||
-rw-r--r-- | src/itdb_device.c | 107 | ||||
-rw-r--r-- | src/itdb_device.h | 6 | ||||
-rw-r--r-- | src/itdb_itunesdb.c | 43 | ||||
-rw-r--r-- | src/itdb_photoalbum.c | 6 |
7 files changed, 162 insertions, 29 deletions
@@ -1,3 +1,22 @@ +2006-06-07 Jorg Schuler <jcsjcs at users.sourceforge.net> + + * 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. + + 2006-06-05 Jorg Schuler <jcsjcs at users.sourceforge.net> * src/db-artwork-parser.h @@ -16,7 +35,9 @@ itdb_info_get_ipod_generation_string() * src/itdb_itunesdb.c (itdb_create_directories): add space after - ":" when writing SysInfo file. + ":" when writing SysInfo file, only write SysInfo file if + model_number was given, write original model number, not + abbreviated model number from info->model_number. 2006-06-04 Jorg Schuler <jcsjcs at users.sourceforge.net> diff --git a/docs/reference/tmpl/device.sgml b/docs/reference/tmpl/device.sgml index f984e1e..67534e9 100644 --- a/docs/reference/tmpl/device.sgml +++ b/docs/reference/tmpl/device.sgml @@ -26,6 +26,7 @@ Data structure holding information about the iPod (model, mount point, ...) @musicdirs: @byte_order: @sysinfo: +@sysinfo_changed: <!-- ##### FUNCTION itdb_device_new ##### --> <para> @@ -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 @@ Itdb_Device *itdb_device_new (void); 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); diff --git a/src/itdb_device.c b/src/itdb_device.c index 4407a56..4f987b8 100644 --- a/src/itdb_device.c +++ b/src/itdb_device.c @@ -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 @@ static void itdb_device_reset_sysinfo (Itdb_Device *device) 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 @@ gboolean itdb_device_read_sysinfo (Itdb_Device *device) 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 @@ gboolean itdb_device_read_sysinfo (Itdb_Device *device) 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 @@ gchar *itdb_device_get_sysinfo (Itdb_Device *device, const gchar *field) 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: diff --git a/src/itdb_device.h b/src/itdb_device.h index ecd2bfd..ec97a5a 100644 --- a/src/itdb_device.h +++ b/src/itdb_device.h @@ -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 @@ struct _Itdb_Device * 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 diff --git a/src/itdb_itunesdb.c b/src/itdb_itunesdb.c index 0e9664e..43f7ca6 100644 --- a/src/itdb_itunesdb.c +++ b/src/itdb_itunesdb.c @@ -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 @@ gboolean itdb_write_file (Itdb_iTunesDB *itdb, const gchar *filename, 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 @@ gboolean itdb_write (Itdb_iTunesDB *itdb, GError **error) 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 @@ gchar *itdb_get_device_dir (const gchar *mountpoint) * 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 @@ gboolean itdb_init_ipod (const gchar *mountpoint, /* 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 @@ gboolean itdb_init_ipod (const gchar *mountpoint, * 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 @@ static gboolean itdb_create_directories (Itdb_Device *device, GError **error) gboolean result; gchar *pbuf; gint i, dirnum; - FILE *sysinfo = NULL; Itdb_IpodInfo const *info = NULL; gboolean calconnotes, devicefile; gchar *podpath; @@ -5830,6 +5838,8 @@ static gboolean itdb_create_directories (Itdb_Device *device, GError **error) /* 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 @@ static gboolean itdb_create_directories (Itdb_Device *device, GError **error) } 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; diff --git a/src/itdb_photoalbum.c b/src/itdb_photoalbum.c index d204238..0c49baf 100644 --- a/src/itdb_photoalbum.c +++ b/src/itdb_photoalbum.c @@ -368,6 +368,12 @@ gboolean itdb_photodb_write (Itdb_PhotoDB *photodb, GError **error) 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 |