firstlaunch_moc.cpp 20 KB

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