diff --git a/src/actions.cpp b/src/actions.cpp index cf8e97b2..1a2f0d98 100644 --- a/src/actions.cpp +++ b/src/actions.cpp @@ -878,7 +878,9 @@ namespace Action { rc = writeThumbnail(); } if (Params::instance().target_ & ~Params::ctThumb) { - std::string exvPath = Util::dirname(path_) + SEPERATOR_STR + std::string directory = Params::instance().directory_; + if (directory.empty()) directory = Util::dirname(path_); + std::string exvPath = directory + SEPERATOR_STR + Util::basename(path_, true) + ".exv"; if (!Params::instance().force_ && Util::fileExists(exvPath)) { std::cout << Params::instance().progname() @@ -923,7 +925,9 @@ namespace Action { return -3; } - std::string thumb = Util::dirname(path_) + SEPERATOR_STR + std::string directory = Params::instance().directory_; + if (directory.empty()) directory = Util::dirname(path_); + std::string thumb = directory + SEPERATOR_STR + Util::basename(path_, true) + "-thumb"; std::string thumbExt = exifData.thumbnailExtension(); if (thumbExt.empty()) { @@ -977,7 +981,9 @@ namespace Action { && Params::instance().target_ & Params::ctExif || Params::instance().target_ & Params::ctIptc || Params::instance().target_ & Params::ctComment) { - std::string exvPath = Util::dirname(path) + SEPERATOR_STR + std::string directory = Params::instance().directory_; + if (directory.empty()) directory = Util::dirname(path); + std::string exvPath = directory + SEPERATOR_STR + Util::basename(path, true) + ".exv"; rc = metacopy(exvPath, path, true); } @@ -992,7 +998,9 @@ namespace Action { int Insert::insertThumbnail(const std::string& path) const { - std::string thumbPath = Util::dirname(path) + SEPERATOR_STR + std::string directory = Params::instance().directory_; + if (directory.empty()) directory = Util::dirname(path); + std::string thumbPath = directory + SEPERATOR_STR + Util::basename(path, true) + "-thumb.jpg"; if (!Util::fileExists(thumbPath, true)) { std::cerr << thumbPath diff --git a/src/exiv2.cpp b/src/exiv2.cpp index 992b4cf6..7a16c591 100644 --- a/src/exiv2.cpp +++ b/src/exiv2.cpp @@ -53,7 +53,7 @@ EXIV2_RCSID("@(#) $Id$"); // local declarations namespace { - //! List of all command itentifiers and corresponding strings + //! List of all command identifiers and corresponding strings static const CmdIdAndString cmdIdAndString[] = { add, "add", set, "set", @@ -179,8 +179,8 @@ void Params::help(std::ostream& os) const os << "\nActions:\n" << " ad | adjust Adjust Exif timestamps by the given time. This\n" << " action requires the option -a time.\n" - << " pr | print Print Exif or Iptc image metadata.\n" - << " rm | delete Delete the Exif section or thumbnail from the files.\n" + << " pr | print Print image metadata.\n" + << " rm | delete Delete image metadata from the files.\n" << " in | insert Insert metadata from corresponding *.exv files.\n" << " ex | extract Extract metadata to *.exv and thumbnail image files.\n" << " mv | rename Rename files according to the Exif create timestamp.\n" @@ -217,8 +217,9 @@ void Params::help(std::ostream& os) const << format_ << ".\n" << " -m file Command file for the modify action. The format for commands is\n" << " set|add|del [[] ].\n" - << " -M cmd One command line for the modify action. The format for the\n" - << " commands is the same as that of the lines of a command file.\n\n"; + << " -M cmd Command line for the modify action. The format for the\n" + << " commands is the same as that of the lines of a command file.\n" + << " -l dir Location (directory) for files to be inserted or extracted.\n\n"; } // Params::help int Params::option(int opt, const std::string& optarg, int optopt) @@ -237,6 +238,7 @@ int Params::option(int opt, const std::string& optarg, int optopt) case 'i': rc = evalInsert(optarg); break; case 'm': rc = evalModify(opt, optarg); break; case 'M': rc = evalModify(opt, optarg); break; + case 'l': directory_ = optarg; break; case ':': std::cerr << progname() << ": Option -" << static_cast(optopt) << " requires an argument\n"; @@ -558,6 +560,10 @@ int Params::getopt(int argc, char* const argv[]) rc = 1; } } + if (!directory_.empty() && !(action_ == Action::insert || action_ == Action::extract)) { + std::cerr << progname() << ": -l option can only be used with extract or insert actions\n"; + rc = 1; + } return rc; } // Params::getopt diff --git a/src/exiv2.hpp b/src/exiv2.hpp index 982029cd..0ae2aab3 100644 --- a/src/exiv2.hpp +++ b/src/exiv2.hpp @@ -141,6 +141,7 @@ public: CmdFiles cmdFiles_; //!< Names of the modification command files CmdLines cmdLines_; //!< Commands from the command line ModifyCmds modifyCmds_; //!< Parsed modification commands + std::string directory_; //!< Location for files to extract/insert Files files_; //!< List of non-option arguments. private: @@ -148,7 +149,7 @@ private: @brief Default constructor. Note that optstring_ is initialized here. The c'tor is private to force instantiation through instance(). */ - Params() : optstring_(":hVvfa:r:p:d:e:i:m:M:"), + Params() : optstring_(":hVvfa:r:p:d:e:i:m:M:l:"), help_(false), version_(false), verbose_(false), diff --git a/test/data/exiv2-test.out b/test/data/exiv2-test.out index c1daa9a7..4a51527e 100644 --- a/test/data/exiv2-test.out +++ b/test/data/exiv2-test.out @@ -9,15 +9,15 @@ This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. Exiv2 help --------------------------------------------------------------- -Usage: lt-exiv2 [ options ] [ action ] file ... +Usage: exiv2 [ options ] [ action ] file ... Manipulate the Exif metadata of images. Actions: ad | adjust Adjust Exif timestamps by the given time. This action requires the option -a time. - pr | print Print Exif or Iptc image metadata. - rm | delete Delete the Exif section or thumbnail from the files. + pr | print Print image metadata. + rm | delete Delete image metadata from the files. in | insert Insert metadata from corresponding *.exv files. ex | extract Extract metadata to *.exv and thumbnail image files. mv | rename Rename files according to the Exif create timestamp. @@ -54,8 +54,9 @@ Options: follows strftime(3). Default filename format is %Y%m%d_%H%M%S. -m file Command file for the modify action. The format for commands is set|add|del [[] ]. - -M cmd One command line for the modify action. The format for the + -M cmd Command line for the modify action. The format for the commands is the same as that of the lines of a command file. + -l dir Location (directory) for files to be inserted or extracted. Adjust -------------------------------------------------------------------