From 4db66e25742e2f5146ff75b3c74d9a50e04df0cf Mon Sep 17 00:00:00 2001 From: Moritz Bunkus Date: Tue, 9 Apr 2019 21:35:04 +0200 Subject: [PATCH] GUI: mux: temporarily ignore invalid destination file names Before the GUI tried to make the destination file name valid after each change. This worked badly with the user trying to change the drive letter by adding the new one and removing the old one in two steps. Now the GUI will simply ignore an invalid destination file name for the time being. The file name will still be verified when the job is started or added to the queue. Fixes #2527. --- NEWS.md | 5 +++++ src/mkvtoolnix-gui/merge/output.cpp | 9 ++++----- src/mkvtoolnix-gui/merge/tab.cpp | 13 +++++++++++-- 3 files changed, 20 insertions(+), 7 deletions(-) diff --git a/NEWS.md b/NEWS.md index 07e3313c8..16b093555 100644 --- a/NEWS.md +++ b/NEWS.md @@ -11,6 +11,11 @@ stripped anymore during the process of ensuring the destination file name is unique. Only those suffixes added automatically in prior attempts to make the file name unique will be removed. Fixes #2521. +* MKVToolNix GUI: multiplexer: Windows: the GUI will let the user change the + drive letter part of the destination file name freely again and only verify + its validity right before starting to mux/adding to the job queue. Before it + tried to force that into something valid, often resulting in unintentional + paths (such as "C:\users\…\DC\files\…"). Fixes #2527. # Version 32.0.0 "Astral Progressions" 2019-03-12 diff --git a/src/mkvtoolnix-gui/merge/output.cpp b/src/mkvtoolnix-gui/merge/output.cpp index dc439b089..f0488ce06 100644 --- a/src/mkvtoolnix-gui/merge/output.cpp +++ b/src/mkvtoolnix-gui/merge/output.cpp @@ -342,13 +342,12 @@ Tab::onTitleChanged(QString newValue) { void Tab::setDestination(QString const &newValue) { - QString prefix; #if defined(SYS_WINDOWS) - if (newValue.startsWith(Q(":"))) - prefix = Q(":"); + if (!newValue.contains(QRegularExpression{Q("^[a-zA-Z]:[\\\\/]|^\\\\\\\\.+\\.+")})) + return; #endif - m_config.m_destination = QDir::toNativeSeparators(prefix + Util::removeInvalidPathCharacters(newValue)); + m_config.m_destination = QDir::toNativeSeparators(Util::removeInvalidPathCharacters(newValue)); if (!m_config.m_destination.isEmpty()) { auto &settings = Util::Settings::get(); settings.m_lastOutputDir = QFileInfo{ newValue }.absoluteDir(); @@ -359,7 +358,7 @@ Tab::setDestination(QString const &newValue) { if (m_config.m_destination == newValue) return; - auto newPosition = std::max(ui->output->cursorPosition(), 1) - 1; + auto newPosition = ui->output->cursorPosition(); ui->output->setText(m_config.m_destination); ui->output->setCursorPosition(newPosition); } diff --git a/src/mkvtoolnix-gui/merge/tab.cpp b/src/mkvtoolnix-gui/merge/tab.cpp index 718cb09a6..1e01466a2 100644 --- a/src/mkvtoolnix-gui/merge/tab.cpp +++ b/src/mkvtoolnix-gui/merge/tab.cpp @@ -335,12 +335,21 @@ Tab::retranslateUi() { bool Tab::isReadyForMerging() { - if (m_config.m_destination.isEmpty()) { + auto destination = QDir::toNativeSeparators(ui->output->text()); + + if (destination.isEmpty()) { Util::MessageBox::critical(this)->title(QY("Cannot start multiplexing")).text(QY("You have to set the destination file name before you can start multiplexing or add a job to the job queue.")).exec(); return false; } - if (m_config.m_destination != Util::removeInvalidPathCharacters(m_config.m_destination)) { + auto destinationValid = destination == Util::removeInvalidPathCharacters(destination); + +#if defined(SYS_WINDOWS) + if (destinationValid) + destinationValid = destination.contains(QRegularExpression{Q("^[a-zA-Z]:[\\\\/]|^\\\\\\\\.+\\.+")}); +#endif // SYS_WINDOWS + + if (!destinationValid) { Util::MessageBox::critical(this)->title(QY("Cannot start multiplexing")).text(QY("The destination file name is invalid and must be fixed before you can start multiplexing or add a job to the job queue.")).exec(); return false; }