Bug 634819 - Use the nsIWindowsRegKey APIs instead of direct Win32 API calls; r=josh,jimm a=shaver

This commit is contained in:
Ehsan Akhgari 2011-02-17 16:18:53 -05:00
Родитель ff0a762dc3
Коммит b6e363a27f
3 изменённых файлов: 228 добавлений и 244 удалений

Просмотреть файл

@ -48,6 +48,9 @@
#include "prmem.h" #include "prmem.h"
#include "nsArrayEnumerator.h" #include "nsArrayEnumerator.h"
#include <windows.h>
#include "nsIWindowsRegKey.h"
typedef struct structVer typedef struct structVer
{ {
WORD wMajor; WORD wMajor;
@ -237,6 +240,10 @@ nsPluginDirServiceProvider::GetFile(const char *charProp, PRBool *persistant,
if (!prefs) if (!prefs)
return NS_ERROR_FAILURE; return NS_ERROR_FAILURE;
nsCOMPtr<nsIWindowsRegKey> regKey =
do_CreateInstance("@mozilla.org/windows-registry-key;1");
NS_ENSURE_TRUE(regKey, NS_ERROR_FAILURE);
if (nsCRT::strcmp(charProp, NS_WIN_4DOTX_SCAN_KEY) == 0) { if (nsCRT::strcmp(charProp, NS_WIN_4DOTX_SCAN_KEY) == 0) {
// Check our prefs to see if scanning the 4.x folder has been // 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 // explictly overriden failure to get the pref is okay, we'll do
@ -249,38 +256,29 @@ nsPluginDirServiceProvider::GetFile(const char *charProp, PRBool *persistant,
// Look for the plugin folder that the user has in their // Look for the plugin folder that the user has in their
// Communicator 4x install // Communicator 4x install
HKEY keyloc; rv = regKey->Open(nsIWindowsRegKey::ROOT_KEY_LOCAL_MACHINE,
long result; NS_LITERAL_STRING("Software\\Netscape\\Netscape Navigator"),
DWORD type; nsIWindowsRegKey::ACCESS_READ);
WCHAR szKey[_MAX_PATH] = L"Software\\Netscape\\Netscape Navigator"; if (NS_SUCCEEDED(rv)) {
WCHAR path[_MAX_PATH]; nsAutoString currentVersion;
rv = regKey->ReadStringValue(NS_LITERAL_STRING("CurrentVersion"),
currentVersion);
if (NS_SUCCEEDED(rv)) {
nsAutoString childName = currentVersion;
childName.Append(NS_LITERAL_STRING("\\Main"));
nsCOMPtr<nsIWindowsRegKey> childKey;
result = ::RegOpenKeyExW(HKEY_LOCAL_MACHINE, szKey, 0, KEY_READ, &keyloc); rv = regKey->OpenChild(childName, nsIWindowsRegKey::ACCESS_READ,
getter_AddRefs(childKey));
if (result == ERROR_SUCCESS) { if (NS_SUCCEEDED(rv) && childKey) {
WCHAR current_version[80]; nsAutoString pluginsDirectory;
DWORD length = NS_ARRAY_LENGTH(current_version); rv = childKey->ReadStringValue(NS_LITERAL_STRING("Plugins Directory"),
pluginsDirectory);
result = ::RegQueryValueExW(keyloc, L"CurrentVersion", NULL, &type, if (NS_SUCCEEDED(rv)) {
(LPBYTE)&current_version, &length); rv = NS_NewLocalFile(pluginsDirectory, PR_TRUE,
getter_AddRefs(localFile));
::RegCloseKey(keyloc); }
wcscat(szKey, L"\\");
wcscat(szKey, current_version);
wcscat(szKey, L"\\Main");
result = ::RegOpenKeyExW(HKEY_LOCAL_MACHINE, szKey, 0, KEY_READ, &keyloc);
if (result == ERROR_SUCCESS) {
DWORD pathlen = NS_ARRAY_LENGTH(path);
result = ::RegQueryValueExW(keyloc, L"Plugins Directory", NULL, &type,
(LPBYTE)&path, &pathlen);
if (result == ERROR_SUCCESS) {
rv = NS_NewLocalFile(nsDependentString(path),
PR_TRUE, getter_AddRefs(localFile));
} }
::RegCloseKey(keyloc);
} }
} }
} else if (nsCRT::strcmp(charProp, NS_WIN_JRE_SCAN_KEY) == 0) { } else if (nsCRT::strcmp(charProp, NS_WIN_JRE_SCAN_KEY) == 0) {
@ -290,110 +288,89 @@ nsPluginDirServiceProvider::GetFile(const char *charProp, PRBool *persistant,
verBlock minVer; verBlock minVer;
TranslateVersionStr(NS_ConvertASCIItoUTF16(strVer).get(), &minVer); TranslateVersionStr(NS_ConvertASCIItoUTF16(strVer).get(), &minVer);
// Look for the Java OJI plugin via the JRE install path rv = regKey->Open(nsIWindowsRegKey::ROOT_KEY_LOCAL_MACHINE,
HKEY baseloc; NS_LITERAL_STRING("Software\\JavaSoft\\Java Runtime Environment"),
HKEY keyloc; nsIWindowsRegKey::ACCESS_READ);
HKEY entryloc; NS_ENSURE_SUCCESS(rv, rv);
FILETIME modTime;
DWORD type;
DWORD index = 0;
DWORD numChars = _MAX_PATH;
DWORD pathlen;
verBlock maxVer; verBlock maxVer;
ClearVersion(&maxVer); ClearVersion(&maxVer);
WCHAR curKey[_MAX_PATH] = L"Software\\JavaSoft\\Java Runtime Environment";
WCHAR path[_MAX_PATH];
// Add + 15 to prevent buffer overrun when adding \bin (+ optionally
// \new_plugin)
#define JAVA_PATH_SIZE _MAX_PATH + 15
WCHAR newestPath[JAVA_PATH_SIZE];
WCHAR browserJavaVersion[_MAX_PATH];
newestPath[0] = 0; nsAutoString newestPath;
LONG result = ::RegOpenKeyExW(HKEY_LOCAL_MACHINE, curKey, 0, KEY_READ, nsAutoString browserJavaVersion;
&baseloc); regKey->ReadStringValue(NS_LITERAL_STRING("BrowserJavaVersion"),
if (ERROR_SUCCESS != result) browserJavaVersion);
return NS_ERROR_FAILURE;
// Look for "BrowserJavaVersion" PRUint32 childCount = 0;
if (ERROR_SUCCESS != ::RegQueryValueExW(baseloc, L"BrowserJavaVersion", NULL, regKey->GetChildCount(&childCount);
NULL, (LPBYTE)&browserJavaVersion,
&numChars))
browserJavaVersion[0] = 0;
// We must enumerate through the keys because what if there is // We must enumerate through the keys because what if there is
// more than one version? // more than one version?
do { for (PRUint32 index = 0; index < childCount; ++index) {
path[0] = 0; nsAutoString childName;
numChars = _MAX_PATH; rv = regKey->GetChildName(index, childName);
pathlen = NS_ARRAY_LENGTH(path); if (NS_SUCCEEDED(rv)) {
result = ::RegEnumKeyExW(baseloc, index, curKey, &numChars, NULL, NULL, // Skip major.minor as it always points to latest in its family
NULL, &modTime); PRUint32 numChars = 0;
index++; PRInt32 offset = 0;
while ((offset = childName.FindChar(L'.', offset + 1)) >= 0) {
// Skip major.minor as it always points to latest in its family ++numChars;
numChars = 0;
for (WCHAR *p = curKey; *p; p++) {
if (*p == '.') {
numChars++;
} }
} if (numChars < 2)
if (numChars < 2) continue;
continue;
if (ERROR_SUCCESS == result) { nsCOMPtr<nsIWindowsRegKey> childKey;
if (ERROR_SUCCESS == ::RegOpenKeyExW(baseloc, curKey, 0, rv = regKey->OpenChild(childName, nsIWindowsRegKey::ACCESS_QUERY_VALUE,
KEY_QUERY_VALUE, &keyloc)) { getter_AddRefs(childKey));
// We have a sub key if (NS_SUCCEEDED(rv) && childKey) {
if (ERROR_SUCCESS == ::RegQueryValueExW(keyloc, L"JavaHome", NULL, nsAutoString path;
&type, (LPBYTE)&path, rv = childKey->ReadStringValue(NS_LITERAL_STRING("JavaHome"), path);
&pathlen)) { if (NS_SUCCEEDED(rv)) {
verBlock curVer; verBlock curVer;
TranslateVersionStr(curKey, &curVer); TranslateVersionStr(PromiseFlatString(childName).get(), &curVer);
if (CompareVersion(curVer, minVer) >= 0) { if (CompareVersion(curVer, minVer) >= 0) {
if (!wcsncmp(browserJavaVersion, curKey, _MAX_PATH)) { if (browserJavaVersion == childName) {
wcscpy(newestPath, path); newestPath = path;
::RegCloseKey(keyloc);
break; break;
} }
if (CompareVersion(curVer, maxVer) >= 0) { if (CompareVersion(curVer, maxVer) >= 0) {
wcscpy(newestPath, path); newestPath = path;
CopyVersion(&maxVer, &curVer); CopyVersion(&maxVer, &curVer);
} }
} }
} }
::RegCloseKey(keyloc);
} }
} }
} while (ERROR_SUCCESS == result); }
::RegCloseKey(baseloc); if (newestPath.IsEmpty()) {
if (newestPath[0] == 0) {
return NS_ERROR_FAILURE; return NS_ERROR_FAILURE;
} }
// We require the newer NPAPI Java plugin. // We require the newer NPAPI Java plugin.
wcscat(newestPath, L"\\bin\\new_plugin"); newestPath += NS_LITERAL_STRING("\\bin\\new_plugin");
rv = NS_NewLocalFile(nsDependentString(newestPath), rv = NS_NewLocalFile(newestPath,
PR_TRUE, getter_AddRefs(localFile)); PR_TRUE, getter_AddRefs(localFile));
if (NS_SUCCEEDED(rv)) { if (NS_SUCCEEDED(rv)) {
const WCHAR mozPath[_MAX_PATH] = L"Software\\mozilla.org\\Mozilla"; nsCOMPtr<nsIWindowsRegKey> newKey =
if (ERROR_SUCCESS == ::RegCreateKeyExW(HKEY_LOCAL_MACHINE, mozPath, 0, do_CreateInstance("@mozilla.org/windows-registry-key;1");
NULL, REG_OPTION_NON_VOLATILE, NS_ENSURE_TRUE(newKey, NS_ERROR_FAILURE);
KEY_SET_VALUE|KEY_QUERY_VALUE,
NULL, &entryloc, NULL)) { rv = newKey->Create(nsIWindowsRegKey::ROOT_KEY_LOCAL_MACHINE,
if (ERROR_SUCCESS != ::RegQueryValueExW(entryloc, L"CurrentVersion", 0, NS_LITERAL_STRING("Software\\mozilla.org\\Mozilla"),
NULL, NULL, NULL)) { nsIWindowsRegKey::ACCESS_QUERY_VALUE |
static const WCHAR kMozillaVersion[] = NS_L(MOZILLA_VERSION); nsIWindowsRegKey::ACCESS_SET_VALUE);
::RegSetValueExW(entryloc, L"CurrentVersion", 0, REG_SZ, if (NS_SUCCEEDED(rv)) {
(const BYTE*) kMozillaVersion, PRBool currentVersionExists = PR_FALSE;
NS_ARRAY_LENGTH(kMozillaVersion)); newKey->HasValue(NS_LITERAL_STRING("CurrentVersion"),
&currentVersionExists);
if (!currentVersionExists) {
newKey->WriteStringValue(NS_LITERAL_STRING("CurrentVersion"),
NS_LITERAL_STRING(MOZILLA_VERSION));
} }
::RegCloseKey(entryloc);
} }
} }
} else if (nsCRT::strcmp(charProp, NS_WIN_QUICKTIME_SCAN_KEY) == 0) { } else if (nsCRT::strcmp(charProp, NS_WIN_QUICKTIME_SCAN_KEY) == 0) {
@ -404,40 +381,36 @@ nsPluginDirServiceProvider::GetFile(const char *charProp, PRBool *persistant,
TranslateVersionStr(NS_ConvertASCIItoUTF16(strVer).get(), &minVer); TranslateVersionStr(NS_ConvertASCIItoUTF16(strVer).get(), &minVer);
// Look for the Quicktime system installation plugins directory // Look for the Quicktime system installation plugins directory
HKEY keyloc;
long result;
DWORD type;
verBlock qtVer; verBlock qtVer;
ClearVersion(&qtVer); ClearVersion(&qtVer);
WCHAR path[_MAX_PATH];
DWORD pathlen = NS_ARRAY_LENGTH(path);
// First we need to check the version of Quicktime via checking // First we need to check the version of Quicktime via checking
// the EXE's version table // the EXE's version table
if (ERROR_SUCCESS == ::RegOpenKeyExW(HKEY_LOCAL_MACHINE, rv = regKey->Open(nsIWindowsRegKey::ROOT_KEY_LOCAL_MACHINE,
L"software\\Microsoft\\Windows\\CurrentVersion\\App Paths\\QuickTimePlayer.exe", NS_LITERAL_STRING("software\\Microsoft\\Windows\\CurrentVersion\\App Paths\\QuickTimePlayer.exe"),
0, KEY_READ, &keyloc)) { nsIWindowsRegKey::ACCESS_READ);
if (ERROR_SUCCESS == ::RegQueryValueExW(keyloc, NULL, NULL, &type, if (NS_SUCCEEDED(rv)) {
(LPBYTE)&path, &pathlen)) { nsAutoString path;
GetFileVersion(path, &qtVer); rv = regKey->ReadStringValue(NS_LITERAL_STRING(""), path);
if (NS_SUCCEEDED(rv)) {
GetFileVersion(PromiseFlatString(path).get(), &qtVer);
} }
::RegCloseKey(keyloc); regKey->Close();
} }
if (CompareVersion(qtVer, minVer) < 0) if (CompareVersion(qtVer, minVer) < 0)
return rv; return rv;
if (ERROR_SUCCESS == ::RegOpenKeyExW(HKEY_LOCAL_MACHINE, rv = regKey->Open(nsIWindowsRegKey::ROOT_KEY_LOCAL_MACHINE,
L"software\\Apple Computer, Inc.\\QuickTime", NS_LITERAL_STRING("software\\Apple Computer, Inc.\\QuickTime"),
0, KEY_READ, &keyloc)) { nsIWindowsRegKey::ACCESS_READ);
DWORD pathlen = NS_ARRAY_LENGTH(path); if (NS_SUCCEEDED(rv)) {
nsAutoString path;
result = ::RegQueryValueExW(keyloc, L"InstallDir", NULL, &type, rv = regKey->ReadStringValue(NS_LITERAL_STRING("InstallDir"), path);
(LPBYTE)&path, &pathlen); if (NS_SUCCEEDED(rv)) {
wcscat(path, L"\\Plugins"); path += NS_LITERAL_STRING("\\Plugins");
if (result == ERROR_SUCCESS) rv = NS_NewLocalFile(path, PR_TRUE,
rv = NS_NewLocalFile(nsDependentString(path), PR_TRUE,
getter_AddRefs(localFile)); getter_AddRefs(localFile));
::RegCloseKey(keyloc); }
} }
} else if (nsCRT::strcmp(charProp, NS_WIN_WMP_SCAN_KEY) == 0) { } else if (nsCRT::strcmp(charProp, NS_WIN_WMP_SCAN_KEY) == 0) {
nsXPIDLCString strVer; nsXPIDLCString strVer;
@ -447,37 +420,35 @@ nsPluginDirServiceProvider::GetFile(const char *charProp, PRBool *persistant,
TranslateVersionStr(NS_ConvertASCIItoUTF16(strVer).get(), &minVer); TranslateVersionStr(NS_ConvertASCIItoUTF16(strVer).get(), &minVer);
// Look for Windows Media Player system installation plugins directory // Look for Windows Media Player system installation plugins directory
HKEY keyloc;
DWORD type;
verBlock wmpVer; verBlock wmpVer;
ClearVersion(&wmpVer); ClearVersion(&wmpVer);
WCHAR path[_MAX_PATH];
DWORD pathlen = NS_ARRAY_LENGTH(path);
// First we need to check the version of WMP // First we need to check the version of WMP
if (ERROR_SUCCESS == ::RegOpenKeyExW(HKEY_LOCAL_MACHINE, rv = regKey->Open(nsIWindowsRegKey::ROOT_KEY_LOCAL_MACHINE,
L"software\\Microsoft\\Windows\\CurrentVersion\\App Paths\\wmplayer.exe", NS_LITERAL_STRING("software\\Microsoft\\Windows\\CurrentVersion\\App Paths\\wmplayer.exe"),
0, KEY_READ, &keyloc)) { nsIWindowsRegKey::ACCESS_READ);
if (ERROR_SUCCESS == ::RegQueryValueExW(keyloc, NULL, NULL, &type, if (NS_SUCCEEDED(rv)) {
(LPBYTE)&path, &pathlen)) { nsAutoString path;
GetFileVersion(path, &wmpVer); rv = regKey->ReadStringValue(NS_LITERAL_STRING(""), path);
if (NS_SUCCEEDED(rv)) {
GetFileVersion(PromiseFlatString(path).get(), &wmpVer);
} }
::RegCloseKey(keyloc); regKey->Close();
} }
if (CompareVersion(wmpVer, minVer) < 0) if (CompareVersion(wmpVer, minVer) < 0)
return rv; return rv;
if (ERROR_SUCCESS == ::RegOpenKeyExW(HKEY_LOCAL_MACHINE, rv = regKey->Open(nsIWindowsRegKey::ROOT_KEY_LOCAL_MACHINE,
L"software\\Microsoft\\MediaPlayer", 0, NS_LITERAL_STRING("software\\Microsoft\\MediaPlayer"),
KEY_READ, &keyloc)) { nsIWindowsRegKey::ACCESS_READ);
if (ERROR_SUCCESS == ::RegQueryValueExW(keyloc, L"Installation Directory", if (NS_SUCCEEDED(rv)) {
NULL, &type, (LPBYTE)&path, nsAutoString path;
&pathlen)) { rv = regKey->ReadStringValue(NS_LITERAL_STRING("Installation Directory"),
rv = NS_NewLocalFile(nsDependentString(path), PR_TRUE, path);
if (NS_SUCCEEDED(rv)) {
rv = NS_NewLocalFile(path, PR_TRUE,
getter_AddRefs(localFile)); getter_AddRefs(localFile));
} }
::RegCloseKey(keyloc);
} }
} else if (nsCRT::strcmp(charProp, NS_WIN_ACROBAT_SCAN_KEY) == 0) { } else if (nsCRT::strcmp(charProp, NS_WIN_ACROBAT_SCAN_KEY) == 0) {
nsXPIDLCString strVer; nsXPIDLCString strVer;
@ -489,70 +460,60 @@ nsPluginDirServiceProvider::GetFile(const char *charProp, PRBool *persistant,
TranslateVersionStr(NS_ConvertASCIItoUTF16(strVer).get(), &minVer); TranslateVersionStr(NS_ConvertASCIItoUTF16(strVer).get(), &minVer);
// Look for Adobe Acrobat system installation plugins directory // 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; verBlock maxVer;
ClearVersion(&maxVer); ClearVersion(&maxVer);
WCHAR curKey[_MAX_PATH] = L"software\\Adobe\\Acrobat Reader";
WCHAR path[_MAX_PATH];
// Add + 8 to prevent buffer overrun when adding \browser
WCHAR newestPath[_MAX_PATH + 8];
newestPath[0] = 0; nsAutoString newestPath;
if (ERROR_SUCCESS != ::RegOpenKeyExW(HKEY_LOCAL_MACHINE, curKey, 0,
KEY_READ, &baseloc)) { rv = regKey->Open(nsIWindowsRegKey::ROOT_KEY_LOCAL_MACHINE,
wcscpy(curKey, L"software\\Adobe\\Adobe Acrobat"); NS_LITERAL_STRING("software\\Adobe\\Acrobat Reader"),
if (ERROR_SUCCESS != ::RegOpenKeyExW(HKEY_LOCAL_MACHINE, curKey, 0, nsIWindowsRegKey::ACCESS_READ);
KEY_READ, &baseloc)) { if (NS_FAILED(rv)) {
rv = regKey->Open(nsIWindowsRegKey::ROOT_KEY_LOCAL_MACHINE,
NS_LITERAL_STRING("software\\Adobe\\Adobe Reader"),
nsIWindowsRegKey::ACCESS_READ);
if (NS_FAILED(rv)) {
return NS_ERROR_FAILURE; return NS_ERROR_FAILURE;
} }
} }
// We must enumerate through the keys because what if there is // We must enumerate through the keys because what if there is
// more than one version? // more than one version?
LONG result = ERROR_SUCCESS; PRUint32 childCount = 0;
while (ERROR_SUCCESS == result) { regKey->GetChildCount(&childCount);
path[0] = 0;
numChars = _MAX_PATH;
pathlen = NS_ARRAY_LENGTH(path);
result = ::RegEnumKeyExW(baseloc, index, curKey, &numChars, NULL, NULL,
NULL, &modTime);
index++;
if (ERROR_SUCCESS == result) { for (PRUint32 index = 0; index < childCount; ++index) {
nsAutoString childName;
rv = regKey->GetChildName(index, childName);
if (NS_SUCCEEDED(rv)) {
verBlock curVer; verBlock curVer;
TranslateVersionStr(curKey, &curVer); TranslateVersionStr(PromiseFlatString(childName).get(), &curVer);
wcscat(curKey, L"\\InstallPath");
if (ERROR_SUCCESS == ::RegOpenKeyExW(baseloc, curKey, 0, childName += NS_LITERAL_STRING("\\InstallPath");
KEY_QUERY_VALUE, &keyloc)) {
nsCOMPtr<nsIWindowsRegKey> childKey;
rv = regKey->OpenChild(childName, nsIWindowsRegKey::ACCESS_QUERY_VALUE,
getter_AddRefs(childKey));
if (NS_SUCCEEDED(rv)) {
// We have a sub key // We have a sub key
if (ERROR_SUCCESS == ::RegQueryValueExW(keyloc, NULL, NULL, &type, nsAutoString path;
(LPBYTE)&path, &pathlen)) { rv = childKey->ReadStringValue(NS_LITERAL_STRING(""), path);
if (NS_SUCCEEDED(rv)) {
if (CompareVersion(curVer, maxVer) >= 0 && if (CompareVersion(curVer, maxVer) >= 0 &&
CompareVersion(curVer, minVer) >= 0) { CompareVersion(curVer, minVer) >= 0) {
wcscpy(newestPath, path); newestPath = path;
CopyVersion(&maxVer, &curVer); CopyVersion(&maxVer, &curVer);
} }
} }
::RegCloseKey(keyloc);
} }
} }
} }
::RegCloseKey(baseloc); if (!newestPath.IsEmpty()) {
newestPath += NS_LITERAL_STRING("\\browser");
if (newestPath[0] != 0) { rv = NS_NewLocalFile(newestPath, PR_TRUE,
wcscat(newestPath, L"\\browser");
rv = NS_NewLocalFile(nsDependentString(newestPath), PR_TRUE,
getter_AddRefs(localFile)); getter_AddRefs(localFile));
} }
} }
if (localFile && NS_SUCCEEDED(rv)) if (localFile && NS_SUCCEEDED(rv))
@ -569,77 +530,76 @@ nsPluginDirServiceProvider::GetPLIDDirectories(nsISimpleEnumerator **aEnumerator
nsCOMArray<nsILocalFile> dirs; nsCOMArray<nsILocalFile> dirs;
GetPLIDDirectoriesWithHKEY(HKEY_CURRENT_USER, dirs); GetPLIDDirectoriesWithRootKey(nsIWindowsRegKey::ROOT_KEY_CURRENT_USER, dirs);
GetPLIDDirectoriesWithHKEY(HKEY_LOCAL_MACHINE, dirs); GetPLIDDirectoriesWithRootKey(nsIWindowsRegKey::ROOT_KEY_LOCAL_MACHINE, dirs);
return NS_NewArrayEnumerator(aEnumerator, dirs); return NS_NewArrayEnumerator(aEnumerator, dirs);
} }
nsresult nsresult
nsPluginDirServiceProvider::GetPLIDDirectoriesWithHKEY(HKEY aKey, nsCOMArray<nsILocalFile> &aDirs) nsPluginDirServiceProvider::GetPLIDDirectoriesWithRootKey(PRUint32 aKey, nsCOMArray<nsILocalFile> &aDirs)
{ {
WCHAR subkey[_MAX_PATH] = L"Software\\MozillaPlugins"; nsCOMPtr<nsIWindowsRegKey> regKey =
HKEY baseloc; do_CreateInstance("@mozilla.org/windows-registry-key;1");
NS_ENSURE_TRUE(regKey, NS_ERROR_FAILURE);
if (ERROR_SUCCESS != ::RegOpenKeyExW(aKey, subkey, 0, KEY_READ, &baseloc)) nsresult rv = regKey->Open(aKey,
return NS_ERROR_FAILURE; NS_LITERAL_STRING("Software\\MozillaPlugins"),
nsIWindowsRegKey::ACCESS_READ);
NS_ENSURE_SUCCESS(rv, rv);
DWORD index = 0; PRUint32 childCount = 0;
DWORD subkeylen = _MAX_PATH; regKey->GetChildCount(&childCount);
FILETIME modTime;
while (ERROR_SUCCESS == ::RegEnumKeyExW(baseloc, index++, subkey, &subkeylen,
NULL, NULL, NULL, &modTime)) {
subkeylen = _MAX_PATH;
HKEY keyloc;
if (ERROR_SUCCESS == ::RegOpenKeyExW(baseloc, subkey, 0, KEY_QUERY_VALUE, for (PRUint32 index = 0; index < childCount; ++index) {
&keyloc)) { nsAutoString childName;
DWORD type; rv = regKey->GetChildName(index, childName);
WCHAR path[_MAX_PATH]; if (NS_SUCCEEDED(rv)) {
DWORD pathlen = NS_ARRAY_LENGTH(path); nsCOMPtr<nsIWindowsRegKey> childKey;
rv = regKey->OpenChild(childName, nsIWindowsRegKey::ACCESS_QUERY_VALUE,
if (ERROR_SUCCESS == ::RegQueryValueExW(keyloc, L"Path", NULL, &type, getter_AddRefs(childKey));
(LPBYTE)&path, &pathlen)) { if (NS_SUCCEEDED(rv) && childKey) {
nsCOMPtr<nsILocalFile> localFile; nsAutoString path;
if (NS_SUCCEEDED(NS_NewLocalFile(nsDependentString(path), PR_TRUE, rv = childKey->ReadStringValue(NS_LITERAL_STRING("Path"), path);
getter_AddRefs(localFile))) && if (NS_SUCCEEDED(rv)) {
localFile) nsCOMPtr<nsILocalFile> localFile;
{ if (NS_SUCCEEDED(NS_NewLocalFile(path, PR_TRUE,
// Some vendors use a path directly to the DLL so chop off getter_AddRefs(localFile))) &&
// the filename localFile) {
PRBool isDir = PR_FALSE; // Some vendors use a path directly to the DLL so chop off
if (NS_SUCCEEDED(localFile->IsDirectory(&isDir)) && !isDir) { // the filename
nsCOMPtr<nsIFile> temp; PRBool isDir = PR_FALSE;
localFile->GetParent(getter_AddRefs(temp)); if (NS_SUCCEEDED(localFile->IsDirectory(&isDir)) && !isDir) {
if (temp) nsCOMPtr<nsIFile> temp;
localFile = do_QueryInterface(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) {
PRInt32 c = aDirs.Count();
for (PRInt32 i = 0; i < c; i++) {
nsIFile *dup = static_cast<nsIFile*>(aDirs[i]);
if (dup &&
NS_SUCCEEDED(dup->Equals(localFile, &isDupEntry)) &&
isDupEntry) {
break;
}
} }
if (!isDupEntry) { // Now we check to make sure it's actually on disk and
aDirs.AppendObject(localFile); // 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) {
PRInt32 c = aDirs.Count();
for (PRInt32 i = 0; i < c; i++) {
nsIFile *dup = static_cast<nsIFile*>(aDirs[i]);
if (dup &&
NS_SUCCEEDED(dup->Equals(localFile, &isDupEntry)) &&
isDupEntry) {
break;
}
}
if (!isDupEntry) {
aDirs.AppendObject(localFile);
}
} }
} }
} }
} }
::RegCloseKey(keyloc);
} }
} }
::RegCloseKey(baseloc);
return NS_OK; return NS_OK;
} }

Просмотреть файл

@ -43,7 +43,6 @@
#if defined (XP_WIN) #if defined (XP_WIN)
#include "nsCOMArray.h" #include "nsCOMArray.h"
#include <windows.h>
#endif #endif
class nsISimpleEnumerator; class nsISimpleEnumerator;
@ -71,7 +70,7 @@ public:
#ifdef XP_WIN #ifdef XP_WIN
static nsresult GetPLIDDirectories(nsISimpleEnumerator **aEnumerator); static nsresult GetPLIDDirectories(nsISimpleEnumerator **aEnumerator);
private: private:
static nsresult GetPLIDDirectoriesWithHKEY(HKEY aKey, static nsresult GetPLIDDirectoriesWithRootKey(PRUint32 aKey,
nsCOMArray<nsILocalFile> &aDirs); nsCOMArray<nsILocalFile> &aDirs);
#endif #endif

Просмотреть файл

@ -328,9 +328,34 @@ nsWindowsRegKey::ReadStringValue(const nsAString &name, nsAString &result)
if (begin.size_forward() != resultLen) if (begin.size_forward() != resultLen)
return NS_ERROR_OUT_OF_MEMORY; return NS_ERROR_OUT_OF_MEMORY;
rv = RegQueryValueExW(mKey, flatName.get(), 0, NULL, (LPBYTE) begin.get(), rv = RegQueryValueExW(mKey, flatName.get(), 0, &type, (LPBYTE) begin.get(),
&size); &size);
// Expand the environment variables if needed
if (type == REG_EXPAND_SZ) {
const nsString &flatSource = PromiseFlatString(result);
resultLen = ExpandEnvironmentStringsW(flatSource.get(), NULL, 0);
if (resultLen > 0) {
nsAutoString expandedResult;
expandedResult.SetLength(resultLen);
nsAString::iterator begin;
expandedResult.BeginWriting(begin);
if (begin.size_forward() != resultLen)
return NS_ERROR_OUT_OF_MEMORY;
resultLen = ExpandEnvironmentStringsW(flatSource.get(),
begin.get(),
resultLen);
if (resultLen <= 0) {
rv = ERROR_UNKNOWN_FEATURE;
result.Truncate();
} else if (resultLen > 0) {
rv = ERROR_SUCCESS;
result = expandedResult;
}
}
}
return (rv == ERROR_SUCCESS) ? NS_OK : NS_ERROR_FAILURE; return (rv == ERROR_SUCCESS) ? NS_OK : NS_ERROR_FAILURE;
} }