# HG changeset patch # User nadvornik # Date 1224361075 0 # Node ID 01e743d275f229fd99cd621695c77bbaa7b0801f # Parent abf48b53216b63e80a52fddb09dfa3d6b1afd91d create xmp sidecar when needed diff -r abf48b53216b -r 01e743d275f2 src/exiv2.cc --- a/src/exiv2.cc Sat Oct 18 19:20:27 2008 +0000 +++ b/src/exiv2.cc Sat Oct 18 20:17:55 2008 +0000 @@ -50,6 +50,7 @@ #if EXIV2_TEST_VERSION(0,17,0) #include +#include #endif @@ -111,6 +112,12 @@ guint cp_length_; public: + _ExifDataOriginal(Exiv2::Image::AutoPtr image) + { + cp_data_ = NULL; + cp_length_ = 0; + image_ = image; + } _ExifDataOriginal(gchar *path) { @@ -252,10 +259,29 @@ } else { - imageData_->image()->setExifData(exifData_); - imageData_->image()->setIptcData(iptcData_); - imageData_->image()->setXmpData(xmpData_); - imageData_->image()->writeMetadata(); + try { + imageData_->image()->setExifData(exifData_); + imageData_->image()->setIptcData(iptcData_); + imageData_->image()->setXmpData(xmpData_); + imageData_->image()->writeMetadata(); + } + catch (Exiv2::AnyError& e) + { + // can't write into the image, create sidecar +#if EXIV2_TEST_VERSION(0,17,0) + gchar *base = remove_extension_from_path(imageData_->image()->io().path().c_str()); + gchar *pathl = g_strconcat(base, ".xmp", NULL); + + Exiv2::Image::AutoPtr sidecar = Exiv2::ImageFactory::create(Exiv2::ImageType::xmp, pathl); + + g_free(base); + g_free(pathl); + + sidecarData_ = new _ExifDataOriginal(sidecar); + sidecarData_->image()->setXmpData(xmpData_); + sidecarData_->image()->writeMetadata(); +#endif + } } }