-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIniFile.cpp
More file actions
205 lines (186 loc) · 4.4 KB
/
Copy pathIniFile.cpp
File metadata and controls
205 lines (186 loc) · 4.4 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
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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
#include "IniFile.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
////////////////////////////////////////////////////////////////////////////////////////
void CIniFile::ReadSection(StringArray& setArray)
{
char szBuf[1024*64];
memset(szBuf, 0, sizeof(szBuf));
char* p = szBuf;
int nLen = 0;
if (GetPrivateProfileStringA(NULL, NULL, "", szBuf, sizeof(szBuf)/sizeof(char), m_strFile.c_str()) > 0)
{
while (*p != '\0')
{
setArray.push_back(p);
nLen = (int)strlen(p) + 1;
p += nLen;
}
}
}
bool CIniFile::ReadSectionKey(StringArray& setArray, const char* pSection)
{
char szBuf[1024*64] = {0};
char* p = szBuf;
int nLen = 0;
if (!pSection)
{
if (!m_pCurrentSection)
return false;
else
pSection = m_pCurrentSection;
}
if (GetPrivateProfileStringA(pSection, NULL, "", szBuf, sizeof(szBuf)/sizeof(char), m_strFile.c_str()) > 0)
{
while (*p != '\0')
{
setArray.push_back(p);
nLen = (int)strlen(p) + 1;
p += nLen;
}
}
return true;
}
bool CIniFile::ReadSectionString(StringArray& setArray, const char* pSection)
{
if (!pSection)
{
if (!m_pCurrentSection)
return false;
else
pSection = m_pCurrentSection;
}
StringArray ayKey;
std::string strItem;
ReadSectionKey(ayKey,pSection);
for (int i = 0; i< ayKey.size(); ++i)
{
ReadKey(ayKey[i], strItem,pSection);
if (strItem.size())
setArray.push_back(strItem);
}
return true;
}
bool CIniFile::ReadKey(const char* pKey,std::string& strItem, const char* pSection)
{
if (!pSection)
{
if (!m_pCurrentSection)
return false;
else
pSection = m_pCurrentSection;
}
char szReturn[1024*4];
memset(szReturn, 0, sizeof(szReturn));
strItem.clear();
if (GetPrivateProfileStringA(pSection, pKey, "", szReturn, _countof(szReturn), m_strFile.c_str()) > 0)
{
strItem = szReturn;
}
return true;
}
bool CIniFile::ReadKey(std::string& pKey, std::string& strItem, const char* pSection)
{
if (!pSection)
{
if (!m_pCurrentSection)
return false;
else
pSection = m_pCurrentSection;
}
char szReturn[1024 * 4];
memset(szReturn, 0, sizeof(szReturn));
strItem.clear();
if (GetPrivateProfileStringA(pSection, pKey.c_str(), "",szReturn, _countof(szReturn),m_strFile.c_str()) > 0)
{
strItem = szReturn;
}
return true;
}
bool CIniFile::ReadKey(const char* pKey, int& nValue, const char* pSection)
{
if (!pSection)
{
if (!m_pCurrentSection)
return false;
else
pSection = m_pCurrentSection;
}
char szReturn[32];
memset(szReturn, 0, sizeof(szReturn));
if (GetPrivateProfileStringA(pSection, pKey, "", szReturn, _countof(szReturn),m_strFile.c_str()) > 0)
nValue = strtol(szReturn,nullptr,10);
else
nValue = 0;
return true;
}
bool CIniFile::ReadKey(const char* pKey, short& nValue, const char* pSection)
{
if (!pSection)
{
if (!m_pCurrentSection)
return false;
else
pSection = m_pCurrentSection;
}
int nIntValue = 0;
ReadKey( pKey, nIntValue,pSection);
nValue = (short)nIntValue;
return true;
}
bool CIniFile::WriteKey(const char* pKey, const char* pItem, const char* pSection)
{
if (!pSection)
{
if (!m_pCurrentSection)
return false;
else
pSection = m_pCurrentSection;
}
WritePrivateProfileStringA(pSection, pKey, pItem, m_strFile.c_str());
return true;
}
bool CIniFile::WriteKey(const char* pKey, std::string pItem, const char* pSection)
{
if (!pSection)
{
if (!m_pCurrentSection)
return false;
else
pSection = m_pCurrentSection;
}
WritePrivateProfileStringA(pSection, pKey, pItem.c_str(), m_strFile.c_str());
return true;
}
bool CIniFile::EraseKey(const char* pKey, const char* pSection)
{
if (!pSection)
{
if (!m_pCurrentSection)
return false;
else
pSection = m_pCurrentSection;
}
WritePrivateProfileStringA(pSection, pKey, NULL, m_strFile.c_str());
return true;
}
bool CIniFile::WriteKey(const char* pKey, int nValue, const char* pSection)
{
if (!pSection)
{
if (!m_pCurrentSection)
return false;
else
pSection = m_pCurrentSection;
}
char szValue[32];
sprintf(szValue, "%d", nValue);
WriteKey( pKey, szValue,pSection);
return true;
}
void CIniFile::EraseSection(const char* pSection)
{
WritePrivateProfileStructA(pSection, NULL, NULL, 0, m_strFile.c_str());
}
////////////////////////////////////////////////////////////////////////////////////////