firstlaunch_moc.cpp 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633
  1. /*
  2. * firstlaunch_moc.cpp, part of VCMI engine
  3. *
  4. * Authors: listed in file AUTHORS in main folder
  5. *
  6. * License: GNU General Public License v2.0 or later
  7. * Full text of license available in license.txt file, in main folder
  8. *
  9. */
  10. #include "StdInc.h"
  11. #include "firstlaunch_moc.h"
  12. #include "ui_firstlaunch_moc.h"
  13. #include "mainwindow_moc.h"
  14. #include "modManager/cmodlistview_moc.h"
  15. #include "../../lib/CConfigHandler.h"
  16. #include "../../lib/texts/CGeneralTextHandler.h"
  17. #include "../../lib/texts/Languages.h"
  18. #include "../../lib/VCMIDirs.h"
  19. #include "../../lib/filesystem/Filesystem.h"
  20. #include "../helper.h"
  21. #include "../languages.h"
  22. #include "../innoextract.h"
  23. #ifdef VCMI_IOS
  24. #include "ios/selectdirectory.h"
  25. #include "iOS_utils.h"
  26. #elif defined(VCMI_ANDROID)
  27. #include <QAndroidJniObject>
  28. #include <QtAndroid>
  29. static FirstLaunchView * thiz;
  30. extern "C" JNIEXPORT void JNICALL Java_eu_vcmi_vcmi_NativeMethods_heroesDataUpdate(JNIEnv * env, jclass cls)
  31. {
  32. thiz->heroesDataUpdate();
  33. }
  34. #endif
  35. FirstLaunchView::FirstLaunchView(QWidget * parent)
  36. : QWidget(parent)
  37. , ui(new Ui::FirstLaunchView)
  38. {
  39. ui->setupUi(this);
  40. enterSetup();
  41. activateTabLanguage();
  42. ui->lineEditDataSystem->setText(pathToQString(boost::filesystem::absolute(VCMIDirs::get().dataPaths().front())));
  43. ui->lineEditDataUser->setText(pathToQString(boost::filesystem::absolute(VCMIDirs::get().userDataPath())));
  44. Helper::enableScrollBySwiping(ui->listWidgetLanguage);
  45. #ifdef VCMI_MOBILE
  46. // This directory is not accessible to players without rooting of their device
  47. ui->lineEditDataSystem->hide();
  48. #endif
  49. #ifndef ENABLE_INNOEXTRACT
  50. ui->pushButtonGogInstall->hide();
  51. ui->labelDataGogTitle->hide();
  52. ui->labelDataGogDescr->hide();
  53. #endif
  54. }
  55. void FirstLaunchView::on_buttonTabLanguage_clicked()
  56. {
  57. activateTabLanguage();
  58. }
  59. void FirstLaunchView::on_buttonTabHeroesData_clicked()
  60. {
  61. activateTabHeroesData();
  62. }
  63. void FirstLaunchView::on_buttonTabModPreset_clicked()
  64. {
  65. activateTabModPreset();
  66. }
  67. void FirstLaunchView::on_listWidgetLanguage_currentRowChanged(int currentRow)
  68. {
  69. languageSelected(ui->listWidgetLanguage->item(currentRow)->data(Qt::UserRole).toString());
  70. }
  71. void FirstLaunchView::changeEvent(QEvent * event)
  72. {
  73. if(event->type() == QEvent::LanguageChange)
  74. {
  75. ui->retranslateUi(this);
  76. Languages::fillLanguages(ui->listWidgetLanguage, false);
  77. }
  78. QWidget::changeEvent(event);
  79. }
  80. void FirstLaunchView::on_pushButtonLanguageNext_clicked()
  81. {
  82. activateTabHeroesData();
  83. }
  84. void FirstLaunchView::on_pushButtonDataNext_clicked()
  85. {
  86. activateTabModPreset();
  87. }
  88. void FirstLaunchView::on_pushButtonDataBack_clicked()
  89. {
  90. activateTabLanguage();
  91. }
  92. void FirstLaunchView::on_pushButtonDataSearch_clicked()
  93. {
  94. heroesDataUpdate();
  95. }
  96. void FirstLaunchView::on_pushButtonDataCopy_clicked()
  97. {
  98. #ifdef VCMI_ANDROID
  99. thiz = this;
  100. QtAndroid::androidActivity().callMethod<void>("copyHeroesData");
  101. #else
  102. // iOS can't display modal dialogs when called directly on button press
  103. // https://bugreports.qt.io/browse/QTBUG-98651
  104. QTimer::singleShot(0, this, [this]{ copyHeroesData(); });
  105. #endif
  106. }
  107. void FirstLaunchView::on_pushButtonGogInstall_clicked()
  108. {
  109. // iOS can't display modal dialogs when called directly on button press
  110. // https://bugreports.qt.io/browse/QTBUG-98651
  111. QTimer::singleShot(0, this, &FirstLaunchView::extractGogData);
  112. }
  113. void FirstLaunchView::enterSetup()
  114. {
  115. Languages::fillLanguages(ui->listWidgetLanguage, false);
  116. }
  117. void FirstLaunchView::setSetupProgress(int progress)
  118. {
  119. ui->buttonTabLanguage->setDisabled(progress < 1);
  120. ui->buttonTabHeroesData->setDisabled(progress < 2);
  121. ui->buttonTabModPreset->setDisabled(progress < 3);
  122. }
  123. void FirstLaunchView::activateTabLanguage()
  124. {
  125. setSetupProgress(1);
  126. ui->installerTabs->setCurrentIndex(0);
  127. ui->buttonTabLanguage->setChecked(true);
  128. ui->buttonTabHeroesData->setChecked(false);
  129. ui->buttonTabModPreset->setChecked(false);
  130. }
  131. void FirstLaunchView::activateTabHeroesData()
  132. {
  133. setSetupProgress(2);
  134. ui->installerTabs->setCurrentIndex(1);
  135. ui->buttonTabLanguage->setChecked(false);
  136. ui->buttonTabHeroesData->setChecked(true);
  137. ui->buttonTabModPreset->setChecked(false);
  138. if(heroesDataUpdate())
  139. {
  140. activateTabModPreset();
  141. return;
  142. }
  143. QString installPath = getHeroesInstallDir();
  144. if(!installPath.isEmpty())
  145. {
  146. auto reply = QMessageBox::question(this, tr("Heroes III installation found!"), tr("Copy data to VCMI folder?"), QMessageBox::Yes | QMessageBox::No);
  147. if(reply == QMessageBox::Yes)
  148. copyHeroesData(installPath);
  149. }
  150. }
  151. void FirstLaunchView::activateTabModPreset()
  152. {
  153. setSetupProgress(3);
  154. ui->installerTabs->setCurrentIndex(2);
  155. ui->buttonTabLanguage->setChecked(false);
  156. ui->buttonTabHeroesData->setChecked(false);
  157. ui->buttonTabModPreset->setChecked(true);
  158. modPresetUpdate();
  159. }
  160. void FirstLaunchView::exitSetup()
  161. {
  162. if(auto * mainWindow = dynamic_cast<MainWindow *>(QApplication::activeWindow()))
  163. mainWindow->exitSetup();
  164. }
  165. // Tab Language
  166. void FirstLaunchView::languageSelected(const QString & selectedLanguage)
  167. {
  168. Settings node = settings.write["general"]["language"];
  169. node->String() = selectedLanguage.toStdString();
  170. if(auto * mainWindow = dynamic_cast<MainWindow *>(QApplication::activeWindow()))
  171. mainWindow->updateTranslation();
  172. }
  173. bool FirstLaunchView::heroesDataUpdate()
  174. {
  175. bool detected = heroesDataDetect();
  176. if(detected)
  177. heroesDataDetected();
  178. else
  179. heroesDataMissing();
  180. return detected;
  181. }
  182. void FirstLaunchView::heroesDataMissing()
  183. {
  184. QPalette newPalette = palette();
  185. newPalette.setColor(QPalette::Base, QColor(200, 50, 50));
  186. ui->lineEditDataSystem->setPalette(newPalette);
  187. ui->lineEditDataUser->setPalette(newPalette);
  188. ui->labelDataManualTitle->setVisible(true);
  189. ui->labelDataManualDescr->setVisible(true);
  190. ui->pushButtonDataSearch->setVisible(true);
  191. #ifdef VCMI_ANDROID
  192. // selecting directory with ACTION_OPEN_DOCUMENT_TREE is available only since API level 21
  193. const bool canUseDataCopy = QtAndroid::androidSdkVersion() >= 21;
  194. #elif defined(VCMI_IOS)
  195. // selecting directory through UIDocumentPickerViewController is available only since iOS 13
  196. const bool canUseDataCopy = iOS_utils::isOsVersionAtLeast(13);
  197. #else
  198. const bool canUseDataCopy = true;
  199. #endif
  200. ui->labelDataCopyTitle->setVisible(canUseDataCopy);
  201. ui->labelDataCopyDescr->setVisible(canUseDataCopy);
  202. ui->pushButtonDataCopy->setVisible(canUseDataCopy);
  203. #ifdef ENABLE_INNOEXTRACT
  204. ui->pushButtonGogInstall->setVisible(true);
  205. ui->labelDataGogTitle->setVisible(true);
  206. ui->labelDataGogDescr->setVisible(true);
  207. #endif
  208. ui->labelDataFound->setVisible(false);
  209. ui->pushButtonDataNext->setEnabled(false);
  210. }
  211. void FirstLaunchView::heroesDataDetected()
  212. {
  213. QPalette newPalette = palette();
  214. newPalette.setColor(QPalette::Base, QColor(50, 200, 50));
  215. ui->lineEditDataSystem->setPalette(newPalette);
  216. ui->lineEditDataUser->setPalette(newPalette);
  217. ui->pushButtonDataSearch->setVisible(false);
  218. ui->pushButtonDataCopy->setVisible(false);
  219. ui->labelDataManualTitle->setVisible(false);
  220. ui->labelDataManualDescr->setVisible(false);
  221. ui->labelDataCopyTitle->setVisible(false);
  222. ui->labelDataCopyDescr->setVisible(false);
  223. #ifdef ENABLE_INNOEXTRACT
  224. ui->pushButtonGogInstall->setVisible(false);
  225. ui->labelDataGogTitle->setVisible(false);
  226. ui->labelDataGogDescr->setVisible(false);
  227. #endif
  228. ui->labelDataFound->setVisible(true);
  229. ui->pushButtonDataNext->setEnabled(true);
  230. CGeneralTextHandler::detectInstallParameters();
  231. }
  232. // Tab Heroes III Data
  233. bool FirstLaunchView::heroesDataDetect()
  234. {
  235. // user might have copied files to one of our data path.
  236. // perform full reinitialization of virtual filesystem
  237. CResourceHandler::destroy();
  238. CResourceHandler::initialize();
  239. CResourceHandler::load("config/filesystem.json");
  240. // use file from lod archive to check presence of H3 data. Very rough estimate, but will work in majority of cases
  241. bool heroesDataFoundROE = CResourceHandler::get()->existsResource(ResourcePath("DATA/GENRLTXT.TXT"));
  242. bool heroesDataFoundSOD = CResourceHandler::get()->existsResource(ResourcePath("DATA/TENTCOLR.TXT"));
  243. return heroesDataFoundROE && heroesDataFoundSOD;
  244. }
  245. QString FirstLaunchView::getHeroesInstallDir()
  246. {
  247. #ifdef VCMI_WINDOWS
  248. QString gogPath = QSettings("HKEY_LOCAL_MACHINE\\SOFTWARE\\GOG.com\\Games\\1207658787", QSettings::NativeFormat).value("path").toString();
  249. if(!gogPath.isEmpty())
  250. return gogPath;
  251. QString cdPath = QSettings("HKEY_LOCAL_MACHINE\\SOFTWARE\\New World Computing\\Heroes of Might and Magic® III\\1.0", QSettings::NativeFormat).value("AppPath").toString();
  252. if(!cdPath.isEmpty())
  253. return cdPath;
  254. #endif
  255. return QString{};
  256. }
  257. void FirstLaunchView::extractGogData()
  258. {
  259. #ifdef ENABLE_INNOEXTRACT
  260. auto fileSelection = [this](QByteArray magic, QString filter, QString startPath = {}) {
  261. QString titleSel = tr("Select %1 file...", "param is file extension").arg(filter);
  262. QString titleErr = tr("You have to select %1 file!", "param is file extension").arg(filter);
  263. #if defined(VCMI_MOBILE)
  264. filter = tr("GOG file (*.*)");
  265. QMessageBox::information(this, tr("File selection"), titleSel);
  266. #endif
  267. QString file = QFileDialog::getOpenFileName(this, titleSel, startPath.isEmpty() ? QDir::homePath() : startPath, filter);
  268. if(file.isEmpty())
  269. return QString{};
  270. QFile tmpFile(file);
  271. if(!tmpFile.open(QIODevice::ReadOnly))
  272. {
  273. QMessageBox::critical(this, tr("File cannot be opened"), tmpFile.errorString());
  274. return QString{};
  275. }
  276. QByteArray magicFile = tmpFile.read(magic.length());
  277. if(!magicFile.startsWith(magic))
  278. {
  279. QMessageBox::critical(this, tr("Invalid file selected"), titleErr);
  280. return QString{};
  281. }
  282. return file;
  283. };
  284. QString fileBin = fileSelection(QByteArray{"idska32"}, tr("GOG data") + " (*.bin)");
  285. if(fileBin.isEmpty())
  286. return;
  287. QString fileExe = fileSelection(QByteArray{"MZ"}, tr("GOG installer") + " (*.exe)", QFileInfo(fileBin).absolutePath());
  288. if(fileExe.isEmpty())
  289. return;
  290. ui->progressBarGog->setVisible(true);
  291. ui->pushButtonGogInstall->setVisible(false);
  292. setEnabled(false);
  293. QTimer::singleShot(100, this, [this, fileExe, fileBin](){ // background to make sure FileDialog is closed...
  294. QDir tempDir(pathToQString(VCMIDirs::get().userDataPath()));
  295. if(tempDir.cd("tmp"))
  296. {
  297. tempDir.removeRecursively(); // remove if already exists (e.g. previous crash)
  298. tempDir.cdUp();
  299. }
  300. tempDir.mkdir("tmp");
  301. if(!tempDir.cd("tmp"))
  302. return; // should not happen - but avoid deleting wrong folder in any case
  303. QString tmpFileExe = tempDir.filePath("h3_gog.exe");
  304. QString tmpFileBin = tempDir.filePath("h3_gog-1.bin");
  305. QFile(fileExe).copy(tmpFileExe);
  306. QFile(fileBin).copy(tmpFileBin);
  307. QString errorText{};
  308. auto isGogGalaxyExe = [](QString fileToTest) {
  309. QFile file(fileToTest);
  310. quint64 fileSize = file.size();
  311. if(fileSize > 10 * 1024 * 1024)
  312. return false; // avoid to load big files; galaxy exe is smaller...
  313. if(!file.open(QIODevice::ReadOnly))
  314. return false;
  315. QByteArray data = file.readAll();
  316. const QByteArray magicId{reinterpret_cast<const char*>(u"GOG Galaxy"), 20};
  317. return data.contains(magicId);
  318. };
  319. if(isGogGalaxyExe(tmpFileExe))
  320. errorText = tr("You've provided GOG Galaxy installer! This file doesn't contain the game. Please download the offline backup game installer!");
  321. if(errorText.isEmpty())
  322. errorText = Innoextract::extract(tmpFileExe, tempDir.path(), [this](float progress) {
  323. ui->progressBarGog->setValue(progress * 100);
  324. qApp->processEvents();
  325. });
  326. QString hashError;
  327. if(!errorText.isEmpty())
  328. hashError = Innoextract::getHashError(tmpFileExe, tmpFileBin);
  329. ui->progressBarGog->setVisible(false);
  330. ui->pushButtonGogInstall->setVisible(true);
  331. setEnabled(true);
  332. QStringList dirData = tempDir.entryList({"data"}, QDir::Filter::Dirs);
  333. if(!errorText.isEmpty() || dirData.empty() || QDir(tempDir.filePath(dirData.front())).entryList({"*.lod"}, QDir::Filter::Files).empty())
  334. {
  335. if(!errorText.isEmpty())
  336. {
  337. QMessageBox::critical(this, tr("Extracting error!"), errorText, QMessageBox::Ok, QMessageBox::Ok);
  338. if(!hashError.isEmpty())
  339. QMessageBox::critical(this, tr("Hash error!"), hashError, QMessageBox::Ok, QMessageBox::Ok);
  340. }
  341. else
  342. QMessageBox::critical(this, tr("No Heroes III data!"), tr("Selected files do not contain Heroes III data!"), QMessageBox::Ok, QMessageBox::Ok);
  343. tempDir.removeRecursively();
  344. return;
  345. }
  346. copyHeroesData(tempDir.path(), true);
  347. tempDir.removeRecursively();
  348. });
  349. #endif
  350. }
  351. void FirstLaunchView::copyHeroesData(const QString & path, bool move)
  352. {
  353. QDir sourceRoot{path};
  354. #ifdef VCMI_IOS
  355. // TODO: Qt 6.5 can select directories https://codereview.qt-project.org/c/qt/qtbase/+/446449
  356. SelectDirectory iosDirectorySelector;
  357. if(path.isEmpty())
  358. sourceRoot.setPath(iosDirectorySelector.getExistingDirectory());
  359. #else
  360. if(path.isEmpty())
  361. sourceRoot.setPath(QFileDialog::getExistingDirectory(this, {}, {}, QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks));
  362. #endif
  363. if(!sourceRoot.exists())
  364. return;
  365. if (sourceRoot.dirName().compare("data", Qt::CaseInsensitive) == 0)
  366. {
  367. // We got Data folder. Possibly user selected "Data" folder of Heroes III install. Check whether valid data might exist 1 level above
  368. QStringList dirData = sourceRoot.entryList({"data"}, QDir::Filter::Dirs);
  369. if (dirData.empty())
  370. {
  371. // This is "Data" folder without any "Data" folders inside. Try to check for data 1 level above
  372. sourceRoot.cdUp();
  373. }
  374. }
  375. QStringList dirData = sourceRoot.entryList({"data"}, QDir::Filter::Dirs);
  376. QStringList dirMaps = sourceRoot.entryList({"maps"}, QDir::Filter::Dirs);
  377. QStringList dirMp3 = sourceRoot.entryList({"mp3"}, QDir::Filter::Dirs);
  378. const auto noDataMessage = tr("Failed to detect valid Heroes III data in chosen directory.\nPlease select directory with installed Heroes III data.");
  379. if(dirData.empty())
  380. {
  381. QMessageBox::critical(this, tr("Heroes III data not found!"), noDataMessage);
  382. return;
  383. }
  384. QDir sourceData = sourceRoot.filePath(dirData.front());
  385. QStringList roeFiles = sourceData.entryList({"*.lod"}, QDir::Filter::Files);
  386. QStringList sodFiles = sourceData.entryList({"H3ab*.lod"}, QDir::Filter::Files);
  387. QStringList hdFiles = sourceData.entryList({"*.pak"}, QDir::Filter::Files);
  388. if(sodFiles.empty())
  389. {
  390. if (roeFiles.empty())
  391. {
  392. // Directory structure is correct (Data/Maps/Mp3) but no .lod archives that should be present in any install
  393. QMessageBox::critical(this, tr("Heroes III data not found!"), noDataMessage);
  394. return;
  395. }
  396. if (!hdFiles.empty())
  397. {
  398. // HD Edition contains only RoE data so we can't use even unmodified files from it
  399. QMessageBox::critical(this, tr("Heroes III data not found!"), tr("Heroes III: HD Edition files are not supported by VCMI.\nPlease select directory with Heroes III: Complete Edition or Heroes III: Shadow of Death."));
  400. return;
  401. }
  402. // RoE or some other unsupported edition. Demo version?
  403. QMessageBox::critical(this, tr("Heroes III data not found!"), tr("Unknown or unsupported Heroes III version found.\nPlease select directory with Heroes III: Complete Edition or Heroes III: Shadow of Death."));
  404. return;
  405. }
  406. QStringList copyDirectories;
  407. copyDirectories += dirData.front();
  408. if (!dirMaps.empty())
  409. copyDirectories += dirMaps.front();
  410. if (!dirMp3.empty())
  411. copyDirectories += dirMp3.front();
  412. QDir targetRoot = pathToQString(VCMIDirs::get().userDataPath());
  413. for(const QString & dirName : copyDirectories)
  414. {
  415. QDir sourceDir = sourceRoot.filePath(dirName);
  416. QDir targetDir = targetRoot.filePath(dirName);
  417. if(!targetRoot.exists(dirName))
  418. targetRoot.mkdir(dirName);
  419. for(const QString & filename : sourceDir.entryList(QDir::Filter::Files))
  420. {
  421. QFile sourceFile(sourceDir.filePath(filename));
  422. if(move)
  423. sourceFile.rename(targetDir.filePath(filename));
  424. else
  425. sourceFile.copy(targetDir.filePath(filename));
  426. }
  427. }
  428. heroesDataUpdate();
  429. }
  430. // Tab Mod Preset
  431. void FirstLaunchView::modPresetUpdate()
  432. {
  433. bool translationExists = !findTranslationModName().isEmpty();
  434. ui->labelPresetLanguageDescr->setVisible(translationExists);
  435. ui->buttonPresetLanguage->setVisible(translationExists);
  436. ui->buttonPresetLanguage->setVisible(checkCanInstallTranslation());
  437. ui->buttonPresetExtras->setVisible(checkCanInstallExtras());
  438. ui->buttonPresetHota->setVisible(checkCanInstallHota());
  439. ui->buttonPresetWog->setVisible(checkCanInstallWog());
  440. ui->labelPresetLanguageDescr->setVisible(checkCanInstallTranslation());
  441. ui->labelPresetExtrasDescr->setVisible(checkCanInstallExtras());
  442. ui->labelPresetHotaDescr->setVisible(checkCanInstallHota());
  443. ui->labelPresetWogDescr->setVisible(checkCanInstallWog());
  444. // we can't install anything - either repository checkout is off or all recommended mods are already installed
  445. if (!checkCanInstallTranslation() && !checkCanInstallExtras() && !checkCanInstallHota() && !checkCanInstallWog())
  446. exitSetup();
  447. }
  448. QString FirstLaunchView::findTranslationModName()
  449. {
  450. if (!getModView())
  451. return QString();
  452. QString preferredlanguage = QString::fromStdString(settings["general"]["language"].String());
  453. QString installedlanguage = QString::fromStdString(settings["session"]["language"].String());
  454. if (preferredlanguage == installedlanguage)
  455. return QString();
  456. return getModView()->getTranslationModName(preferredlanguage);
  457. }
  458. bool FirstLaunchView::checkCanInstallTranslation()
  459. {
  460. QString modName = findTranslationModName();
  461. if(modName.isEmpty())
  462. return false;
  463. return checkCanInstallMod(modName);
  464. }
  465. bool FirstLaunchView::checkCanInstallWog()
  466. {
  467. return checkCanInstallMod("wake-of-gods");
  468. }
  469. bool FirstLaunchView::checkCanInstallHota()
  470. {
  471. return checkCanInstallMod("hota");
  472. }
  473. bool FirstLaunchView::checkCanInstallExtras()
  474. {
  475. return checkCanInstallMod("vcmi-extras");
  476. }
  477. CModListView * FirstLaunchView::getModView()
  478. {
  479. auto * mainWindow = dynamic_cast<MainWindow *>(QApplication::activeWindow());
  480. assert(mainWindow);
  481. if (!mainWindow)
  482. return nullptr;
  483. return mainWindow->getModView();
  484. }
  485. bool FirstLaunchView::checkCanInstallMod(const QString & modID)
  486. {
  487. return getModView() && getModView()->isModAvailable(modID);
  488. }
  489. void FirstLaunchView::on_pushButtonPresetBack_clicked()
  490. {
  491. activateTabHeroesData();
  492. }
  493. void FirstLaunchView::on_pushButtonPresetNext_clicked()
  494. {
  495. QStringList modsToInstall;
  496. if (ui->buttonPresetLanguage->isChecked() && checkCanInstallTranslation())
  497. modsToInstall.push_back(findTranslationModName());
  498. if (ui->buttonPresetExtras->isChecked() && checkCanInstallExtras())
  499. modsToInstall.push_back("vcmi-extras");
  500. if (ui->buttonPresetWog->isChecked() && checkCanInstallWog())
  501. modsToInstall.push_back("wake-of-gods");
  502. if (ui->buttonPresetHota->isChecked() && checkCanInstallHota())
  503. modsToInstall.push_back("hota");
  504. exitSetup();
  505. for (auto const & modName : modsToInstall)
  506. getModView()->doInstallMod(modName);
  507. }
  508. void FirstLaunchView::on_pushButtonDiscord_clicked()
  509. {
  510. QDesktopServices::openUrl(QUrl("https://discord.gg/chBT42V"));
  511. }
  512. void FirstLaunchView::on_pushButtonGithub_clicked()
  513. {
  514. QDesktopServices::openUrl(QUrl("https://github.com/vcmi/vcmi"));
  515. }