forked from CatalystCode/windows-registry-node
-
Notifications
You must be signed in to change notification settings - Fork 1
/
key.js
83 lines (71 loc) · 2.18 KB
/
key.js
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
'use strict';
/**
* An object wrapper for easier use of registry api
*/
class Key {
constructor (pHKeyOrPredefined, path, accessLevel) {
var isPredefined = false;
this._registry = require('./registry');
this._windef = require('./windef');
for (var k in this._windef.HKEY) {
if (this._windef.HKEY[k] === pHKeyOrPredefined) {
isPredefined = true;
break;
}
}
// this is a predefined key
if (isPredefined) {
return this._registry.openKeyFromPredefined(pHKeyOrPredefined, path, accessLevel);
}
this.handle = pHKeyOrPredefined;
this.path = path;
}
/**
* Closes this Key, releasing the native OS handle
* all the containers matching the query. Automatically closes current key
*/
close () {
this._registry.closeKey(this);
}
deleteKey () {
this._registry.deleteKey(this);
}
/**
* Deletes a value from a key
*/
deleteValue (value) {
this._registry.deleteValue(this, value);
}
/**
* Sets a value for a value name on this key
* all the containers matching the query.
* @param {DS.Record Container} selectedContainer - The container to be selected
*/
setValue (valueName, valueType, value) {
this._registry.setValueForKeyObject(this, valueName, valueType, value);
}
getValue (valueName) {
return this._registry.queryValueForKeyObject(this, valueName);
}
/**
* Returns a new Key object given a subkeyName
* @param {string} subKeyName - The container to be selected
* @param {string} accessLevel - The container to be selected
* @return {Key}
*/
openSubKey (subKeyName, accessLevel) {
var key = this._registry.openKeyFromKeyObject(this, subKeyName, accessLevel);
return key;
}
createSubKey (subKeyName, accessLevel) {
this._registry.createKey(this, subKeyName, accessLevel);
return new Key(this.handle, subKeyName, accessLevel);
}
/**
* Returns the string representing this Key
*/
toString () {
return this.path;
}
}
module.exports = Key;