ohmu
·
2026-10-15
1#pragma once
2
3#include "fastfetch.h"
4#include "common/argType.h"
5#include "common/io.h"
6#include "common/windows/nt.h"
7
8#ifndef HKEY_CURRENT_USER
9 #define HKEY_CLASSES_ROOT ((HKEY) (ULONG_PTR) ((LONG) 0x80000000))
10 #define HKEY_CURRENT_USER ((HKEY) (ULONG_PTR) ((LONG) 0x80000001))
11 #define HKEY_LOCAL_MACHINE ((HKEY) (ULONG_PTR) ((LONG) 0x80000002))
12 #define HKEY_USERS ((HKEY) (ULONG_PTR) ((LONG) 0x80000003))
13 #define HKEY_PERFORMANCE_DATA ((HKEY) (ULONG_PTR) ((LONG) 0x80000004))
14 #define HKEY_CURRENT_CONFIG ((HKEY) (ULONG_PTR) ((LONG) 0x80000005))
15 #define HKEY_DYN_DATA ((HKEY) (ULONG_PTR) ((LONG) 0x80000006))
16 #define HKEY_CURRENT_USER_LOCAL_SETTINGS ((HKEY) (ULONG_PTR) ((LONG) 0x80000007))
17#endif
18
19typedef struct FFRegValueArg {
20 FFArgType type;
21 const void* value;
22 const wchar_t* name;
23} FFRegValueArg;
24
25HANDLE ffRegGetRootKeyHandle(HKEY hKey);
26bool ffRegOpenSubkeyForRead(HANDLE hKey, const wchar_t* subKeyW, HANDLE* result, FFstrbuf* error);
27bool ffRegReadValue(HANDLE hKey, const FFRegValueArg* arg, FFstrbuf* error);
28bool ffRegReadValues(HANDLE hKey, uint32_t argc, const FFRegValueArg argv[], FFstrbuf* error);
29bool ffRegGetSubKey(HANDLE hKey, uint32_t index, FFstrbuf* result, FFstrbuf* error);
30// Fills `result` with the counters the key object caches, including LastWriteTime: the number of
31// 100-nanosecond intervals since this key or any of its values was last changed (FILETIME epoch).
32bool ffRegQueryKey(HANDLE hKey, KEY_CACHED_INFORMATION* result, FFstrbuf* error);
33
34static inline bool ffRegOpenKeyForRead(HKEY hRootKey, const wchar_t* subKeyW, HANDLE* result, FFstrbuf* error) {
35 return ffRegOpenSubkeyForRead(ffRegGetRootKeyHandle(hRootKey), subKeyW, result, error);
36}
37
38static inline bool ffRegReadStrbuf(HANDLE hKey, const wchar_t* valueNameW, FFstrbuf* result, FFstrbuf* error) {
39 return ffRegReadValue(hKey, &(FFRegValueArg) {
40 .type = FF_ARG_TYPE_STRBUF,
41 .value = result,
42 .name = valueNameW,
43 },
44 error);
45}
46static inline bool ffRegReadUint(HANDLE hKey, const wchar_t* valueNameW, uint32_t* result, FFstrbuf* error) {
47 return ffRegReadValue(hKey, &(FFRegValueArg) {
48 .type = FF_ARG_TYPE_UINT,
49 .value = result,
50 .name = valueNameW,
51 },
52 error);
53}
54static inline bool ffRegReadUint64(HANDLE hKey, const wchar_t* valueNameW, uint64_t* result, FFstrbuf* error) {
55 return ffRegReadValue(hKey, &(FFRegValueArg) {
56 .type = FF_ARG_TYPE_UINT64,
57 .value = result,
58 .name = valueNameW,
59 },
60 error);
61}
62static inline bool ffRegReadData(HANDLE hKey, const wchar_t* valueNameW, FFArgBuffer* buffer, FFstrbuf* error) {
63 return ffRegReadValue(hKey, &(FFRegValueArg) {
64 .type = FF_ARG_TYPE_BUFFER,
65 .value = buffer,
66 .name = valueNameW,
67 },
68 error);
69}