From 92dcac90ae4e3c3a500c80d34fd5f44e54094473 Mon Sep 17 00:00:00 2001 From: Ivan Savenko Date: Sun, 15 Dec 2024 19:15:54 +0000 Subject: [PATCH 1/5] Reload start game tab state on language change --- launcher/startGame/StartGameTab.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/launcher/startGame/StartGameTab.cpp b/launcher/startGame/StartGameTab.cpp index 0f1926a57..bf3e6c3f4 100644 --- a/launcher/startGame/StartGameTab.cpp +++ b/launcher/startGame/StartGameTab.cpp @@ -23,7 +23,10 @@ void StartGameTab::changeEvent(QEvent *event) { if(event->type() == QEvent::LanguageChange) + { ui->retranslateUi(this); + refreshState(); + } QWidget::changeEvent(event); } From 63af2d174fd50d0e1bd45cf28dbd6ee45b52d307 Mon Sep 17 00:00:00 2001 From: Ivan Savenko Date: Sun, 15 Dec 2024 19:16:49 +0000 Subject: [PATCH 2/5] Fix overwriting mod download URL during repo checkout --- launcher/modManager/cmodlistview_moc.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/launcher/modManager/cmodlistview_moc.cpp b/launcher/modManager/cmodlistview_moc.cpp index 79d774b22..99b61a6fd 100644 --- a/launcher/modManager/cmodlistview_moc.cpp +++ b/launcher/modManager/cmodlistview_moc.cpp @@ -27,12 +27,13 @@ #include "../vcmiqt/jsonutils.h" #include "../helper.h" -#include "../../lib/VCMIDirs.h" #include "../../lib/CConfigHandler.h" -#include "../../lib/texts/Languages.h" -#include "../../lib/modding/CModVersion.h" +#include "../../lib/VCMIDirs.h" #include "../../lib/filesystem/Filesystem.h" +#include "../../lib/json/JsonUtils.h" +#include "../../lib/modding/CModVersion.h" #include "../../lib/texts/CGeneralTextHandler.h" +#include "../../lib/texts/Languages.h" #include @@ -747,7 +748,7 @@ void CModListView::installFiles(QStringList files) else if(filename.endsWith(".json", Qt::CaseInsensitive)) { //download and merge additional files - const auto &repoData = JsonUtils::jsonFromFile(filename); + JsonNode repoData = JsonUtils::jsonFromFile(filename); if(repoData["name"].isNull()) { // This is main repository index. Download all referenced mods @@ -769,7 +770,7 @@ void CModListView::installFiles(QStringList files) // This is json of a single mod. Extract name of mod and add it to repo auto modName = QFileInfo(filename).baseName().toStdString(); auto modNameLower = boost::algorithm::to_lower_copy(modName); - accumulatedRepositoryData[modNameLower] = repoData; + JsonUtils::merge(accumulatedRepositoryData[modNameLower], repoData); } } else if(filename.endsWith(".png", Qt::CaseInsensitive)) From 88bf46f57bdf77e42883ae3cba162b4673aed4d2 Mon Sep 17 00:00:00 2001 From: Ivan Savenko Date: Sun, 15 Dec 2024 19:17:06 +0000 Subject: [PATCH 3/5] Add more logging to Launcher --- launcher/modManager/cmodlistview_moc.cpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/launcher/modManager/cmodlistview_moc.cpp b/launcher/modManager/cmodlistview_moc.cpp index 99b61a6fd..27c671586 100644 --- a/launcher/modManager/cmodlistview_moc.cpp +++ b/launcher/modManager/cmodlistview_moc.cpp @@ -779,25 +779,34 @@ void CModListView::installFiles(QStringList files) if (!accumulatedRepositoryData.isNull() && !repositoryFilesEnqueued) { + logGlobal->info("Installing repository: started"); manager->setRepositoryData(accumulatedRepositoryData); modModel->reloadRepositories(); static const QString repositoryCachePath = CLauncherDirs::downloadsPath() + "/repositoryCache.json"; JsonUtils::jsonToFile(repositoryCachePath, modStateModel->getRepositoryData()); + logGlobal->info("Installing repository: ended"); } if(!mods.empty()) { + logGlobal->info("Installing mods: started"); installMods(mods); modStateModel->reloadLocalState(); modModel->reloadRepositories(); + logGlobal->info("Installing mods: ended"); } if(!maps.empty()) + { + logGlobal->info("Installing maps: started"); installMaps(maps); + logGlobal->info("Installing maps: ended"); + } if(!exe.empty()) { + logGlobal->info("Installing chronicles: started"); ui->progressBar->setFormat(tr("Installing Heroes Chronicles")); ui->progressWidget->setVisible(true); ui->pushButton->setEnabled(false); @@ -827,6 +836,7 @@ void CModListView::installFiles(QStringList files) modStateModel->reloadLocalState(); modModel->reloadRepositories(); } + logGlobal->info("Installing chronicles: ended"); } if(!images.empty()) @@ -852,6 +862,7 @@ void CModListView::installMods(QStringList archives) { if(modStateModel->getMod(mod).isInstalled()) { + logGlobal->info("Uninstalling old version of mod '%s'", mod.toStdString()); if (modStateModel->isModEnabled(mod)) modsToEnable.push_back(mod); @@ -866,17 +877,23 @@ void CModListView::installMods(QStringList archives) for(int i = 0; i < modNames.size(); i++) { + logGlobal->info("Installing mod '%s'", modNames[i].toStdString()); ui->progressBar->setFormat(tr("Installing mod %1").arg(modNames[i])); manager->installMod(modNames[i], archives[i]); } if (!modsToEnable.empty()) + { manager->enableMods(modsToEnable); + } checkManagerErrors(); for(QString archive : archives) + { + logGlobal->info("Erasing archive '%s'", archive.toStdString()); QFile::remove(archive); + } } void CModListView::installMaps(QStringList maps) @@ -885,6 +902,7 @@ void CModListView::installMaps(QStringList maps) for(QString map : maps) { + logGlobal->info("Importing map '%s'", map.toStdString()); QFile(map).rename(destDir + map.section('/', -1, -1)); } } From d42ae2995bfe4e631ec23f740fde118a10e9dbdc Mon Sep 17 00:00:00 2001 From: Ivan Savenko Date: Sun, 15 Dec 2024 19:37:25 +0000 Subject: [PATCH 4/5] Fix crash on attempt to install mod not present in mod repository --- launcher/modManager/cmodlistview_moc.cpp | 2 +- launcher/modManager/modstatecontroller.cpp | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/launcher/modManager/cmodlistview_moc.cpp b/launcher/modManager/cmodlistview_moc.cpp index 27c671586..974c4062f 100644 --- a/launcher/modManager/cmodlistview_moc.cpp +++ b/launcher/modManager/cmodlistview_moc.cpp @@ -860,7 +860,7 @@ void CModListView::installMods(QStringList archives) // uninstall old version of mod, if installed for(QString mod : modNames) { - if(modStateModel->getMod(mod).isInstalled()) + if(modStateModel->isModExists(mod) && modStateModel->getMod(mod).isInstalled()) { logGlobal->info("Uninstalling old version of mod '%s'", mod.toStdString()); if (modStateModel->isModEnabled(mod)) diff --git a/launcher/modManager/modstatecontroller.cpp b/launcher/modManager/modstatecontroller.cpp index 718f9841a..77bd3fc03 100644 --- a/launcher/modManager/modstatecontroller.cpp +++ b/launcher/modManager/modstatecontroller.cpp @@ -120,6 +120,9 @@ bool ModStateController::disableMod(QString modname) bool ModStateController::canInstallMod(QString modname) { + if (!modList->isModExists(modname)) + return true; // for installation of unknown mods, e.g. via "Install from file" option + auto mod = modList->getMod(modname); if(mod.isSubmod()) From 50838f24bf956ed93623890253b54f523834fb64 Mon Sep 17 00:00:00 2001 From: Ivan Savenko Date: Sun, 15 Dec 2024 19:43:43 +0000 Subject: [PATCH 5/5] Auto-recover from cases when active preset is invalid --- lib/modding/ModManager.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/modding/ModManager.cpp b/lib/modding/ModManager.cpp index a117eff2c..20dcc9fc6 100644 --- a/lib/modding/ModManager.cpp +++ b/lib/modding/ModManager.cpp @@ -163,7 +163,7 @@ ModsPresetState::ModsPresetState() CResourceHandler::get("local")->createResource(settingsPath.getOriginalName() + ".json"); } - if(modConfig["presets"].isNull()) + if(modConfig["presets"].isNull() || modConfig["presets"].Struct().empty()) { modConfig["activePreset"] = JsonNode("default"); if(modConfig["activeMods"].isNull()) @@ -171,6 +171,10 @@ ModsPresetState::ModsPresetState() else importInitialPreset(); // 1.5 format import } + + auto allPresets = getAllPresets(); + if (!vstd::contains(allPresets, modConfig["activePreset"].String())) + modConfig["activePreset"] = JsonNode(allPresets.front()); } void ModsPresetState::createInitialPreset()