-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement writing and reading values.
- Loading branch information
Showing
9 changed files
with
603 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
export class WindowsRegistry { | ||
/** | ||
* Constructs a new `WindowsRegistry` instance. This will start a background thread to perform | ||
* operations that will live as long as this instance does. | ||
*/ | ||
constructor() | ||
/** | ||
* Closes the registry, ending its background thread immediately. This is not necessary to call, | ||
* as the background thread will be automatically ended upon garbage collection, but can be used | ||
* if you would like to exit the process immediately. | ||
*/ | ||
close(): void | ||
|
||
read(hive: Hkey, key: string, name: string): Promise<RegistryDataTypeJs[RegistryDataType]> | ||
write<R extends RegistryDataType>( | ||
hive: Hkey, | ||
key: string, | ||
name: string, | ||
type: R, | ||
value: RegistryDataTypeJs[R], | ||
): Promise<void> | ||
} | ||
|
||
export const HKCU = 'HKEY_CURRENT_USER' | ||
export const HKLM = 'HKEY_LOCAL_MACHINE' | ||
export const HKCR = 'HKEY_CLASSES_ROOT' | ||
export const HKU = 'HKEY_USERS' | ||
export const HKCC = 'HKEY_CURRENT_CONFIG' | ||
export type Hkey = typeof HKCU | typeof HKLM | typeof HKCR | typeof HKU | typeof HKCC | ||
|
||
export const REG_NONE = 'REG_NONE' | ||
export const REG_SZ = 'REG_SZ' | ||
export const REG_MULTI_SZ = 'REG_MULTI_SZ' | ||
export const REG_EXPAND_SZ = 'REG_EXPAND_SZ' | ||
export const REG_DWORD = 'REG_DWORD' | ||
export const REG_QWORD = 'REG_QWORD' | ||
export const REG_BINARY = 'REG_BINARY' | ||
export type RegistryDataType = | ||
| typeof REG_NONE | ||
| typeof REG_SZ | ||
| typeof REG_MULTI_SZ | ||
| typeof REG_EXPAND_SZ | ||
| typeof REG_DWORD | ||
| typeof REG_QWORD | ||
| typeof REG_BINARY | ||
|
||
interface RegistryDataTypeJs extends Record<RegistryDataType, any> { | ||
[REG_NONE]: undefined | null | ||
[REG_SZ]: string | ||
[REG_MULTI_SZ]: string[] | ||
[REG_EXPAND_SZ]: string | ||
[REG_DWORD]: number | ||
[REG_QWORD]: number | ||
[REG_BINARY]: Uint8Array | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
const { registryNew, registryClose, registryRead, registryWrite } = require('./native.js') | ||
|
||
class WindowsRegistry { | ||
/** | ||
* Constructs a new `WindowsRegistry` instance. This will start a background thread to perform | ||
* operations that will live as long as this instance does. | ||
*/ | ||
constructor() { | ||
this.registry = registryNew() | ||
} | ||
|
||
/** | ||
* Closes the registry, ending its background thread immediately. This is not necessary to call, | ||
* as the background thread will be automatically ended upon garbage collection, but can be used | ||
* if you would like to exit the process immediately. | ||
*/ | ||
close() { | ||
registryClose.call(this.registry) | ||
} | ||
|
||
read(hive, key, value) { | ||
return registryRead.call(this.registry, hive, key, value) | ||
} | ||
|
||
write(hive, key, value, type, data) { | ||
return registryWrite.call(this.registry, hive, key, value, type, data) | ||
} | ||
} | ||
|
||
module.exports = { | ||
WindowsRegistry, | ||
|
||
HKCU: 'HKEY_CURRENT_USER', | ||
HKLM: 'HKEY_LOCAL_MACHINE', | ||
HKCR: 'HKEY_CLASSES_ROOT', | ||
HKU: 'HKEY_USERS', | ||
HKCC: 'HKEY_CURRENT_CONFIG', | ||
|
||
REG_NONE: 'REG_NONE', | ||
REG_SZ: 'REG_SZ', | ||
REG_MULTI_SZ: 'REG_MULTI_SZ', | ||
REG_EXPAND_SZ: 'REG_EXPAND_SZ', | ||
REG_DWORD: 'REG_DWORD', | ||
REG_QWORD: 'REG_QWORD', | ||
REG_BINARY: 'REG_BINARY', | ||
|
||
DEFAULT_VALUE: '', | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
// TODO(tec27): Pick between 32 and 64-bit, as well as whether to use a locally built binary? | ||
let native | ||
try { | ||
native = require('./prebuilds/x64.node') | ||
} catch (e) { | ||
native = require('./native/index.node') | ||
} | ||
|
||
module.exports = native |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.