瀏覽代碼

Install from file; add translation strings; fix button size

Laserlicht 1 年之前
父節點
當前提交
19f606e84b

+ 4 - 4
launcher/firstLaunch/firstlaunch_moc.cpp

@@ -379,7 +379,7 @@ void FirstLaunchView::copyHeroesData(const QString & path, bool move)
 
 
 	if(dirData.empty())
 	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;
 		return;
 	}
 	}
 
 
@@ -393,19 +393,19 @@ void FirstLaunchView::copyHeroesData(const QString & path, bool move)
 		if (roeFiles.empty())
 		if (roeFiles.empty())
 		{
 		{
 			// Directory structure is correct (Data/Maps/Mp3) but no .lod archives that should be present in any install
 			// 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;
 			return;
 		}
 		}
 
 
 		if (!hdFiles.empty())
 		if (!hdFiles.empty())
 		{
 		{
 			// HD Edition contains only RoE data so we can't use even unmodified files from it
 			// 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;
 			return;
 		}
 		}
 
 
 		// RoE or some other unsupported edition. Demo version?
 		// 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;
 		return;
 	}
 	}
 
 

+ 23 - 0
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)
 void CModListView::downloadFile(QString file, QString url, QString description, qint64 size)
 {
 {
 	if(!dlManager)
 	if(!dlManager)

+ 2 - 0
launcher/modManager/cmodlistview_moc.h

@@ -120,6 +120,8 @@ private slots:
 
 
 	void on_installButton_clicked();
 	void on_installButton_clicked();
 
 
+	void on_installFromFileButton_clicked();
+
 	void on_pushButton_clicked();
 	void on_pushButton_clicked();
 
 
 	void on_refreshButton_clicked();
 	void on_refreshButton_clicked();

+ 36 - 1
launcher/modManager/cmodlistview_moc.ui

@@ -349,6 +349,41 @@ hr { height: 1px; border-width: 0; }
      <property name="spacing">
      <property name="spacing">
       <number>6</number>
       <number>6</number>
      </property>
      </property>
+     <item>
+      <widget class="QPushButton" name="installFromFileButton">
+       <property name="sizePolicy">
+        <sizepolicy hsizetype="Expanding" vsizetype="Fixed">
+         <horstretch>0</horstretch>
+         <verstretch>0</verstretch>
+        </sizepolicy>
+       </property>
+       <property name="minimumSize">
+        <size>
+         <width>51</width>
+         <height>0</height>
+        </size>
+       </property>
+       <property name="maximumSize">
+        <size>
+         <width>150</width>
+         <height>16777215</height>
+        </size>
+       </property>
+       <property name="text">
+        <string>Install from file</string>
+       </property>
+       <property name="icon">
+        <iconset>
+         <normaloff>icons:mod-download.png</normaloff>icons:mod-download.png</iconset>
+       </property>
+       <property name="iconSize">
+        <size>
+         <width>20</width>
+         <height>20</height>
+        </size>
+       </property>
+      </widget>
+     </item>
      <item>
      <item>
       <spacer name="modButtonSpacer">
       <spacer name="modButtonSpacer">
        <property name="orientation">
        <property name="orientation">
@@ -521,7 +556,7 @@ hr { height: 1px; border-width: 0; }
        </property>
        </property>
        <property name="maximumSize">
        <property name="maximumSize">
         <size>
         <size>
-         <width>100</width>
+         <width>120</width>
          <height>16777215</height>
          <height>16777215</height>
         </size>
         </size>
        </property>
        </property>

+ 3 - 3
launcher/modManager/cmodmanager.cpp

@@ -274,15 +274,15 @@ bool CModManager::doInstallMod(QString modname, QString archivePath)
 	const auto destDir = CLauncherDirs::modsPath() + QChar{'/'};
 	const auto destDir = CLauncherDirs::modsPath() + QChar{'/'};
 
 
 	if(!QFile(archivePath).exists())
 	if(!QFile(archivePath).exists())
-		return addError(modname, "Mod archive is missing");
+		return addError(modname, tr("Mod archive is missing"));
 
 
 	if(localMods.contains(modname))
 	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<std::string> filesToExtract;
 	std::vector<std::string> filesToExtract;
 	QString modDirName = ::detectModArchive(archivePath, modname, filesToExtract);
 	QString modDirName = ::detectModArchive(archivePath, modname, filesToExtract);
 	if(!modDirName.size())
 	if(!modDirName.size())
-		return addError(modname, "Mod archive is invalid or corrupted");
+		return addError(modname, tr("Mod archive is invalid or corrupted"));
 	
 	
 	std::atomic<int> filesCounter = 0;
 	std::atomic<int> filesCounter = 0;