[Bf-blender-cvs] [0fc4289] master: Console detection now works reliably when starting blender-app directly

Sergey Sharybin noreply at git.blender.org
Tue Aug 12 12:49:03 CEST 2014


Commit: 0fc4289c39bd2412abe83adb30751bf43a571973
Author: Sergey Sharybin
Date:   Tue Aug 12 16:40:23 2014 +0600
Branches: master
https://developer.blender.org/rB0fc4289c39bd2412abe83adb30751bf43a571973

Console detection now works reliably when starting blender-app directly

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

M	intern/ghost/intern/GHOST_SystemWin32.cpp

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

diff --git a/intern/ghost/intern/GHOST_SystemWin32.cpp b/intern/ghost/intern/GHOST_SystemWin32.cpp
index bc2a210..3be6f0d 100644
--- a/intern/ghost/intern/GHOST_SystemWin32.cpp
+++ b/intern/ghost/intern/GHOST_SystemWin32.cpp
@@ -1408,19 +1408,41 @@ static DWORD GetParentProcessID(void)
 	return ppid;
 }
 
+static bool getProcessName(int pid, char *buffer, int max_len)
+{
+	bool result = false;
+	HANDLE handle = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ,
+	                            FALSE, pid);
+	if (handle) {
+		GetModuleFileNameEx(handle, 0, buffer, max_len);
+		result = true;
+	}
+	CloseHandle(handle);
+	return result;
+}
+
 static bool isStartedFromCommandPrompt()
 {
 	HWND hwnd = GetConsoleWindow();
 	
 	if (hwnd) {
 		DWORD pid = (DWORD)-1;
+		DWORD ppid = GetParentProcessID();
+        char parent_name[MAX_PATH];
+		bool start_from_launcher = false;
 
 		GetWindowThreadProcessId(hwnd, &pid);
+		if (getProcessName(ppid, parent_name, sizeof(parent_name))) {
+			char *filename = strrchr(parent_name, '\\');
+			if (filename != NULL) {
+				start_from_launcher = strstr(filename, "blender.exe") != NULL;
+			}
+		}
 
-		/* Because we're starting from a wrapper we need to comare with
+		/* When we're starting from a wrapper we need to comare with
 		 * parent process ID.
 		 */
-		if (pid == GetParentProcessID())
+		if (pid == (start_from_launcher ? ppid : GetCurrentProcessId()))
 			return true;
 	}




More information about the Bf-blender-cvs mailing list