-
Notifications
You must be signed in to change notification settings - Fork 151
/
IniHelper.cpp
107 lines (88 loc) · 2.17 KB
/
IniHelper.cpp
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
#pragma once
#include "IniHelper.h"
#include "Base.cpp"
BOOL IniReadString(LPCWSTR FilePath, LPCWSTR KeyPath, LPCWSTR ValueName, CString& Str)
{
int cchData = Str.GetAllocLength()>100 ? Str.GetAllocLength() : 100;
while (auto chNewData = GetPrivateProfileStringW(KeyPath, ValueName, NULL, Str.GetBuffer(cchData), cchData, FilePath))
{
if (cchData - chNewData <= 2)
{
//³ÖÐø¼Ó´ó»º³åÇø
cchData *= 2;
}
else
{
Str.ReleaseBuffer(chNewData);
return TRUE;
}
}
return FALSE;
}
BOOL IniReadBinaryData(LPCWSTR FilePath, LPCWSTR KeyPath, LPCWSTR ValueName, CStringA& Data)
{
CString Buffer;
if (IniReadString(FilePath, KeyPath, ValueName, Buffer) == 0)
{
return FALSE;
}
else
{
Data = HexString2Binary(Buffer);
return TRUE;
}
}
BOOL IniWriteString(LPCWSTR FilePath, LPCWSTR KeyPath, LPCWSTR ValueName, LPCWSTR Str)
{
return WritePrivateProfileStringW(KeyPath, ValueName, Str, FilePath);
}
BOOL IniWriteBinaryData(LPCWSTR FilePath, LPCWSTR KeyPath, LPCWSTR ValueName, const void*pBinaryData, DWORD ccbData)
{
return WritePrivateProfileStringW(KeyPath, ValueName, Binary2String((byte*)pBinaryData, ccbData), FilePath);
}
BOOL IniDeleteString(LPCWSTR FilePath, LPCWSTR KeyPath, LPCWSTR ValueName)
{
return WritePrivateProfileStringW(KeyPath, ValueName, NULL, FilePath);
}
BOOL IniDeleteSection(
LPCWSTR FilePath,
LPCWSTR KeyPath
)
{
return WritePrivateProfileStringW(KeyPath, NULL, NULL, FilePath);
}
BOOL IniGetSectionNames(LPCWSTR FilePath, CString& Names)
{
int cchData = Names.GetAllocLength()>100 ? Names.GetAllocLength() : 100;
while (auto chNewData = GetPrivateProfileSectionNamesW(Names.GetBuffer(cchData), cchData, FilePath))
{
if (cchData - chNewData == 2)
{
cchData *= 2;
}
else
{
Names.ReleaseBuffer(chNewData);
return TRUE;
}
}
return FALSE;
}
BOOL IniGetValues(LPCWSTR FilePath, LPCWSTR Path, CString& Values)
{
Values.GetBuffer(1024);
int cchData = Values.GetAllocLength();
while (auto chNewData = GetPrivateProfileSectionW(Path, Values.GetBuffer(cchData), cchData, FilePath))
{
if (cchData - chNewData == 2)
{
cchData *= 2;
}
else
{
Values.ReleaseBuffer(chNewData);
return TRUE;
}
}
return FALSE;
}