main.cpp 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /*
  2. * main.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 "main.h"
  12. #include "mainwindow_moc.h"
  13. #include <QApplication>
  14. #include <QProcess>
  15. #include <QMessageBox>
  16. #include "../lib/VCMIDirs.h"
  17. // Conan workaround https://github.com/conan-io/conan-center-index/issues/13332
  18. #ifdef VCMI_IOS
  19. #if __has_include("QIOSIntegrationPlugin.h")
  20. #include "QIOSIntegrationPlugin.h"
  21. #endif
  22. int argcForClient;
  23. char ** argvForClient;
  24. #endif
  25. int main(int argc, char * argv[])
  26. {
  27. int result;
  28. #ifdef VCMI_IOS
  29. {
  30. #endif
  31. QApplication vcmilauncher(argc, argv);
  32. //QTranslator translator;
  33. //translator.load("./launcher_uk.qm");
  34. //vcmilauncher.installTranslator(&translator);
  35. MainWindow mainWindow;
  36. mainWindow.show();
  37. result = vcmilauncher.exec();
  38. #ifdef VCMI_IOS
  39. }
  40. if (result == 0)
  41. launchGame(argcForClient, argvForClient);
  42. #endif
  43. return result;
  44. }
  45. void startGame(const QStringList & args)
  46. {
  47. logGlobal->warn("Starting game with the arguments: %s", args.join(" ").toStdString());
  48. #ifdef Q_OS_IOS
  49. argcForClient = args.size() + 1; //first argument is omitted
  50. argvForClient = new char*[argcForClient];
  51. argvForClient[0] = "vcmiclient";
  52. for(int i = 1; i < argcForClient; ++i)
  53. {
  54. std::string s = args.at(i - 1).toStdString();
  55. argvForClient[i] = new char[s.size() + 1];
  56. strcpy(argvForClient[i], s.c_str());
  57. }
  58. qApp->quit();
  59. #else
  60. startExecutable(pathToQString(VCMIDirs::get().clientPath()), args);
  61. #endif
  62. }
  63. #ifndef Q_OS_IOS
  64. void startExecutable(QString name, const QStringList & args)
  65. {
  66. QProcess process;
  67. // Start the executable
  68. if(process.startDetached(name, args))
  69. {
  70. qApp->quit();
  71. }
  72. else
  73. {
  74. QMessageBox::critical(qApp->activeWindow(),
  75. "Error starting executable",
  76. "Failed to start " + name + "\n"
  77. "Reason: " + process.errorString(),
  78. QMessageBox::Ok,
  79. QMessageBox::Ok);
  80. }
  81. }
  82. #endif