main.cpp 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. MainWindow mainWindow;
  33. mainWindow.show();
  34. result = vcmilauncher.exec();
  35. #ifdef VCMI_IOS
  36. }
  37. if (result == 0)
  38. launchGame(argcForClient, argvForClient);
  39. #endif
  40. return result;
  41. }
  42. void startGame(const QStringList & args)
  43. {
  44. logGlobal->warn("Starting game with the arguments: %s", args.join(" ").toStdString());
  45. #ifdef Q_OS_IOS
  46. argcForClient = args.size() + 1; //first argument is omitted
  47. argvForClient = new char*[argcForClient];
  48. argvForClient[0] = "vcmiclient";
  49. for(int i = 1; i < argcForClient; ++i)
  50. {
  51. std::string s = args.at(i - 1).toStdString();
  52. argvForClient[i] = new char[s.size() + 1];
  53. strcpy(argvForClient[i], s.c_str());
  54. }
  55. qApp->quit();
  56. #else
  57. startExecutable(pathToQString(VCMIDirs::get().clientPath()), args);
  58. #endif
  59. }
  60. #ifndef Q_OS_IOS
  61. void startExecutable(QString name, const QStringList & args)
  62. {
  63. QProcess process;
  64. // Start the executable
  65. if(process.startDetached(name, args))
  66. {
  67. qApp->quit();
  68. }
  69. else
  70. {
  71. QMessageBox::critical(qApp->activeWindow(),
  72. "Error starting executable",
  73. "Failed to start " + name + "\n"
  74. "Reason: " + process.errorString(),
  75. QMessageBox::Ok,
  76. QMessageBox::Ok);
  77. }
  78. }
  79. #endif