diff --git a/app/CMakeLists.txt b/app/CMakeLists.txt index a06bc53d..e3bbf0f3 100644 --- a/app/CMakeLists.txt +++ b/app/CMakeLists.txt @@ -4,7 +4,6 @@ add_executable( exiv2 actions.cpp actions.hpp getopt.cpp getopt.hpp app_utils.cpp app_utils.hpp - $ ) target_include_directories(exiv2 PRIVATE ${CMAKE_SOURCE_DIR}/src) # To find i18n.hpp diff --git a/app/actions.cpp b/app/actions.cpp index f8cefa07..6175a982 100644 --- a/app/actions.cpp +++ b/app/actions.cpp @@ -1975,20 +1975,19 @@ namespace { std::string path = newPath; auto oldFsPath = fs::path(path); std::string format = Params::instance().format_; - replace(format, ":basename:", p.stem().string()); - replace(format, ":dirname:", p.parent_path().filename().string()); + replace(format, ":basename:", p.stem().string()); + replace(format, ":dirname:", p.parent_path().filename().string()); replace(format, ":parentname:", p.parent_path().parent_path().filename().string()); const size_t max = 1024; char basename[max]; std::memset(basename, 0x0, max); if (strftime(basename, max, format.c_str(), tm) == 0) { - std::cerr << _("Filename format yields empty filename for the file") << " " - << path << "\n"; + std::cerr << _("Filename format yields empty filename for the file") << " " << path << "\n"; return 1; } - newPath = p.parent_path() / (basename + p.extension().string()); + newPath = (p.parent_path() / (basename + p.extension().string())).string(); p = fs::path(newPath); if (p.parent_path() == oldFsPath.parent_path() && p.filename() == oldFsPath.filename()) { @@ -2001,44 +2000,40 @@ namespace { bool go = true; int seq = 1; std::string s; - Params::FileExistsPolicy fileExistsPolicy - = Params::instance().fileExistsPolicy_; + Params::FileExistsPolicy fileExistsPolicy = Params::instance().fileExistsPolicy_; while (go) { if (Exiv2::fileExists(newPath)) { switch (fileExistsPolicy) { - case Params::overwritePolicy: - go = false; - break; - case Params::renamePolicy: - newPath = p.parent_path() / (std::string(basename) + "_" - + Exiv2::toString(seq++) - + p.extension().string()); - break; - case Params::askPolicy: - std::cout << Params::instance().progname() - << ": " << _("File") << " `" << newPath - << "' " << _("exists. [O]verwrite, [r]ename or [s]kip?") - << " "; - std::cin >> s; - switch (s.at(0)) { - case 'o': - case 'O': + case Params::overwritePolicy: go = false; break; - case 'r': - case 'R': - fileExistsPolicy = Params::renamePolicy; - newPath = p.parent_path() / (std::string(basename) + "_" - + Exiv2::toString(seq++) - + p.extension().string()); + case Params::renamePolicy: + newPath = (p.parent_path() / + (std::string(basename) + "_" + Exiv2::toString(seq++) + p.extension().string())) + .string(); break; - default: // skip - return -1; - break; - } + case Params::askPolicy: + std::cout << Params::instance().progname() << ": " << _("File") << " `" << newPath << "' " + << _("exists. [O]verwrite, [r]ename or [s]kip?") << " "; + std::cin >> s; + switch (s.at(0)) { + case 'o': + case 'O': + go = false; + break; + case 'r': + case 'R': + fileExistsPolicy = Params::renamePolicy; + newPath = (p.parent_path() / (std::string(basename) + "_" + Exiv2::toString(seq++) + + p.extension().string())) + .string(); + break; + default: // skip + return -1; + break; + } } - } - else { + } else { go = false; } } @@ -2054,15 +2049,13 @@ namespace { // Workaround for MinGW rename which does not overwrite existing files remove(newPath.c_str()); if (std::rename(path.c_str(), newPath.c_str()) == -1) { - std::cerr << Params::instance().progname() - << ": " << _("Failed to rename") << " " - << path << " " << _("to") << " " << newPath << ": " - << Exiv2::strError() << "\n"; + std::cerr << Params::instance().progname() << ": " << _("Failed to rename") << " " << path << " " << _("to") + << " " << newPath << ": " << Exiv2::strError() << "\n"; return 1; } return 0; - } // renameFile + } std::string newFilePath(const std::string& path, const std::string& ext) { @@ -2072,7 +2065,7 @@ namespace { directory = p.parent_path(); if (Exiv2::fileProtocol(path) != Exiv2::pFile) directory.clear(); // use current directory for remote files - return directory / (p.stem().string() + ext); + return (directory / (p.stem().string() + ext)).string(); } int dontOverwrite(const std::string& path) diff --git a/src/wmain.c b/app/wmain.c similarity index 100% rename from src/wmain.c rename to app/wmain.c