2007-03-22 10:30:00 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
|
|
|
*
|
|
|
|
* The Original Code is mozilla.org code.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is
|
|
|
|
* Netscape Communications Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 2001
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
* Conrad Carlen <ccarlen@netscape.com>
|
2007-04-03 08:56:31 -07:00
|
|
|
* Ere Maijala <emaijala@kolumbus.fi>
|
2007-03-22 10:30:00 -07:00
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
|
|
|
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
|
|
|
|
|
|
|
#include "nsPluginDirServiceProvider.h"
|
|
|
|
|
|
|
|
#include "nsCRT.h"
|
|
|
|
#include "nsILocalFile.h"
|
|
|
|
#include "nsIPrefBranch.h"
|
|
|
|
#include "nsIPrefService.h"
|
|
|
|
#include "nsDependentString.h"
|
|
|
|
#include "nsXPIDLString.h"
|
|
|
|
#include "prmem.h"
|
|
|
|
#include "nsArrayEnumerator.h"
|
|
|
|
|
|
|
|
typedef struct structVer
|
|
|
|
{
|
|
|
|
WORD wMajor;
|
|
|
|
WORD wMinor;
|
|
|
|
WORD wRelease;
|
|
|
|
WORD wBuild;
|
|
|
|
} verBlock;
|
|
|
|
|
|
|
|
static void
|
|
|
|
ClearVersion(verBlock *ver)
|
|
|
|
{
|
|
|
|
ver->wMajor = 0;
|
|
|
|
ver->wMinor = 0;
|
|
|
|
ver->wRelease = 0;
|
|
|
|
ver->wBuild = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static BOOL
|
2010-02-19 12:31:28 -08:00
|
|
|
FileExists(LPCWSTR szFile)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2010-02-19 12:31:28 -08:00
|
|
|
return GetFileAttributesW(szFile) != 0xFFFFFFFF;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// Get file version information from a file
|
|
|
|
static BOOL
|
2010-02-19 12:31:28 -08:00
|
|
|
GetFileVersion(LPCWSTR szFile, verBlock *vbVersion)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
UINT uLen;
|
|
|
|
UINT dwLen;
|
|
|
|
BOOL bRv;
|
|
|
|
DWORD dwHandle;
|
|
|
|
LPVOID lpData;
|
|
|
|
LPVOID lpBuffer;
|
|
|
|
VS_FIXEDFILEINFO *lpBuffer2;
|
|
|
|
|
|
|
|
ClearVersion(vbVersion);
|
|
|
|
if (FileExists(szFile)) {
|
|
|
|
bRv = TRUE;
|
2010-02-19 21:53:38 -08:00
|
|
|
#ifdef WINCE
|
|
|
|
// WinCe takes a non const file path string, while desktop take a const
|
|
|
|
LPWSTR lpFilepath = const_cast<LPWSTR>(szFile);
|
|
|
|
#else
|
|
|
|
LPCWSTR lpFilepath = szFile;
|
|
|
|
#endif
|
|
|
|
dwLen = GetFileVersionInfoSizeW(lpFilepath, &dwHandle);
|
2007-03-22 10:30:00 -07:00
|
|
|
lpData = (LPVOID)malloc(dwLen);
|
|
|
|
uLen = 0;
|
|
|
|
|
2010-02-19 21:53:38 -08:00
|
|
|
if (lpData && GetFileVersionInfoW(lpFilepath, dwHandle, dwLen, lpData) != 0) {
|
2010-02-13 13:59:39 -08:00
|
|
|
if (VerQueryValueW(lpData, L"\\", &lpBuffer, &uLen) != 0) {
|
2007-03-22 10:30:00 -07:00
|
|
|
lpBuffer2 = (VS_FIXEDFILEINFO *)lpBuffer;
|
|
|
|
|
|
|
|
vbVersion->wMajor = HIWORD(lpBuffer2->dwFileVersionMS);
|
|
|
|
vbVersion->wMinor = LOWORD(lpBuffer2->dwFileVersionMS);
|
|
|
|
vbVersion->wRelease = HIWORD(lpBuffer2->dwFileVersionLS);
|
|
|
|
vbVersion->wBuild = LOWORD(lpBuffer2->dwFileVersionLS);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
free(lpData);
|
|
|
|
} else {
|
|
|
|
/* File does not exist */
|
|
|
|
bRv = FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return bRv;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Will deep copy ver2 into ver1
|
|
|
|
static void
|
|
|
|
CopyVersion(verBlock *ver1, verBlock *ver2)
|
|
|
|
{
|
|
|
|
ver1->wMajor = ver2->wMajor;
|
|
|
|
ver1->wMinor = ver2->wMinor;
|
|
|
|
ver1->wRelease = ver2->wRelease;
|
|
|
|
ver1->wBuild = ver2->wBuild;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Convert a string version to a version struct
|
|
|
|
static void
|
2010-02-13 13:59:39 -08:00
|
|
|
TranslateVersionStr(const WCHAR* szVersion, verBlock *vbVersion)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2010-02-19 12:31:28 -08:00
|
|
|
WCHAR* szNum1 = NULL;
|
|
|
|
WCHAR* szNum2 = NULL;
|
|
|
|
WCHAR* szNum3 = NULL;
|
|
|
|
WCHAR* szNum4 = NULL;
|
|
|
|
WCHAR* szJavaBuild = NULL;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-02-13 13:59:39 -08:00
|
|
|
WCHAR *strVer = nsnull;
|
2007-03-22 10:30:00 -07:00
|
|
|
if (szVersion) {
|
2010-02-13 13:59:39 -08:00
|
|
|
strVer = wcsdup(szVersion);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!strVer) {
|
|
|
|
// Out of memory
|
|
|
|
ClearVersion(vbVersion);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Java may be using an underscore instead of a dot for the build ID
|
2010-02-13 13:59:39 -08:00
|
|
|
szJavaBuild = wcschr(strVer, '_');
|
2007-03-22 10:30:00 -07:00
|
|
|
if (szJavaBuild) {
|
|
|
|
szJavaBuild[0] = '.';
|
|
|
|
}
|
|
|
|
|
2010-02-13 13:59:39 -08:00
|
|
|
szNum1 = wcstok(strVer, L".");
|
|
|
|
szNum2 = wcstok(NULL, L".");
|
|
|
|
szNum3 = wcstok(NULL, L".");
|
|
|
|
szNum4 = wcstok(NULL, L".");
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-02-19 12:31:28 -08:00
|
|
|
vbVersion->wMajor = szNum1 ? (WORD) _wtoi(szNum1) : 0;
|
|
|
|
vbVersion->wMinor = szNum2 ? (WORD) _wtoi(szNum2) : 0;
|
|
|
|
vbVersion->wRelease = szNum3 ? (WORD) _wtoi(szNum3) : 0;
|
|
|
|
vbVersion->wBuild = szNum4 ? (WORD) _wtoi(szNum4) : 0;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2009-03-08 22:07:00 -07:00
|
|
|
free(strVer);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// Compare two version struct, return zero if the same
|
|
|
|
static int
|
|
|
|
CompareVersion(verBlock vbVersionOld, verBlock vbVersionNew)
|
|
|
|
{
|
|
|
|
if (vbVersionOld.wMajor > vbVersionNew.wMajor) {
|
|
|
|
return 4;
|
|
|
|
} else if (vbVersionOld.wMajor < vbVersionNew.wMajor) {
|
|
|
|
return -4;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (vbVersionOld.wMinor > vbVersionNew.wMinor) {
|
|
|
|
return 3;
|
|
|
|
} else if (vbVersionOld.wMinor < vbVersionNew.wMinor) {
|
|
|
|
return -3;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (vbVersionOld.wRelease > vbVersionNew.wRelease) {
|
|
|
|
return 2;
|
|
|
|
} else if (vbVersionOld.wRelease < vbVersionNew.wRelease) {
|
|
|
|
return -2;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (vbVersionOld.wBuild > vbVersionNew.wBuild) {
|
|
|
|
return 1;
|
|
|
|
} else if (vbVersionOld.wBuild < vbVersionNew.wBuild) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* the versions are all the same */
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
//*****************************************************************************
|
|
|
|
// nsPluginDirServiceProvider::Constructor/Destructor
|
|
|
|
//*****************************************************************************
|
|
|
|
|
|
|
|
nsPluginDirServiceProvider::nsPluginDirServiceProvider()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
nsPluginDirServiceProvider::~nsPluginDirServiceProvider()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
//*****************************************************************************
|
|
|
|
// nsPluginDirServiceProvider::nsISupports
|
|
|
|
//*****************************************************************************
|
|
|
|
|
|
|
|
NS_IMPL_THREADSAFE_ISUPPORTS1(nsPluginDirServiceProvider,
|
|
|
|
nsIDirectoryServiceProvider)
|
|
|
|
|
|
|
|
//*****************************************************************************
|
|
|
|
// nsPluginDirServiceProvider::nsIDirectoryServiceProvider
|
|
|
|
//*****************************************************************************
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2009-03-08 22:07:00 -07:00
|
|
|
nsPluginDirServiceProvider::GetFile(const char *charProp, PRBool *persistant,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsIFile **_retval)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsILocalFile> localFile;
|
|
|
|
nsresult rv = NS_ERROR_FAILURE;
|
|
|
|
|
2009-03-08 22:07:00 -07:00
|
|
|
NS_ENSURE_ARG(charProp);
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
*_retval = nsnull;
|
2007-08-03 15:57:54 -07:00
|
|
|
*persistant = PR_FALSE;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
nsCOMPtr<nsIPrefBranch> prefs(do_GetService(NS_PREFSERVICE_CONTRACTID));
|
2009-06-11 10:40:38 -07:00
|
|
|
if (!prefs)
|
|
|
|
return NS_ERROR_FAILURE;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2009-03-08 22:07:00 -07:00
|
|
|
if (nsCRT::strcmp(charProp, NS_WIN_4DOTX_SCAN_KEY) == 0) {
|
2007-03-22 10:30:00 -07:00
|
|
|
// Check our prefs to see if scanning the 4.x folder has been
|
|
|
|
// explictly overriden failure to get the pref is okay, we'll do
|
|
|
|
// what we've been doing -- a filtered scan
|
|
|
|
PRBool bScan4x;
|
|
|
|
if (NS_SUCCEEDED(prefs->GetBoolPref(NS_WIN_4DOTX_SCAN_KEY, &bScan4x)) &&
|
|
|
|
!bScan4x) {
|
2009-06-11 10:40:38 -07:00
|
|
|
return NS_ERROR_FAILURE;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// Look for the plugin folder that the user has in their
|
|
|
|
// Communicator 4x install
|
|
|
|
HKEY keyloc;
|
|
|
|
long result;
|
|
|
|
DWORD type;
|
2010-02-13 13:59:39 -08:00
|
|
|
WCHAR szKey[_MAX_PATH] = L"Software\\Netscape\\Netscape Navigator";
|
|
|
|
WCHAR path[_MAX_PATH];
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-02-13 13:59:39 -08:00
|
|
|
result = ::RegOpenKeyExW(HKEY_LOCAL_MACHINE, szKey, 0, KEY_READ, &keyloc);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
if (result == ERROR_SUCCESS) {
|
2010-02-13 13:59:39 -08:00
|
|
|
WCHAR current_version[80];
|
2009-03-08 22:07:00 -07:00
|
|
|
DWORD length = NS_ARRAY_LENGTH(current_version);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-02-13 13:59:39 -08:00
|
|
|
result = ::RegQueryValueExW(keyloc, L"CurrentVersion", NULL, &type,
|
|
|
|
(LPBYTE)¤t_version, &length);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
::RegCloseKey(keyloc);
|
2010-02-13 13:59:39 -08:00
|
|
|
wcscat(szKey, L"\\");
|
|
|
|
wcscat(szKey, current_version);
|
|
|
|
wcscat(szKey, L"\\Main");
|
|
|
|
result = ::RegOpenKeyExW(HKEY_LOCAL_MACHINE, szKey, 0, KEY_READ, &keyloc);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
if (result == ERROR_SUCCESS) {
|
2009-03-08 22:07:00 -07:00
|
|
|
DWORD pathlen = NS_ARRAY_LENGTH(path);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-02-13 13:59:39 -08:00
|
|
|
result = ::RegQueryValueExW(keyloc, L"Plugins Directory", NULL, &type,
|
2007-03-22 10:30:00 -07:00
|
|
|
(LPBYTE)&path, &pathlen);
|
|
|
|
if (result == ERROR_SUCCESS) {
|
2010-02-13 13:59:39 -08:00
|
|
|
rv = NS_NewLocalFile(nsDependentString(path),
|
|
|
|
PR_TRUE, getter_AddRefs(localFile));
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
::RegCloseKey(keyloc);
|
|
|
|
}
|
|
|
|
}
|
2009-03-08 22:07:00 -07:00
|
|
|
} else if (nsCRT::strcmp(charProp, NS_WIN_JRE_SCAN_KEY) == 0) {
|
2007-03-22 10:30:00 -07:00
|
|
|
nsXPIDLCString strVer;
|
2009-03-08 22:07:00 -07:00
|
|
|
if (NS_FAILED(prefs->GetCharPref(charProp, getter_Copies(strVer))))
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
verBlock minVer;
|
2010-02-13 13:59:39 -08:00
|
|
|
TranslateVersionStr(NS_ConvertASCIItoUTF16(strVer).get(), &minVer);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// Look for the Java OJI plugin via the JRE install path
|
|
|
|
HKEY baseloc;
|
|
|
|
HKEY keyloc;
|
|
|
|
HKEY entryloc;
|
|
|
|
FILETIME modTime;
|
|
|
|
DWORD type;
|
|
|
|
DWORD index = 0;
|
|
|
|
DWORD numChars = _MAX_PATH;
|
|
|
|
DWORD pathlen;
|
|
|
|
verBlock maxVer;
|
|
|
|
ClearVersion(&maxVer);
|
2010-02-13 13:59:39 -08:00
|
|
|
WCHAR curKey[_MAX_PATH] = L"Software\\JavaSoft\\Java Runtime Environment";
|
|
|
|
WCHAR path[_MAX_PATH];
|
2007-12-01 00:12:22 -08:00
|
|
|
// Add + 15 to prevent buffer overrun when adding \bin (+ optionally
|
|
|
|
// \new_plugin)
|
|
|
|
#define JAVA_PATH_SIZE _MAX_PATH + 15
|
2010-02-13 13:59:39 -08:00
|
|
|
WCHAR newestPath[JAVA_PATH_SIZE];
|
|
|
|
const WCHAR mozPath[_MAX_PATH] = L"Software\\mozilla.org\\Mozilla";
|
|
|
|
WCHAR browserJavaVersion[_MAX_PATH];
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
newestPath[0] = 0;
|
2010-02-13 13:59:39 -08:00
|
|
|
LONG result = ::RegOpenKeyExW(HKEY_LOCAL_MACHINE, curKey, 0, KEY_READ,
|
|
|
|
&baseloc);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (ERROR_SUCCESS != result)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
// Look for "BrowserJavaVersion"
|
2010-02-13 13:59:39 -08:00
|
|
|
if (ERROR_SUCCESS != ::RegQueryValueExW(baseloc, L"BrowserJavaVersion", NULL,
|
|
|
|
NULL, (LPBYTE)&browserJavaVersion,
|
|
|
|
&numChars))
|
2007-03-22 10:30:00 -07:00
|
|
|
browserJavaVersion[0] = 0;
|
|
|
|
|
|
|
|
// We must enumerate through the keys because what if there is
|
|
|
|
// more than one version?
|
|
|
|
do {
|
|
|
|
path[0] = 0;
|
|
|
|
numChars = _MAX_PATH;
|
2009-03-08 22:07:00 -07:00
|
|
|
pathlen = NS_ARRAY_LENGTH(path);
|
2010-02-19 12:31:28 -08:00
|
|
|
result = ::RegEnumKeyExW(baseloc, index, curKey, &numChars, NULL, NULL,
|
|
|
|
NULL, &modTime);
|
2007-03-22 10:30:00 -07:00
|
|
|
index++;
|
|
|
|
|
|
|
|
// Skip major.minor as it always points to latest in its family
|
|
|
|
numChars = 0;
|
2010-02-13 13:59:39 -08:00
|
|
|
for (WCHAR *p = curKey; *p; p++) {
|
2007-03-22 10:30:00 -07:00
|
|
|
if (*p == '.') {
|
|
|
|
numChars++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (numChars < 2)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (ERROR_SUCCESS == result) {
|
2010-02-13 13:59:39 -08:00
|
|
|
if (ERROR_SUCCESS == ::RegOpenKeyExW(baseloc, curKey, 0,
|
|
|
|
KEY_QUERY_VALUE, &keyloc)) {
|
2007-03-22 10:30:00 -07:00
|
|
|
// We have a sub key
|
2010-02-13 13:59:39 -08:00
|
|
|
if (ERROR_SUCCESS == ::RegQueryValueExW(keyloc, L"JavaHome", NULL,
|
|
|
|
&type, (LPBYTE)&path,
|
|
|
|
&pathlen)) {
|
2007-03-22 10:30:00 -07:00
|
|
|
verBlock curVer;
|
|
|
|
TranslateVersionStr(curKey, &curVer);
|
|
|
|
if (CompareVersion(curVer, minVer) >= 0) {
|
2010-02-13 13:59:39 -08:00
|
|
|
if (!wcsncmp(browserJavaVersion, curKey, _MAX_PATH)) {
|
|
|
|
wcscpy(newestPath, path);
|
2007-03-22 10:30:00 -07:00
|
|
|
::RegCloseKey(keyloc);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (CompareVersion(curVer, maxVer) >= 0) {
|
2010-02-13 13:59:39 -08:00
|
|
|
wcscpy(newestPath, path);
|
2007-03-22 10:30:00 -07:00
|
|
|
CopyVersion(&maxVer, &curVer);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
::RegCloseKey(keyloc);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} while (ERROR_SUCCESS == result);
|
|
|
|
|
|
|
|
::RegCloseKey(baseloc);
|
|
|
|
|
2010-02-13 13:59:39 -08:00
|
|
|
static const WCHAR kMozillaVersion[] = NS_L(MOZILLA_VERSION);
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// If nothing is found, then don't add \bin dir and don't set
|
|
|
|
// CurrentVersion for Mozilla
|
|
|
|
if (newestPath[0] != 0) {
|
2010-02-19 12:31:28 -08:00
|
|
|
if (ERROR_SUCCESS == ::RegCreateKeyExW(HKEY_LOCAL_MACHINE, mozPath, 0,
|
|
|
|
NULL, REG_OPTION_NON_VOLATILE,
|
|
|
|
KEY_SET_VALUE|KEY_QUERY_VALUE,
|
|
|
|
NULL, &entryloc, NULL)) {
|
2010-02-13 13:59:39 -08:00
|
|
|
if (ERROR_SUCCESS != ::RegQueryValueExW(entryloc, L"CurrentVersion", 0,
|
2007-03-22 10:30:00 -07:00
|
|
|
NULL, NULL, NULL)) {
|
2010-02-13 13:59:39 -08:00
|
|
|
::RegSetValueExW(entryloc, L"CurrentVersion", 0, REG_SZ,
|
|
|
|
(const BYTE*) kMozillaVersion,
|
|
|
|
NS_ARRAY_LENGTH(kMozillaVersion));
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
::RegCloseKey(entryloc);
|
|
|
|
}
|
|
|
|
|
2010-02-13 13:59:39 -08:00
|
|
|
wcscat(newestPath, L"\\bin");
|
2007-12-01 00:12:22 -08:00
|
|
|
|
2009-06-11 10:40:38 -07:00
|
|
|
// See whether the "new_plugin" directory exists
|
2010-02-13 13:59:39 -08:00
|
|
|
WCHAR tmpPath[JAVA_PATH_SIZE];
|
2009-06-11 10:40:38 -07:00
|
|
|
nsCOMPtr<nsILocalFile> tmpFile;
|
|
|
|
|
2010-02-13 13:59:39 -08:00
|
|
|
wcscpy(tmpPath, newestPath);
|
|
|
|
wcscat(tmpPath, L"\\new_plugin");
|
|
|
|
rv = NS_NewLocalFile(nsDependentString(tmpPath),
|
|
|
|
PR_TRUE, getter_AddRefs(tmpFile));
|
2009-06-11 10:40:38 -07:00
|
|
|
if (NS_SUCCEEDED(rv) && tmpFile) {
|
|
|
|
PRBool exists = PR_FALSE;
|
|
|
|
PRBool isDir = PR_FALSE;
|
|
|
|
if (NS_SUCCEEDED(tmpFile->Exists(&exists)) && exists &&
|
|
|
|
NS_SUCCEEDED(tmpFile->IsDirectory(&isDir)) && isDir) {
|
|
|
|
// Assume we're supposed to use this as the search
|
|
|
|
// directory for the Java Plug-In instead of the normal
|
|
|
|
// one
|
2010-02-13 13:59:39 -08:00
|
|
|
wcscpy(newestPath, tmpPath);
|
2007-12-01 00:12:22 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-02-13 13:59:39 -08:00
|
|
|
rv = NS_NewLocalFile(nsDependentString(newestPath),
|
|
|
|
PR_TRUE, getter_AddRefs(localFile));
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2009-03-08 22:07:00 -07:00
|
|
|
} else if (nsCRT::strcmp(charProp, NS_WIN_QUICKTIME_SCAN_KEY) == 0) {
|
2007-03-22 10:30:00 -07:00
|
|
|
nsXPIDLCString strVer;
|
2009-03-08 22:07:00 -07:00
|
|
|
if (NS_FAILED(prefs->GetCharPref(charProp, getter_Copies(strVer))))
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
verBlock minVer;
|
2010-02-13 13:59:39 -08:00
|
|
|
TranslateVersionStr(NS_ConvertASCIItoUTF16(strVer).get(), &minVer);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// Look for the Quicktime system installation plugins directory
|
|
|
|
HKEY keyloc;
|
|
|
|
long result;
|
|
|
|
DWORD type;
|
|
|
|
verBlock qtVer;
|
|
|
|
ClearVersion(&qtVer);
|
2010-02-13 13:59:39 -08:00
|
|
|
WCHAR path[_MAX_PATH];
|
2009-03-08 22:07:00 -07:00
|
|
|
DWORD pathlen = NS_ARRAY_LENGTH(path);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// First we need to check the version of Quicktime via checking
|
|
|
|
// the EXE's version table
|
2010-02-13 13:59:39 -08:00
|
|
|
if (ERROR_SUCCESS == ::RegOpenKeyExW(HKEY_LOCAL_MACHINE,
|
|
|
|
L"software\\Microsoft\\Windows\\CurrentVersion\\App Paths\\QuickTimePlayer.exe",
|
|
|
|
0, KEY_READ, &keyloc)) {
|
|
|
|
if (ERROR_SUCCESS == ::RegQueryValueExW(keyloc, NULL, NULL, &type,
|
|
|
|
(LPBYTE)&path, &pathlen)) {
|
2009-03-08 22:07:00 -07:00
|
|
|
GetFileVersion(path, &qtVer);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
::RegCloseKey(keyloc);
|
|
|
|
}
|
|
|
|
if (CompareVersion(qtVer, minVer) < 0)
|
|
|
|
return rv;
|
|
|
|
|
2010-02-13 13:59:39 -08:00
|
|
|
if (ERROR_SUCCESS == ::RegOpenKeyExW(HKEY_LOCAL_MACHINE,
|
|
|
|
L"software\\Apple Computer, Inc.\\QuickTime",
|
2009-03-08 22:07:00 -07:00
|
|
|
0, KEY_READ, &keyloc)) {
|
|
|
|
DWORD pathlen = NS_ARRAY_LENGTH(path);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-02-13 13:59:39 -08:00
|
|
|
result = ::RegQueryValueExW(keyloc, L"InstallDir", NULL, &type,
|
|
|
|
(LPBYTE)&path, &pathlen);
|
|
|
|
wcscat(path, L"\\Plugins");
|
2007-03-22 10:30:00 -07:00
|
|
|
if (result == ERROR_SUCCESS)
|
2010-02-13 13:59:39 -08:00
|
|
|
rv = NS_NewLocalFile(nsDependentString(path), PR_TRUE,
|
|
|
|
getter_AddRefs(localFile));
|
2007-03-22 10:30:00 -07:00
|
|
|
::RegCloseKey(keyloc);
|
|
|
|
}
|
2009-03-08 22:07:00 -07:00
|
|
|
} else if (nsCRT::strcmp(charProp, NS_WIN_WMP_SCAN_KEY) == 0) {
|
2007-03-22 10:30:00 -07:00
|
|
|
nsXPIDLCString strVer;
|
2009-03-08 22:07:00 -07:00
|
|
|
if (NS_FAILED(prefs->GetCharPref(charProp, getter_Copies(strVer))))
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
verBlock minVer;
|
2010-02-13 13:59:39 -08:00
|
|
|
TranslateVersionStr(NS_ConvertASCIItoUTF16(strVer).get(), &minVer);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// Look for Windows Media Player system installation plugins directory
|
|
|
|
HKEY keyloc;
|
|
|
|
DWORD type;
|
|
|
|
verBlock wmpVer;
|
|
|
|
ClearVersion(&wmpVer);
|
2010-02-13 13:59:39 -08:00
|
|
|
WCHAR path[_MAX_PATH];
|
2009-03-08 22:07:00 -07:00
|
|
|
DWORD pathlen = NS_ARRAY_LENGTH(path);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// First we need to check the version of WMP
|
2010-02-13 13:59:39 -08:00
|
|
|
if (ERROR_SUCCESS == ::RegOpenKeyExW(HKEY_LOCAL_MACHINE,
|
|
|
|
L"software\\Microsoft\\Windows\\CurrentVersion\\App Paths\\wmplayer.exe",
|
|
|
|
0, KEY_READ, &keyloc)) {
|
|
|
|
if (ERROR_SUCCESS == ::RegQueryValueExW(keyloc, NULL, NULL, &type,
|
|
|
|
(LPBYTE)&path, &pathlen)) {
|
2009-03-08 22:07:00 -07:00
|
|
|
GetFileVersion(path, &wmpVer);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
::RegCloseKey(keyloc);
|
|
|
|
}
|
|
|
|
if (CompareVersion(wmpVer, minVer) < 0)
|
|
|
|
return rv;
|
|
|
|
|
2010-02-13 13:59:39 -08:00
|
|
|
if (ERROR_SUCCESS == ::RegOpenKeyExW(HKEY_LOCAL_MACHINE,
|
|
|
|
L"software\\Microsoft\\MediaPlayer", 0,
|
|
|
|
KEY_READ, &keyloc)) {
|
|
|
|
if (ERROR_SUCCESS == ::RegQueryValueExW(keyloc, L"Installation Directory",
|
2007-03-22 10:30:00 -07:00
|
|
|
NULL, &type, (LPBYTE)&path,
|
|
|
|
&pathlen)) {
|
2010-02-13 13:59:39 -08:00
|
|
|
rv = NS_NewLocalFile(nsDependentString(path), PR_TRUE,
|
|
|
|
getter_AddRefs(localFile));
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
::RegCloseKey(keyloc);
|
|
|
|
}
|
2009-03-08 22:07:00 -07:00
|
|
|
} else if (nsCRT::strcmp(charProp, NS_WIN_ACROBAT_SCAN_KEY) == 0) {
|
2007-03-22 10:30:00 -07:00
|
|
|
nsXPIDLCString strVer;
|
2009-03-08 22:07:00 -07:00
|
|
|
if (NS_FAILED(prefs->GetCharPref(charProp, getter_Copies(strVer)))) {
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
verBlock minVer;
|
2010-02-13 13:59:39 -08:00
|
|
|
TranslateVersionStr(NS_ConvertASCIItoUTF16(strVer).get(), &minVer);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// Look for Adobe Acrobat system installation plugins directory
|
|
|
|
HKEY baseloc;
|
|
|
|
HKEY keyloc;
|
|
|
|
FILETIME modTime;
|
|
|
|
DWORD type;
|
|
|
|
DWORD index = 0;
|
|
|
|
DWORD numChars = _MAX_PATH;
|
|
|
|
DWORD pathlen;
|
|
|
|
verBlock maxVer;
|
|
|
|
ClearVersion(&maxVer);
|
2010-02-13 13:59:39 -08:00
|
|
|
WCHAR curKey[_MAX_PATH] = L"software\\Adobe\\Acrobat Reader";
|
|
|
|
WCHAR path[_MAX_PATH];
|
2007-03-22 10:30:00 -07:00
|
|
|
// Add + 8 to prevent buffer overrun when adding \browser
|
2010-02-13 13:59:39 -08:00
|
|
|
WCHAR newestPath[_MAX_PATH + 8];
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
newestPath[0] = 0;
|
2010-02-13 13:59:39 -08:00
|
|
|
if (ERROR_SUCCESS != ::RegOpenKeyExW(HKEY_LOCAL_MACHINE, curKey, 0,
|
|
|
|
KEY_READ, &baseloc)) {
|
|
|
|
wcscpy(curKey, L"software\\Adobe\\Adobe Acrobat");
|
|
|
|
if (ERROR_SUCCESS != ::RegOpenKeyExW(HKEY_LOCAL_MACHINE, curKey, 0,
|
|
|
|
KEY_READ, &baseloc)) {
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// We must enumerate through the keys because what if there is
|
|
|
|
// more than one version?
|
|
|
|
LONG result = ERROR_SUCCESS;
|
|
|
|
while (ERROR_SUCCESS == result) {
|
|
|
|
path[0] = 0;
|
|
|
|
numChars = _MAX_PATH;
|
2009-03-08 22:07:00 -07:00
|
|
|
pathlen = NS_ARRAY_LENGTH(path);
|
2010-02-19 12:31:28 -08:00
|
|
|
result = ::RegEnumKeyExW(baseloc, index, curKey, &numChars, NULL, NULL,
|
|
|
|
NULL, &modTime);
|
2007-03-22 10:30:00 -07:00
|
|
|
index++;
|
|
|
|
|
|
|
|
if (ERROR_SUCCESS == result) {
|
|
|
|
verBlock curVer;
|
|
|
|
TranslateVersionStr(curKey, &curVer);
|
2010-02-13 13:59:39 -08:00
|
|
|
wcscat(curKey, L"\\InstallPath");
|
|
|
|
if (ERROR_SUCCESS == ::RegOpenKeyExW(baseloc, curKey, 0,
|
|
|
|
KEY_QUERY_VALUE, &keyloc)) {
|
2007-03-22 10:30:00 -07:00
|
|
|
// We have a sub key
|
2010-02-13 13:59:39 -08:00
|
|
|
if (ERROR_SUCCESS == ::RegQueryValueExW(keyloc, NULL, NULL, &type,
|
|
|
|
(LPBYTE)&path, &pathlen)) {
|
2007-03-22 10:30:00 -07:00
|
|
|
if (CompareVersion(curVer, maxVer) >= 0 &&
|
|
|
|
CompareVersion(curVer, minVer) >= 0) {
|
2010-02-13 13:59:39 -08:00
|
|
|
wcscpy(newestPath, path);
|
2007-03-22 10:30:00 -07:00
|
|
|
CopyVersion(&maxVer, &curVer);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
::RegCloseKey(keyloc);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
::RegCloseKey(baseloc);
|
|
|
|
|
|
|
|
if (newestPath[0] != 0) {
|
2010-02-13 13:59:39 -08:00
|
|
|
wcscat(newestPath, L"\\browser");
|
|
|
|
rv = NS_NewLocalFile(nsDependentString(newestPath), PR_TRUE,
|
|
|
|
getter_AddRefs(localFile));
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (localFile && NS_SUCCEEDED(rv))
|
|
|
|
return CallQueryInterface(localFile, _retval);
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsPluginDirServiceProvider::GetPLIDDirectories(nsISimpleEnumerator **aEnumerator)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aEnumerator);
|
|
|
|
*aEnumerator = nsnull;
|
|
|
|
|
|
|
|
nsCOMArray<nsILocalFile> dirs;
|
|
|
|
|
2007-04-03 08:56:31 -07:00
|
|
|
GetPLIDDirectoriesWithHKEY(HKEY_CURRENT_USER, dirs);
|
|
|
|
GetPLIDDirectoriesWithHKEY(HKEY_LOCAL_MACHINE, dirs);
|
|
|
|
|
|
|
|
return NS_NewArrayEnumerator(aEnumerator, dirs);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsPluginDirServiceProvider::GetPLIDDirectoriesWithHKEY(HKEY aKey, nsCOMArray<nsILocalFile> &aDirs)
|
|
|
|
{
|
2010-02-13 13:59:39 -08:00
|
|
|
WCHAR subkey[_MAX_PATH] = L"Software\\MozillaPlugins";
|
2007-03-22 10:30:00 -07:00
|
|
|
HKEY baseloc;
|
|
|
|
|
2010-02-13 13:59:39 -08:00
|
|
|
if (ERROR_SUCCESS != ::RegOpenKeyExW(aKey, subkey, 0, KEY_READ, &baseloc))
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
DWORD index = 0;
|
2007-04-03 08:56:31 -07:00
|
|
|
DWORD subkeylen = _MAX_PATH;
|
|
|
|
FILETIME modTime;
|
2010-02-19 12:31:28 -08:00
|
|
|
while (ERROR_SUCCESS == ::RegEnumKeyExW(baseloc, index++, subkey, &subkeylen,
|
|
|
|
NULL, NULL, NULL, &modTime)) {
|
2007-04-03 08:56:31 -07:00
|
|
|
subkeylen = _MAX_PATH;
|
|
|
|
HKEY keyloc;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-02-13 13:59:39 -08:00
|
|
|
if (ERROR_SUCCESS == ::RegOpenKeyExW(baseloc, subkey, 0, KEY_QUERY_VALUE,
|
|
|
|
&keyloc)) {
|
2007-04-03 08:56:31 -07:00
|
|
|
DWORD type;
|
2010-02-13 13:59:39 -08:00
|
|
|
WCHAR path[_MAX_PATH];
|
2009-03-08 22:07:00 -07:00
|
|
|
DWORD pathlen = NS_ARRAY_LENGTH(path);
|
2007-04-03 08:56:31 -07:00
|
|
|
|
2010-02-13 13:59:39 -08:00
|
|
|
if (ERROR_SUCCESS == ::RegQueryValueExW(keyloc, L"Path", NULL, &type,
|
|
|
|
(LPBYTE)&path, &pathlen)) {
|
2007-03-22 10:30:00 -07:00
|
|
|
nsCOMPtr<nsILocalFile> localFile;
|
2010-02-13 13:59:39 -08:00
|
|
|
if (NS_SUCCEEDED(NS_NewLocalFile(nsDependentString(path), PR_TRUE,
|
|
|
|
getter_AddRefs(localFile))) &&
|
2009-03-08 22:07:00 -07:00
|
|
|
localFile)
|
|
|
|
{
|
2007-03-22 10:30:00 -07:00
|
|
|
// Some vendors use a path directly to the DLL so chop off
|
|
|
|
// the filename
|
|
|
|
PRBool isDir = PR_FALSE;
|
|
|
|
if (NS_SUCCEEDED(localFile->IsDirectory(&isDir)) && !isDir) {
|
|
|
|
nsCOMPtr<nsIFile> temp;
|
|
|
|
localFile->GetParent(getter_AddRefs(temp));
|
|
|
|
if (temp)
|
|
|
|
localFile = do_QueryInterface(temp);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Now we check to make sure it's actually on disk and
|
|
|
|
// To see if we already have this directory in the array
|
|
|
|
PRBool isFileThere = PR_FALSE;
|
|
|
|
PRBool isDupEntry = PR_FALSE;
|
|
|
|
if (NS_SUCCEEDED(localFile->Exists(&isFileThere)) && isFileThere) {
|
2007-04-03 08:56:31 -07:00
|
|
|
PRInt32 c = aDirs.Count();
|
2007-03-22 10:30:00 -07:00
|
|
|
for (PRInt32 i = 0; i < c; i++) {
|
2007-07-08 00:08:04 -07:00
|
|
|
nsIFile *dup = static_cast<nsIFile*>(aDirs[i]);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (dup &&
|
|
|
|
NS_SUCCEEDED(dup->Equals(localFile, &isDupEntry)) &&
|
|
|
|
isDupEntry) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!isDupEntry) {
|
2007-04-03 08:56:31 -07:00
|
|
|
aDirs.AppendObject(localFile);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
::RegCloseKey(keyloc);
|
|
|
|
}
|
2007-04-03 08:56:31 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
::RegCloseKey(baseloc);
|
2007-04-03 08:56:31 -07:00
|
|
|
return NS_OK;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|