1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-01-26 03:52:01 +02:00

Merge pull request #4034 from Laserlicht/innoextract_userpath

extract files into userdata instead of tmp
This commit is contained in:
Ivan Savenko 2024-05-28 16:47:24 +03:00 committed by GitHub
commit 0c1dd45e9e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -316,44 +316,47 @@ void FirstLaunchView::extractGogData()
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](){ // background to make sure FileDialog is closed...
QTemporaryDir dir; QDir tempDir(pathToQString(VCMIDirs::get().userDataPath()));
if(dir.isValid()) { tempDir.mkdir("tmp");
QDir tempDir{dir.path()}; if(!tempDir.cd("tmp"))
return; // should not happen - but avoid deleting wrong folder in any case
QString tmpFileExe = dir.filePath("h3_gog.exe"); QString tmpFileExe = tempDir.filePath("h3_gog.exe");
QFile(fileExe).copy(tmpFileExe); QFile(fileExe).copy(tmpFileExe);
QFile(fileBin).copy(dir.filePath("h3_gog-1.bin")); QFile(fileBin).copy(tempDir.filePath("h3_gog-1.bin"));
::extract_options o; ::extract_options o;
o.extract = true; o.extract = true;
// standard settings // standard settings
o.gog_galaxy = true; o.gog_galaxy = true;
o.codepage = 0U; o.codepage = 0U;
o.output_dir = dir.path().toStdString(); o.output_dir = tempDir.path().toStdString();
o.extract_temp = true; o.extract_temp = true;
o.extract_unknown = true; o.extract_unknown = true;
o.filenames.set_expand(true); o.filenames.set_expand(true);
o.preserve_file_times = true; // also correctly closes file -> without it: on Windows the files are not written completly o.preserve_file_times = true; // also correctly closes file -> without it: on Windows the files are not written completly
process_file(tmpFileExe.toStdString(), o, [this](float progress) { process_file(tmpFileExe.toStdString(), o, [this](float progress) {
ui->progressBarGog->setValue(progress * 100); ui->progressBarGog->setValue(progress * 100);
qApp->processEvents(); qApp->processEvents();
}); });
ui->progressBarGog->setVisible(false); ui->progressBarGog->setVisible(false);
ui->pushButtonGogInstall->setVisible(true); ui->pushButtonGogInstall->setVisible(true);
setEnabled(true); setEnabled(true);
QStringList dirData = tempDir.entryList({"data"}, QDir::Filter::Dirs); QStringList dirData = tempDir.entryList({"data"}, QDir::Filter::Dirs);
if(dirData.empty() || QDir(tempDir.filePath(dirData.front())).entryList({"*.lod"}, QDir::Filter::Files).empty()) if(dirData.empty() || QDir(tempDir.filePath(dirData.front())).entryList({"*.lod"}, QDir::Filter::Files).empty())
{ {
QMessageBox::critical(this, tr("No Heroes III data!"), tr("Selected files do not contain Heroes III data!"), QMessageBox::Ok, QMessageBox::Ok); QMessageBox::critical(this, tr("No Heroes III data!"), tr("Selected files do not contain Heroes III data!"), QMessageBox::Ok, QMessageBox::Ok);
return; tempDir.removeRecursively();
} return;
copyHeroesData(dir.path(), true);
} }
copyHeroesData(tempDir.path(), true);
tempDir.removeRecursively();
}); });
#endif #endif
} }