-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSettings.cpp
More file actions
70 lines (64 loc) · 2.11 KB
/
Settings.cpp
File metadata and controls
70 lines (64 loc) · 2.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
// Copyright 2019-2025 namazso <admin@namazso.eu>
// This file is part of OpenHashTab.
//
// OpenHashTab is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// OpenHashTab is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with OpenHashTab. If not, see <https://www.gnu.org/licenses/>.
#include "pch.h"
#include "Settings.h"
#include "utl.h"
static constexpr auto k_reg_path = L"Software\\OpenHashTab";
DWORD detail::GetMachineSettingDWORD(const char* name, DWORD default_value) {
DWORD value;
DWORD size = sizeof(value);
const auto status = RegGetValueW(
HKEY_LOCAL_MACHINE,
k_reg_path,
utl::UTF8ToWide(name).c_str(),
RRF_RT_REG_DWORD,
nullptr,
&value,
&size
);
return status == ERROR_SUCCESS ? value : default_value;
}
DWORD detail::GetSettingDWORD(const char* name, DWORD default_value) {
DWORD value;
DWORD size = sizeof(value);
const auto status = RegGetValueW(
HKEY_CURRENT_USER,
k_reg_path,
utl::UTF8ToWide(name).c_str(),
RRF_RT_REG_DWORD,
nullptr,
&value,
&size
);
return status == ERROR_SUCCESS ? value : default_value;
}
void detail::SetSettingDWORD(const char* name, DWORD new_value) {
RegSetKeyValueW(
HKEY_CURRENT_USER,
k_reg_path,
utl::UTF8ToWide(name).c_str(),
REG_DWORD,
&new_value,
sizeof(new_value)
);
}
Settings::Settings() {
bool defaults[LegacyHashAlgorithm::k_count]{};
for (const auto name : {"MD5", "SHA-1", "SHA-256", "SHA-512"})
defaults[LegacyHashAlgorithm::IdxByName(name)] = true;
for (auto i = 0u; i < LegacyHashAlgorithm::k_count; ++i)
algorithms[i].Init(LegacyHashAlgorithm::Algorithms()[i].GetName(), defaults[i]);
}