firstlaunch_moc.cpp 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639
  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. QVector<QPair<QString, QString>> regKeys = {
  249. { "HKEY_LOCAL_MACHINE\\SOFTWARE\\GOG.com\\Games\\1207658787", "path" }, // Gog on x86 system
  250. { "HKEY_LOCAL_MACHINE\\SOFTWARE\\WOW6432Node\\GOG.com\\Games\\1207658787", "path" }, // Gog on x64 system
  251. { "HKEY_LOCAL_MACHINE\\SOFTWARE\\New World Computing\\Heroes of Might and Magic® III\\1.0", "AppPath" }, // H3 Complete on x86 system
  252. { "HKEY_LOCAL_MACHINE\\SOFTWARE\\WOW6432Node\\New World Computing\\Heroes of Might and Magic® III\\1.0", "AppPath" }, // H3 Complete on x64 system
  253. { "HKEY_LOCAL_MACHINE\\SOFTWARE\\New World Computing\\Heroes of Might and Magic III\\1.0", "AppPath" }, // some localized H3 on x86 system
  254. { "HKEY_LOCAL_MACHINE\\SOFTWARE\\WOW6432Node\\New World Computing\\Heroes of Might and Magic III\\1.0", "AppPath" }, // some localized H3 on x64 system
  255. };
  256. for(auto & regKey : regKeys)
  257. {
  258. QString path = QSettings(regKey.first, QSettings::NativeFormat).value(regKey.second).toString();
  259. if(!path.isEmpty())
  260. return path;
  261. }
  262. #endif
  263. return QString{};
  264. }
  265. void FirstLaunchView::extractGogData()
  266. {
  267. #ifdef ENABLE_INNOEXTRACT
  268. auto fileSelection = [this](QByteArray magic, QString filter, QString startPath = {}) {
  269. QString titleSel = tr("Select %1 file...", "param is file extension").arg(filter);
  270. QString titleErr = tr("You have to select %1 file!", "param is file extension").arg(filter);
  271. #if defined(VCMI_MOBILE)
  272. filter = tr("GOG file (*.*)");
  273. QMessageBox::information(this, tr("File selection"), titleSel);
  274. #endif
  275. QString file = QFileDialog::getOpenFileName(this, titleSel, startPath.isEmpty() ? QDir::homePath() : startPath, filter);
  276. if(file.isEmpty())
  277. return QString{};
  278. QFile tmpFile(file);
  279. if(!tmpFile.open(QIODevice::ReadOnly))
  280. {
  281. QMessageBox::critical(this, tr("File cannot be opened"), tmpFile.errorString());
  282. return QString{};
  283. }
  284. QByteArray magicFile = tmpFile.read(magic.length());
  285. if(!magicFile.startsWith(magic))
  286. {
  287. QMessageBox::critical(this, tr("Invalid file selected"), titleErr);
  288. return QString{};
  289. }
  290. return file;
  291. };
  292. QString fileBin = fileSelection(QByteArray{"idska32"}, tr("GOG data") + " (*.bin)");
  293. if(fileBin.isEmpty())
  294. return;
  295. QString fileExe = fileSelection(QByteArray{"MZ"}, tr("GOG installer") + " (*.exe)", QFileInfo(fileBin).absolutePath());
  296. if(fileExe.isEmpty())
  297. return;
  298. ui->progressBarGog->setVisible(true);
  299. ui->pushButtonGogInstall->setVisible(false);
  300. setEnabled(false);
  301. QTimer::singleShot(100, this, [this, fileExe, fileBin](){ // background to make sure FileDialog is closed...
  302. QDir tempDir(pathToQString(VCMIDirs::get().userDataPath()));
  303. if(tempDir.cd("tmp"))
  304. {
  305. tempDir.removeRecursively(); // remove if already exists (e.g. previous crash)
  306. tempDir.cdUp();
  307. }
  308. tempDir.mkdir("tmp");
  309. if(!tempDir.cd("tmp"))
  310. return; // should not happen - but avoid deleting wrong folder in any case
  311. QString tmpFileExe = tempDir.filePath("h3_gog.exe");
  312. QString tmpFileBin = tempDir.filePath("h3_gog-1.bin");
  313. QFile(fileExe).copy(tmpFileExe);
  314. QFile(fileBin).copy(tmpFileBin);
  315. QString errorText{};
  316. auto isGogGalaxyExe = [](QString fileToTest) {
  317. QFile file(fileToTest);
  318. quint64 fileSize = file.size();
  319. if(fileSize > 10 * 1024 * 1024)
  320. return false; // avoid to load big files; galaxy exe is smaller...
  321. if(!file.open(QIODevice::ReadOnly))
  322. return false;
  323. QByteArray data = file.readAll();
  324. const QByteArray magicId{reinterpret_cast<const char*>(u"GOG Galaxy"), 20};
  325. return data.contains(magicId);
  326. };
  327. if(isGogGalaxyExe(tmpFileExe))
  328. errorText = tr("You've provided a GOG Galaxy installer! This file doesn't contain the game. Please download the offline backup game installer!");
  329. if(errorText.isEmpty())
  330. errorText = Innoextract::extract(tmpFileExe, tempDir.path(), [this](float progress) {
  331. ui->progressBarGog->setValue(progress * 100);
  332. qApp->processEvents();
  333. });
  334. QString hashError;
  335. if(!errorText.isEmpty())
  336. hashError = Innoextract::getHashError(tmpFileExe, tmpFileBin, fileExe, fileBin);
  337. ui->progressBarGog->setVisible(false);
  338. ui->pushButtonGogInstall->setVisible(true);
  339. setEnabled(true);
  340. QStringList dirData = tempDir.entryList({"data"}, QDir::Filter::Dirs);
  341. if(!errorText.isEmpty() || dirData.empty() || QDir(tempDir.filePath(dirData.front())).entryList({"*.lod"}, QDir::Filter::Files).empty())
  342. {
  343. if(!errorText.isEmpty())
  344. {
  345. QMessageBox::critical(this, tr("Extracting error!"), errorText, QMessageBox::Ok, QMessageBox::Ok);
  346. if(!hashError.isEmpty())
  347. QMessageBox::critical(this, tr("Hash error!"), hashError, QMessageBox::Ok, QMessageBox::Ok);
  348. }
  349. else
  350. QMessageBox::critical(this, tr("No Heroes III data!"), tr("Selected files do not contain Heroes III data!"), QMessageBox::Ok, QMessageBox::Ok);
  351. tempDir.removeRecursively();
  352. return;
  353. }
  354. copyHeroesData(tempDir.path(), true);
  355. tempDir.removeRecursively();
  356. });
  357. #endif
  358. }
  359. void FirstLaunchView::copyHeroesData(const QString & path, bool move)
  360. {
  361. QDir sourceRoot{path};
  362. #ifdef VCMI_IOS
  363. // TODO: Qt 6.5 can select directories https://codereview.qt-project.org/c/qt/qtbase/+/446449
  364. SelectDirectory iosDirectorySelector;
  365. if(path.isEmpty())
  366. sourceRoot.setPath(iosDirectorySelector.getExistingDirectory());
  367. #else
  368. if(path.isEmpty())
  369. sourceRoot.setPath(QFileDialog::getExistingDirectory(this, {}, {}, QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks));
  370. #endif
  371. if(!sourceRoot.exists())
  372. return;
  373. if (sourceRoot.dirName().compare("data", Qt::CaseInsensitive) == 0)
  374. {
  375. // We got Data folder. Possibly user selected "Data" folder of Heroes III install. Check whether valid data might exist 1 level above
  376. QStringList dirData = sourceRoot.entryList({"data"}, QDir::Filter::Dirs);
  377. if (dirData.empty())
  378. {
  379. // This is "Data" folder without any "Data" folders inside. Try to check for data 1 level above
  380. sourceRoot.cdUp();
  381. }
  382. }
  383. QStringList dirData = sourceRoot.entryList({"data"}, QDir::Filter::Dirs);
  384. QStringList dirMaps = sourceRoot.entryList({"maps"}, QDir::Filter::Dirs);
  385. QStringList dirMp3 = sourceRoot.entryList({"mp3"}, QDir::Filter::Dirs);
  386. const auto noDataMessage = tr("Failed to detect valid Heroes III data in chosen directory.\nPlease select the directory with installed Heroes III data.");
  387. if(dirData.empty())
  388. {
  389. QMessageBox::critical(this, tr("Heroes III data not found!"), noDataMessage);
  390. return;
  391. }
  392. QDir sourceData = sourceRoot.filePath(dirData.front());
  393. QStringList roeFiles = sourceData.entryList({"*.lod"}, QDir::Filter::Files);
  394. QStringList sodFiles = sourceData.entryList({"H3ab*.lod"}, QDir::Filter::Files);
  395. QStringList hdFiles = sourceData.entryList({"*.pak"}, QDir::Filter::Files);
  396. if(sodFiles.empty())
  397. {
  398. if (roeFiles.empty())
  399. {
  400. // Directory structure is correct (Data/Maps/Mp3) but no .lod archives that should be present in any install
  401. QMessageBox::critical(this, tr("Heroes III data not found!"), noDataMessage);
  402. return;
  403. }
  404. if (!hdFiles.empty())
  405. {
  406. // HD Edition contains only RoE data so we can't use even unmodified files from it
  407. 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."));
  408. return;
  409. }
  410. // RoE or some other unsupported edition. Demo version?
  411. 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."));
  412. return;
  413. }
  414. QStringList copyDirectories;
  415. copyDirectories += dirData.front();
  416. if (!dirMaps.empty())
  417. copyDirectories += dirMaps.front();
  418. if (!dirMp3.empty())
  419. copyDirectories += dirMp3.front();
  420. QDir targetRoot = pathToQString(VCMIDirs::get().userDataPath());
  421. for(const QString & dirName : copyDirectories)
  422. {
  423. QDir sourceDir = sourceRoot.filePath(dirName);
  424. QDir targetDir = targetRoot.filePath(dirName);
  425. if(!targetRoot.exists(dirName))
  426. targetRoot.mkdir(dirName);
  427. for(const QString & filename : sourceDir.entryList(QDir::Filter::Files))
  428. {
  429. QFile sourceFile(sourceDir.filePath(filename));
  430. if(move)
  431. sourceFile.rename(targetDir.filePath(filename));
  432. else
  433. sourceFile.copy(targetDir.filePath(filename));
  434. }
  435. }
  436. heroesDataUpdate();
  437. }
  438. // Tab Mod Preset
  439. void FirstLaunchView::modPresetUpdate()
  440. {
  441. bool translationExists = !findTranslationModName().isEmpty();
  442. ui->labelPresetLanguageDescr->setVisible(translationExists);
  443. ui->buttonPresetLanguage->setVisible(translationExists);
  444. ui->buttonPresetLanguage->setVisible(checkCanInstallTranslation());
  445. ui->buttonPresetExtras->setVisible(checkCanInstallExtras());
  446. ui->buttonPresetHota->setVisible(checkCanInstallHota());
  447. ui->buttonPresetWog->setVisible(checkCanInstallWog());
  448. ui->labelPresetLanguageDescr->setVisible(checkCanInstallTranslation());
  449. ui->labelPresetExtrasDescr->setVisible(checkCanInstallExtras());
  450. ui->labelPresetHotaDescr->setVisible(checkCanInstallHota());
  451. ui->labelPresetWogDescr->setVisible(checkCanInstallWog());
  452. // we can't install anything - either repository checkout is off or all recommended mods are already installed
  453. if (!checkCanInstallTranslation() && !checkCanInstallExtras() && !checkCanInstallHota() && !checkCanInstallWog())
  454. exitSetup();
  455. }
  456. QString FirstLaunchView::findTranslationModName()
  457. {
  458. auto * mainWindow = dynamic_cast<MainWindow *>(QApplication::activeWindow());
  459. auto status = mainWindow->getTranslationStatus();
  460. if (status == ETranslationStatus::ACTIVE || status == ETranslationStatus::NOT_AVAILABLE)
  461. return QString();
  462. QString preferredlanguage = QString::fromStdString(settings["general"]["language"].String());
  463. return getModView()->getTranslationModName(preferredlanguage);
  464. }
  465. bool FirstLaunchView::checkCanInstallTranslation()
  466. {
  467. QString modName = findTranslationModName();
  468. if(modName.isEmpty())
  469. return false;
  470. return checkCanInstallMod(modName);
  471. }
  472. bool FirstLaunchView::checkCanInstallWog()
  473. {
  474. return checkCanInstallMod("wake-of-gods");
  475. }
  476. bool FirstLaunchView::checkCanInstallHota()
  477. {
  478. return checkCanInstallMod("hota");
  479. }
  480. bool FirstLaunchView::checkCanInstallExtras()
  481. {
  482. return checkCanInstallMod("vcmi-extras");
  483. }
  484. CModListView * FirstLaunchView::getModView()
  485. {
  486. auto * mainWindow = dynamic_cast<MainWindow *>(QApplication::activeWindow());
  487. assert(mainWindow);
  488. if (!mainWindow)
  489. return nullptr;
  490. return mainWindow->getModView();
  491. }
  492. bool FirstLaunchView::checkCanInstallMod(const QString & modID)
  493. {
  494. return getModView() && getModView()->isModAvailable(modID);
  495. }
  496. void FirstLaunchView::on_pushButtonPresetBack_clicked()
  497. {
  498. activateTabHeroesData();
  499. }
  500. void FirstLaunchView::on_pushButtonPresetNext_clicked()
  501. {
  502. QStringList modsToInstall;
  503. if (ui->buttonPresetLanguage->isChecked() && checkCanInstallTranslation())
  504. modsToInstall.push_back(findTranslationModName());
  505. if (ui->buttonPresetExtras->isChecked() && checkCanInstallExtras())
  506. modsToInstall.push_back("vcmi-extras");
  507. if (ui->buttonPresetWog->isChecked() && checkCanInstallWog())
  508. modsToInstall.push_back("wake-of-gods");
  509. if (ui->buttonPresetHota->isChecked() && checkCanInstallHota())
  510. modsToInstall.push_back("hota");
  511. exitSetup();
  512. for (auto const & modName : modsToInstall)
  513. getModView()->doInstallMod(modName);
  514. }
  515. void FirstLaunchView::on_pushButtonDiscord_clicked()
  516. {
  517. QDesktopServices::openUrl(QUrl("https://discord.gg/chBT42V"));
  518. }
  519. void FirstLaunchView::on_pushButtonGithub_clicked()
  520. {
  521. QDesktopServices::openUrl(QUrl("https://github.com/vcmi/vcmi"));
  522. }