[Bf-blender-cvs] [4a7ace4a783] blender-v3.3-release: win-launcher: linger when launched from steam

Ray Molenkamp noreply at git.blender.org
Mon Nov 28 14:55:11 CET 2022


Commit: 4a7ace4a783f71d0f5ebc6c152fb503039290e7d
Author: Ray Molenkamp
Date:   Thu Nov 17 07:29:09 2022 -0700
Branches: blender-v3.3-release
https://developer.blender.org/rB4a7ace4a783f71d0f5ebc6c152fb503039290e7d

win-launcher: linger when launched from steam

The launcher is designed to exit as soon as possible
so there's no useless processes idling. Now when steam
launches blender with the launcher, this breaks the
time tracking steam has as the thing it just started
exits within milliseconds.

There already is some code in the launcher that makes
the launcher linger to support background mode. This
patch extends this a bit to also wait if the parent
process is steam.exe

Reviewed by: brecht lichtwerk dingto
Differential Revision: https://developer.blender.org/D16527

===================================================================

M	source/creator/blender_launcher_win32.c

===================================================================

diff --git a/source/creator/blender_launcher_win32.c b/source/creator/blender_launcher_win32.c
index 242105e5e05..993efafb53d 100644
--- a/source/creator/blender_launcher_win32.c
+++ b/source/creator/blender_launcher_win32.c
@@ -4,6 +4,54 @@
 #include <strsafe.h>
 
 #include <PathCch.h>
+#include <tlhelp32.h>
+
+BOOL LaunchedFromSteam()
+{
+  HANDLE hSnapShot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
+  BOOL isSteam = FALSE;
+  if (!hSnapShot)
+    return (FALSE);
+
+  PROCESSENTRY32 process_entry;
+  process_entry.dwSize = sizeof(PROCESSENTRY32);
+
+  if (!Process32First(hSnapShot, &process_entry)) {
+    CloseHandle(hSnapShot);
+    return (FALSE);
+  }
+
+  /* First find our parent process ID. */
+  DWORD our_pid = GetCurrentProcessId();
+  DWORD parent_pid = -1;
+
+  do {
+    if (process_entry.th32ProcessID == our_pid) {
+      parent_pid = process_entry.th32ParentProcessID;
+      break;
+    }
+  } while (Process32Next(hSnapShot, &process_entry));
+
+  if (parent_pid == -1 || !Process32First(hSnapShot, &process_entry)) {
+    CloseHandle(hSnapShot);
+    return (FALSE);
+  }
+  /* Then do another loop to find the process name of the parent.
+   * this is done in 2 loops, since the order of the processes is
+   * unknown and we may already have passed the parent process by
+   * the time we figure out its pid in the first loop. */
+  do {
+    if (process_entry.th32ProcessID == parent_pid) {
+      if (_wcsicmp(process_entry.szExeFile, L"steam.exe") == 0) {
+        isSteam = TRUE;
+      }
+      break;
+    }
+  } while (Process32Next(hSnapShot, &process_entry));
+
+  CloseHandle(hSnapShot);
+  return isSteam;
+}
 
 int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PWSTR pCmdLine, int nCmdShow)
 {
@@ -68,9 +116,9 @@ int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PWSTR pCmdLine
   DWORD returnValue = success ? 0 : -1;
 
   if (success) {
-    /* If blender-launcher is called with background command line flag,
+    /* If blender-launcher is called with background command line flag or launched from steam,
      * wait for the blender process to exit and return its return value. */
-    BOOL background = FALSE;
+    BOOL background = LaunchedFromSteam();
     int argc = 0;
     LPWSTR *argv = CommandLineToArgvW(pCmdLine, &argc);
     for (int i = 0; i < argc; i++) {



More information about the Bf-blender-cvs mailing list