From 02b116aae049349ee343a6fcc4a0b0d1a0911575 Mon Sep 17 00:00:00 2001 From: "Ryan C. Gordon" Date: Wed, 31 May 2017 01:02:26 -0400 Subject: [PATCH] Initial Windows autoupdater support: the ioq3 internal bits. This is just the piece that will launch the autoupdater; the autoupdater itself will be a separate commit. --- code/sys/sys_main.c | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/code/sys/sys_main.c b/code/sys/sys_main.c index e7543044..81d5c977 100644 --- a/code/sys/sys_main.c +++ b/code/sys/sys_main.c @@ -31,9 +31,14 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #include #include -#ifndef _WIN32 +#ifdef USE_AUTOUPDATER +#ifdef _WIN32 +#define WIN32_LEAN_AND_MEAN 1 +#include +#else #include #endif +#endif #ifndef DEDICATED #ifdef USE_LOCAL_HEADERS @@ -669,6 +674,20 @@ int main( int argc, char **argv ) #error The build system should have defined AUTOUPDATER_BIN #endif + #ifdef _WIN32 + { + /* We don't need the Unix pipe() tapdance here because Windows lets children wait on parent processes. */ + PROCESS_INFORMATION procinfo; + char cmdline[128]; + Com_sprintf(cmdline, sizeof (cmdline), AUTOUPDATER_BIN " --waitpid %u", (unsigned int) GetCurrentProcessId()); + if (CreateProcessA(AUTOUPDATER_BIN, cmdline, NULL, NULL, FALSE, 0, NULL, NULL, NULL, &procinfo)) + { + /* close handles now so child cleans up immediately if nothing to do */ + CloseHandle(procinfo.hProcess); + CloseHandle(procinfo.hThread); + } + } + #else int updater_pipes[2]; if (pipe(updater_pipes) == 0) { @@ -702,6 +721,7 @@ int main( int argc, char **argv ) close(updater_pipes[0]); } } + #endif } #endif