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
|
|
|
|
|
|
|
serializationFormat Winreg,
|
|
|
|
Reader = WinregReader,
|
|
|
|
Writer = WinregWriter,
|
|
|
|
PreferedOutput = void
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
|
|
|
template saveFile*(Format: type, filename: string, value: auto, params: varargs[untyped]) =
|
|
|
|
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)
|