Fix RestartApplication on Linux

(and hopefully don't break it on Windows)
qteditor
Lukas Werling 2016-08-11 22:11:15 +02:00
parent 4869eff787
commit abef0da0aa
4 changed files with 22 additions and 8 deletions

View File

@ -259,7 +259,7 @@ void C4StartupMainDlg::OnOptionsBtn(C4GUI::Control *btn)
void C4StartupMainDlg::OnEditorBtn(C4GUI::Control *btn)
{
if (!RestartApplication("--editor"))
if (!RestartApplication({"--editor"}))
{
C4GUI::TheScreen.ShowErrorMessage(LoadResStr("IDS_ERR_STARTEDITOR"));
}

View File

@ -1126,7 +1126,7 @@ bool C4StartupNetDlg::DoOK()
{
if (join_data.SaveToFile(tmpfn.getData()))
{
if (RestartApplication(FormatString("--editor --join=\"%s%s\"", C4Game::DirectJoinFilePrefix, tmpfn.getData()).getData())) // hope for no " in temp path
if (RestartApplication({"--editor", FormatString("--join=%s%s", C4Game::DirectJoinFilePrefix, tmpfn.getData()).getData()})) // hope for no " in temp path
{
// Application.Quit() has been called. Will quit after returning from this callback.
// The temp file will be deleted by the new instance

View File

@ -15,11 +15,11 @@
*/
#include "C4Include.h"
#include "game/C4Application.h"
#ifdef _WIN32
#include "platform/C4windowswrapper.h"
#include <shellapi.h>
#include "game/C4Application.h"
bool OpenURL(const char *szURL)
{
return (intptr_t)ShellExecuteW(NULL, L"open", GetWideChar(szURL), NULL, NULL, SW_SHOW) > 32;
@ -79,7 +79,7 @@ bool OpenURL(char const*) {return 0;}
#endif
bool RestartApplication(const char *parameters)
bool RestartApplication(std::vector<const char *> parameters)
{
// restart with given parameters
bool success = false;
@ -88,7 +88,14 @@ bool RestartApplication(const char *parameters)
DWORD sz = ::GetModuleFileName(::GetModuleHandle(NULL), buf, _MAX_PATH);
if (sz)
{
intptr_t iError = (intptr_t)::ShellExecute(NULL, NULL, buf, StdStrBuf(parameters).GetWideChar(), Config.General.ExePath.GetWideChar(), SW_SHOW);
StdStrBuf params;
for (auto p : parameters)
{
params += "\"";
params += p;
params += "\" ";
}
intptr_t iError = (intptr_t)::ShellExecute(NULL, NULL, buf, params.GetWideChar(), Config.General.ExePath.GetWideChar(), SW_SHOW);
if (iError > 32) success = true;
}
#else
@ -97,9 +104,14 @@ bool RestartApplication(const char *parameters)
{
case -1: break; // error message shown below
case 0:
execl("/proc/self/exe", "openclonk", parameters, NULL);
{
std::vector<const char*> params = {"openclonk"};
params.insert(params.end(), parameters.begin(), parameters.end());
params.push_back(NULL);
execv("/proc/self/exe", const_cast<char *const *>(params.data()));
perror("editor launch failed");
exit(1);
}
default:
success = true;
}
@ -107,4 +119,4 @@ bool RestartApplication(const char *parameters)
// must quit ourselves for new instance to be shown
if (success) Application.Quit();
return success;
}
}

View File

@ -20,6 +20,8 @@
#ifndef INC_PLATFORMABSTRACTION
#define INC_PLATFORMABSTRACTION
#include <vector>
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif // HAVE_CONFIG_H
@ -176,7 +178,7 @@ bool IsGermanSystem();
bool OpenURL(const char* szURL);
// reopen the engine with given parameters
bool RestartApplication(const char *parameters);
bool RestartApplication(std::vector<const char *> parameters);
#ifdef _WIN32
#include <io.h>