toolkit/modules/WindowsRegistry.jsm

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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

mercurial