From: Michal MalĂ˝ Date: Sat, 18 Apr 2015 00:35:36 +0000 (+0200) Subject: Fix check for already existing files X-Git-Tag: 0.5c~2 X-Git-Url: https://gitweb.devoid-pointer.net/?a=commitdiff_plain;h=65c51bf3713e08ef00052ab16539f866df1328a3;p=anyanka.git Fix check for already existing files --- diff --git a/datafileexporter.cpp b/datafileexporter.cpp index 1e12c48..54dca7d 100644 --- a/datafileexporter.cpp +++ b/datafileexporter.cpp @@ -47,27 +47,19 @@ DataFileExporter::DataFileExporter(QObject* parent) : DataFileExporter::ReturnCode DataFileExporter:: exportData(const WriteList& list, const QString& path, const std::string& formatTag) { - QDir dir(path); - QFile file(path); - QString plainName = file.fileName(); OutputFormats format; DataFileExporter::ReturnCode ret; DataWriterBackend* backend; + QDir dir(path); + QFile file(path); + QString plainName = file.fileName(); if (path.compare("") == 0) { return ReturnCode::E_NO_OUTPUT; } if (dir.exists()) { return ReturnCode::E_IS_DIRECTORY; - } - - if (file.exists()) { - int ret = QMessageBox::question(nullptr, "Data export", "The selected file already exists. Do you wish to overwrite it?"); - if (ret == QMessageBox::No) - return ReturnCode::E_WOULD_OVERWRITE; - else - file.remove(); - } + } format = formatTagToFormat(formatTag); switch (format) { @@ -86,6 +78,15 @@ exportData(const WriteList& list, const QString& path, const std::string& format else file.setFileName(backend->filename(plainName)); + if (file.exists()) { + int ret = QMessageBox::question(nullptr, "Data export", QString("The selected file \"%1\" already exists. Do you wish to overwrite it?").arg(file.fileName())); + if (ret == QMessageBox::No) { + file.close(); + continue; + } else + file.remove(); + } + if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) { QMessageBox::critical(nullptr, "Data export error", "Cannot open output file '" + file.fileName() + "' for writing."); ret = ReturnCode::E_FAILED;