diff options
author | Sergey Sharybin <sergey.vfx@gmail.com> | 2014-08-12 14:40:23 +0400 |
---|---|---|
committer | Sergey Sharybin <sergey.vfx@gmail.com> | 2014-08-12 14:48:46 +0400 |
commit | 0fc4289c39bd2412abe83adb30751bf43a571973 (patch) | |
tree | 570537d1a7d89a0c27e9f6fecf6d1ff9fd67c3e6 /intern | |
parent | 1743c81ce1b01e89728f98ea66ba1c07192bcff9 (diff) |
Console detection now works reliably when starting blender-app directly
Diffstat (limited to 'intern')
-rw-r--r-- | intern/ghost/intern/GHOST_SystemWin32.cpp | 26 |
1 files changed, 24 insertions, 2 deletions
diff --git a/intern/ghost/intern/GHOST_SystemWin32.cpp b/intern/ghost/intern/GHOST_SystemWin32.cpp index bc2a210fb1e..3be6f0d0e06 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; } |