2020-10-21 05:01:48 +00:00
|
|
|
import
|
|
|
|
stew/shims/macros,
|
2020-10-22 05:09:34 +00:00
|
|
|
serialization, ./reader, ./writer, ./utils, ./types
|
2020-10-21 05:01:48 +00:00
|
|
|
|
|
|
|
export
|
2020-10-22 05:09:34 +00:00
|
|
|
serialization, reader, writer, types
|
2020-10-21 05:01:48 +00:00
|
|
|
|
2021-03-19 02:01:44 +00:00
|
|
|
serializationFormat Winreg
|
|
|
|
|
|
|
|
Winreg.setReader WinregReader
|
|
|
|
Winreg.setWriter WinregWriter, PreferredOutput = void
|
2020-10-21 05:01:48 +00:00
|
|
|
|
|
|
|
template supports*(_: type Winreg, T: type): bool =
|
|
|
|
# The Winreg format should support every type
|
|
|
|
true
|
|
|
|
|
|
|
|
template decode*(_: type Winreg,
|
|
|
|
hKey: HKEY,
|
|
|
|
path: string,
|
|
|
|
RecordType: distinct type,
|
|
|
|
params: varargs[untyped]): auto =
|
|
|
|
mixin init, ReaderType
|
|
|
|
|
|
|
|
{.noSideEffect.}:
|
|
|
|
var reader = unpackArgs(init, [WinregReader, hKey, path, params])
|
|
|
|
reader.readValue(RecordType)
|
|
|
|
|
|
|
|
template encode*(_: type Winreg,
|
|
|
|
hKey: HKEY,
|
|
|
|
path: string,
|
2020-10-21 09:07:25 +00:00
|
|
|
value: auto,
|
2020-10-21 05:01:48 +00:00
|
|
|
params: varargs[untyped]) =
|
|
|
|
mixin init, WriterType, writeValue
|
|
|
|
|
|
|
|
{.noSideEffect.}:
|
|
|
|
var writer = unpackArgs(init, [WinregWriter, hKey, path, params])
|
|
|
|
writeValue writer, value
|
|
|
|
|
|
|
|
template loadFile*(_: type Winreg,
|
|
|
|
filename: string,
|
|
|
|
RecordType: distinct type,
|
|
|
|
params: varargs[untyped]): auto =
|
|
|
|
mixin init, ReaderType, readValue
|
|
|
|
|
2020-10-21 09:07:25 +00:00
|
|
|
# filename should be a Windows Registry path
|
|
|
|
# such as "HKEY_CLASSES_ROOT\\SOFTWARE\\Nimbus"
|
|
|
|
# or "HKCU\\SOFTWARE\\Nimbus"
|
2020-10-21 05:01:48 +00:00
|
|
|
let (hKey, path) = parseWinregPath(filename)
|
|
|
|
var reader = unpackArgs(init, [WinregReader, hKey, path, params])
|
|
|
|
reader.readValue(RecordType)
|
|
|
|
|
2020-10-28 09:12:30 +00:00
|
|
|
template saveFile*(_: type Winreg, filename: string, value: auto, params: varargs[untyped]) =
|
2020-10-21 05:01:48 +00:00
|
|
|
mixin init, WriterType, writeValue
|
|
|
|
|
2020-10-21 09:07:25 +00:00
|
|
|
# filename should be a Windows Registry path
|
2020-10-21 05:01:48 +00:00
|
|
|
let (hKey, path) = parseWinregPath(filename)
|
|
|
|
var writer = unpackArgs(init, [WinregWriter, hKey, path, params])
|
|
|
|
writer.writeValue(value)
|