xpcom/tests/TestWinReg.js

branch
TOR_BUG_3246
changeset 7
129ffea94266
equal deleted inserted replaced
-1:000000000000 0:5385681439f2
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/. */
4
5 /*
6 * This script is intended to be run using xpcshell
7 */
8
9 const nsIWindowsRegKey = Components.interfaces.nsIWindowsRegKey;
10 const BASE_PATH = "SOFTWARE\\Mozilla\\Firefox";
11
12 function idump(indent, str)
13 {
14 for (var j = 0; j < indent; ++j)
15 dump(" ");
16 dump(str);
17 }
18
19 function list_values(indent, key) {
20 idump(indent, "{\n");
21 var count = key.valueCount;
22 for (var i = 0; i < count; ++i) {
23 var vn = key.getValueName(i);
24 var val = "";
25 if (key.getValueType(vn) == nsIWindowsRegKey.TYPE_STRING) {
26 val = key.readStringValue(vn);
27 }
28 if (vn == "")
29 idump(indent + 1, "(Default): \"" + val + "\"\n");
30 else
31 idump(indent + 1, vn + ": \"" + val + "\"\n");
32 }
33 idump(indent, "}\n");
34 }
35
36 function list_children(indent, key) {
37 list_values(indent, key);
38
39 var count = key.childCount;
40 for (var i = 0; i < count; ++i) {
41 var cn = key.getChildName(i);
42 idump(indent, "[" + cn + "]\n");
43 list_children(indent + 1, key.openChild(cn, nsIWindowsRegKey.ACCESS_READ));
44 }
45 }
46
47 // enumerate everything under BASE_PATH
48 var key = Components.classes["@mozilla.org/windows-registry-key;1"].
49 createInstance(nsIWindowsRegKey);
50 key.open(nsIWindowsRegKey.ROOT_KEY_LOCAL_MACHINE, BASE_PATH,
51 nsIWindowsRegKey.ACCESS_READ);
52 list_children(1, key);
53
54 key.close();
55 key.open(nsIWindowsRegKey.ROOT_KEY_CURRENT_USER, BASE_PATH,
56 nsIWindowsRegKey.ACCESS_READ);
57 list_children(1, key);

mercurial