michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: "use strict"; michael@0: const {classes: Cc, interfaces: Ci, utils: Cu, results: Cr} = Components; michael@0: michael@0: this.EXPORTED_SYMBOLS = ["WindowsRegistry"]; michael@0: michael@0: const WindowsRegistry = { michael@0: /** michael@0: * Safely reads a value from the registry. michael@0: * michael@0: * @param aRoot michael@0: * The root registry to use. michael@0: * @param aPath michael@0: * The registry path to the key. michael@0: * @param aKey michael@0: * The key name. michael@0: * @return The key value or undefined if it doesn't exist. If the key is michael@0: * a REG_MULTI_SZ, an array is returned. michael@0: */ michael@0: readRegKey: function(aRoot, aPath, aKey) { michael@0: const kRegMultiSz = 7; michael@0: let registry = Cc["@mozilla.org/windows-registry-key;1"]. michael@0: createInstance(Ci.nsIWindowsRegKey); michael@0: try { michael@0: registry.open(aRoot, aPath, Ci.nsIWindowsRegKey.ACCESS_READ); michael@0: if (registry.hasValue(aKey)) { michael@0: let type = registry.getValueType(aKey); michael@0: switch (type) { michael@0: case kRegMultiSz: michael@0: // nsIWindowsRegKey doesn't support REG_MULTI_SZ type out of the box. michael@0: let str = registry.readStringValue(aKey); michael@0: return [v for each (v in str.split("\0")) if (v)]; michael@0: case Ci.nsIWindowsRegKey.TYPE_STRING: michael@0: return registry.readStringValue(aKey); michael@0: case Ci.nsIWindowsRegKey.TYPE_INT: michael@0: return registry.readIntValue(aKey); michael@0: default: michael@0: throw new Error("Unsupported registry value."); michael@0: } michael@0: } michael@0: } catch (ex) { michael@0: } finally { michael@0: registry.close(); michael@0: } michael@0: return undefined; michael@0: }, michael@0: };