Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
michael@0 | 2 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 5 | |
michael@0 | 6 | #include "nsPluginDirServiceProvider.h" |
michael@0 | 7 | |
michael@0 | 8 | #include "nsCRT.h" |
michael@0 | 9 | #include "nsIFile.h" |
michael@0 | 10 | #include "nsDependentString.h" |
michael@0 | 11 | #include "nsArrayEnumerator.h" |
michael@0 | 12 | #include "mozilla/Preferences.h" |
michael@0 | 13 | |
michael@0 | 14 | #include <windows.h> |
michael@0 | 15 | #include "nsIWindowsRegKey.h" |
michael@0 | 16 | |
michael@0 | 17 | using namespace mozilla; |
michael@0 | 18 | |
michael@0 | 19 | typedef struct structVer |
michael@0 | 20 | { |
michael@0 | 21 | WORD wMajor; |
michael@0 | 22 | WORD wMinor; |
michael@0 | 23 | WORD wRelease; |
michael@0 | 24 | WORD wBuild; |
michael@0 | 25 | } verBlock; |
michael@0 | 26 | |
michael@0 | 27 | static void |
michael@0 | 28 | ClearVersion(verBlock *ver) |
michael@0 | 29 | { |
michael@0 | 30 | ver->wMajor = 0; |
michael@0 | 31 | ver->wMinor = 0; |
michael@0 | 32 | ver->wRelease = 0; |
michael@0 | 33 | ver->wBuild = 0; |
michael@0 | 34 | } |
michael@0 | 35 | |
michael@0 | 36 | static BOOL |
michael@0 | 37 | FileExists(LPCWSTR szFile) |
michael@0 | 38 | { |
michael@0 | 39 | return GetFileAttributesW(szFile) != 0xFFFFFFFF; |
michael@0 | 40 | } |
michael@0 | 41 | |
michael@0 | 42 | // Get file version information from a file |
michael@0 | 43 | static BOOL |
michael@0 | 44 | GetFileVersion(LPCWSTR szFile, verBlock *vbVersion) |
michael@0 | 45 | { |
michael@0 | 46 | UINT uLen; |
michael@0 | 47 | UINT dwLen; |
michael@0 | 48 | BOOL bRv; |
michael@0 | 49 | DWORD dwHandle; |
michael@0 | 50 | LPVOID lpData; |
michael@0 | 51 | LPVOID lpBuffer; |
michael@0 | 52 | VS_FIXEDFILEINFO *lpBuffer2; |
michael@0 | 53 | |
michael@0 | 54 | ClearVersion(vbVersion); |
michael@0 | 55 | if (FileExists(szFile)) { |
michael@0 | 56 | bRv = TRUE; |
michael@0 | 57 | LPCWSTR lpFilepath = szFile; |
michael@0 | 58 | dwLen = GetFileVersionInfoSizeW(lpFilepath, &dwHandle); |
michael@0 | 59 | lpData = (LPVOID)malloc(dwLen); |
michael@0 | 60 | uLen = 0; |
michael@0 | 61 | |
michael@0 | 62 | if (lpData && GetFileVersionInfoW(lpFilepath, dwHandle, dwLen, lpData) != 0) { |
michael@0 | 63 | if (VerQueryValueW(lpData, L"\\", &lpBuffer, &uLen) != 0) { |
michael@0 | 64 | lpBuffer2 = (VS_FIXEDFILEINFO *)lpBuffer; |
michael@0 | 65 | |
michael@0 | 66 | vbVersion->wMajor = HIWORD(lpBuffer2->dwFileVersionMS); |
michael@0 | 67 | vbVersion->wMinor = LOWORD(lpBuffer2->dwFileVersionMS); |
michael@0 | 68 | vbVersion->wRelease = HIWORD(lpBuffer2->dwFileVersionLS); |
michael@0 | 69 | vbVersion->wBuild = LOWORD(lpBuffer2->dwFileVersionLS); |
michael@0 | 70 | } |
michael@0 | 71 | } |
michael@0 | 72 | |
michael@0 | 73 | free(lpData); |
michael@0 | 74 | } else { |
michael@0 | 75 | /* File does not exist */ |
michael@0 | 76 | bRv = FALSE; |
michael@0 | 77 | } |
michael@0 | 78 | |
michael@0 | 79 | return bRv; |
michael@0 | 80 | } |
michael@0 | 81 | |
michael@0 | 82 | // Will deep copy ver2 into ver1 |
michael@0 | 83 | static void |
michael@0 | 84 | CopyVersion(verBlock *ver1, verBlock *ver2) |
michael@0 | 85 | { |
michael@0 | 86 | ver1->wMajor = ver2->wMajor; |
michael@0 | 87 | ver1->wMinor = ver2->wMinor; |
michael@0 | 88 | ver1->wRelease = ver2->wRelease; |
michael@0 | 89 | ver1->wBuild = ver2->wBuild; |
michael@0 | 90 | } |
michael@0 | 91 | |
michael@0 | 92 | // Convert a string version to a version struct |
michael@0 | 93 | static void |
michael@0 | 94 | TranslateVersionStr(const WCHAR* szVersion, verBlock *vbVersion) |
michael@0 | 95 | { |
michael@0 | 96 | WCHAR* szNum1 = nullptr; |
michael@0 | 97 | WCHAR* szNum2 = nullptr; |
michael@0 | 98 | WCHAR* szNum3 = nullptr; |
michael@0 | 99 | WCHAR* szNum4 = nullptr; |
michael@0 | 100 | WCHAR* szJavaBuild = nullptr; |
michael@0 | 101 | |
michael@0 | 102 | WCHAR *strVer = nullptr; |
michael@0 | 103 | if (szVersion) { |
michael@0 | 104 | strVer = wcsdup(szVersion); |
michael@0 | 105 | } |
michael@0 | 106 | |
michael@0 | 107 | if (!strVer) { |
michael@0 | 108 | // Out of memory |
michael@0 | 109 | ClearVersion(vbVersion); |
michael@0 | 110 | return; |
michael@0 | 111 | } |
michael@0 | 112 | |
michael@0 | 113 | // Java may be using an underscore instead of a dot for the build ID |
michael@0 | 114 | szJavaBuild = wcschr(strVer, '_'); |
michael@0 | 115 | if (szJavaBuild) { |
michael@0 | 116 | szJavaBuild[0] = '.'; |
michael@0 | 117 | } |
michael@0 | 118 | |
michael@0 | 119 | szNum1 = wcstok(strVer, L"."); |
michael@0 | 120 | szNum2 = wcstok(nullptr, L"."); |
michael@0 | 121 | szNum3 = wcstok(nullptr, L"."); |
michael@0 | 122 | szNum4 = wcstok(nullptr, L"."); |
michael@0 | 123 | |
michael@0 | 124 | vbVersion->wMajor = szNum1 ? (WORD) _wtoi(szNum1) : 0; |
michael@0 | 125 | vbVersion->wMinor = szNum2 ? (WORD) _wtoi(szNum2) : 0; |
michael@0 | 126 | vbVersion->wRelease = szNum3 ? (WORD) _wtoi(szNum3) : 0; |
michael@0 | 127 | vbVersion->wBuild = szNum4 ? (WORD) _wtoi(szNum4) : 0; |
michael@0 | 128 | |
michael@0 | 129 | free(strVer); |
michael@0 | 130 | } |
michael@0 | 131 | |
michael@0 | 132 | // Compare two version struct, return zero if the same |
michael@0 | 133 | static int |
michael@0 | 134 | CompareVersion(verBlock vbVersionOld, verBlock vbVersionNew) |
michael@0 | 135 | { |
michael@0 | 136 | if (vbVersionOld.wMajor > vbVersionNew.wMajor) { |
michael@0 | 137 | return 4; |
michael@0 | 138 | } else if (vbVersionOld.wMajor < vbVersionNew.wMajor) { |
michael@0 | 139 | return -4; |
michael@0 | 140 | } |
michael@0 | 141 | |
michael@0 | 142 | if (vbVersionOld.wMinor > vbVersionNew.wMinor) { |
michael@0 | 143 | return 3; |
michael@0 | 144 | } else if (vbVersionOld.wMinor < vbVersionNew.wMinor) { |
michael@0 | 145 | return -3; |
michael@0 | 146 | } |
michael@0 | 147 | |
michael@0 | 148 | if (vbVersionOld.wRelease > vbVersionNew.wRelease) { |
michael@0 | 149 | return 2; |
michael@0 | 150 | } else if (vbVersionOld.wRelease < vbVersionNew.wRelease) { |
michael@0 | 151 | return -2; |
michael@0 | 152 | } |
michael@0 | 153 | |
michael@0 | 154 | if (vbVersionOld.wBuild > vbVersionNew.wBuild) { |
michael@0 | 155 | return 1; |
michael@0 | 156 | } else if (vbVersionOld.wBuild < vbVersionNew.wBuild) { |
michael@0 | 157 | return -1; |
michael@0 | 158 | } |
michael@0 | 159 | |
michael@0 | 160 | /* the versions are all the same */ |
michael@0 | 161 | return 0; |
michael@0 | 162 | } |
michael@0 | 163 | |
michael@0 | 164 | //***************************************************************************** |
michael@0 | 165 | // nsPluginDirServiceProvider::Constructor/Destructor |
michael@0 | 166 | //***************************************************************************** |
michael@0 | 167 | |
michael@0 | 168 | nsPluginDirServiceProvider::nsPluginDirServiceProvider() |
michael@0 | 169 | { |
michael@0 | 170 | } |
michael@0 | 171 | |
michael@0 | 172 | nsPluginDirServiceProvider::~nsPluginDirServiceProvider() |
michael@0 | 173 | { |
michael@0 | 174 | } |
michael@0 | 175 | |
michael@0 | 176 | //***************************************************************************** |
michael@0 | 177 | // nsPluginDirServiceProvider::nsISupports |
michael@0 | 178 | //***************************************************************************** |
michael@0 | 179 | |
michael@0 | 180 | NS_IMPL_ISUPPORTS(nsPluginDirServiceProvider, |
michael@0 | 181 | nsIDirectoryServiceProvider) |
michael@0 | 182 | |
michael@0 | 183 | //***************************************************************************** |
michael@0 | 184 | // nsPluginDirServiceProvider::nsIDirectoryServiceProvider |
michael@0 | 185 | //***************************************************************************** |
michael@0 | 186 | |
michael@0 | 187 | NS_IMETHODIMP |
michael@0 | 188 | nsPluginDirServiceProvider::GetFile(const char *charProp, bool *persistant, |
michael@0 | 189 | nsIFile **_retval) |
michael@0 | 190 | { |
michael@0 | 191 | nsCOMPtr<nsIFile> localFile; |
michael@0 | 192 | nsresult rv = NS_ERROR_FAILURE; |
michael@0 | 193 | |
michael@0 | 194 | NS_ENSURE_ARG(charProp); |
michael@0 | 195 | |
michael@0 | 196 | *_retval = nullptr; |
michael@0 | 197 | *persistant = false; |
michael@0 | 198 | |
michael@0 | 199 | nsCOMPtr<nsIWindowsRegKey> regKey = |
michael@0 | 200 | do_CreateInstance("@mozilla.org/windows-registry-key;1"); |
michael@0 | 201 | NS_ENSURE_TRUE(regKey, NS_ERROR_FAILURE); |
michael@0 | 202 | |
michael@0 | 203 | if (nsCRT::strcmp(charProp, NS_WIN_QUICKTIME_SCAN_KEY) == 0) { |
michael@0 | 204 | nsAdoptingCString strVer = Preferences::GetCString(charProp); |
michael@0 | 205 | if (!strVer) { |
michael@0 | 206 | return NS_ERROR_FAILURE; |
michael@0 | 207 | } |
michael@0 | 208 | verBlock minVer; |
michael@0 | 209 | TranslateVersionStr(NS_ConvertASCIItoUTF16(strVer).get(), &minVer); |
michael@0 | 210 | |
michael@0 | 211 | // Look for the Quicktime system installation plugins directory |
michael@0 | 212 | verBlock qtVer; |
michael@0 | 213 | ClearVersion(&qtVer); |
michael@0 | 214 | |
michael@0 | 215 | // First we need to check the version of Quicktime via checking |
michael@0 | 216 | // the EXE's version table |
michael@0 | 217 | rv = regKey->Open(nsIWindowsRegKey::ROOT_KEY_LOCAL_MACHINE, |
michael@0 | 218 | NS_LITERAL_STRING("software\\Microsoft\\Windows\\CurrentVersion\\App Paths\\QuickTimePlayer.exe"), |
michael@0 | 219 | nsIWindowsRegKey::ACCESS_READ); |
michael@0 | 220 | if (NS_SUCCEEDED(rv)) { |
michael@0 | 221 | nsAutoString path; |
michael@0 | 222 | rv = regKey->ReadStringValue(NS_LITERAL_STRING(""), path); |
michael@0 | 223 | if (NS_SUCCEEDED(rv)) { |
michael@0 | 224 | GetFileVersion(path.get(), &qtVer); |
michael@0 | 225 | } |
michael@0 | 226 | regKey->Close(); |
michael@0 | 227 | } |
michael@0 | 228 | if (CompareVersion(qtVer, minVer) < 0) |
michael@0 | 229 | return rv; |
michael@0 | 230 | |
michael@0 | 231 | rv = regKey->Open(nsIWindowsRegKey::ROOT_KEY_LOCAL_MACHINE, |
michael@0 | 232 | NS_LITERAL_STRING("software\\Apple Computer, Inc.\\QuickTime"), |
michael@0 | 233 | nsIWindowsRegKey::ACCESS_READ); |
michael@0 | 234 | if (NS_SUCCEEDED(rv)) { |
michael@0 | 235 | nsAutoString path; |
michael@0 | 236 | rv = regKey->ReadStringValue(NS_LITERAL_STRING("InstallDir"), path); |
michael@0 | 237 | if (NS_SUCCEEDED(rv)) { |
michael@0 | 238 | path += NS_LITERAL_STRING("\\Plugins"); |
michael@0 | 239 | rv = NS_NewLocalFile(path, true, |
michael@0 | 240 | getter_AddRefs(localFile)); |
michael@0 | 241 | } |
michael@0 | 242 | } |
michael@0 | 243 | } else if (nsCRT::strcmp(charProp, NS_WIN_WMP_SCAN_KEY) == 0) { |
michael@0 | 244 | nsAdoptingCString strVer = Preferences::GetCString(charProp); |
michael@0 | 245 | if (!strVer) { |
michael@0 | 246 | return NS_ERROR_FAILURE; |
michael@0 | 247 | } |
michael@0 | 248 | verBlock minVer; |
michael@0 | 249 | TranslateVersionStr(NS_ConvertASCIItoUTF16(strVer).get(), &minVer); |
michael@0 | 250 | |
michael@0 | 251 | // Look for Windows Media Player system installation plugins directory |
michael@0 | 252 | verBlock wmpVer; |
michael@0 | 253 | ClearVersion(&wmpVer); |
michael@0 | 254 | |
michael@0 | 255 | // First we need to check the version of WMP |
michael@0 | 256 | rv = regKey->Open(nsIWindowsRegKey::ROOT_KEY_LOCAL_MACHINE, |
michael@0 | 257 | NS_LITERAL_STRING("software\\Microsoft\\Windows\\CurrentVersion\\App Paths\\wmplayer.exe"), |
michael@0 | 258 | nsIWindowsRegKey::ACCESS_READ); |
michael@0 | 259 | if (NS_SUCCEEDED(rv)) { |
michael@0 | 260 | nsAutoString path; |
michael@0 | 261 | rv = regKey->ReadStringValue(NS_LITERAL_STRING(""), path); |
michael@0 | 262 | if (NS_SUCCEEDED(rv)) { |
michael@0 | 263 | GetFileVersion(path.get(), &wmpVer); |
michael@0 | 264 | } |
michael@0 | 265 | regKey->Close(); |
michael@0 | 266 | } |
michael@0 | 267 | if (CompareVersion(wmpVer, minVer) < 0) |
michael@0 | 268 | return rv; |
michael@0 | 269 | |
michael@0 | 270 | rv = regKey->Open(nsIWindowsRegKey::ROOT_KEY_LOCAL_MACHINE, |
michael@0 | 271 | NS_LITERAL_STRING("software\\Microsoft\\MediaPlayer"), |
michael@0 | 272 | nsIWindowsRegKey::ACCESS_READ); |
michael@0 | 273 | if (NS_SUCCEEDED(rv)) { |
michael@0 | 274 | nsAutoString path; |
michael@0 | 275 | rv = regKey->ReadStringValue(NS_LITERAL_STRING("Installation Directory"), |
michael@0 | 276 | path); |
michael@0 | 277 | if (NS_SUCCEEDED(rv)) { |
michael@0 | 278 | rv = NS_NewLocalFile(path, true, |
michael@0 | 279 | getter_AddRefs(localFile)); |
michael@0 | 280 | } |
michael@0 | 281 | } |
michael@0 | 282 | } else if (nsCRT::strcmp(charProp, NS_WIN_ACROBAT_SCAN_KEY) == 0) { |
michael@0 | 283 | nsAdoptingCString strVer = Preferences::GetCString(charProp); |
michael@0 | 284 | if (!strVer) { |
michael@0 | 285 | return NS_ERROR_FAILURE; |
michael@0 | 286 | } |
michael@0 | 287 | |
michael@0 | 288 | verBlock minVer; |
michael@0 | 289 | TranslateVersionStr(NS_ConvertASCIItoUTF16(strVer).get(), &minVer); |
michael@0 | 290 | |
michael@0 | 291 | // Look for Adobe Acrobat system installation plugins directory |
michael@0 | 292 | verBlock maxVer; |
michael@0 | 293 | ClearVersion(&maxVer); |
michael@0 | 294 | |
michael@0 | 295 | nsAutoString newestPath; |
michael@0 | 296 | |
michael@0 | 297 | rv = regKey->Open(nsIWindowsRegKey::ROOT_KEY_LOCAL_MACHINE, |
michael@0 | 298 | NS_LITERAL_STRING("software\\Adobe\\Acrobat Reader"), |
michael@0 | 299 | nsIWindowsRegKey::ACCESS_READ); |
michael@0 | 300 | if (NS_FAILED(rv)) { |
michael@0 | 301 | rv = regKey->Open(nsIWindowsRegKey::ROOT_KEY_LOCAL_MACHINE, |
michael@0 | 302 | NS_LITERAL_STRING("software\\Adobe\\Adobe Acrobat"), |
michael@0 | 303 | nsIWindowsRegKey::ACCESS_READ); |
michael@0 | 304 | if (NS_FAILED(rv)) { |
michael@0 | 305 | return NS_ERROR_FAILURE; |
michael@0 | 306 | } |
michael@0 | 307 | } |
michael@0 | 308 | |
michael@0 | 309 | // We must enumerate through the keys because what if there is |
michael@0 | 310 | // more than one version? |
michael@0 | 311 | uint32_t childCount = 0; |
michael@0 | 312 | regKey->GetChildCount(&childCount); |
michael@0 | 313 | |
michael@0 | 314 | for (uint32_t index = 0; index < childCount; ++index) { |
michael@0 | 315 | nsAutoString childName; |
michael@0 | 316 | rv = regKey->GetChildName(index, childName); |
michael@0 | 317 | if (NS_SUCCEEDED(rv)) { |
michael@0 | 318 | verBlock curVer; |
michael@0 | 319 | TranslateVersionStr(childName.get(), &curVer); |
michael@0 | 320 | |
michael@0 | 321 | childName += NS_LITERAL_STRING("\\InstallPath"); |
michael@0 | 322 | |
michael@0 | 323 | nsCOMPtr<nsIWindowsRegKey> childKey; |
michael@0 | 324 | rv = regKey->OpenChild(childName, nsIWindowsRegKey::ACCESS_QUERY_VALUE, |
michael@0 | 325 | getter_AddRefs(childKey)); |
michael@0 | 326 | if (NS_SUCCEEDED(rv)) { |
michael@0 | 327 | // We have a sub key |
michael@0 | 328 | nsAutoString path; |
michael@0 | 329 | rv = childKey->ReadStringValue(NS_LITERAL_STRING(""), path); |
michael@0 | 330 | if (NS_SUCCEEDED(rv)) { |
michael@0 | 331 | if (CompareVersion(curVer, maxVer) >= 0 && |
michael@0 | 332 | CompareVersion(curVer, minVer) >= 0) { |
michael@0 | 333 | newestPath = path; |
michael@0 | 334 | CopyVersion(&maxVer, &curVer); |
michael@0 | 335 | } |
michael@0 | 336 | } |
michael@0 | 337 | } |
michael@0 | 338 | } |
michael@0 | 339 | } |
michael@0 | 340 | |
michael@0 | 341 | if (!newestPath.IsEmpty()) { |
michael@0 | 342 | newestPath += NS_LITERAL_STRING("\\browser"); |
michael@0 | 343 | rv = NS_NewLocalFile(newestPath, true, |
michael@0 | 344 | getter_AddRefs(localFile)); |
michael@0 | 345 | } |
michael@0 | 346 | } |
michael@0 | 347 | |
michael@0 | 348 | if (NS_FAILED(rv)) { |
michael@0 | 349 | return rv; |
michael@0 | 350 | } |
michael@0 | 351 | |
michael@0 | 352 | localFile.forget(_retval); |
michael@0 | 353 | return NS_OK; |
michael@0 | 354 | } |
michael@0 | 355 | |
michael@0 | 356 | nsresult |
michael@0 | 357 | nsPluginDirServiceProvider::GetPLIDDirectories(nsISimpleEnumerator **aEnumerator) |
michael@0 | 358 | { |
michael@0 | 359 | NS_ENSURE_ARG_POINTER(aEnumerator); |
michael@0 | 360 | *aEnumerator = nullptr; |
michael@0 | 361 | |
michael@0 | 362 | nsCOMArray<nsIFile> dirs; |
michael@0 | 363 | |
michael@0 | 364 | GetPLIDDirectoriesWithRootKey(nsIWindowsRegKey::ROOT_KEY_CURRENT_USER, dirs); |
michael@0 | 365 | GetPLIDDirectoriesWithRootKey(nsIWindowsRegKey::ROOT_KEY_LOCAL_MACHINE, dirs); |
michael@0 | 366 | |
michael@0 | 367 | return NS_NewArrayEnumerator(aEnumerator, dirs); |
michael@0 | 368 | } |
michael@0 | 369 | |
michael@0 | 370 | nsresult |
michael@0 | 371 | nsPluginDirServiceProvider::GetPLIDDirectoriesWithRootKey(uint32_t aKey, nsCOMArray<nsIFile> &aDirs) |
michael@0 | 372 | { |
michael@0 | 373 | nsCOMPtr<nsIWindowsRegKey> regKey = |
michael@0 | 374 | do_CreateInstance("@mozilla.org/windows-registry-key;1"); |
michael@0 | 375 | NS_ENSURE_TRUE(regKey, NS_ERROR_FAILURE); |
michael@0 | 376 | |
michael@0 | 377 | nsresult rv = regKey->Open(aKey, |
michael@0 | 378 | NS_LITERAL_STRING("Software\\MozillaPlugins"), |
michael@0 | 379 | nsIWindowsRegKey::ACCESS_READ); |
michael@0 | 380 | if (NS_FAILED(rv)) { |
michael@0 | 381 | return rv; |
michael@0 | 382 | } |
michael@0 | 383 | |
michael@0 | 384 | uint32_t childCount = 0; |
michael@0 | 385 | regKey->GetChildCount(&childCount); |
michael@0 | 386 | |
michael@0 | 387 | for (uint32_t index = 0; index < childCount; ++index) { |
michael@0 | 388 | nsAutoString childName; |
michael@0 | 389 | rv = regKey->GetChildName(index, childName); |
michael@0 | 390 | if (NS_SUCCEEDED(rv)) { |
michael@0 | 391 | nsCOMPtr<nsIWindowsRegKey> childKey; |
michael@0 | 392 | rv = regKey->OpenChild(childName, nsIWindowsRegKey::ACCESS_QUERY_VALUE, |
michael@0 | 393 | getter_AddRefs(childKey)); |
michael@0 | 394 | if (NS_SUCCEEDED(rv) && childKey) { |
michael@0 | 395 | nsAutoString path; |
michael@0 | 396 | rv = childKey->ReadStringValue(NS_LITERAL_STRING("Path"), path); |
michael@0 | 397 | if (NS_SUCCEEDED(rv)) { |
michael@0 | 398 | nsCOMPtr<nsIFile> localFile; |
michael@0 | 399 | if (NS_SUCCEEDED(NS_NewLocalFile(path, true, |
michael@0 | 400 | getter_AddRefs(localFile))) && |
michael@0 | 401 | localFile) { |
michael@0 | 402 | // Some vendors use a path directly to the DLL so chop off |
michael@0 | 403 | // the filename |
michael@0 | 404 | bool isDir = false; |
michael@0 | 405 | if (NS_SUCCEEDED(localFile->IsDirectory(&isDir)) && !isDir) { |
michael@0 | 406 | nsCOMPtr<nsIFile> temp; |
michael@0 | 407 | localFile->GetParent(getter_AddRefs(temp)); |
michael@0 | 408 | if (temp) |
michael@0 | 409 | localFile = temp; |
michael@0 | 410 | } |
michael@0 | 411 | |
michael@0 | 412 | // Now we check to make sure it's actually on disk and |
michael@0 | 413 | // To see if we already have this directory in the array |
michael@0 | 414 | bool isFileThere = false; |
michael@0 | 415 | bool isDupEntry = false; |
michael@0 | 416 | if (NS_SUCCEEDED(localFile->Exists(&isFileThere)) && isFileThere) { |
michael@0 | 417 | int32_t c = aDirs.Count(); |
michael@0 | 418 | for (int32_t i = 0; i < c; i++) { |
michael@0 | 419 | nsIFile *dup = static_cast<nsIFile*>(aDirs[i]); |
michael@0 | 420 | if (dup && |
michael@0 | 421 | NS_SUCCEEDED(dup->Equals(localFile, &isDupEntry)) && |
michael@0 | 422 | isDupEntry) { |
michael@0 | 423 | break; |
michael@0 | 424 | } |
michael@0 | 425 | } |
michael@0 | 426 | |
michael@0 | 427 | if (!isDupEntry) { |
michael@0 | 428 | aDirs.AppendObject(localFile); |
michael@0 | 429 | } |
michael@0 | 430 | } |
michael@0 | 431 | } |
michael@0 | 432 | } |
michael@0 | 433 | } |
michael@0 | 434 | } |
michael@0 | 435 | } |
michael@0 | 436 | return NS_OK; |
michael@0 | 437 | } |
michael@0 | 438 |