diff options
author | Chris Xiong <chirs241097@gmail.com> | 2022-10-07 22:28:27 -0400 |
---|---|---|
committer | Chris Xiong <chirs241097@gmail.com> | 2022-10-07 22:28:27 -0400 |
commit | 350b0dd1780f93e15fd86ebf8b38f96e3987edb3 (patch) | |
tree | 51491ee9b01d2f533d110a2e9e135cbca205257b | |
parent | 0069cd015c713bca311adbdcd7c0578c64cdddf8 (diff) | |
download | deduper-350b0dd1780f93e15fd86ebf8b38f96e3987edb3.tar.xz |
Avoid using std::wfstream when it crashes on mingw. Patch by @BLumia.
-rw-r--r-- | qdeduper/mingui.cpp | 37 |
1 files 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<ImageItem*>(im->item(i))->path()); |