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
|
#include "_globals.h"
#include "mirandasettings.h"
MirandaSettings::MirandaSettings()
: m_hContact(0)
{
}
bool MirandaSettings::readBool(const mu_ansi* szSetting, bool bDefault) const
{
return (readByte(szSetting, bDefault ? 1 : 0) != 0);
}
int MirandaSettings::readByte(const mu_ansi* szSetting, int bDefault) const
{
return db_get_b(m_hContact, m_strModule.c_str(), szSetting, bDefault);
}
int MirandaSettings::readWord(const mu_ansi* szSetting, int wDefault) const
{
return db_get_w(m_hContact, m_strModule.c_str(), szSetting, wDefault);
}
int MirandaSettings::readDWord(const mu_ansi* szSetting, int dwDefault) const
{
return db_get_dw(m_hContact, m_strModule.c_str(), szSetting, dwDefault);
}
ext::string MirandaSettings::readStr(const mu_ansi* szSetting, const mu_text* szDefault) const
{
DBVARIANT dbv;
if (db_get_s(m_hContact, m_strModule.c_str(), szSetting, &dbv))
return szDefault;
ext::string str = (dbv.type != DBVT_ASCIIZ) ? szDefault : utils::fromUTF8(dbv.pszVal);
db_free(&dbv);
return str;
}
ext::string MirandaSettings::readStrDirect(const mu_ansi* szSetting, const mu_text* szDefault) const
{
DBVARIANT dbv;
ZeroMemory(&dbv, sizeof(dbv));
dbv.type = DBVT_WCHAR;
if (db_get_s(m_hContact, m_strModule.c_str(), szSetting, &dbv, 0))
return szDefault;
ext::string str;
switch (dbv.type) {
case DBVT_ASCIIZ:
str = utils::fromA(dbv.pszVal);
break;
case DBVT_WCHAR:
str = utils::fromW(dbv.pwszVal);
break;
case DBVT_UTF8:
str = utils::fromUTF8(dbv.pszVal);
break;
default:
str = szDefault;
break;
}
db_free(&dbv);
return str;
}
void MirandaSettings::readTree(const mu_ansi* szSetting, const mu_text* szDefault, SettingsTree& value) const
{
value.fromString(readStr(szSetting, szDefault));
}
void MirandaSettings::writeBool(const mu_ansi* szSetting, bool bValue) const
{
writeByte(szSetting, bValue ? 1 : 0);
}
void MirandaSettings::writeByte(const mu_ansi* szSetting, int bValue) const
{
db_set_b(m_hContact, m_strModule.c_str(), szSetting, bValue);
}
void MirandaSettings::writeWord(const mu_ansi* szSetting, int wValue) const
{
db_set_w(m_hContact, m_strModule.c_str(), szSetting, wValue);
}
void MirandaSettings::writeDWord(const mu_ansi* szSetting, int dwValue) const
{
db_set_dw(m_hContact, m_strModule.c_str(), szSetting, dwValue);
}
void MirandaSettings::writeStr(const mu_ansi* szSetting, const mu_text* szValue) const
{
db_set_ts(m_hContact, m_strModule.c_str(), szSetting, szValue);
}
void MirandaSettings::writeStrDirect(const mu_ansi* szSetting, const mu_text* szValue) const
{
db_set_ts(m_hContact, m_strModule.c_str(), szSetting, szValue);
}
void MirandaSettings::writeTree(const mu_ansi* szSetting, const SettingsTree& value) const
{
writeStr(szSetting, value.toString().c_str());
}
bool MirandaSettings::settingExists(const mu_ansi* szSetting) const
{
DBVARIANT dbv;
if (db_get_s(m_hContact, m_strModule.c_str(), szSetting, &dbv, 0))
return false;
db_free(&dbv);
return true;
}
bool MirandaSettings::delSetting(const mu_ansi* szSetting)
{
return db_unset(m_hContact, m_strModule.c_str(), szSetting) == 0;
}
int MirandaSettings::enumSettingsProc(const mu_ansi* szSetting, LPARAM lParam)
{
SetInserter* pInserter = reinterpret_cast<SetInserter*>(lParam);
*pInserter = szSetting;
return 0;
}
void MirandaSettings::enumSettings(SetInserter& insertIterator)
{
mu::db_contact::enumSettings(m_hContact, m_strModule.c_str(), enumSettingsProc, reinterpret_cast<LPARAM>(&insertIterator));
}
|