mirror of
https://github.com/vcmi/vcmi.git
synced 2025-08-10 22:31:40 +02:00
Merge pull request #5444 from IvanSavenko/launcher_import
[1.6.6] Attempt to fix one more possible import failure on Android
This commit is contained in:
@@ -318,9 +318,8 @@ QString FirstLaunchView::getHeroesInstallDir()
|
|||||||
void FirstLaunchView::extractGogData()
|
void FirstLaunchView::extractGogData()
|
||||||
{
|
{
|
||||||
#ifdef ENABLE_INNOEXTRACT
|
#ifdef ENABLE_INNOEXTRACT
|
||||||
auto fileSelection = [this](QByteArray magic, QString filter, QString startPath = {}) {
|
auto fileSelection = [this](QString filter, QString startPath = {}) {
|
||||||
QString titleSel = tr("Select %1 file...", "param is file extension").arg(filter);
|
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)
|
#if defined(VCMI_MOBILE)
|
||||||
filter = tr("GOG file (*.*)");
|
filter = tr("GOG file (*.*)");
|
||||||
QMessageBox::information(this, tr("File selection"), titleSel);
|
QMessageBox::information(this, tr("File selection"), titleSel);
|
||||||
@@ -328,27 +327,35 @@ void FirstLaunchView::extractGogData()
|
|||||||
QString file = QFileDialog::getOpenFileName(this, titleSel, startPath.isEmpty() ? QDir::homePath() : startPath, filter);
|
QString file = QFileDialog::getOpenFileName(this, titleSel, startPath.isEmpty() ? QDir::homePath() : startPath, filter);
|
||||||
if(file.isEmpty())
|
if(file.isEmpty())
|
||||||
return QString{};
|
return QString{};
|
||||||
|
return file;
|
||||||
QFile tmpFile(file);
|
};
|
||||||
|
|
||||||
|
auto checkMagic = [this](QString filename, QString filter, QByteArray magic)
|
||||||
|
{
|
||||||
|
QString titleErr = tr("You have to select %1 file!", "param is file extension").arg(filter);
|
||||||
|
|
||||||
|
QFile tmpFile(filename);
|
||||||
if(!tmpFile.open(QIODevice::ReadOnly))
|
if(!tmpFile.open(QIODevice::ReadOnly))
|
||||||
{
|
{
|
||||||
QMessageBox::critical(this, tr("File cannot be opened"), tmpFile.errorString());
|
QMessageBox::critical(this, tr("File cannot be opened"), tmpFile.errorString());
|
||||||
return QString{};
|
return false;
|
||||||
}
|
}
|
||||||
QByteArray magicFile = tmpFile.read(magic.length());
|
QByteArray magicFile = tmpFile.read(magic.length());
|
||||||
if(!magicFile.startsWith(magic))
|
if(!magicFile.startsWith(magic))
|
||||||
{
|
{
|
||||||
QMessageBox::critical(this, tr("Invalid file selected"), titleErr);
|
QMessageBox::critical(this, tr("Invalid file selected"), titleErr);
|
||||||
return QString{};
|
return false;
|
||||||
}
|
}
|
||||||
|
return true;
|
||||||
return file;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
QString fileBin = fileSelection(QByteArray{"idska32"}, tr("GOG data") + " (*.bin)");
|
QString filterBin = tr("GOG data") + " (*.bin)";
|
||||||
|
QString filterExe = tr("GOG installer") + " (*.exe)";
|
||||||
|
|
||||||
|
QString fileBin = fileSelection(filterBin);
|
||||||
if(fileBin.isEmpty())
|
if(fileBin.isEmpty())
|
||||||
return;
|
return;
|
||||||
QString fileExe = fileSelection(QByteArray{"MZ"}, tr("GOG installer") + " (*.exe)", QFileInfo(fileBin).absolutePath());
|
QString fileExe = fileSelection(filterExe, QFileInfo(fileBin).absolutePath());
|
||||||
if(fileExe.isEmpty())
|
if(fileExe.isEmpty())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@@ -356,7 +363,7 @@ void FirstLaunchView::extractGogData()
|
|||||||
ui->pushButtonGogInstall->setVisible(false);
|
ui->pushButtonGogInstall->setVisible(false);
|
||||||
setEnabled(false);
|
setEnabled(false);
|
||||||
|
|
||||||
QTimer::singleShot(100, this, [this, fileExe, fileBin](){ // background to make sure FileDialog is closed...
|
QTimer::singleShot(100, this, [this, fileExe, fileBin, checkMagic, filterBin, filterExe](){ // background to make sure FileDialog is closed...
|
||||||
QDir tempDir(pathToQString(VCMIDirs::get().userDataPath()));
|
QDir tempDir(pathToQString(VCMIDirs::get().userDataPath()));
|
||||||
if(tempDir.cd("tmp"))
|
if(tempDir.cd("tmp"))
|
||||||
{
|
{
|
||||||
@@ -373,6 +380,10 @@ void FirstLaunchView::extractGogData()
|
|||||||
Helper::performNativeCopy(fileExe, tmpFileExe);
|
Helper::performNativeCopy(fileExe, tmpFileExe);
|
||||||
Helper::performNativeCopy(fileBin, tmpFileBin);
|
Helper::performNativeCopy(fileBin, tmpFileBin);
|
||||||
|
|
||||||
|
if (!checkMagic(tmpFileBin, filterBin, QByteArray{"idska32"}) ||
|
||||||
|
!checkMagic(tmpFileExe, filterExe, QByteArray{"MZ"}))
|
||||||
|
return;
|
||||||
|
|
||||||
logGlobal->info("Installing exe '%s' ('%s')", tmpFileExe.toStdString(), fileExe.toStdString());
|
logGlobal->info("Installing exe '%s' ('%s')", tmpFileExe.toStdString(), fileExe.toStdString());
|
||||||
logGlobal->info("Installing bin '%s' ('%s')", tmpFileBin.toStdString(), fileBin.toStdString());
|
logGlobal->info("Installing bin '%s' ('%s')", tmpFileBin.toStdString(), fileBin.toStdString());
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user