зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1357154 - Cache Windows executable path after BinaryPath::Get is called in main. r=ehsan
MozReview-Commit-ID: Qby9b4ngz2
This commit is contained in:
Родитель
f80ffdab06
Коммит
45ea222ca2
|
@ -4,6 +4,11 @@
|
||||||
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||||
|
|
||||||
|
# For BinaryPath::GetLong for Windows
|
||||||
|
LOCAL_INCLUDES += [
|
||||||
|
'/xpcom/build'
|
||||||
|
]
|
||||||
|
|
||||||
XPCSHELL_TESTS_MANIFESTS += ['test/unit/xpcshell.ini']
|
XPCSHELL_TESTS_MANIFESTS += ['test/unit/xpcshell.ini']
|
||||||
BROWSER_CHROME_MANIFESTS += ['test/browser.ini']
|
BROWSER_CHROME_MANIFESTS += ['test/browser.ini']
|
||||||
|
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
|
|
||||||
#include "nsWindowsShellService.h"
|
#include "nsWindowsShellService.h"
|
||||||
|
|
||||||
|
#include "BinaryPath.h"
|
||||||
#include "city.h"
|
#include "city.h"
|
||||||
#include "imgIContainer.h"
|
#include "imgIContainer.h"
|
||||||
#include "imgIRequest.h"
|
#include "imgIRequest.h"
|
||||||
|
@ -228,13 +229,10 @@ nsWindowsShellService::IsDefaultBrowser(bool aStartupCheck,
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
wchar_t exePath[MAX_BUF] = L"";
|
wchar_t exePath[MAXPATHLEN] = L"";
|
||||||
if (!::GetModuleFileNameW(0, exePath, MAX_BUF)) {
|
nsresult rv = BinaryPath::GetLong(exePath);
|
||||||
return NS_OK;
|
|
||||||
}
|
if (NS_FAILED(rv)) {
|
||||||
// Convert the path to a long path since GetModuleFileNameW returns the path
|
|
||||||
// that was used to launch Firefox which is not necessarily a long path.
|
|
||||||
if (!::GetLongPathNameW(exePath, exePath, MAX_BUF)) {
|
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -20,6 +20,8 @@
|
||||||
#include "mozilla/UniquePtrExtensions.h"
|
#include "mozilla/UniquePtrExtensions.h"
|
||||||
|
|
||||||
#ifdef MOZILLA_INTERNAL_API
|
#ifdef MOZILLA_INTERNAL_API
|
||||||
|
#include "nsCOMPtr.h"
|
||||||
|
#include "nsIFile.h"
|
||||||
#include "nsString.h"
|
#include "nsString.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -41,13 +43,51 @@ public:
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static nsresult GetLong(wchar_t aResult[MAXPATHLEN])
|
||||||
|
{
|
||||||
|
static bool cached = false;
|
||||||
|
static wchar_t exeLongPath[MAXPATHLEN] = L"";
|
||||||
|
|
||||||
|
if (!cached) {
|
||||||
|
nsresult rv = GetW(nullptr, exeLongPath);
|
||||||
|
|
||||||
|
if (NS_FAILED(rv)) {
|
||||||
|
return rv;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!::GetLongPathNameW(exeLongPath, exeLongPath, MAXPATHLEN)) {
|
||||||
|
return NS_ERROR_FAILURE;
|
||||||
|
}
|
||||||
|
|
||||||
|
cached = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (wcscpy_s(aResult, MAXPATHLEN, exeLongPath)) {
|
||||||
|
return NS_ERROR_FAILURE;
|
||||||
|
}
|
||||||
|
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static nsresult GetW(const char* argv0, wchar_t aResult[MAXPATHLEN])
|
static nsresult GetW(const char* argv0, wchar_t aResult[MAXPATHLEN])
|
||||||
{
|
{
|
||||||
if (::GetModuleFileNameW(0, aResult, MAXPATHLEN)) {
|
static bool cached = false;
|
||||||
return NS_OK;
|
static wchar_t moduleFileName[MAXPATHLEN] = L"";
|
||||||
|
|
||||||
|
if (!cached) {
|
||||||
|
if (!::GetModuleFileNameW(0, moduleFileName, MAXPATHLEN)) {
|
||||||
|
return NS_ERROR_FAILURE;
|
||||||
|
}
|
||||||
|
|
||||||
|
cached = true;
|
||||||
}
|
}
|
||||||
return NS_ERROR_FAILURE;
|
|
||||||
|
if (wcscpy_s(aResult, MAXPATHLEN, moduleFileName)) {
|
||||||
|
return NS_ERROR_FAILURE;
|
||||||
|
}
|
||||||
|
|
||||||
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
#elif defined(XP_MACOSX)
|
#elif defined(XP_MACOSX)
|
||||||
|
|
Загрузка…
Ссылка в новой задаче