From 19f606e84bb207997ff41f32d302a6dd7467e76e Mon Sep 17 00:00:00 2001
From: Laserlicht <13953785+Laserlicht@users.noreply.github.com>
Date: Sat, 20 Apr 2024 00:26:58 +0200
Subject: [PATCH] Install from file; add translation strings; fix button size
---
launcher/firstLaunch/firstlaunch_moc.cpp | 8 ++---
launcher/modManager/cmodlistview_moc.cpp | 23 +++++++++++++++
launcher/modManager/cmodlistview_moc.h | 2 ++
launcher/modManager/cmodlistview_moc.ui | 37 +++++++++++++++++++++++-
launcher/modManager/cmodmanager.cpp | 6 ++--
5 files changed, 68 insertions(+), 8 deletions(-)
diff --git a/launcher/firstLaunch/firstlaunch_moc.cpp b/launcher/firstLaunch/firstlaunch_moc.cpp
index 0ea484ffa..c21e66e07 100644
--- a/launcher/firstLaunch/firstlaunch_moc.cpp
+++ b/launcher/firstLaunch/firstlaunch_moc.cpp
@@ -379,7 +379,7 @@ void FirstLaunchView::copyHeroesData(const QString & path, bool move)
if(dirData.empty())
{
- QMessageBox::critical(this, "Heroes III data not found!", "Failed to detect valid Heroes III data in chosen directory.\nPlease select directory with installed Heroes III data.");
+ QMessageBox::critical(this, tr("Heroes III data not found!"), tr("Failed to detect valid Heroes III data in chosen directory.\nPlease select directory with installed Heroes III data."));
return;
}
@@ -393,19 +393,19 @@ void FirstLaunchView::copyHeroesData(const QString & path, bool move)
if (roeFiles.empty())
{
// Directory structure is correct (Data/Maps/Mp3) but no .lod archives that should be present in any install
- QMessageBox::critical(this, "Heroes III data not found!", "Failed to detect valid Heroes III data in chosen directory.\nPlease select directory with installed Heroes III data.");
+ QMessageBox::critical(this, tr("Heroes III data not found!"), tr("Failed to detect valid Heroes III data in chosen directory.\nPlease select directory with installed Heroes III data."));
return;
}
if (!hdFiles.empty())
{
// HD Edition contains only RoE data so we can't use even unmodified files from it
- QMessageBox::critical(this, "Heroes III data not found!", "Heroes III: HD Edition files are not supported by VCMI.\nPlease select directory with Heroes III: Complete Edition or Heroes III: Shadow of Death.");
+ QMessageBox::critical(this, tr("Heroes III data not found!"), tr("Heroes III: HD Edition files are not supported by VCMI.\nPlease select directory with Heroes III: Complete Edition or Heroes III: Shadow of Death."));
return;
}
// RoE or some other unsupported edition. Demo version?
- QMessageBox::critical(this, "Heroes III data not found!", "Unknown or unsupported Heroes III version found.\nPlease select directory with Heroes III: Complete Edition or Heroes III: Shadow of Death.");
+ QMessageBox::critical(this, tr("Heroes III data not found!"), tr("Unknown or unsupported Heroes III version found.\nPlease select directory with Heroes III: Complete Edition or Heroes III: Shadow of Death."));
return;
}
diff --git a/launcher/modManager/cmodlistview_moc.cpp b/launcher/modManager/cmodlistview_moc.cpp
index 347091803..e60c61c0c 100644
--- a/launcher/modManager/cmodlistview_moc.cpp
+++ b/launcher/modManager/cmodlistview_moc.cpp
@@ -617,6 +617,29 @@ void CModListView::on_installButton_clicked()
}
}
+void CModListView::on_installFromFileButton_clicked()
+{
+ QString filter = tr("Maps") + " (*.h3m *.vmap);;" + tr("Campaigns") + " (*.h3c *.vcmp);;" + tr("Mods") + " (*.zip)";
+ QStringList files = QFileDialog::getOpenFileNames(this, tr("Select files (mods, maps, campaigns) to install..."), QDir::homePath(), filter);
+
+ for (const auto & file : files)
+ {
+ QUrl url = QUrl::fromLocalFile(file);
+ QString fileUrl = url.toString();
+ QString fileName = url.fileName();
+
+ if(fileUrl.endsWith(".zip", Qt::CaseInsensitive))
+ downloadFile(fileName.toLower()
+ // mod name currently comes from zip file -> remove suffixes from github zip download
+ .replace(QRegularExpression("-[0-9a-f]{40}"), "")
+ .replace(QRegularExpression("-vcmi-.+\\.zip"), ".zip")
+ .replace("-main.zip", ".zip")
+ , fileUrl, "mods", 0);
+ else
+ downloadFile(fileName, fileUrl, "mods", 0);
+ }
+}
+
void CModListView::downloadFile(QString file, QString url, QString description, qint64 size)
{
if(!dlManager)
diff --git a/launcher/modManager/cmodlistview_moc.h b/launcher/modManager/cmodlistview_moc.h
index 2edbab3a8..1c8ae7c28 100644
--- a/launcher/modManager/cmodlistview_moc.h
+++ b/launcher/modManager/cmodlistview_moc.h
@@ -120,6 +120,8 @@ private slots:
void on_installButton_clicked();
+ void on_installFromFileButton_clicked();
+
void on_pushButton_clicked();
void on_refreshButton_clicked();
diff --git a/launcher/modManager/cmodlistview_moc.ui b/launcher/modManager/cmodlistview_moc.ui
index d5bfa0b34..2b3759669 100644
--- a/launcher/modManager/cmodlistview_moc.ui
+++ b/launcher/modManager/cmodlistview_moc.ui
@@ -349,6 +349,41 @@ hr { height: 1px; border-width: 0; }
6
+ -
+
+
+
+ 0
+ 0
+
+
+
+
+ 51
+ 0
+
+
+
+
+ 150
+ 16777215
+
+
+
+ Install from file
+
+
+
+ icons:mod-download.pngicons:mod-download.png
+
+
+
+ 20
+ 20
+
+
+
+
-
@@ -521,7 +556,7 @@ hr { height: 1px; border-width: 0; }
- 100
+ 120
16777215
diff --git a/launcher/modManager/cmodmanager.cpp b/launcher/modManager/cmodmanager.cpp
index d50747e73..aa0aee4e1 100644
--- a/launcher/modManager/cmodmanager.cpp
+++ b/launcher/modManager/cmodmanager.cpp
@@ -274,15 +274,15 @@ bool CModManager::doInstallMod(QString modname, QString archivePath)
const auto destDir = CLauncherDirs::modsPath() + QChar{'/'};
if(!QFile(archivePath).exists())
- return addError(modname, "Mod archive is missing");
+ return addError(modname, tr("Mod archive is missing"));
if(localMods.contains(modname))
- return addError(modname, "Mod with such name is already installed");
+ return addError(modname, tr("Mod with such name is already installed"));
std::vector filesToExtract;
QString modDirName = ::detectModArchive(archivePath, modname, filesToExtract);
if(!modDirName.size())
- return addError(modname, "Mod archive is invalid or corrupted");
+ return addError(modname, tr("Mod archive is invalid or corrupted"));
std::atomic filesCounter = 0;