all files / registryResolver/src/ RegistryResolver.js

62.5% Statements 10/16
100% Branches 0/0
33.33% Functions 1/3
62.5% Lines 10/16
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68                                                                                                                   
/*
 * Registry Resolver
 *
 * Copyright 2012 OCAD University
 *
 * Licensed under the New BSD license. You may not use this file except in
 * compliance with this License.
 *
 * The research leading to these results has received funding from the European Union's
 * Seventh Framework Programme (FP7/2007-2013)
 * under grant agreement no. 289016.
 *
 * You may obtain a copy of the License at
 * https://github.com/GPII/universal/blob/master/LICENSE.txt
 */
 
"use strict";
 
var fluid = require("universal"),
    gpii = fluid.registerNamespace("gpii");
 
fluid.logObjectRenderChars = 2048;
 
require("../../registrySettingsHandler/src/RegistrySettingsHandler.js");
 
/*  Registry resolver reads registry key based on the path provided.
 *  Arguments:
 *  registryPath {string} - a path into the Windows Registry to be resolved.
 */
gpii.windows.registryResolver = function (registryPath) {
    var args = gpii.windows.registryResolver.parseArguments(registryPath);
    return gpii.windows.readRegistryKey.apply(null, args).value;
};
 
/*  Parses the path into the registry into an array of arguments taken by gpii.windows.readRegistryKey.
 *  Arguments:
 *  value {string} - a path into the Windows Registry to be parsed.
 */
// TODO: support other than String values
gpii.windows.registryResolver.parseArguments = function (value) {
    var splitString = value.split("\\");
    var subKey = splitString.pop();
    var baseKey = splitString.shift();
    return [ baseKey, splitString.join("\\"), subKey, "REG_SZ" ];
};
 
/*  Component function definition for looking up if a registry key exists
 *  in the windows registry. Example usages are in the solutions registry
 *  json definition where we can add a device reporter entry to check if
 *  a program is installed by looking to see if it's key(s) is there.
 */
fluid.defaults("gpii.deviceReporter.registryKeyExists", {
    gradeNames: "fluid.function",
    argumentMap: {
        hKey: 0,
        path: 1,
        subPath: 2,
        dataType: 3
    }
});
 
gpii.deviceReporter.registryKeyExists = function (hKey, path, subPath, dataType) {
    fluid.log("gpii.deviceReporter.registryKeyExists:" + hKey + " " + path +
        " " + subPath + " " + dataType);
    var results = gpii.windows.readRegistryKey(hKey, path, subPath, dataType);
    return results.statusCode === 200;
};