From b97f863ea832d69278d3249775bb51378037d7f4 Mon Sep 17 00:00:00 2001 From: woblight Date: Sun, 2 Apr 2023 23:13:20 +0200 Subject: [PATCH] Do not change folder name if multiple toc files are present and they do not match supported suffixes. --- control.cpp | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/control.cpp b/control.cpp index aafa633..0f99b1b 100644 --- a/control.cpp +++ b/control.cpp @@ -374,18 +374,27 @@ void Control::clone(QUrl url, int i) QDir dir(m_addonsPaths[i]); dir.cd(data.name); QStringList tocs = dir.entryList({"*.toc"}); - if (tocs.isEmpty()) { - } else { - auto toc = tocs.first(); - toc.replace("-Classic.toc",".toc", Qt::CaseInsensitive); - toc.replace("-BCC.toc",".toc", Qt::CaseInsensitive); - toc.replace("_Vanilla.toc",".toc", Qt::CaseInsensitive); - toc.replace("_TBC.toc",".toc", Qt::CaseInsensitive); - toc.replace("_Mainline.toc",".toc", Qt::CaseInsensitive); - if (toc.toLower() != dir.dirName().toLower() + ".toc") { + QString expectedTocName = dir.dirName() + ".toc"; + if (!tocs.isEmpty()) { + std::transform(tocs.begin(), tocs.end(), + tocs.begin(), + [](auto toc) { + toc.replace("-Classic.toc",".toc", Qt::CaseInsensitive); + toc.replace("-BCC.toc",".toc", Qt::CaseInsensitive); + toc.replace("_Vanilla.toc",".toc", Qt::CaseInsensitive); + toc.replace("_TBC.toc",".toc", Qt::CaseInsensitive); + toc.replace("_Mainline.toc",".toc", Qt::CaseInsensitive); + toc.replace("_Wrath.toc",".toc", Qt::CaseInsensitive); + toc.replace("-WOTLKC.toc",".toc", Qt::CaseInsensitive); + return toc; + }); + if (!std::all_of(tocs.begin() + 1, tocs.end(), + [tocs](const auto &toc){ return !QString::compare(toc, tocs.first()); })) + qWarning() << "Multiple toc files found! Expect troubles..."; + else if (QString::compare(tocs.first(), dir.dirName() + ".toc", Qt::CaseInsensitive)) { git_repository_free(data.repo); dir.cdUp(); - QString newName = toc.chopped(4); + QString newName = tocs.first().chopped(4); dir.rename(data.name, newName); data.name = newName; dir.cd(data.name);