Skip to content

Commit 6202be5

Browse files
Paul Gofmanivyl
Paul Gofman
authored andcommitted
steam_helper: Try to handle same app id restart ourselves instead of forwarding to Steam command handler.
CW-Bug-Id: #23816
1 parent 77f1af2 commit 6202be5

File tree

1 file changed

+68
-1
lines changed

1 file changed

+68
-1
lines changed

steam_helper/steam.cpp

+68-1
Original file line numberDiff line numberDiff line change
@@ -1356,8 +1356,10 @@ static BOOL steam_command_handler(int argc, char *argv[])
13561356
typedef NTSTATUS (WINAPI *__WINE_UNIX_SPAWNVP)(char *const argv[], int wait);
13571357
static __WINE_UNIX_SPAWNVP p__wine_unix_spawnvp;
13581358
NTSTATUS status = STATUS_UNSUCCESSFUL;
1359+
BOOL restart_self = FALSE;
13591360
char **unix_argv;
13601361
HMODULE module;
1362+
const char *sgi;
13611363
int i, j;
13621364
static char *unix_steam[] =
13631365
{
@@ -1370,6 +1372,33 @@ static BOOL steam_command_handler(int argc, char *argv[])
13701372
if (argc > 1 && StrStrIA(argv[1], "steam://") != argv[1] && argv[1][0] != '-')
13711373
return FALSE;
13721374

1375+
if (argc > 2 && !strcmp(argv[1], "--") && (sgi = getenv("SteamGameId")))
1376+
{
1377+
char s[64];
1378+
1379+
snprintf(s, sizeof(s), "steam://launch/%s", sgi);
1380+
if (!(restart_self = !strcmp(argv[2], s)))
1381+
{
1382+
snprintf(s, sizeof(s), "steam://rungameid/%s", sgi);
1383+
restart_self = !strcmp(argv[2], s);
1384+
}
1385+
}
1386+
if (restart_self)
1387+
{
1388+
HANDLE event;
1389+
1390+
event = OpenEventA(SYNCHRONIZE, FALSE, "PROTON_STEAM_EXE_RESTART_APP");
1391+
if (event)
1392+
{
1393+
SetEvent(event);
1394+
CloseHandle(event);
1395+
WINE_TRACE("Signalled app restart.\n");
1396+
}
1397+
else
1398+
WINE_ERR("Restart event not found.\n");
1399+
return TRUE;
1400+
}
1401+
13731402
if (!p__wine_unix_spawnvp)
13741403
{
13751404
module = GetModuleHandleA("ntdll.dll");
@@ -1737,8 +1766,46 @@ int main(int argc, char *argv[])
17371766

17381767
if(wait_handle != INVALID_HANDLE_VALUE)
17391768
{
1769+
HANDLE waits[2];
1770+
DWORD ret;
1771+
int wait_count;
1772+
1773+
waits[0] = wait_handle;
1774+
waits[1] = NULL;
1775+
wait_count = 1;
1776+
if (game_process)
1777+
{
1778+
if ((waits[1] = CreateEventA(NULL, FALSE, FALSE, "PROTON_STEAM_EXE_RESTART_APP")))
1779+
{
1780+
++wait_count;
1781+
}
1782+
else
1783+
{
1784+
WINE_ERR("Failed to create restart event, err %lu.\n", GetLastError());
1785+
}
1786+
}
17401787
FreeConsole();
1741-
WaitForSingleObject(wait_handle, INFINITE);
1788+
while ((ret = WaitForMultipleObjects(wait_count, waits, FALSE, INFINITE) != WAIT_OBJECT_0))
1789+
{
1790+
BOOL should_await;
1791+
1792+
if (ret != WAIT_OBJECT_0 + 1)
1793+
{
1794+
WINE_ERR("Wait failed.\n");
1795+
break;
1796+
}
1797+
if (child != INVALID_HANDLE_VALUE)
1798+
{
1799+
if (WaitForSingleObject(child, 0) == WAIT_TIMEOUT)
1800+
{
1801+
WINE_ERR("Child is still running, not restarting.\n");
1802+
continue;
1803+
}
1804+
CloseHandle(child);
1805+
}
1806+
child = run_process(&should_await, game_process);
1807+
}
1808+
CloseHandle(waits[1]);
17421809
}
17431810

17441811
if (event != INVALID_HANDLE_VALUE)

0 commit comments

Comments
 (0)