From a39e6779e4cee8b92ff035a9cd21fbb3d2843657 Mon Sep 17 00:00:00 2001 From: Scott Gilbertson Date: Mon, 15 Jan 2024 15:27:09 -0500 Subject: [PATCH] Fix: If %p or %P queue template term includes start of file path, prepend the leading /, \ or \\ from the file path --- rtgui/batchqueue.cc | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/rtgui/batchqueue.cc b/rtgui/batchqueue.cc index df653976c..bb2d7526f 100644 --- a/rtgui/batchqueue.cc +++ b/rtgui/batchqueue.cc @@ -75,6 +75,23 @@ namespace // local helper functions } return pathIndex; } + + // Extract the initial characters from a canonical absolute path, and append + // those to a path string. Initial characters are '/' for Unix/Linux paths and + // '\\' for UNC paths. A single backslash is also accepted, for driveless + // Windows paths. + void appendAbsolutePathPrefix(Glib::ustring& path, const Glib::ustring& absolutePath) + { + if (absolutePath[0] == '/') { + path += '/'; // Start of a Unix/Linux path + } else if (absolutePath[0] == '\\') { + if (absolutePath.size() > 1 && absolutePath[1] == '\\') { + path += "\\\\"; // Start of a UNC path + } else { + path += '\\'; // Start of a Windows path that does not include a drive letter + } + } + } } BatchQueue::BatchQueue (FileCatalog* aFileCatalog) : processing(nullptr), fileCatalog(aFileCatalog), sequence(0), listener(nullptr) @@ -916,6 +933,9 @@ Glib::ustring BatchQueue::calcAutoFileNameBase (const Glib::ustring& origFileNam ix++; unsigned int n = decodePathIndex(ix, options.savePathTemplate, da.size()); if (n < da.size()) { + if (n == 0) { + appendAbsolutePathPrefix(path, origFileName); + } for (unsigned int i=n; i < da.size(); i++) { path += da[i] + PATH_SEPARATOR; } @@ -930,6 +950,9 @@ Glib::ustring BatchQueue::calcAutoFileNameBase (const Glib::ustring& origFileNam ix++; unsigned int n = decodePathIndex(ix, options.savePathTemplate, da.size()); for (unsigned int i=0; i <= n && i < da.size(); i++) { + if (i == 0) { + appendAbsolutePathPrefix(path, origFileName); + } path += da[i] + PATH_SEPARATOR; } // If the next template character is a separator, skip it, because path already has one