mirror of
https://github.com/vcmi/vcmi.git
synced 2025-04-13 11:40:38 +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:
commit
bf0fbeca54
@ -318,9 +318,8 @@ QString FirstLaunchView::getHeroesInstallDir()
|
||||
void FirstLaunchView::extractGogData()
|
||||
{
|
||||
#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 titleErr = tr("You have to select %1 file!", "param is file extension").arg(filter);
|
||||
#if defined(VCMI_MOBILE)
|
||||
filter = tr("GOG file (*.*)");
|
||||
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);
|
||||
if(file.isEmpty())
|
||||
return QString{};
|
||||
|
||||
QFile tmpFile(file);
|
||||
return 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))
|
||||
{
|
||||
QMessageBox::critical(this, tr("File cannot be opened"), tmpFile.errorString());
|
||||
return QString{};
|
||||
return false;
|
||||
}
|
||||
QByteArray magicFile = tmpFile.read(magic.length());
|
||||
if(!magicFile.startsWith(magic))
|
||||
{
|
||||
QMessageBox::critical(this, tr("Invalid file selected"), titleErr);
|
||||
return QString{};
|
||||
return false;
|
||||
}
|
||||
|
||||
return file;
|
||||
return true;
|
||||
};
|
||||
|
||||
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())
|
||||
return;
|
||||
QString fileExe = fileSelection(QByteArray{"MZ"}, tr("GOG installer") + " (*.exe)", QFileInfo(fileBin).absolutePath());
|
||||
QString fileExe = fileSelection(filterExe, QFileInfo(fileBin).absolutePath());
|
||||
if(fileExe.isEmpty())
|
||||
return;
|
||||
|
||||
@ -356,7 +363,7 @@ void FirstLaunchView::extractGogData()
|
||||
ui->pushButtonGogInstall->setVisible(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()));
|
||||
if(tempDir.cd("tmp"))
|
||||
{
|
||||
@ -373,6 +380,10 @@ void FirstLaunchView::extractGogData()
|
||||
Helper::performNativeCopy(fileExe, tmpFileExe);
|
||||
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 bin '%s' ('%s')", tmpFileBin.toStdString(), fileBin.toStdString());
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user