firstlaunch_moc.cpp 19 KB

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