mirror of
https://github.com/vcmi/vcmi.git
synced 2025-11-27 22:49:25 +02:00
Fix launcher crash at close
This commit is contained in:
@@ -11,6 +11,8 @@
|
||||
#include "mainwindow_moc.h"
|
||||
|
||||
#include <QApplication>
|
||||
#include <QProcess>
|
||||
#include "../lib/VCMIDirs.h"
|
||||
|
||||
// Conan workaround https://github.com/conan-io/conan-center-index/issues/13332
|
||||
#ifdef VCMI_IOS
|
||||
@@ -19,6 +21,9 @@
|
||||
#endif
|
||||
#endif
|
||||
|
||||
int __argc;
|
||||
char ** __argv;
|
||||
|
||||
int main(int argc, char * argv[])
|
||||
{
|
||||
int result;
|
||||
@@ -38,3 +43,45 @@ int main(int argc, char * argv[])
|
||||
#endif
|
||||
return result;
|
||||
}
|
||||
|
||||
void startGame(const QStringList & args)
|
||||
{
|
||||
__argc = args.size() + 1; //first argument is omitted
|
||||
__argv = new char*[__argc];
|
||||
__argv[0] = new char[strlen("vcmi")];
|
||||
strcpy(__argv[0], "vcmi");
|
||||
for(int i = 1; i < __argc; ++i)
|
||||
{
|
||||
const char * s = args[i - 1].toLocal8Bit().constData();
|
||||
__argv[i] = new char[strlen(s)];
|
||||
strcpy(__argv[i], s);
|
||||
}
|
||||
#ifdef Q_OS_IOS
|
||||
logGlobal->warn("Starting game with the arguments: %s", args.join(" ").toStdString());
|
||||
qApp->quit();
|
||||
#else
|
||||
startExecutable(pathToQString(VCMIDirs::get().clientPath()), args);
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifndef Q_OS_IOS
|
||||
void startExecutable(QString name, const QStringList & args)
|
||||
{
|
||||
QProcess process;
|
||||
|
||||
// Start the executable
|
||||
if(process.startDetached(name, args))
|
||||
{
|
||||
qApp->quit();
|
||||
}
|
||||
else
|
||||
{
|
||||
QMessageBox::critical(qApp->activeWindow(),
|
||||
"Error starting executable",
|
||||
"Failed to start " + name + "\n"
|
||||
"Reason: " + process.errorString(),
|
||||
QMessageBox::Ok,
|
||||
QMessageBox::Ok);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user