| 31 | } |
| 32 | |
| 33 | bool RegExportImport::ExportKey(HKEY hKey, HANDLE hFile, PCWSTR section) const { |
| 34 | WriteString(hFile, CString(L"[") + section + L"]\n"); |
| 35 | |
| 36 | RegistryKey key(hKey, false); |
| 37 | Registry::EnumKeyValues(hKey, [&](auto type, auto name, auto size) { |
| 38 | CString sname(name); |
| 39 | if (sname.IsEmpty()) |
| 40 | sname = L"@"; |
| 41 | else |
| 42 | sname = L"\"" + sname + L"\""; |
| 43 | |
| 44 | auto data = std::make_unique<BYTE[]>(size + 3); |
| 45 | auto count{ size }; |
| 46 | if (ERROR_SUCCESS != key.QueryValue(name, nullptr, data.get(), &count)) |
| 47 | return true; |
| 48 | |
| 49 | switch (type) |
| 50 | { |
| 51 | case REG_DWORD: |
| 52 | // c++20 https://www.modernescpp.com/index.php/std-format-in-c-20 |
| 53 | WriteString(hFile, sname + (L"=dword:" + std::format(L"{:08x}\n", *(DWORD*)data.get())).c_str()); |
| 54 | break; |
| 55 | |
| 56 | case REG_SZ: { |
| 57 | CString text(data.get()); |
| 58 | text.Replace(L"\"", L"\\\""); |
| 59 | WriteString(hFile, sname + L"=\"" + text + L"\"\n"); |
| 60 | break; |
| 61 | } |
| 62 | |
| 63 | case REG_BINARY: |
| 64 | WriteString(hFile, sname + L"=hex:" + BytesToString(data.get(), count) + L"\n"); |
| 65 | break; |
| 66 | |
| 67 | default: |
| 68 | WriteString(hFile, sname + std::format(L"=hex({:x}):", type).c_str() + |
| 69 | BytesToString(data.get(), count) + L"\n"); |
| 70 | break; |
| 71 | } |
| 72 | |
| 73 | return true; |
| 74 | }); |
| 75 | WriteString(hFile, L"\n"); |
| 76 | return true; |
| 77 | } |
| 78 | |
| 79 | CString RegExportImport::BytesToString(BYTE const* data, DWORD count) { |
| 80 | CString text, chars; |
nothing calls this directly
no test coverage detected