diff options
| author | Jorg Schuler <jcsjcs@users.sourceforge.net> | 2006-05-30 14:09:44 +0000 |
|---|---|---|
| committer | Jorg Schuler <jcsjcs@users.sourceforge.net> | 2006-05-30 14:09:44 +0000 |
| commit | 4ff7387c3f4eefe1e86e44ad3ae52043770baf1e (patch) | |
| tree | 64cc40dc42c33925c6183222667354276479c362 /src/db-artwork-parser.c | |
| parent | eba7d3fff1076914dda819eb8120304f059f4be9 (diff) | |
| download | libgpod-4ff7387c3f4eefe1e86e44ad3ae52043770baf1e.tar.gz libgpod-4ff7387c3f4eefe1e86e44ad3ae52043770baf1e.tar.xz libgpod-4ff7387c3f4eefe1e86e44ad3ae52043770baf1e.zip | |
***** merged photo-support branch back to MAIN. branch is tagged
photo-support-merged_00
ipod.py will need minor patching (flag2, flag3).
git-svn-id: https://gtkpod.svn.sf.net/svnroot/gtkpod/libgpod/trunk@1292 f01d2545-417e-4e96-918e-98f8d0dbbcb6
Diffstat (limited to 'src/db-artwork-parser.c')
| -rw-r--r-- | src/db-artwork-parser.c | 344 |
1 files changed, 240 insertions, 104 deletions
diff --git a/src/db-artwork-parser.c b/src/db-artwork-parser.c index 17dd390..df80305 100644 --- a/src/db-artwork-parser.c +++ b/src/db-artwork-parser.c @@ -31,6 +31,7 @@ #include <sys/types.h> #include "itdb.h" +#include "itdb_private.h" #include "itdb_endianness.h" #include "db-artwork-debug.h" #include "db-artwork-parser.h" @@ -39,9 +40,9 @@ #include "db-parse-context.h" #include <glib/gi18n-lib.h> -typedef int (*ParseListItem)(DBParseContext *ctx, Itdb_iTunesDB *db, GError *error); +typedef int (*ParseListItem)(DBParseContext *ctx, GError *error); -#ifndef DEBUG_ARTWORKDB +#ifndef NOT_DEFINED_DEBUG_ARTWORKDB static Itdb_Track * get_song_by_dbid (Itdb_iTunesDB *db, guint64 id) { @@ -61,7 +62,7 @@ get_song_by_dbid (Itdb_iTunesDB *db, guint64 id) static int -parse_mhif (DBParseContext *ctx, Itdb_iTunesDB *db, GError *error) +parse_mhif (DBParseContext *ctx, GError *error) { MhifHeader *mhif; @@ -70,21 +71,25 @@ parse_mhif (DBParseContext *ctx, Itdb_iTunesDB *db, GError *error) return -1; } dump_mhif (mhif); - db_parse_context_set_total_len (ctx, get_gint32_db (db, mhif->total_len)); + db_parse_context_set_total_len (ctx, get_gint32 (mhif->total_len, ctx->byte_order)); return 0; } static int -parse_mhia (DBParseContext *ctx, Itdb_iTunesDB *db, GError *error) +parse_mhia (DBParseContext *ctx, Itdb_PhotoAlbum *photo_album, GError *error) { MhiaHeader *mhia; + gint image_id; mhia = db_parse_context_get_m_header (ctx, MhiaHeader, "mhia"); if (mhia == NULL) { return -1; } dump_mhia (mhia); - db_parse_context_set_total_len (ctx, get_gint32_db (db, mhia->total_len)); + image_id = get_gint32 (mhia->image_id, ctx->byte_order); + photo_album->members = g_list_append (photo_album->members + , GINT_TO_POINTER(image_id)); + db_parse_context_set_total_len (ctx, get_gint32_db (ctx->db, mhia->total_len)); return 0; } @@ -109,22 +114,20 @@ get_utf16_string (void* buffer, gint length, guint byte_order) } static char * -mhod3_get_ithmb_filename (ArtworkDB_MhodHeaderArtworkType3 *mhod3, - Itdb_iTunesDB *db) +mhod3_get_ithmb_filename (DBParseContext *ctx, ArtworkDB_MhodHeaderArtworkType3 *mhod3) { char *filename=NULL; g_assert (mhod3 != NULL); - g_assert (db != NULL); if (mhod3->mhod_version == 2) filename = get_utf16_string ((gunichar2 *)mhod3->string, - get_gint32_db (db, mhod3->string_len), - db->device->byte_order); + get_gint32 (mhod3->string_len, ctx->byte_order), + ctx->byte_order); else if ((mhod3->mhod_version == 0) || (mhod3->mhod_version == 1)) filename = g_strndup (mhod3->string, - get_gint32_db (db, mhod3->string_len)); + get_gint32 (mhod3->string_len, ctx->byte_order)); else g_warning (_("Unexpected mhod3 string type: %d\n"), mhod3->mhod_version); @@ -133,7 +136,7 @@ mhod3_get_ithmb_filename (ArtworkDB_MhodHeaderArtworkType3 *mhod3, static int -parse_mhod_3 (DBParseContext *ctx, Itdb_iTunesDB *db, +parse_mhod_3 (DBParseContext *ctx, Itdb_Thumb *thumb, GError *error) { ArtworkDB_MhodHeader *mhod; @@ -144,23 +147,23 @@ parse_mhod_3 (DBParseContext *ctx, Itdb_iTunesDB *db, if (mhod == NULL) { return -1; } - db_parse_context_set_total_len (ctx, get_gint32_db (db, mhod->total_len)); + db_parse_context_set_total_len (ctx, get_gint32 (mhod->total_len, ctx->byte_order)); - if (get_gint32_db (db, mhod->total_len) < sizeof (ArtworkDB_MhodHeaderArtworkType3)){ + if (get_gint32 (mhod->total_len, ctx->byte_order) < sizeof (ArtworkDB_MhodHeaderArtworkType3)){ return -1; } mhod3 = (ArtworkDB_MhodHeaderArtworkType3*)mhod; - mhod3_type = get_gint16_db (db, mhod3->type); + mhod3_type = get_gint16 (mhod3->type, ctx->byte_order); if (mhod3_type != MHOD_ARTWORK_TYPE_FILE_NAME) { return -1; } - thumb->filename = mhod3_get_ithmb_filename (mhod3, db); + thumb->filename = mhod3_get_ithmb_filename (ctx, mhod3); dump_mhod_type_3 (mhod3); return 0; } static int -parse_mhni (DBParseContext *ctx, iPodSong *song, GError *error) +parse_photo_mhni (DBParseContext *ctx, Itdb_Artwork *artwork, GError *error) { MhniHeader *mhni; DBParseContext *mhod_ctx; @@ -170,10 +173,40 @@ parse_mhni (DBParseContext *ctx, iPodSong *song, GError *error) if (mhni == NULL) { return -1; } - db_parse_context_set_total_len (ctx, get_gint32_db (song->itdb, mhni->total_len)); + db_parse_context_set_total_len (ctx, get_gint32 (mhni->total_len, ctx->byte_order)); dump_mhni (mhni); - thumb = ipod_image_new_from_mhni (mhni, song->itdb); + thumb = ipod_image_new_from_mhni (mhni, ctx->db); + if (thumb == NULL) { + return 0; + } + + artwork->thumbnails = g_list_append (artwork->thumbnails, thumb); + + mhod_ctx = db_parse_context_get_sub_context (ctx, ctx->header_len); + if (mhod_ctx == NULL) { + return -1; + } + parse_mhod_3 (mhod_ctx, thumb, error); + g_free (mhod_ctx); + + return 0; +} + +static int +parse_mhni (DBParseContext *ctx, iPodSong *song, GError *error) +{ + MhniHeader *mhni; + DBParseContext *mhod_ctx; + Itdb_Thumb *thumb; + + mhni = db_parse_context_get_m_header (ctx, MhniHeader, "mhni"); + if (mhni == NULL) { + return -1; + } + db_parse_context_set_total_len (ctx, get_gint32 (mhni->total_len, ctx->byte_order)); + dump_mhni (mhni); + thumb = ipod_image_new_from_mhni (mhni, ctx->db); if (thumb == NULL) { return 0; } @@ -185,26 +218,24 @@ parse_mhni (DBParseContext *ctx, iPodSong *song, GError *error) if (mhod_ctx == NULL) { return -1; } - parse_mhod_3 (mhod_ctx, song->itdb, thumb, error); + parse_mhod_3 (mhod_ctx, thumb, error); g_free (mhod_ctx); return 0; } static int -parse_mhod (DBParseContext *ctx, iPodSong *song, GError *error) +parse_photo_mhod (DBParseContext *ctx, Itdb_Artwork *artwork, GError *error) { ArtworkDB_MhodHeader *mhod; DBParseContext *mhni_ctx; int type; - gint32 total_len; mhod = db_parse_context_get_m_header (ctx, ArtworkDB_MhodHeader, "mhod"); if (mhod == NULL) { return -1; } - total_len = get_gint32_db (song->itdb, mhod->total_len); - db_parse_context_set_total_len (ctx, total_len); + db_parse_context_set_total_len (ctx, get_gint32 (mhod->total_len, ctx->byte_order)); /* The MHODs found in the ArtworkDB and Photo Database files are * significantly different than those found in the iTunesDB. @@ -212,11 +243,48 @@ parse_mhod (DBParseContext *ctx, iPodSong *song, GError *error) * - low 3 bytes are actual type; * - high byte is padding length of string (0-3). */ - type = get_gint16_db (song->itdb, mhod->type); - if (type == MHOD_ARTWORK_TYPE_ALBUM_NAME) + type = get_gint16 (mhod->type, ctx->byte_order) & 0x00FFFFFF; + + if ( type == MHOD_ARTWORK_TYPE_ALBUM_NAME) { dump_mhod_type_1 ((MhodHeaderArtworkType1 *)mhod); - else + } else { dump_mhod (mhod); + } + + /* if this is a container... */ + if (type == MHOD_ARTWORK_TYPE_THUMBNAIL) { + mhni_ctx = db_parse_context_get_sub_context (ctx, ctx->header_len); + if (mhni_ctx == NULL) { + return -1; + } + parse_photo_mhni (mhni_ctx, artwork, NULL); + g_free (mhni_ctx); + } + + return 0; +} +static int +parse_mhod (DBParseContext *ctx, iPodSong *song, GError *error) +{ + ArtworkDB_MhodHeader *mhod; + DBParseContext *mhni_ctx; + int type; + gint32 total_len; + + mhod = db_parse_context_get_m_header (ctx, ArtworkDB_MhodHeader, "mhod"); + if (mhod == NULL) { + return -1; + } + total_len = get_gint32 (mhod->total_len, ctx->byte_order); + db_parse_context_set_total_len (ctx, total_len); + + type = get_gint16 (mhod->type, ctx->byte_order); + + if ( type == MHOD_ARTWORK_TYPE_ALBUM_NAME) { + dump_mhod_type_1 ((MhodHeaderArtworkType1 *)mhod); + } else { + dump_mhod (mhod); + } /* if this is a container... */ if (type == MHOD_ARTWORK_TYPE_THUMBNAIL) { @@ -233,60 +301,81 @@ parse_mhod (DBParseContext *ctx, iPodSong *song, GError *error) static int -parse_mhii (DBParseContext *ctx, Itdb_iTunesDB *db, GError *error) +parse_mhii (DBParseContext *ctx, GError *error) { MhiiHeader *mhii; DBParseContext *mhod_ctx; int num_children; off_t cur_offset; iPodSong *song; + Itdb_Artwork *artwork; mhii = db_parse_context_get_m_header (ctx, MhiiHeader, "mhii"); if (mhii == NULL) { return -1; } - db_parse_context_set_total_len (ctx, get_gint32_db (db, mhii->total_len)); - + db_parse_context_set_total_len (ctx, get_gint32 (mhii->total_len, ctx->byte_order)); dump_mhii (mhii); -#ifdef DEBUG_ARTWORKDB - song = NULL; -#else - song = get_song_by_dbid (db, get_gint64_db (db, mhii->song_id)); - if (song == NULL) { - return -1; - } - - song->artwork->artwork_size = get_gint32_db (db, mhii->orig_img_size); - if ((song->artwork_size+song->artwork_count) != - song->artwork->artwork_size) { - g_warning (_("iTunesDB and ArtworkDB artwork sizes inconsistent (%d+%d != %d)"), song->artwork_size, song->artwork_count, song->artwork->artwork_size); - } + switch (ctx->db->db_type) { + case DB_TYPE_PHOTO: + artwork = g_new0( Itdb_Artwork, 1 ); + artwork->type = ITDB_PHOTO; + artwork->artwork_size = get_gint32 (mhii->orig_img_size, ctx->byte_order); + artwork->id = get_gint32 (mhii->image_id, ctx->byte_order); + artwork->creation_date = itdb_time_mac_to_host( get_gint32 (mhii->digitised_date, ctx->byte_order) ); - song->artwork->id = get_gint32_db (db, mhii->image_id); + cur_offset = ctx->header_len; + mhod_ctx = db_parse_context_get_sub_context (ctx, cur_offset); + num_children = get_gint32 (mhii->num_children, ctx->byte_order); + while ((num_children > 0) && (mhod_ctx != NULL)) { + parse_photo_mhod (mhod_ctx, artwork, NULL); + num_children--; + cur_offset += mhod_ctx->total_len; + g_free (mhod_ctx); + mhod_ctx = db_parse_context_get_sub_context (ctx, cur_offset); + } + ctx->db->db.photodb->photos = g_list_append (ctx->db->db.photodb->photos, artwork); + break; + case DB_TYPE_ITUNES: +#ifdef NOT_DEFINED_DEBUG_ARTWORKDB + song = NULL; +#else + song = get_song_by_dbid (ctx->db->db.itdb, get_gint64 (mhii->song_id, ctx->byte_order)); + if (song == NULL) { + return -1; + } + song->artwork->artwork_size = get_gint32 (mhii->orig_img_size, ctx->byte_order); + if ((song->artwork_size+song->artwork_count) != + song->artwork->artwork_size) { + g_warning (_("iTunesDB and ArtworkDB artwork sizes inconsistent (%d+%d != %d)"), song->artwork_size, song->artwork_count, song->artwork->artwork_size); + } + song->artwork->id = get_gint32 (mhii->image_id, ctx->byte_order); #endif - cur_offset = ctx->header_len; - mhod_ctx = db_parse_context_get_sub_context (ctx, cur_offset); - num_children = get_gint32_db (db, mhii->num_children); - while ((num_children > 0) && (mhod_ctx != NULL)) { - parse_mhod (mhod_ctx, song, NULL); - num_children--; - cur_offset += mhod_ctx->total_len; - g_free (mhod_ctx); + cur_offset = ctx->header_len; mhod_ctx = db_parse_context_get_sub_context (ctx, cur_offset); + num_children = get_gint32 (mhii->num_children, ctx->byte_order); + while ((num_children > 0) && (mhod_ctx != NULL)) { + parse_mhod (mhod_ctx, song, NULL); + num_children--; + cur_offset += mhod_ctx->total_len; + g_free (mhod_ctx); + mhod_ctx = db_parse_context_get_sub_context (ctx, cur_offset); + } + break; } - return 0; } - static int -parse_mhba (DBParseContext *ctx, Itdb_iTunesDB *db, GError *error) +parse_mhba (DBParseContext *ctx, GError *error) { MhbaHeader *mhba; + ArtworkDB_MhodHeader *mhod; DBParseContext *mhod_ctx; DBParseContext *mhia_ctx; + Itdb_PhotoAlbum *photo_album; int num_children; off_t cur_offset; @@ -294,36 +383,49 @@ parse_mhba (DBParseContext *ctx, Itdb_iTunesDB *db, GError *error) if (mhba == NULL) { return -1; } - db_parse_context_set_total_len (ctx, get_gint32_db (db, mhba->total_len)); + db_parse_context_set_total_len (ctx, get_gint32 (mhba->total_len, ctx->byte_order)); dump_mhba (mhba); + photo_album = g_new0 (Itdb_PhotoAlbum, 1); + photo_album->num_images = get_gint32( mhba->num_mhias, ctx->byte_order); + photo_album->album_id = get_gint32( mhba->playlist_id, ctx->byte_order); + photo_album->master = get_gint32( mhba->master, ctx->byte_order); + photo_album->prev_album_id = get_gint32( mhba->prev_playlist_id, ctx->byte_order); + cur_offset = ctx->header_len; mhod_ctx = db_parse_context_get_sub_context (ctx, cur_offset); - num_children = get_gint32_db (db, mhba->num_mhods); + num_children = get_gint32 (mhba->num_mhods, ctx->byte_order); while ((num_children > 0) && (mhod_ctx != NULL)) { - parse_mhod (mhod_ctx, NULL, NULL); - num_children--; + /* FIXME: First mhod is album name, whats the others for? */ + mhod = db_parse_context_get_m_header (mhod_ctx, ArtworkDB_MhodHeader, "mhod"); + if (mhod == NULL) { + return -1; + } + db_parse_context_set_total_len (mhod_ctx, get_gint32(mhod->total_len, ctx->byte_order)); + photo_album->name = g_strdup( (char *)((MhodHeaderArtworkType1*)mhod)->string ); cur_offset += mhod_ctx->total_len; + dump_mhod_type_1 ((MhodHeaderArtworkType1*)mhod); g_free (mhod_ctx); - mhod_ctx = db_parse_context_get_sub_context (ctx, cur_offset); + num_children--; } + mhia_ctx = db_parse_context_get_sub_context (ctx, cur_offset); - num_children = get_gint32_db (db, mhba->num_mhias); + num_children = get_gint32 (mhba->num_mhias, ctx->byte_order); while ((num_children > 0) && (mhia_ctx != NULL)) { - parse_mhia (mhia_ctx, db, NULL); + parse_mhia (mhia_ctx, photo_album, NULL); num_children--; cur_offset += mhia_ctx->total_len; g_free (mhia_ctx); mhia_ctx = db_parse_context_get_sub_context (ctx, cur_offset); } - + ctx->db->db.photodb->photoalbums = g_list_append (ctx->db->db.photodb->photoalbums, photo_album); return 0; } static int -parse_mhl (DBParseContext *ctx, Itdb_iTunesDB *db, GError *error, +parse_mhl (DBParseContext *ctx, GError *error, const char *id, ParseListItem parse_child) { MhlHeader *mhl; @@ -338,7 +440,7 @@ parse_mhl (DBParseContext *ctx, Itdb_iTunesDB *db, GError *error, dump_mhl (mhl, id); - num_children = get_gint32_db (db, mhl->num_children); + num_children = get_gint32 (mhl->num_children, ctx->byte_order); if (num_children < 0) { return -1; } @@ -347,7 +449,7 @@ parse_mhl (DBParseContext *ctx, Itdb_iTunesDB *db, GError *error, mhi_ctx = db_parse_context_get_sub_context (ctx, cur_offset); while ((num_children > 0) && (mhi_ctx != NULL)) { if (parse_child != NULL) { - parse_child (mhi_ctx, db, NULL); + parse_child (mhi_ctx, NULL); } num_children--; cur_offset += mhi_ctx->total_len; @@ -361,7 +463,7 @@ parse_mhl (DBParseContext *ctx, Itdb_iTunesDB *db, GError *error, static int -parse_mhsd (DBParseContext *ctx, Itdb_iTunesDB *db, GError **error) +parse_mhsd (DBParseContext *ctx, GError **error) { ArtworkDB_MhsdHeader *mhsd; @@ -370,33 +472,33 @@ parse_mhsd (DBParseContext *ctx, Itdb_iTunesDB *db, GError **error) return -1; } - db_parse_context_set_total_len (ctx, get_gint32_db (db, mhsd->total_len)); + db_parse_context_set_total_len (ctx, get_gint32 (mhsd->total_len, ctx->byte_order)); dump_mhsd (mhsd); - switch (get_gint16_db (db, mhsd->index)) { + switch (get_gint16_db (ctx->db, mhsd->index)) { case MHSD_IMAGE_LIST: { DBParseContext *mhli_context; mhli_context = db_parse_context_get_next_child (ctx); - parse_mhl (mhli_context, db, NULL, "mhli", parse_mhii); + parse_mhl (mhli_context, NULL, "mhli", parse_mhii); g_free (mhli_context); break; } case MHSD_ALBUM_LIST: { DBParseContext *mhla_context; mhla_context = db_parse_context_get_next_child (ctx); - parse_mhl (mhla_context, db, NULL, "mhla", parse_mhba); + parse_mhl (mhla_context, NULL, "mhla", parse_mhba); g_free (mhla_context); break; } case MHSD_FILE_LIST: { DBParseContext *mhlf_context; mhlf_context = db_parse_context_get_next_child (ctx); - parse_mhl (mhlf_context, db, NULL, "mhlf", parse_mhif); + parse_mhl (mhlf_context, NULL, "mhlf", parse_mhif); g_free (mhlf_context); break; } default: g_warning (_("Unexpected mhsd index: %d\n"), - get_gint16_db (db, mhsd->index)); + get_gint16_db (ctx->db, mhsd->index)); return -1; break; } @@ -406,7 +508,7 @@ parse_mhsd (DBParseContext *ctx, Itdb_iTunesDB *db, GError **error) /* Database Object */ static int -parse_mhfd (DBParseContext *ctx, Itdb_iTunesDB *db, GError **error) +parse_mhfd (DBParseContext *ctx, GError **error) { MhfdHeader *mhfd; DBParseContext *mhsd_context; @@ -419,7 +521,7 @@ parse_mhfd (DBParseContext *ctx, Itdb_iTunesDB *db, GError **error) } /* Sanity check */ - total_len = get_gint32_db (db, mhfd->total_len); + total_len = get_gint32_db (ctx->db, mhfd->total_len); g_return_val_if_fail (total_len == ctx->total_len, -1); dump_mhfd (mhfd); cur_pos = ctx->header_len; @@ -432,7 +534,7 @@ parse_mhfd (DBParseContext *ctx, Itdb_iTunesDB *db, GError **error) if (mhsd_context == NULL) { return -1; } - parse_mhsd (mhsd_context, db, NULL); + parse_mhsd (mhsd_context, NULL); cur_pos += mhsd_context->total_len; g_free (mhsd_context); @@ -440,7 +542,7 @@ parse_mhfd (DBParseContext *ctx, Itdb_iTunesDB *db, GError **error) if (mhsd_context == NULL) { return -1; } - parse_mhsd (mhsd_context, db, NULL); + parse_mhsd (mhsd_context, NULL); cur_pos += mhsd_context->total_len; g_free (mhsd_context); @@ -448,7 +550,7 @@ parse_mhfd (DBParseContext *ctx, Itdb_iTunesDB *db, GError **error) if (mhsd_context == NULL) { return -1; } - parse_mhsd (mhsd_context, db, NULL); + parse_mhsd (mhsd_context, NULL); cur_pos += mhsd_context->total_len; g_free (mhsd_context); @@ -476,13 +578,13 @@ ipod_db_get_artwork_db_path (const char *mount_point) { /* attempt to create Artwork dir */ gchar *control_dir = itdb_get_control_dir (mount_point); - gchar *dir; if (control_dir) { - dir = g_build_filename (control_dir, "Artwork", NULL); + gchar *dir = g_build_filename (control_dir, "Artwork", NULL); mkdir (dir, 0777); - g_free (dir); g_free (control_dir); + g_free (dir); + artwork_dir = itdb_get_artwork_dir (mount_point); } } if (artwork_dir) @@ -496,7 +598,6 @@ ipod_db_get_artwork_db_path (const char *mount_point) return filename; } - static gboolean ipod_supports_cover_art (Itdb_Device *device) { @@ -523,19 +624,22 @@ ipod_supports_cover_art (Itdb_Device *device) } int -ipod_parse_artwork_db (Itdb_iTunesDB *db) +ipod_parse_artwork_db (Itdb_iTunesDB *itdb) { DBParseContext *ctx; char *filename; + Itdb_DB db; + + db.db.itdb = itdb; + db.db_type = DB_TYPE_ITUNES; - g_return_val_if_fail (db, -1); - g_return_val_if_fail (db->device, -1); + g_return_val_if_fail (itdb, -1); - if (!ipod_supports_cover_art (db->device)) { + if (!ipod_supports_cover_art (db.db.itdb->device)) { return -1; } ctx = NULL; - filename = ipod_db_get_artwork_db_path (itdb_get_mountpoint (db)); + filename = ipod_db_get_artwork_db_path (itdb_get_mountpoint (db.db.itdb)); if (filename == NULL) { goto error; } @@ -544,14 +648,13 @@ ipod_parse_artwork_db (Itdb_iTunesDB *db) goto error; } - ctx = db_parse_context_new_from_file (filename, - db->device->byte_order); + ctx = db_parse_context_new_from_file (filename, &db); g_free (filename); if (ctx == NULL) { goto error; } - parse_mhfd (ctx, db, NULL); + parse_mhfd (ctx, NULL); db_parse_context_destroy (ctx, TRUE); return 0; @@ -562,35 +665,68 @@ ipod_parse_artwork_db (Itdb_iTunesDB *db) return -1; } -#if 0 -static char * -ipod_db_get_photo_db_path (const char *mount_point) + +G_GNUC_INTERNAL char * +ipod_db_get_photos_db_path (const char *mount_point) { - const char *paths[] = {"Photos", "Photo Database", NULL}; - g_return_val_if_fail (mount_point != NULL, NULL); - return itdb_resolve_path (mount_point, paths); - + gchar *filename=NULL; + + /* fail silently if no mount point given */ + if (!mount_point) return NULL; + + filename = itdb_get_photodb_path (mount_point); + + /* itdb_resolve_path() only returns existing paths */ + if (!filename) + { + gchar *photos_dir; + + photos_dir = itdb_get_photos_dir (mount_point); + if (!photos_dir) + { + /* attempt to create Photos dir */ + gchar *dir = g_build_filename (mount_point, "Photos", NULL); + mkdir (dir, 0777); + g_free (dir); + photos_dir = itdb_get_photos_dir (mount_point); + } + if (photos_dir) + { + filename = g_build_filename (photos_dir, + "Photo Database", NULL); + g_free (photos_dir); + } + } + + return filename; } + int -ipod_parse_photo_db (const char *mount_point) +ipod_parse_photo_db (Itdb_PhotoDB *photodb) { DBParseContext *ctx; char *filename; + Itdb_DB db; + + db.db.photodb = photodb; + db.db_type = DB_TYPE_PHOTO; - filename = ipod_db_get_photo_db_path (mount_point); + + filename = itdb_get_photodb_path ( + itdb_photodb_get_mountpoint (photodb)); if (filename == NULL) { return -1; } - ctx = db_parse_context_new_from_file (filename); + + ctx = db_parse_context_new_from_file (filename, &db ); g_free (filename); if (ctx == NULL) { return -1; } - - parse_mhfd (ctx, NULL, NULL); + parse_mhfd (ctx, NULL); db_parse_context_destroy (ctx, TRUE); return 0; } -#endif + |
