diff --git a/avogadro/io/fileformat.cpp b/avogadro/io/fileformat.cpp index 95f26fa495..e993c56a17 100644 --- a/avogadro/io/fileformat.cpp +++ b/avogadro/io/fileformat.cpp @@ -63,7 +63,7 @@ bool FileFormat::open(const std::string& fileName_, Operation mode_) close(); m_fileName = fileName_; m_mode = mode_; - if (!m_fileName.empty() && validateFileName(m_fileName)) { + if (!m_fileName.empty()) { // Imbue the standard C locale. locale cLocale("C"); if (m_mode & Read) { @@ -76,7 +76,7 @@ bool FileFormat::open(const std::string& fileName_, Operation mode_) appendError("Error opening file: " + fileName_); return false; } - } else if (m_mode & Write) { + } else if (m_mode & Write && validateFileName(m_fileName)) { auto* file = new ofstream(m_fileName.c_str(), std::ofstream::binary); m_out = file; if (file->is_open()) { diff --git a/avogadro/qtgui/fileformatdialog.cpp b/avogadro/qtgui/fileformatdialog.cpp index 16adfcee54..73765967ff 100644 --- a/avogadro/qtgui/fileformatdialog.cpp +++ b/avogadro/qtgui/fileformatdialog.cpp @@ -42,14 +42,6 @@ FileFormatDialog::FormatFilePair FileFormatDialog::fileToRead( if (fileName.isEmpty()) // user cancel return result; - if (FileFormat::validateFileName(fileName.toStdString()) == false) { - QMessageBox::warning( - parent, caption, - tr("The file name contains invalid characters. Please choose another " - "file name.")); - continue; - } - const Io::FileFormat* format = findFileFormat( parent, caption, fileName, FileFormat::File | FileFormat::Read); @@ -94,6 +86,14 @@ FileFormatDialog::FormatFilePair FileFormatDialog::fileToWrite( if (fileName.isEmpty()) // user cancel return result; + if (FileFormat::validateFileName(fileName.toStdString()) == false) { + QMessageBox::warning( + parentWidget, caption, + tr("The file name contains invalid characters. Please choose another " + "file name.")); + continue; + } + const Io::FileFormat* format = findFileFormat( parentWidget, caption, fileName, FileFormat::File | FileFormat::Write);