From ee53312652af10fbddb5d1d16db6212bca2b9665 Mon Sep 17 00:00:00 2001 From: isanae <14251494+isanae@users.noreply.github.com> Date: Mon, 17 Aug 2020 02:41:57 -0400 Subject: moved naturalCompare() to uibase don't try to delete paths that don't exist natsort for instance names and games --- src/createinstancedialogpages.cpp | 6 +++--- src/instancemanagerdialog.cpp | 38 +++++++++++++++++++++++++----------- src/modinfodialog.cpp | 24 ----------------------- src/modinfodialogconflictsmodels.cpp | 3 +++ src/modinfodialogfwd.h | 3 --- 5 files changed, 33 insertions(+), 41 deletions(-) (limited to 'src') diff --git a/src/createinstancedialogpages.cpp b/src/createinstancedialogpages.cpp index 8d304635..73b265c8 100644 --- a/src/createinstancedialogpages.cpp +++ b/src/createinstancedialogpages.cpp @@ -7,13 +7,13 @@ #include "shared/appconfig.h" #include #include +#include namespace cid { -using MOBase::IPluginGame; +using namespace MOBase; using MOBase::TaskDialog; -using MOBase::FilterWidget; QString makeDefaultPath(const std::wstring& dir) { @@ -305,7 +305,7 @@ std::vector GamePage::sortedGamePlugins() const } std::sort(v.begin(), v.end(), [](auto* a, auto* b) { - return (a->gameName() < b->gameName()); + return (naturalCompare(a->gameName(), b->gameName()) < 0); }); return v; diff --git a/src/instancemanagerdialog.cpp b/src/instancemanagerdialog.cpp index 37bdea7b..3b9dd344 100644 --- a/src/instancemanagerdialog.cpp +++ b/src/instancemanagerdialog.cpp @@ -191,13 +191,17 @@ public: // a portable instance has its location in the installation directory, // don't delete that if (!isPortable()) { - roots.push_back({loc, true}); + if (QDir(loc).exists()) { + roots.push_back({loc, true}); + } } // the base directory is the location directory by default, don't add it // if it's the same if (canonicalDir(base) != canonicalDir(loc)) { - roots.push_back({base, false}); + if (QDir(base).exists()) { + roots.push_back({base, false}); + } } @@ -234,8 +238,11 @@ public: } if (!inRoots) { - // not in roots, this is a path that was changed by the user - cleanDirs.push_back({prettyDir(f.path), f.mandatoryDelete}); + // not in roots, this is a path that was changed by the user; make + // sure it exists + if (QDir(f.path).exists()) { + cleanDirs.push_back({prettyDir(f.path), f.mandatoryDelete}); + } } } @@ -264,8 +271,11 @@ public: } if (!inRoots) { - // not in roots, this is a path that was changed by the user - cleanFiles.push_back({prettyFile(f.path), f.mandatoryDelete}); + // not in roots, this is a path that was changed by the user; make + // sure it exists + if (QFileInfo(f.path).exists()) { + cleanFiles.push_back({prettyFile(f.path), f.mandatoryDelete}); + } } } @@ -338,14 +348,20 @@ void InstanceManagerDialog::updateInstances() m_instances.clear(); - if (m.portableInstanceExists()) { - m_instances.push_back(std::make_unique( - m.portablePath(), true)); - } - for (auto&& d : m.instancePaths()) { m_instances.push_back(std::make_unique(d, false)); } + + // sort first, prepend portable after so it's always on top + std::sort(m_instances.begin(), m_instances.end(), [](auto&& a, auto&& b) { + return (MOBase::naturalCompare(a->name(), b->name()) < 0); + }); + + if (m.portableInstanceExists()) { + m_instances.insert( + m_instances.begin(), + std::make_unique(m.portablePath(), true)); + } } void InstanceManagerDialog::updateList() diff --git a/src/modinfodialog.cpp b/src/modinfodialog.cpp index c3239e0d..cc50d446 100644 --- a/src/modinfodialog.cpp +++ b/src/modinfodialog.cpp @@ -40,30 +40,6 @@ namespace fs = std::filesystem; const int max_scan_for_context_menu = 50; -int naturalCompare(const QString& a, const QString& b) -{ - static QCollator c = []{ - QCollator c; - c.setNumericMode(true); - c.setCaseSensitivity(Qt::CaseInsensitive); - return c; - }(); - - - // todo: remove this once the fix is released - // see https://bugreports.qt.io/projects/QTBUG/issues/QTBUG-81673 - // and https://codereview.qt-project.org/c/qt/qtbase/+/287966/5/src/corelib/text/qcollator_win.cpp - if (!a.size()) { - return b.size() ? -1 : 0; - } - if (!b.size()) { - return +1; - } - - - return c.compare(a, b); -} - bool canPreviewFile( const PluginContainer& pluginContainer, bool isArchive, const QString& filename) diff --git a/src/modinfodialogconflictsmodels.cpp b/src/modinfodialogconflictsmodels.cpp index 17fdef90..464abbd3 100644 --- a/src/modinfodialogconflictsmodels.cpp +++ b/src/modinfodialogconflictsmodels.cpp @@ -1,5 +1,8 @@ #include "modinfodialogconflictsmodels.h" #include "modinfodialog.h" +#include + +using MOBase::naturalCompare; ConflictItem::ConflictItem( QString before, QString relativeName, QString after, diff --git a/src/modinfodialogfwd.h b/src/modinfodialogfwd.h index c758573c..805e8a06 100644 --- a/src/modinfodialogfwd.h +++ b/src/modinfodialogfwd.h @@ -35,9 +35,6 @@ FileRenamer::RenameResults unhideFile(FileRenamer& renamer, const QString& oldNa FileRenamer::RenameResults restoreHiddenFilesRecursive(FileRenamer& renamer, const QString &targetDir); -int naturalCompare(const QString& a, const QString& b); - - class ElideLeftDelegate : public QStyledItemDelegate { public: -- cgit v1.3.1