xpcom/tests/TestWinReg.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/xpcom/tests/TestWinReg.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,57 @@
     1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.7 +
     1.8 +/*
     1.9 + * This script is intended to be run using xpcshell
    1.10 + */
    1.11 +
    1.12 +const nsIWindowsRegKey = Components.interfaces.nsIWindowsRegKey;
    1.13 +const BASE_PATH = "SOFTWARE\\Mozilla\\Firefox";
    1.14 +
    1.15 +function idump(indent, str)
    1.16 +{
    1.17 +  for (var j = 0; j < indent; ++j)
    1.18 +    dump(" ");
    1.19 +  dump(str);
    1.20 +}
    1.21 +
    1.22 +function list_values(indent, key) {
    1.23 +  idump(indent, "{\n");
    1.24 +  var count = key.valueCount;
    1.25 +  for (var i = 0; i < count; ++i) {
    1.26 +    var vn = key.getValueName(i);
    1.27 +    var val = "";
    1.28 +    if (key.getValueType(vn) == nsIWindowsRegKey.TYPE_STRING) {
    1.29 +      val = key.readStringValue(vn);
    1.30 +    }
    1.31 +    if (vn == "") 
    1.32 +      idump(indent + 1, "(Default): \"" + val + "\"\n");
    1.33 +    else
    1.34 +      idump(indent + 1, vn + ": \"" + val + "\"\n");
    1.35 +  } 
    1.36 +  idump(indent, "}\n");
    1.37 +}
    1.38 +
    1.39 +function list_children(indent, key) {
    1.40 +  list_values(indent, key);
    1.41 +
    1.42 +  var count = key.childCount;
    1.43 +  for (var i = 0; i < count; ++i) {
    1.44 +    var cn = key.getChildName(i);
    1.45 +    idump(indent, "[" + cn + "]\n");
    1.46 +    list_children(indent + 1, key.openChild(cn, nsIWindowsRegKey.ACCESS_READ));
    1.47 +  }
    1.48 +}
    1.49 +
    1.50 +// enumerate everything under BASE_PATH
    1.51 +var key = Components.classes["@mozilla.org/windows-registry-key;1"].
    1.52 +    createInstance(nsIWindowsRegKey);
    1.53 +key.open(nsIWindowsRegKey.ROOT_KEY_LOCAL_MACHINE, BASE_PATH,
    1.54 +         nsIWindowsRegKey.ACCESS_READ);
    1.55 +list_children(1, key);
    1.56 +
    1.57 +key.close();
    1.58 +key.open(nsIWindowsRegKey.ROOT_KEY_CURRENT_USER, BASE_PATH,
    1.59 +         nsIWindowsRegKey.ACCESS_READ);
    1.60 +list_children(1, key);

mercurial