New option OverwriteOutputFile
This commit is contained in:
@@ -57,6 +57,7 @@ PathTemplate=%p1/converted/%f
|
||||
PathFolder=
|
||||
UsePathTemplate=true
|
||||
LastSaveAsPath=
|
||||
OverwriteOutputFile=false
|
||||
|
||||
[Profiles]
|
||||
Directory=profiles
|
||||
|
@@ -57,6 +57,7 @@ PathTemplate=%p1/converted/%f
|
||||
PathFolder=
|
||||
UsePathTemplate=true
|
||||
LastSaveAsPath=
|
||||
OverwriteOutputFile=false
|
||||
|
||||
[Profiles]
|
||||
Directory=profiles
|
||||
|
@@ -57,6 +57,7 @@ PathTemplate=%p1/converted/%f
|
||||
PathFolder=
|
||||
UsePathTemplate=true
|
||||
LastSaveAsPath=
|
||||
OverwriteOutputFile=false
|
||||
|
||||
[Profiles]
|
||||
Directory=profiles
|
||||
|
@@ -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.");
|
||||
|
@@ -18,10 +18,12 @@
|
||||
*/
|
||||
#include <batchqueue.h>
|
||||
#include <glibmm.h>
|
||||
#include <glib/gstdio.h>
|
||||
#include <multilangmgr.h>
|
||||
#include <filecatalog.h>
|
||||
#include <batchqueuebuttonset.h>
|
||||
#include <guiutils.h>
|
||||
#include <safegtk.h>
|
||||
|
||||
using namespace rtengine;
|
||||
|
||||
@@ -336,6 +338,10 @@ Glib::ustring BatchQueue::autoCompleteFileName (const Glib::ustring& fileName, c
|
||||
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;
|
||||
if (tries==0)
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
@@ -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);
|
||||
|
@@ -123,6 +123,7 @@ class Options {
|
||||
std::vector<Glib::ustring> favoriteDirs;
|
||||
std::vector<Glib::ustring> renameTemplates;
|
||||
bool renameUseTemplates;
|
||||
bool overwriteOutputFile;
|
||||
|
||||
std::vector<double> thumbnailZoomRatios;
|
||||
bool overlayedFileNames;
|
||||
|
Reference in New Issue
Block a user