forked from epsylon3/odbgscript
-
Notifications
You must be signed in to change notification settings - Fork 0
/
IniReader.cpp
112 lines (90 loc) · 2.97 KB
/
IniReader.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
108
109
110
111
112
// IniReader.cpp: implementation of the CIniReader class.
//
//////////////////////////////////////////////////////////////////////
//unable to debug with CString !!?
#ifdef _DEBUG
#undef _DEBUG
#endif
#include "StdAfx.h"
#include "IniReader.h"
#include <afxcoll.h>
//#ifdef _DEBUG
//#undef THIS_FILE
//static char THIS_FILE[]=__FILE__;
//#define new DEBUG_NEW
//#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
// Used to retrieve a value give the section and key
CString CIniReader::getKeyValue(CString strKey,CString strSection)
{
wchar_t ac_Result[255];
// Get the info from the .ini file
m_lRetValue = GetPrivateProfileString((LPCTSTR)strSection,(LPCTSTR)strKey,
L"",ac_Result, 255, (LPCTSTR)m_strFileName);
CString strResult(ac_Result);
return strResult;
}
// Used to add or set a key value pair to a section
long CIniReader::setKey(CString strValue, CString strKey, CString strSection)
{
m_lRetValue = WritePrivateProfileString (strSection, strKey,
strValue, m_strFileName);
return m_lRetValue;
}
// Used to find out if a given section exists
BOOL CIniReader::sectionExists(CString strSection)
{
wchar_t ac_Result[100];
CString csAux;
// Get the info from the .ini file
m_lRetValue = GetPrivateProfileString((LPCTSTR)strSection,NULL,
L"",ac_Result, 90, (LPCTSTR)m_strFileName);
// Return if we could retrieve any info from that section
return (m_lRetValue > 0);
}
// Used to retrieve all of the section names in the ini file
CStringList* CIniReader::getSectionNames() //returns collection of section names
{
wchar_t ac_Result[2000];
m_sectionList->RemoveAll();
m_lRetValue = GetPrivateProfileSectionNames(ac_Result,2000,(LPCTSTR)m_strFileName);
CString strSectionName;
for(int i=0; i<m_lRetValue; i++)
{
if(ac_Result[i] != '\0') {
strSectionName = strSectionName + ac_Result[i];
} else {
if(strSectionName != L"") {
m_sectionList->InsertAfter(m_sectionList->GetTailPosition(),strSectionName);
}
strSectionName = L"";
}
}
return m_sectionList;
}
// Used to retrieve all key/value pairs of a given section.
CStringList* CIniReader::getSectionData(CString strSection)
{
wchar_t ac_Result[2000]; //change size depending on needs
m_sectionDataList->RemoveAll();
m_lRetValue = GetPrivateProfileSection((LPCTSTR)strSection, ac_Result, 2000, (LPCTSTR)m_strFileName);
CString strSectionData;
for(int i=0; i<m_lRetValue; i++)
{
if(ac_Result[i] != '\0') {
strSectionData = strSectionData + ac_Result[i];
} else {
if(strSectionData != L"") {
m_sectionDataList->InsertAfter(m_sectionDataList->GetTailPosition(),strSectionData);
}
strSectionData = L"";
}
}
return m_sectionDataList;
}
void CIniReader::setINIFileName(CString strINIFile)
{
m_strFileName = strINIFile;
}