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.
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 "use strict";
6 const {classes: Cc, interfaces: Ci, utils: Cu, results: Cr} = Components;
8 this.EXPORTED_SYMBOLS = ["WindowsRegistry"];
10 const WindowsRegistry = {
11 /**
12 * Safely reads a value from the registry.
13 *
14 * @param aRoot
15 * The root registry to use.
16 * @param aPath
17 * The registry path to the key.
18 * @param aKey
19 * The key name.
20 * @return The key value or undefined if it doesn't exist. If the key is
21 * a REG_MULTI_SZ, an array is returned.
22 */
23 readRegKey: function(aRoot, aPath, aKey) {
24 const kRegMultiSz = 7;
25 let registry = Cc["@mozilla.org/windows-registry-key;1"].
26 createInstance(Ci.nsIWindowsRegKey);
27 try {
28 registry.open(aRoot, aPath, Ci.nsIWindowsRegKey.ACCESS_READ);
29 if (registry.hasValue(aKey)) {
30 let type = registry.getValueType(aKey);
31 switch (type) {
32 case kRegMultiSz:
33 // nsIWindowsRegKey doesn't support REG_MULTI_SZ type out of the box.
34 let str = registry.readStringValue(aKey);
35 return [v for each (v in str.split("\0")) if (v)];
36 case Ci.nsIWindowsRegKey.TYPE_STRING:
37 return registry.readStringValue(aKey);
38 case Ci.nsIWindowsRegKey.TYPE_INT:
39 return registry.readIntValue(aKey);
40 default:
41 throw new Error("Unsupported registry value.");
42 }
43 }
44 } catch (ex) {
45 } finally {
46 registry.close();
47 }
48 return undefined;
49 },
50 };