Skip to content

Commit cb720ba

Browse files
author
Steven Edouard
committed
feat(infrastructure) - Initial module
Added test framework, static validation module layout and package json necessary.
1 parent d8e9839 commit cb720ba

10 files changed

+327
-0
lines changed

.jscsrc

+74
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
{
2+
"disallowEmptyBlocks": true,
3+
"disallowKeywords": [
4+
"with"
5+
],
6+
"disallowKeywordsOnNewLine": [
7+
"else"
8+
],
9+
"disallowMixedSpacesAndTabs": true,
10+
"disallowMultipleLineBreaks": true,
11+
"disallowNewlineBeforeBlockStatements": true,
12+
"disallowPaddingNewlinesInBlocks": true,
13+
"disallowQuotedKeysInObjects": true,
14+
"disallowSpaceAfterObjectKeys": true,
15+
"disallowSpaceAfterPrefixUnaryOperators": true,
16+
"disallowSpaceBeforeBinaryOperators": [
17+
],
18+
"disallowSpaceBeforePostfixUnaryOperators": true,
19+
"disallowSpacesInFunctionDeclaration": {
20+
"beforeOpeningRoundBrace": true
21+
},
22+
"disallowSpacesInNamedFunctionExpression": {
23+
"beforeOpeningRoundBrace": true
24+
},
25+
"disallowSpacesInsideArrayBrackets": true,
26+
"disallowSpacesInsideObjectBrackets": "all",
27+
"disallowSpacesInsideParentheses": true,
28+
"disallowTrailingComma": true,
29+
"disallowTrailingWhitespace": true,
30+
"disallowYodaConditions": true,
31+
"requireBlocksOnNewline": 1,
32+
"requireCamelCaseOrUpperCaseIdentifiers": "ignoreProperties",
33+
"requireCapitalizedConstructors": true,
34+
"requireCommaBeforeLineBreak": true,
35+
"requireCurlyBraces": [
36+
"if",
37+
"else",
38+
"for",
39+
"while",
40+
"do",
41+
"try",
42+
"catch"
43+
],
44+
"requireDotNotation": true,
45+
"requireLineFeedAtFileEnd": true,
46+
"requireParenthesesAroundIIFE": true,
47+
"requireSpaceAfterBinaryOperators": true,
48+
"requireSpaceAfterKeywords": [
49+
"else",
50+
"for",
51+
"while",
52+
"do",
53+
"switch",
54+
"case",
55+
"return",
56+
"try",
57+
"function",
58+
"typeof"
59+
],
60+
"requireSpaceAfterLineComment": "allowSlash",
61+
"requireSpaceBeforeBinaryOperators": true,
62+
"requireSpaceBeforeBlockStatements": true,
63+
"requireSpacesInAnonymousFunctionExpression": {
64+
"beforeOpeningRoundBrace": true
65+
},
66+
"requireSpacesInConditionalExpression": true,
67+
"safeContextKeyword": [
68+
"self"
69+
],
70+
"validateIndentation": 4,
71+
"validateQuoteMarks": "'",
72+
"esnext": true
73+
}
74+

.jshintrc

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"esnext": true,
3+
"node": true,
4+
"browser": true,
5+
"nomen": false,
6+
"bitwise": true,
7+
"eqeqeq": true,
8+
"forin": true,
9+
"immed": true,
10+
"latedef": true,
11+
"newcap": true,
12+
"noarg": true,
13+
"noempty": true,
14+
"nonew": true,
15+
"plusplus": true,
16+
"regexp": true,
17+
"undef": true,
18+
"unused": true,
19+
"trailing": true,
20+
"indent": 4,
21+
"onevar": true,
22+
"white": true,
23+
"quotmark": "single",
24+
"predef": {
25+
}
26+
}

Gruntfile.js

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
var grunt = require('grunt');
2+
require('load-grunt-tasks')(grunt);
3+
var files = ['lib/**/*.js', 'app.js', 'test/**/*.js'];
4+
5+
grunt.initConfig({
6+
mochacli: {
7+
options: {
8+
reporter: 'spec',
9+
bail: true
10+
},
11+
all: ['test/*.js']
12+
},
13+
jshint: {
14+
files: files,
15+
options: {
16+
jshintrc: './.jshintrc'
17+
}
18+
},
19+
jscs: {
20+
files: {
21+
src: files
22+
},
23+
options: {
24+
config: '.jscsrc',
25+
esnext: true
26+
}
27+
},
28+
jsbeautifier: {
29+
test: {
30+
files: {
31+
src: files
32+
},
33+
options: {
34+
mode: 'VERIFY_ONLY',
35+
config: '.beautifyrc'
36+
}
37+
},
38+
write: {
39+
files: {
40+
src: files
41+
},
42+
options: {
43+
config: '.beautifyrc'
44+
}
45+
}
46+
},
47+
watch: {
48+
scripts: {
49+
files: files,
50+
tasks: ['test'],
51+
options: {
52+
spawn: false,
53+
},
54+
},
55+
}
56+
});
57+
grunt.registerTask('test', ['jshint', 'jscs', 'mochacli:all']);

index.js

Whitespace-only changes.

jsconfig.json

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"compilerOptions": {
3+
"target": "ES6"
4+
}
5+
}

lib/registry.js

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
'use strict';
2+
var ffi = require('ffi'),
3+
types = require('./types');
4+
5+
var advApi = ffi.Library('Advapi32', {
6+
'RegOpenCurrentUser': [ 'uint64', [ types.REGSAM, types.PHKEY ] ],
7+
'RegQueryValueExA' : ['uint64', [types.HKEY, 'string', 'pointer', types.LPDWORD, types.LPBYTE, types.LPDWORD]],
8+
'RegOpenKeyExA' : ['uint64', ['uint64', 'string', types.DWORD, types.REGSAM, types.PHKEY]],
9+
'RegSetValueExA' : [ 'uint64', [types.HKEY, 'string', 'pointer', types.DWORD, types.LPBYTE, types.DWORD ] ]
10+
});
11+
12+
class Key {
13+
constructor(pHkey, path) {
14+
15+
}
16+
}
17+
18+
var api = {
19+
openKey: function (key, subKeyName) {
20+
21+
},
22+
queryValue: function (key, valueName) {
23+
24+
},
25+
setValue: function (key, valueName, valueType, value) {
26+
27+
}
28+
}
29+
30+
module.exports = api;

lib/types.js

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
var ref = require('ref');
2+
3+
var types = {
4+
REGSAM: ref.types.uint64,
5+
DWORD: ref.types.uint32,
6+
BYTE: ref.types.uint8,
7+
HKEY: ref.refType(ref.types.void),
8+
PHKEY: ref.refType(this.HKEY),
9+
LPBYTE: ref.refType(this.BYTE),
10+
LPDWORD: ref.refType(this.DWORD),
11+
LPCTSTR: ref.refType(ref.types.CString)
12+
};
13+
14+
module.exports = types;
15+

lib/windef.js

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
var HKEY = {
2+
HKEY_CLASSES_ROOT: 0x80000000,
3+
HKEY_CURRENT_USER: 0x80000001,
4+
HKEY_LOCAL_MACHINE: 0x80000002,
5+
HKEY_USERS: 0x80000003,
6+
HKEY_PERFORMANCE_DATA: 0x80000004,
7+
HKEY_CURRENT_CONFIG: 0x80000005,
8+
HKEY_DYN_DATA: 0x80000006
9+
};
10+
// https://msdn.microsoft.com/en-us/library/windows/desktop/ms724878(v=vs.85).aspx
11+
var KEY_ACCESS = {
12+
KEY_ALL_ACCESS: 0xF003F,
13+
KEY_CREATE_LINK: 0x0020,
14+
KEY_CREATE_SUB_KEY: 0x0004,
15+
KEY_ENUMERATE_SUB_KEYS: 0x0008,
16+
KEY_EXECUTE: 0x20019,
17+
KEY_NOTIFY: 0x0010,
18+
KEY_QUERY_VALUE: 0x0001,
19+
KEY_READ: 0x20019,
20+
KEY_SET_VALUE: 0x0002,
21+
KEY_WOW64_32KEY: 0x0200,
22+
KEY_WOW64_64KEY: 0x0100,
23+
KEY_WRITE: 0x20006
24+
}
25+
26+
module.exports = def;

package.json

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
{
2+
"name": "windows-registry-node",
3+
"version": "1.0.0",
4+
"description": "Read and Write to the Windows registry in-process from Node.js. Easily set application file associations and other goodies & such.",
5+
"main": "index.js",
6+
"directories": {
7+
"test": "test"
8+
},
9+
"dependencies": {
10+
"ffi": "^2.0.0",
11+
"grunt": "^0.4.5",
12+
"grunt-mocha-cli": "^2.0.0",
13+
"load-grunt-tasks": "^3.3.0",
14+
"ref": "^1.2.0"
15+
},
16+
"devDependencies": {
17+
"grunt": "^0.4.5",
18+
"grunt-mocha-cli": "^2.0.0",
19+
"load-grunt-tasks": "^3.3.0",
20+
"grunt-contrib-jshint": "^0.11.3",
21+
"grunt-contrib-watch": "^0.6.1",
22+
"grunt-jsbeautifier": "^0.2.10",
23+
"grunt-jscs": "^2.1.0"
24+
},
25+
"scripts": {
26+
"test": "grunt test"
27+
},
28+
"repository": {
29+
"type": "git",
30+
"url": "git+https://github.com/CatalystCode/windows-registry-node.git"
31+
},
32+
"keywords": [
33+
"Windows",
34+
"Registry",
35+
"regedit",
36+
"file",
37+
"association"
38+
],
39+
"author": "sedouard",
40+
"license": "ISC",
41+
"bugs": {
42+
"url": "https://github.com/CatalystCode/windows-registry-node/issues"
43+
},
44+
"homepage": "https://github.com/CatalystCode/windows-registry-node#readme"
45+
}

test/registry.js

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/* global describe, it */
2+
'use strict';
3+
var registry = require('../lib/registry'),
4+
windef = require('../lib/windef'),
5+
assert = require('assert');
6+
7+
describe('Registry API open tests', function() {
8+
9+
it('Should open a subkey provided a predefined key', () => {
10+
var key = registry.openKey(windef.HKEY.HKEY_CLASSES_ROOT, 'MyProgram');
11+
12+
assert.equal(key.pointer != null);
13+
});
14+
15+
it('Should open a subkey provided a previously opened key', () => {
16+
var key = registry.openKey(windef.HKEY.HKEY_CLASSES_ROOT, 'TestProgram');
17+
var key2 = registry.openKey(key, 'Subkey');
18+
assert.equal(key2.pointer != null);
19+
});
20+
21+
it('Should open a subkey provided a previously opened key', () => {
22+
var key = registry.openKey(windef.HKEY.HKEY_CLASSES_ROOT, 'TestProgram');
23+
var key2 = registry.openKey(key, 'Subkey');
24+
assert.equal(key2.pointer != null);
25+
});
26+
});
27+
28+
29+
describe('Registry API key read test', function() {
30+
31+
it('Should read a key value provided a key and value name', () => {
32+
var key = registry.openKey(windef.HKEY.HKEY_CLASSES_ROOT, 'MyProgram');
33+
34+
assert.equal(key.pointer != null);
35+
});
36+
37+
it('Should open a subkey provided a previously opened key', () => {
38+
var key = registry.openKey(windef.HKEY.HKEY_CLASSES_ROOT, 'TestProgram');
39+
var key2 = registry.openKey(key, 'Subkey');
40+
assert.equal(key2.pointer != null);
41+
});
42+
43+
it('Should open a subkey provided a previously opened key', () => {
44+
var key = registry.openKey(windef.HKEY.HKEY_CLASSES_ROOT, 'TestProgram');
45+
var key2 = registry.openKey(key, 'Subkey');
46+
assert.equal(key2.pointer != null);
47+
})
48+
49+
});

0 commit comments

Comments
 (0)