diff --git a/NEWS.md b/NEWS.md index 3974e820f..f7e421522 100644 --- a/NEWS.md +++ b/NEWS.md @@ -6,6 +6,15 @@ Wikipedia's "List of languages by native speakers" by default. Also by default only those languages will be shown in the language drop-down boxes. +## Bug fixes + +* MKVToolNix GUI: multiplexer: fixed a bug in the "make destination file names + unique" logic that caused an existing number-in-parenthesis at the end of + the file base name to be removed in certain situations (e.g. when the first + added file was named `m (3).mkv` and both `m (3) (1).mkv` and `m (3) + (2).mkv` existed already, the GUI was suddenly use `m.mkv` instead of `m (3) + (3).mkv`). + # Version 36.0.0 "Is That Jazz?" 2019-08-10 diff --git a/src/mkvtoolnix-gui/merge/input.cpp b/src/mkvtoolnix-gui/merge/input.cpp index 988a2d1ab..b0b475891 100644 --- a/src/mkvtoolnix-gui/merge/input.cpp +++ b/src/mkvtoolnix-gui/merge/input.cpp @@ -1562,13 +1562,19 @@ Tab::setOutputFileNameMaybe(bool force) { QString Tab::generateUniqueOutputFileName(QString const &baseName, - QDir const &outputDir) { + QDir const &outputDir, + bool removeUniquenessSuffix) { auto &settings = Util::Settings::get(); auto cleanedBaseName = baseName; auto suffix = suggestOutputFileNameExtension(); + auto needToRemove = removeUniquenessSuffix + && !m_config.m_destinationUniquenessSuffix.isEmpty() + && cleanedBaseName.endsWith(m_config.m_destinationUniquenessSuffix); - if ( !m_config.m_destinationUniquenessSuffix.isEmpty() - && cleanedBaseName.endsWith(m_config.m_destinationUniquenessSuffix)) + qDebug() << "generateUniqueOutputFileName: baseName" << baseName << "suffix" << suffix << "destinationUniquenessSuffix" << m_config.m_destinationUniquenessSuffix + << "removeUniquenessSuffix" << removeUniquenessSuffix << "needToRemove" << needToRemove; + + if (needToRemove) cleanedBaseName.remove(cleanedBaseName.length() - m_config.m_destinationUniquenessSuffix.length(), m_config.m_destinationUniquenessSuffix.length()); auto idx = 0; diff --git a/src/mkvtoolnix-gui/merge/output.cpp b/src/mkvtoolnix-gui/merge/output.cpp index 74d869a72..4c13dfe5b 100644 --- a/src/mkvtoolnix-gui/merge/output.cpp +++ b/src/mkvtoolnix-gui/merge/output.cpp @@ -720,7 +720,7 @@ Tab::changeOutputDirectoryTo(QString const &directory) { auto makeUnique = Util::Settings::get().m_uniqueOutputFileNames; auto oldFileName = QFileInfo{ m_config.m_destination }.fileName(); auto newFileName = !oldFileName.isEmpty() ? oldFileName : Q("%1.%2").arg(QY("unnamed")).arg(suggestOutputFileNameExtension()); - auto newFilePath = makeUnique ? generateUniqueOutputFileName(QFileInfo{newFileName}.completeBaseName(), QDir{directory}) : Q("%1/%2").arg(directory).arg(newFileName); + auto newFilePath = makeUnique ? generateUniqueOutputFileName(QFileInfo{newFileName}.completeBaseName(), QDir{directory}, true) : Q("%1/%2").arg(directory).arg(newFileName); ui->output->setText(QDir::toNativeSeparators(newFilePath)); } diff --git a/src/mkvtoolnix-gui/merge/tab.h b/src/mkvtoolnix-gui/merge/tab.h index 58fbd7f5c..2ebb7718b 100644 --- a/src/mkvtoolnix-gui/merge/tab.h +++ b/src/mkvtoolnix-gui/merge/tab.h @@ -332,7 +332,7 @@ protected: virtual void setOutputFileNameMaybe(bool force = false); virtual QString suggestOutputFileNameExtension() const; - virtual QString generateUniqueOutputFileName(QString const &baseName, QDir const &outputDir); + virtual QString generateUniqueOutputFileName(QString const &baseName, QDir const &outputDir, bool removeUniquenessSuffix = false); virtual void enableDisableAllTracks(bool enable);