wine: try to guess the working directory in the Run dialog
[sugaredwine.git] / patches / 0032-shell32-try-to-guess-the-working-directory-in-the-r.patch
blob9ab56c68e5537d613f82f3accda2efe52dfbe7df
1 From 22c27dd3125b74a6383b466fe89f260bbe559fbf Mon Sep 17 00:00:00 2001
2 From: Vincent Povirk <vincent@codeweavers.com>
3 Date: Tue, 21 Oct 2008 16:07:47 -0500
4 Subject: [PATCH] shell32: try to guess the working directory in the run dialog
6 The Run dialog on Windows, when invoked from the start menu or by
7 passing NULL as a working directory to RunFileDlg, sets the working
8 directory to the parent of the file being run. Programs often rely on
9 the working directory so we should copy this behavior.
10 ---
11 dlls/shell32/dialogs.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++-
12 1 files changed, 50 insertions(+), 2 deletions(-)
14 diff --git a/dlls/shell32/dialogs.c b/dlls/shell32/dialogs.c
15 index b64d306..089c8c0 100644
16 --- a/dlls/shell32/dialogs.c
17 +++ b/dlls/shell32/dialogs.c
18 @@ -113,6 +113,47 @@ void WINAPI RunFileDlgW(
22 +/* find the directory that contains the file being run */
23 +static LPWSTR RunDlg_GetParentDir(LPCWSTR cmdline)
25 + const WCHAR *src;
26 + WCHAR *dest, *result, *result_end=NULL;
28 + result = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(WCHAR)*strlenW(cmdline));
30 + src = cmdline;
31 + dest = result;
33 + if (*src == '"')
34 + src++;
36 + while (*src)
37 + {
38 + *dest = *src;
39 + if (*src == '\\')
40 + {
41 + DWORD attrs = GetFileAttributesW(result);
42 + if (attrs != INVALID_FILE_ATTRIBUTES && attrs & FILE_ATTRIBUTE_DIRECTORY)
43 + result_end = dest;
44 + else
45 + break;
46 + }
47 + src++;
48 + dest++;
49 + }
51 + if (result_end)
52 + {
53 + *result_end = 0;
54 + return result;
55 + }
56 + else
57 + {
58 + HeapFree(GetProcessHeap(), 0, result);
59 + return NULL;
60 + }
63 /* Dialog procedure for RunFileDlg */
64 static INT_PTR CALLBACK RunDlgProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
66 @@ -158,14 +199,20 @@ static INT_PTR CALLBACK RunDlgProc (HWND hwnd, UINT message, WPARAM wParam, LPAR
67 HWND htxt = GetDlgItem (hwnd, IDC_RUNDLG_EDITPATH);
68 if ((ic = GetWindowTextLengthW (htxt)))
70 - WCHAR *psz ;
71 + WCHAR *psz, *parent=NULL ;
72 + LPCWSTR working_dir ;
73 psz = HeapAlloc( GetProcessHeap(), 0, (ic + 1)*sizeof(WCHAR) );
74 GetWindowTextW (htxt, psz, ic + 1) ;
76 /* according to http://www.codeproject.com/KB/shell/runfiledlg.aspx we should send a
77 * WM_NOTIFY before execution */
79 - if (ShellExecuteW(hwnd, NULL, psz, NULL, prfdp->lpstrDirectory, SW_SHOWNORMAL) < (HINSTANCE)33)
80 + if (prfdp->lpstrDirectory)
81 + working_dir = prfdp->lpstrDirectory;
82 + else
83 + working_dir = parent = RunDlg_GetParentDir(psz);
85 + if (ShellExecuteW(hwnd, NULL, psz, NULL, working_dir, SW_SHOWNORMAL) < (HINSTANCE)33)
87 char *pszSysMsg = NULL ;
88 char szMsg[256];
89 @@ -191,6 +238,7 @@ static INT_PTR CALLBACK RunDlgProc (HWND hwnd, UINT message, WPARAM wParam, LPAR
90 FillList (htxt, (LPSTR)psz, FALSE) ;
92 HeapFree(GetProcessHeap(), 0, psz);
93 + HeapFree(GetProcessHeap(), 0, parent);
94 EndDialog (hwnd, 0) ;
97 --
98 1.5.6.5