浏览代码

Merge pull request #3845 from Laserlicht/patch-2

innoextract mobile optimization
Ivan Savenko 1 年之前
父节点
当前提交
d1b9562682
共有 1 个文件被更改,包括 30 次插入13 次删除
  1. 30 13
      launcher/firstLaunch/firstlaunch_moc.cpp

+ 30 - 13
launcher/firstLaunch/firstlaunch_moc.cpp

@@ -296,29 +296,46 @@ QString FirstLaunchView::getHeroesInstallDir()
 void FirstLaunchView::extractGogData()
 {
 #ifdef ENABLE_INNOEXTRACT
-	QString filterExe = tr("GOG executable") + " (*.exe)";
-	QString fileExe = QFileDialog::getOpenFileName(this, tr("Select a GOG installer (exe) file..."), QDir::homePath(), filterExe);
+
+	auto fileSelection = [this](QString type, QString filter, QString startPath = {}) {
+		QString titleSel = tr("Select %1 file...", "param is file extension").arg(filter);
+		QString titleErr = tr("You have to select %1 file!", "param is file extension").arg(filter);
+#if defined(VCMI_MOBILE)
+		filter = "GOG file (*.*)";
+		QMessageBox::information(this, tr("File selection"), titleSel);
+#endif
+		QString file = QFileDialog::getOpenFileName(this, titleSel, startPath.isEmpty() ? QDir::homePath() : startPath, filter);
+		if(file.isEmpty())
+			return QString{};
+		else if(!file.endsWith("." + type, Qt::CaseInsensitive))
+		{
+			QMessageBox::critical(this, tr("Invalid file selected"), titleErr);
+			return QString{};
+		}
+
+		return file;
+	};
+
+	QString fileExe = fileSelection("exe", tr("GOG installer") + " (*.exe)");
 	if(fileExe.isEmpty())
 		return;
-
-	QString filterBin = tr("GOG bin file") + " (*.bin)";
-	QString fileBin = QFileDialog::getOpenFileName(this, tr("Select a GOG data (bin) file..."), QFileInfo(fileExe).absolutePath(), filterBin);
+	QString fileBin = fileSelection("bin", tr("GOG data") + " (*.bin)", QFileInfo(fileExe).absolutePath());
 	if(fileBin.isEmpty())
 		return;
 
+	ui->pushButtonGogInstall->setText(tr("Installing... Please wait!"));
+	QPalette pal = ui->pushButtonGogInstall->palette();
+	pal.setColor(QPalette::Button, QColor(Qt::yellow));
+	ui->pushButtonGogInstall->setAutoFillBackground(true);
+	ui->pushButtonGogInstall->setPalette(pal);
+	ui->pushButtonGogInstall->update();
+	ui->pushButtonGogInstall->repaint();
+
 	QTimer::singleShot(100, this, [this, fileExe, fileBin](){ // background to make sure FileDialog is closed...
 		QTemporaryDir dir;
 		if(dir.isValid()) {
 			QDir tempDir{dir.path()};
 
-			ui->pushButtonGogInstall->setText(tr("Installing... Please wait!"));
-			QPalette pal = ui->pushButtonGogInstall->palette();
-			pal.setColor(QPalette::Button, QColor(Qt::yellow));
-			ui->pushButtonGogInstall->setAutoFillBackground(true);
-			ui->pushButtonGogInstall->setPalette(pal);
-			ui->pushButtonGogInstall->update();
-			ui->pushButtonGogInstall->repaint();
-
 			QString tmpFileExe = dir.filePath("h3_gog.exe");
 			QFile(fileExe).copy(tmpFileExe);
 			QFile(fileBin).copy(dir.filePath("h3_gog-1.bin"));