GUI: mux: unique file names: only remove trailing number on directory changes

The caller of the function `generateUniqueOutputFileName` knows
whether or not the base name given to the function is the base name of
the first added file or the current content of the destination file
name control. Only in the latter case is the suffix added for
uniqueness present and has to be removed.
This commit is contained in:
Moritz Bunkus 2019-08-19 13:33:25 +02:00
parent 22ec2f9ac4
commit 07b412ae6b
No known key found for this signature in database
GPG Key ID: 74AF00ADF2E32C85
4 changed files with 20 additions and 5 deletions

View File

@ -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

View File

@ -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;

View File

@ -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));
}

View File

@ -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);