diff --git a/rtdata/options/options.lin b/rtdata/options/options.lin index 26a34c75c..54b5a2c01 100644 --- a/rtdata/options/options.lin +++ b/rtdata/options/options.lin @@ -57,6 +57,7 @@ PathTemplate=%p1/converted/%f PathFolder= UsePathTemplate=true LastSaveAsPath= +OverwriteOutputFile=false [Profiles] Directory=profiles diff --git a/rtdata/options/options.osx b/rtdata/options/options.osx index 1fcbc3750..1793efe78 100644 --- a/rtdata/options/options.osx +++ b/rtdata/options/options.osx @@ -57,6 +57,7 @@ PathTemplate=%p1/converted/%f PathFolder= UsePathTemplate=true LastSaveAsPath= +OverwriteOutputFile=false [Profiles] Directory=profiles diff --git a/rtdata/options/options.win b/rtdata/options/options.win index 27c925967..519c5bdd3 100644 --- a/rtdata/options/options.win +++ b/rtdata/options/options.win @@ -57,6 +57,7 @@ PathTemplate=%p1/converted/%f PathFolder= UsePathTemplate=true LastSaveAsPath= +OverwriteOutputFile=false [Profiles] Directory=profiles diff --git a/rtengine/imageio.cc b/rtengine/imageio.cc index b7659800e..59c32ebc5 100644 --- a/rtengine/imageio.cc +++ b/rtengine/imageio.cc @@ -482,7 +482,7 @@ int ImageIO::savePNG (Glib::ustring fname, int compression, int bps) { fclose (file); // Rename temporary filename, practically atomic - rename(safe_locale_from_utf8(tmpFname).c_str (),safe_locale_from_utf8(fname).c_str ()); + g_rename(safe_locale_from_utf8(tmpFname).c_str (),safe_locale_from_utf8(fname).c_str ()); if (pl) { pl->setProgressStr ("Ready."); @@ -596,7 +596,7 @@ int ImageIO::saveJPEG (Glib::ustring fname, int quality) { fclose (file); // Rename temporary filename, practically atomic - rename(safe_locale_from_utf8(tmpFname).c_str (),safe_locale_from_utf8(fname).c_str ()); + g_rename(safe_locale_from_utf8(tmpFname).c_str (),safe_locale_from_utf8(fname).c_str ()); if (pl) { pl->setProgressStr ("Ready."); diff --git a/rtgui/batchqueue.cc b/rtgui/batchqueue.cc index 10571944d..01da0ab11 100644 --- a/rtgui/batchqueue.cc +++ b/rtgui/batchqueue.cc @@ -18,10 +18,12 @@ */ #include #include +#include #include #include #include #include +#include using namespace rtengine; @@ -335,6 +337,10 @@ Glib::ustring BatchQueue::autoCompleteFileName (const Glib::ustring& fileName, c // create directory, if does not exist if (g_mkdir_with_parents (dstdir.c_str(), 0755) ) return ""; + + // In overwrite mode we TRY to delete the old file first. + // if that's not possible (e.g. locked by viewer, R/O), we revert to the standard naming scheme + bool inOverwriteMode=options.overwriteOutputFile; for (int tries=0; tries<100; tries++) { Glib::ustring fname; @@ -343,7 +349,16 @@ Glib::ustring BatchQueue::autoCompleteFileName (const Glib::ustring& fileName, c else fname = Glib::ustring::compose ("%1-%2.%3", Glib::build_filename (dstdir, dstfname), tries, format); - if (!Glib::file_test (fname, Glib::FILE_TEST_EXISTS)) { + int fileExists=Glib::file_test (fname, Glib::FILE_TEST_EXISTS); + + if (inOverwriteMode && fileExists) { + if (g_remove(safe_locale_from_utf8(fname).c_str ()) == -1) + inOverwriteMode = false; // failed to delete- revert to old naming scheme + else + fileExists = false; // deleted now + } + + if (!fileExists) { return fname; } } diff --git a/rtgui/options.cc b/rtgui/options.cc index 175dc56e0..9a52d6d45 100644 --- a/rtgui/options.cc +++ b/rtgui/options.cc @@ -209,6 +209,7 @@ if (keyFile.has_group ("Output")) { if (keyFile.has_key ("Output", "AutoSuffix")) autoSuffix = keyFile.get_boolean("Output", "AutoSuffix"); if (keyFile.has_key ("Output", "UsePathTemplate")) saveUsePathTemplate = keyFile.get_boolean("Output", "UsePathTemplate"); if (keyFile.has_key ("Output", "LastSaveAsPath")) lastSaveAsPath = keyFile.get_string ("Output", "LastSaveAsPath"); + if (keyFile.has_key ("Output", "OverwriteOutputFile")) overwriteOutputFile = keyFile.get_boolean("Output", "OverwriteOutputFile"); } if (keyFile.has_group ("Profiles")) { @@ -375,6 +376,7 @@ int Options::saveToFile (Glib::ustring fname) { keyFile.set_boolean ("Output", "AutoSuffix", autoSuffix); keyFile.set_boolean ("Output", "UsePathTemplate", saveUsePathTemplate); keyFile.set_string ("Output", "LastSaveAsPath", lastSaveAsPath); + keyFile.set_boolean ("Output", "OverwriteOutputFile", overwriteOutputFile); keyFile.set_string ("Profiles", "Directory", profilePath); keyFile.set_string ("Profiles", "RawDefault", defProfRaw); diff --git a/rtgui/options.h b/rtgui/options.h index 495ab241e..3b313c6f9 100644 --- a/rtgui/options.h +++ b/rtgui/options.h @@ -123,6 +123,7 @@ class Options { std::vector favoriteDirs; std::vector renameTemplates; bool renameUseTemplates; + bool overwriteOutputFile; std::vector thumbnailZoomRatios; bool overlayedFileNames;