From 4ff5da23f1a3af4b46e09ffd27830b0e946b29f1 Mon Sep 17 00:00:00 2001 From: "Brian R. Bondy" Date: Mon, 14 May 2012 09:19:22 -0400 Subject: [PATCH] Bug 290735 - When launching a file use download path as working directory. r=jimm --- xpcom/io/nsLocalFileWin.cpp | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/xpcom/io/nsLocalFileWin.cpp b/xpcom/io/nsLocalFileWin.cpp index 6cf2355538b..7fa0a142daf 100644 --- a/xpcom/io/nsLocalFileWin.cpp +++ b/xpcom/io/nsLocalFileWin.cpp @@ -253,9 +253,21 @@ private: seinfo.lpParameters = NULL; seinfo.lpDirectory = NULL; seinfo.nShow = SW_SHOWNORMAL; + + // Use the directory of the file we're launching as the working + // directory. That way if we have a self extracting EXE it won't + // suggest to extract to the install directory. + WCHAR workingDirectory[MAX_PATH + 1] = { L'\0' }; + wcsncpy(workingDirectory, mResolvedPath.get(), MAX_PATH); + if (PathRemoveFileSpecW(workingDirectory)) { + seinfo.lpDirectory = workingDirectory; + } else { + NS_WARNING("Could not set working directory for launched file."); + } - if (ShellExecuteExW(&seinfo)) + if (ShellExecuteExW(&seinfo)) { return NS_OK; + } DWORD r = GetLastError(); // if the file has no association, we launch windows' // "what do you want to do" dialog