main.cpp 1.8 KB

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