mirror of
https://github.com/vcmi/vcmi.git
synced 2024-12-24 22:14:36 +02:00
[launcher] treat manually selected/dropped file as a file path instead of URL
fixes file installation on Android
This commit is contained in:
parent
a15a191557
commit
5d9c1f986f
@ -70,9 +70,8 @@ void CModListView::dropEvent(QDropEvent* event)
|
|||||||
if(mimeData->hasUrls())
|
if(mimeData->hasUrls())
|
||||||
{
|
{
|
||||||
const QList<QUrl> urlList = mimeData->urls();
|
const QList<QUrl> urlList = mimeData->urls();
|
||||||
|
|
||||||
for (const auto & url : urlList)
|
for (const auto & url : urlList)
|
||||||
manualInstallFile(url);
|
manualInstallFile(url.toLocalFile());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -636,23 +635,21 @@ void CModListView::on_installFromFileButton_clicked()
|
|||||||
|
|
||||||
for (const auto & file : files)
|
for (const auto & file : files)
|
||||||
{
|
{
|
||||||
QUrl url = QUrl::fromLocalFile(file);
|
manualInstallFile(file);
|
||||||
manualInstallFile(url);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CModListView::manualInstallFile(QUrl url)
|
void CModListView::manualInstallFile(QString filePath)
|
||||||
{
|
{
|
||||||
QString urlStr = url.toString();
|
QString fileName = QFileInfo{filePath}.fileName();
|
||||||
QString fileName = url.fileName();
|
if(filePath.endsWith(".zip", Qt::CaseInsensitive))
|
||||||
if(urlStr.endsWith(".zip", Qt::CaseInsensitive))
|
|
||||||
downloadFile(fileName.toLower()
|
downloadFile(fileName.toLower()
|
||||||
// mod name currently comes from zip file -> remove suffixes from github zip download
|
// mod name currently comes from zip file -> remove suffixes from github zip download
|
||||||
.replace(QRegularExpression("-[0-9a-f]{40}"), "")
|
.replace(QRegularExpression("-[0-9a-f]{40}"), "")
|
||||||
.replace(QRegularExpression("-vcmi-.+\\.zip"), ".zip")
|
.replace(QRegularExpression("-vcmi-.+\\.zip"), ".zip")
|
||||||
.replace("-main.zip", ".zip")
|
.replace("-main.zip", ".zip")
|
||||||
, urlStr, "mods", 0);
|
, QUrl::fromLocalFile(filePath), "mods");
|
||||||
else if(urlStr.endsWith(".json", Qt::CaseInsensitive))
|
else if(filePath.endsWith(".json", Qt::CaseInsensitive))
|
||||||
{
|
{
|
||||||
QDir configDir(QString::fromStdString(VCMIDirs::get().userConfigPath().string()));
|
QDir configDir(QString::fromStdString(VCMIDirs::get().userConfigPath().string()));
|
||||||
QStringList configFile = configDir.entryList({fileName}, QDir::Filter::Files); // case insensitive check
|
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]);
|
const auto configFilePath = configDir.filePath(configFile[0]);
|
||||||
QFile::remove(configFilePath);
|
QFile::remove(configFilePath);
|
||||||
QFile::copy(url.toLocalFile(), configFilePath);
|
QFile::copy(filePath, configFilePath);
|
||||||
|
|
||||||
// reload settings
|
// reload settings
|
||||||
Helper::loadSettings();
|
Helper::loadSettings();
|
||||||
@ -676,10 +673,15 @@ void CModListView::manualInstallFile(QUrl url)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
downloadFile(fileName, urlStr, fileName, 0);
|
downloadFile(fileName, QUrl::fromLocalFile(filePath), fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CModListView::downloadFile(QString file, QString url, QString description, qint64 size)
|
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)
|
if(!dlManager)
|
||||||
{
|
{
|
||||||
@ -690,20 +692,17 @@ void CModListView::downloadFile(QString file, QString url, QString description,
|
|||||||
|
|
||||||
connect(dlManager, SIGNAL(finished(QStringList,QStringList,QStringList)),
|
connect(dlManager, SIGNAL(finished(QStringList,QStringList,QStringList)),
|
||||||
this, SLOT(downloadFinished(QStringList,QStringList,QStringList)));
|
this, SLOT(downloadFinished(QStringList,QStringList,QStringList)));
|
||||||
|
|
||||||
connect(manager.get(), SIGNAL(extractionProgress(qint64,qint64)),
|
connect(manager.get(), SIGNAL(extractionProgress(qint64,qint64)),
|
||||||
this, SLOT(extractionProgress(qint64,qint64)));
|
this, SLOT(extractionProgress(qint64,qint64)));
|
||||||
|
|
||||||
connect(modModel, &CModListModel::dataChanged, filterModel, &QAbstractItemModel::dataChanged);
|
connect(modModel, &CModListModel::dataChanged, filterModel, &QAbstractItemModel::dataChanged);
|
||||||
|
|
||||||
|
const auto progressBarFormat = tr("Downloading %1. %p% (%v MB out of %m MB) finished").arg(description);
|
||||||
QString progressBarFormat = tr("Downloading %s%. %p% (%v MB out of %m MB) finished");
|
|
||||||
|
|
||||||
progressBarFormat.replace("%s%", description);
|
|
||||||
ui->progressBar->setFormat(progressBarFormat);
|
ui->progressBar->setFormat(progressBarFormat);
|
||||||
}
|
}
|
||||||
|
|
||||||
dlManager->downloadFile(QUrl(url), file, size);
|
dlManager->downloadFile(url, file, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CModListView::downloadProgress(qint64 current, qint64 max)
|
void CModListView::downloadProgress(qint64 current, qint64 max)
|
||||||
|
@ -51,8 +51,9 @@ class CModListView : public QWidget
|
|||||||
// find mods that depend on this one
|
// find mods that depend on this one
|
||||||
QStringList findDependentMods(QString mod, bool excludeDisabled);
|
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, QString url, QString description, qint64 size = 0);
|
||||||
|
void downloadFile(QString file, QUrl url, QString description, qint64 size = 0);
|
||||||
|
|
||||||
void installMods(QStringList archives);
|
void installMods(QStringList archives);
|
||||||
void installMaps(QStringList maps);
|
void installMaps(QStringList maps);
|
||||||
|
Loading…
Reference in New Issue
Block a user