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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
|
#pragma once
static IconItem iconList[] =
{
{ LPGEN("Logo"), "logo", IDI_LOGO },
{ LPGEN("Password"), "password", IDI_ICONPASS },
{ LPGEN("Compact"), "compact", IDI_COMPACT }
};
#define MS_DB_CHANGEPASSWORD "DB/UI/ChangePassword"
#define MS_DB_COMPACT "DB/UI/Compact"
class COptionsDialog : public CDlgBase
{
CCtrlCheck m_chkStandart;
CCtrlCheck m_chkTotal;
CCtrlButton m_btnChangePass;
CDbxMDBX *m_db;
bool OnInitDialog() override
{
m_chkStandart.SetState(!m_db->isEncrypted());
m_chkTotal.SetState(m_db->isEncrypted());
m_btnChangePass.SetTextA(Translate(m_db->GetMenuTitle()));
return true;
}
bool OnApply() override
{
SetCursor(LoadCursor(nullptr, IDC_WAIT));
m_db->EnableEncryption(m_chkTotal.GetState() != 0);
SetCursor(LoadCursor(nullptr, IDC_ARROW));
m_chkStandart.SetState(!m_db->isEncrypted());
m_chkTotal.SetState(m_db->isEncrypted());
return true;
}
void ChangePass(CCtrlButton*)
{
CallService(MS_DB_CHANGEPASSWORD, 0, 0);
}
public:
COptionsDialog(CDbxMDBX *db) :
CDlgBase(g_plugin, IDD_OPTIONS),
m_chkStandart(this, IDC_STANDARD),
m_chkTotal(this, IDC_TOTAL),
m_btnChangePass(this, IDC_USERPASS),
m_db(db)
{
m_btnChangePass.OnClick = Callback(this, &COptionsDialog::ChangePass);
}
};
class CSelectCryptoDialog : public CDlgBase
{
CCtrlCombo m_combo;
CCtrlData m_descr;
CCtrlCheck m_chkTotalCrypt;
CRYPTO_PROVIDER **m_provs;
size_t m_provscount;
CRYPTO_PROVIDER *m_selected;
bool m_bTotalEncryption;
bool OnInitDialog() override
{
for (size_t i = 0; i < m_provscount; i++) {
CRYPTO_PROVIDER *prov = m_provs[i];
m_combo.AddStringA(prov->pszName, i);
}
m_combo.SetCurSel(0);
m_descr.SetText(m_provs[0]->szDescr.w);
return true;
}
bool OnClose() override
{
m_selected = m_provs[m_combo.GetItemData(m_combo.GetCurSel())];
m_bTotalEncryption = m_chkTotalCrypt.GetState() != 0;
return true;
}
void OnComboChanged(CCtrlCombo*)
{
m_descr.SetText(m_provs[m_combo.GetItemData(m_combo.GetCurSel())]->szDescr.w);
}
public:
CSelectCryptoDialog(CRYPTO_PROVIDER **provs, size_t count) :
CDlgBase(g_plugin, IDD_SELECT_CRYPTOPROVIDER),
m_combo(this, IDC_SELECTCRYPT_COMBO),
m_descr(this, IDC_CRYPTOPROVIDER_DESCR),
m_chkTotalCrypt(this, IDC_CHECK_TOTALCRYPT),
m_provs(provs),
m_provscount(count),
m_selected(nullptr)
{
m_combo.OnChange = Callback(this, &CSelectCryptoDialog::OnComboChanged);
}
inline CRYPTO_PROVIDER* GetSelected()
{
return m_selected;
}
inline bool TotalSelected()
{
return m_bTotalEncryption;
}
};
struct DlgChangePassParam
{
CDbxMDBX *db;
TCHAR newPass[100];
unsigned short wrongPass;
};
class CEnterPasswordDialog : public CDlgBase
{
CCtrlData m_header;
CCtrlData m_language;
CCtrlEdit m_passwordEdit;
CCtrlButton m_buttonOK;
DlgChangePassParam *m_param;
INT_PTR DlgProc(UINT msg, WPARAM wParam, LPARAM lParam) override
{
if (msg == WM_TIMER) {
UINT_PTR LangID = (UINT_PTR)GetKeyboardLayout(0);
char Lang[3] = { 0 };
GetLocaleInfoA(MAKELCID((LangID & 0xffffffff), SORT_DEFAULT), LOCALE_SABBREVLANGNAME, Lang, 2);
Lang[0] = toupper(Lang[0]);
Lang[1] = tolower(Lang[1]);
m_language.SetTextA(Lang);
return FALSE;
}
else if (msg == WM_CTLCOLORSTATIC) {
if ((HWND)lParam == m_language.GetHwnd()) {
SetTextColor((HDC)wParam, GetSysColor(COLOR_HIGHLIGHTTEXT));
SetBkMode((HDC)wParam, TRANSPARENT);
return (INT_PTR)GetSysColorBrush(COLOR_HIGHLIGHT);
}
}
return CDlgBase::DlgProc(msg, wParam, lParam);
}
bool OnInitDialog() override
{
m_header.SendMsg(WM_SETICON, ICON_SMALL, (LPARAM)LoadIcon(g_plugin.getInst(), MAKEINTRESOURCE(iconList[0].defIconID)));
if (m_param->wrongPass) {
if (m_param->wrongPass > 2) {
m_passwordEdit.Disable();
m_buttonOK.Disable();
m_header.SetText(TranslateT("Too many errors!"));
}
else m_header.SetText(TranslateT("Password is not correct!"));
}
else m_header.SetText(TranslateT("Please type in your password"));
SetTimer(m_hwnd, 1, 200, nullptr);
return true;
}
void OnDestroy() override
{
KillTimer(m_hwnd, 1);
}
void OnOK(CCtrlButton*)
{
m_passwordEdit.GetText(m_param->newPass, _countof(m_param->newPass));
EndDialog(m_hwnd, -128);
}
public:
CEnterPasswordDialog(DlgChangePassParam *param) :
CDlgBase(g_plugin, IDD_LOGIN),
m_header(this, IDC_HEADERBAR),
m_language(this, IDC_LANG),
m_passwordEdit(this, IDC_USERPASS),
m_buttonOK(this, IDOK),
m_param(param)
{
m_buttonOK.OnClick = Callback(this, &CEnterPasswordDialog::OnOK);
}
};
|