2
0
Эх сурвалжийг харах

Merge pull request #4238 from kambala-decapitator/android-install-from-file

treat manually selected/dropped file as a file path instead of URL
Ivan Savenko 1 жил өмнө
parent
commit
7775b31182

+ 18 - 19
launcher/modManager/cmodlistview_moc.cpp

@@ -70,9 +70,8 @@ void CModListView::dropEvent(QDropEvent* event)
 	if(mimeData->hasUrls())
 	{
 		const QList<QUrl> urlList = mimeData->urls();
-
 		for (const auto & url : urlList)
-			manualInstallFile(url);
+			manualInstallFile(url.toLocalFile());
 	}
 }
 
@@ -636,23 +635,21 @@ void CModListView::on_installFromFileButton_clicked()
 
 	for (const auto & file : files)
 	{
-		QUrl url = QUrl::fromLocalFile(file);
-		manualInstallFile(url);
+		manualInstallFile(file);
 	}
 }
 
-void CModListView::manualInstallFile(QUrl url)
+void CModListView::manualInstallFile(QString filePath)
 {
-	QString urlStr = url.toString();
-	QString fileName = url.fileName();
-	if(urlStr.endsWith(".zip", Qt::CaseInsensitive))
+	QString fileName = QFileInfo{filePath}.fileName();
+	if(filePath.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")
-			, urlStr, "mods", 0);
-	else if(urlStr.endsWith(".json", Qt::CaseInsensitive))
+			, QUrl::fromLocalFile(filePath), "mods");
+	else if(filePath.endsWith(".json", Qt::CaseInsensitive))
 	{
 		QDir configDir(QString::fromStdString(VCMIDirs::get().userConfigPath().string()));
 		QStringList configFile = configDir.entryList({fileName}, QDir::Filter::Files); // case insensitive check
@@ -663,7 +660,7 @@ void CModListView::manualInstallFile(QUrl url)
 			{
 				const auto configFilePath = configDir.filePath(configFile[0]);
 				QFile::remove(configFilePath);
-				QFile::copy(url.toLocalFile(), configFilePath);
+				QFile::copy(filePath, configFilePath);
 
 				// reload settings
 				Helper::loadSettings();
@@ -676,10 +673,15 @@ void CModListView::manualInstallFile(QUrl url)
 		}
 	}
 	else
-		downloadFile(fileName, urlStr, fileName, 0);
+		downloadFile(fileName, QUrl::fromLocalFile(filePath), fileName);
 }
 
 void CModListView::downloadFile(QString file, QString url, QString description, qint64 size)
+{
+	downloadFile(file, QUrl{url}, description, size);
+}
+
+void CModListView::downloadFile(QString file, QUrl url, QString description, qint64 size)
 {
 	if(!dlManager)
 	{
@@ -690,20 +692,17 @@ void CModListView::downloadFile(QString file, QString url, QString description,
 
 		connect(dlManager, SIGNAL(finished(QStringList,QStringList,QStringList)),
 			this, SLOT(downloadFinished(QStringList,QStringList,QStringList)));
-		
+
 		connect(manager.get(), SIGNAL(extractionProgress(qint64,qint64)),
 			this, SLOT(extractionProgress(qint64,qint64)));
-		
-		connect(modModel, &CModListModel::dataChanged, filterModel, &QAbstractItemModel::dataChanged);
 
-		
-		QString progressBarFormat = tr("Downloading %s%. %p% (%v MB out of %m MB) finished");
+		connect(modModel, &CModListModel::dataChanged, filterModel, &QAbstractItemModel::dataChanged);
 
-		progressBarFormat.replace("%s%", description);
+		const auto progressBarFormat = tr("Downloading %1. %p% (%v MB out of %m MB) finished").arg(description);
 		ui->progressBar->setFormat(progressBarFormat);
 	}
 
-	dlManager->downloadFile(QUrl(url), file, size);
+	dlManager->downloadFile(url, file, size);
 }
 
 void CModListView::downloadProgress(qint64 current, qint64 max)

+ 2 - 1
launcher/modManager/cmodlistview_moc.h

@@ -51,8 +51,9 @@ class CModListView : public QWidget
 	// find mods that depend on this one
 	QStringList findDependentMods(QString mod, bool excludeDisabled);
 
-	void manualInstallFile(QUrl url);
+	void manualInstallFile(QString filePath);
 	void downloadFile(QString file, QString url, QString description, qint64 size = 0);
+	void downloadFile(QString file, QUrl url, QString description, qint64 size = 0);
 
 	void installMods(QStringList archives);
 	void installMaps(QStringList maps);