mirror of
https://github.com/vcmi/vcmi.git
synced 2025-02-03 13:01:33 +02:00
reduce double code
This commit is contained in:
parent
10d299c74b
commit
81fa8a4efa
@ -296,35 +296,32 @@ QString FirstLaunchView::getHeroesInstallDir()
|
|||||||
void FirstLaunchView::extractGogData()
|
void FirstLaunchView::extractGogData()
|
||||||
{
|
{
|
||||||
#ifdef ENABLE_INNOEXTRACT
|
#ifdef ENABLE_INNOEXTRACT
|
||||||
|
|
||||||
|
auto fileSelection = [this](QString type, QString filter, QString startPath = {}) {
|
||||||
|
QString titleSel = tr("Select a ") + filter + tr(" file...");
|
||||||
|
QString titleErr = tr("You have to select a ") + filter + tr(" file!");
|
||||||
#if defined(VCMI_MOBILE)
|
#if defined(VCMI_MOBILE)
|
||||||
QString filterExe = tr("GOG executable") + " (*.*)";
|
filter = "GOG file (*.*)";
|
||||||
QMessageBox::information(this, tr("File selection"), tr("Select a GOG installer (exe) file..."));
|
QMessageBox::information(this, tr("File selection"), titleSel);
|
||||||
#else
|
|
||||||
QString filterExe = tr("GOG executable") + " (*.exe)";
|
|
||||||
#endif
|
#endif
|
||||||
QString fileExe = QFileDialog::getOpenFileName(this, tr("Select a GOG installer (exe) file..."), QDir::homePath(), filterExe);
|
QString file = QFileDialog::getOpenFileName(this, titleSel, startPath.isEmpty() ? QDir::homePath() : startPath, filter);
|
||||||
|
if(file.isEmpty())
|
||||||
|
return QString{};
|
||||||
|
else if(!file.endsWith("." + type, Qt::CaseInsensitive))
|
||||||
|
{
|
||||||
|
QMessageBox::critical(this, tr("Invalid file selected"), titleErr);
|
||||||
|
return QString{};
|
||||||
|
}
|
||||||
|
|
||||||
|
return file;
|
||||||
|
};
|
||||||
|
|
||||||
|
QString fileExe = fileSelection("exe", tr("GOG installer") + " (*.exe)");
|
||||||
if(fileExe.isEmpty())
|
if(fileExe.isEmpty())
|
||||||
return;
|
return;
|
||||||
if(!fileExe.endsWith(".exe", Qt::CaseInsensitive))
|
QString fileBin = fileSelection("bin", tr("GOG data") + " (*.bin)", QFileInfo(fileExe).absolutePath());
|
||||||
{
|
|
||||||
QMessageBox::critical(this, tr("Invalid file selected"), tr("You have to select a GOG installer (exe) file!"));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
#if defined(VCMI_MOBILE)
|
|
||||||
QString filterBin = tr("GOG bin file") + " (*.*)";
|
|
||||||
QMessageBox::information(this, tr("File selection"), tr("Select a GOG data (bin) file..."));
|
|
||||||
#else
|
|
||||||
QString filterBin = tr("GOG bin file") + " (*.bin)";
|
|
||||||
#endif
|
|
||||||
QString fileBin = QFileDialog::getOpenFileName(this, tr("Select a GOG data (bin) file..."), QFileInfo(fileExe).absolutePath(), filterBin);
|
|
||||||
if(fileBin.isEmpty())
|
if(fileBin.isEmpty())
|
||||||
return;
|
return;
|
||||||
if(!fileBin.endsWith(".bin", Qt::CaseInsensitive))
|
|
||||||
{
|
|
||||||
QMessageBox::critical(this, tr("Invalid file selected"), tr("You have to select a GOG data (bin) file!"));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
ui->pushButtonGogInstall->setText(tr("Installing... Please wait!"));
|
ui->pushButtonGogInstall->setText(tr("Installing... Please wait!"));
|
||||||
QPalette pal = ui->pushButtonGogInstall->palette();
|
QPalette pal = ui->pushButtonGogInstall->palette();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user