-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPolychoraSettings.cpp
More file actions
90 lines (65 loc) · 1.74 KB
/
Copy pathPolychoraSettings.cpp
File metadata and controls
90 lines (65 loc) · 1.74 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#include "PolychoraSettings.h"
CPolychoraSettings::CPolychoraSettings(void) :
UseFXAA(true),
UseComplexRotations(true),
Polychoron(L"Tesseract"),
ShowText(true)
{
MaybeLoad();
}
CPolychoraSettings::~CPolychoraSettings(void)
{
if(regkey!=nullptr)
regkey->Close();
}
std::unique_ptr<CRegKey> & CPolychoraSettings::CreateOrGetSettingsKey()
{
if(regkey == nullptr)
{
auto rt = std::unique_ptr<CRegKey>(new CRegKey);
if(rt->Create(HKEY_CURRENT_USER,L"Software\\Polychora")!=ERROR_SUCCESS)
return std::unique_ptr<CRegKey>(nullptr);
regkey = std::move(rt);
}
return regkey;
}
void CPolychoraSettings::Save()
{
auto & key = CreateOrGetSettingsKey();
if(key == nullptr)
return;
set(L"UseFXAA",UseFXAA?L"yep":L"no");
set(L"UseComplexRotations",UseComplexRotations?L"yep":L"no");
set(L"ShowText",ShowText?L"yep":L"no");
set(L"Polychoron",Polychoron);
}
void CPolychoraSettings::MaybeLoad()
{
auto & key = CreateOrGetSettingsKey();
if(key == nullptr)
return;
if(!query(L"UseFXAA").empty())
UseFXAA = query(L"UseFXAA") == L"yep";
if(!query(L"ShowText").empty())
ShowText = query(L"ShowText") == L"yep";
if(!query(L"UseComplexRotations").empty())
UseComplexRotations = query(L"UseComplexRotations") == L"yep";
if(!query(L"Polychoron").empty())
Polychoron = query(L"Polychoron");
}
std::wstring CPolychoraSettings::query( const std::wstring & valueName )
{
if(nullptr==regkey)
return L"";
wchar_t buf[256];
DWORD len = sizeof(buf);
if(regkey->QueryStringValue(valueName.c_str(),buf,&len)!=ERROR_SUCCESS)
return L"";
return buf;
}
void CPolychoraSettings::set( const std::wstring & valueName,const std::wstring & value )
{
if(nullptr==regkey)
return;
regkey->SetStringValue(valueName.c_str(),value.c_str());
}