mainwindow.cpp 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. #include "StdInc.h"
  2. #include "mainwindow.h"
  3. #include "ui_mainwindow.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::loadMainFileSystem("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. #if defined(Q_OS_WIN)
  39. QString clientName = "VCMI_Client.exe";
  40. #else
  41. // TODO: Right now launcher will only start vcmi from system-default locations
  42. QString clientName = "vcmiclient";
  43. #endif
  44. startExecutable(clientName);
  45. }
  46. void MainWindow::startExecutable(QString name)
  47. {
  48. QProcess process;
  49. // Start the executable
  50. if (process.startDetached(name))
  51. {
  52. close(); // exit launcher
  53. }
  54. else
  55. {
  56. QMessageBox::critical(this,
  57. "Error starting executable",
  58. "Failed to start " + name + ": " + process.errorString(),
  59. QMessageBox::Ok,
  60. QMessageBox::Ok);
  61. return;
  62. }
  63. }