From 350b0dd1780f93e15fd86ebf8b38f96e3987edb3 Mon Sep 17 00:00:00 2001 From: Chris Xiong Date: Fri, 7 Oct 2022 22:28:27 -0400 Subject: Avoid using std::wfstream when it crashes on mingw. Patch by @BLumia. --- qdeduper/mingui.cpp | 37 ++++++++++++++++++++----------------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/qdeduper/mingui.cpp b/qdeduper/mingui.cpp index 6ddeda2..dcda53a 100644 --- a/qdeduper/mingui.cpp +++ b/qdeduper/mingui.cpp @@ -653,36 +653,39 @@ void DeduperMainWindow::update_viewstatus(std::size_t cur, std::size_t size) void DeduperMainWindow::save_list() { QString fn = QFileDialog::getSaveFileName(this, "Save list", QString(), "File List (*.txt)"); + QFile file(fn); + if (!file.open(QIODevice::WriteOnly)) return; + QTextStream fst(&file); + for (const fs::path &x : this->marked) + { #if PATH_VALSIZE == 2 - std::wfstream fst(utilities::qstring_to_path(fn), std::ios_base::out); + fst << QString::fromStdWString(x.native()) << Qt::endl; #else - std::fstream fst(utilities::qstring_to_path(fn), std::ios_base::out); + fst << QString::fromStdString(x.native()) << Qt::endl; #endif - if (fst.fail()) return; - for (auto &x : this->marked) - fst << x.native() << std::endl; - fst.close(); + } + this->markschanged = false; } void DeduperMainWindow::load_list() { QString fn = QFileDialog::getOpenFileName(this, "Load list", QString(), "File List (*.txt)"); + QFile file(fn); + if (!file.open(QIODevice::ReadOnly)) return; + this->marked.clear(); + QTextStream in(&file); + while(!in.atEnd()) + { + QString && s = in.readLine(); #if PATH_VALSIZE == 2 - std::wfstream fst(utilities::qstring_to_path(fn), std::ios_base::in); + fs::path p(s.toStdWString()); #else - std::fstream fst(utilities::qstring_to_path(fn), std::ios_base::in); + fs::path p(s.toStdString()); #endif - if (fst.fail()) return; - this->marked.clear(); - while(!fst.eof()) - { - fs::path::string_type s; - std::getline(fst, s); - if (s.back() == fst.widen('\n')) s.pop_back(); - if (!s.empty()) this->marked.insert(s); + if (!s.isEmpty()) this->marked.insert(p); } - fst.close(); + file.close(); for (int i = 0; i < im->rowCount(); ++i) { fs::path p = utilities::qstring_to_path(static_cast(im->item(i))->path()); -- cgit v1.2.3