/** * itdb_photodb_write: * @photodb: the #Itdb_PhotoDB to write to disk * @error: return location for a #GError or NULL * * Write out a PhotoDB. * * FIXME: error is not set yet. * * Return value: TRUE on success, FALSE on error, in which case @error is * set accordingly. **/ gboolean itdb_photodb_write (Itdb_PhotoDB *photodb, GError **error) { gint result; GList *gl; gint32 id, prev_id; g_return_val_if_fail (photodb, FALSE); g_return_val_if_fail (photodb->device, FALSE); if (photodb->device->byte_order == 0) itdb_device_autodetect_endianess (photodb->device); /* set up photo_ids */ id = 0x40; for (gl=photodb->photos; gl; gl=gl->next) { Itdb_Artwork *photo = gl->data; g_return_val_if_fail (photo, FALSE); photo->id = id; ++id; } /* set up album_ids -- this is how my iPod Nano does it... */ prev_id = 0x64; id = prev_id + g_list_length (photodb->photos); for (gl=photodb->photoalbums; gl; gl=gl->next) { Itdb_PhotoAlbum *album = gl->data; g_return_val_if_fail (album, FALSE); album->album_id = id; album->prev_album_id = prev_id; ++id; ++prev_id; if (gl != photodb->photoalbums) { /* except for the first album */ prev_id += g_list_length (album->members); } } result = ipod_write_photo_db (photodb); /* Write SysInfo file if it has changed */ if (!error || !(*error)) { if (photodb->device->sysinfo_changed) { itdb_device_write_sysinfo (photodb->device, error); } } if (result == -1) return FALSE; else return TRUE; }
DBParseContext * db_parse_context_new_from_file (const char *filename, Itdb_DB *db) { DBParseContext *ctx; Itdb_Device *device; GError* error; GMappedFile* mapped_file; struct stat stat_buf; ctx = NULL; error = NULL; mapped_file = NULL; device = db_get_device (db); g_return_val_if_fail (device, NULL); if (g_stat (filename, &stat_buf) != 0) { return NULL; }; if (stat_buf.st_size > 64 * 1024 * 1024) { g_warning ("%s is too big to be mmapped (%llu bytes)\n", filename, (unsigned long long)stat_buf.st_size); return NULL; } mapped_file = g_mapped_file_new(filename, FALSE, &error); if (mapped_file == NULL) { g_print ("Error while mapping %s: %s\n", filename, error->message); g_error_free(error); return NULL; } if (device->byte_order == 0) itdb_device_autodetect_endianess (device); ctx = db_parse_context_new ((guchar *)g_mapped_file_get_contents(mapped_file), g_mapped_file_get_length(mapped_file), device->byte_order); if (ctx == NULL) { g_mapped_file_unref(mapped_file); return NULL; } ctx->db = db; ctx->mapped_file = mapped_file; return ctx; }