mainwindow_moc.cpp 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. #include "StdInc.h"
  2. #include "mainwindow_moc.h"
  3. #include "ui_mainwindow_moc.h"
  4. #include <QProcess>
  5. #include <QDir>
  6. #include "../lib/CConfigHandler.h"
  7. #include "../lib/VCMIDirs.h"
  8. #include "../lib/filesystem/Filesystem.h"
  9. #include "../lib/logging/CBasicLogConfigurator.h"
  10. void MainWindow::load()
  11. {
  12. console = new CConsoleHandler;
  13. CBasicLogConfigurator logConfig(VCMIDirs::get().userCachePath() + "/VCMI_Launcher_log.txt", console);
  14. logConfig.configureDefault();
  15. CResourceHandler::initialize();
  16. CResourceHandler::load("config/filesystem.json");
  17. for (auto & string : VCMIDirs::get().dataPaths())
  18. QDir::addSearchPath("icons", QString::fromUtf8(string.c_str()) + "/launcher/icons");
  19. QDir::addSearchPath("icons", QString::fromUtf8(VCMIDirs::get().userDataPath().c_str()) + "/launcher/icons");
  20. settings.init();
  21. }
  22. MainWindow::MainWindow(QWidget *parent) :
  23. QMainWindow(parent),
  24. ui(new Ui::MainWindow)
  25. {
  26. load(); // load FS before UI
  27. ui->setupUi(this);
  28. ui->tabListWidget->setCurrentIndex(0);
  29. connect(ui->tabSelectList, SIGNAL(currentRowChanged(int)),
  30. ui->tabListWidget, SLOT(setCurrentIndex(int)));
  31. }
  32. MainWindow::~MainWindow()
  33. {
  34. delete ui;
  35. }
  36. void MainWindow::on_startGameButon_clicked()
  37. {
  38. startExecutable(QString::fromUtf8(VCMIDirs::get().clientPath().c_str()));
  39. }
  40. void MainWindow::startExecutable(QString name)
  41. {
  42. QProcess process;
  43. // Start the executable
  44. if (process.startDetached(name))
  45. {
  46. close(); // exit launcher
  47. }
  48. else
  49. {
  50. QMessageBox::critical(this,
  51. "Error starting executable",
  52. "Failed to start " + name + "\n"
  53. "Reason: " + process.errorString(),
  54. QMessageBox::Ok,
  55. QMessageBox::Ok);
  56. return;
  57. }
  58. }