ReactOS 0.4.16-dev-125-g798ea90
CConfigParser Class Reference

#include <configparser.h>

Collaboration diagram for CConfigParser:

Public Member Functions

 CConfigParser (const CStringW &FilePath)
 
BOOL GetString (const CStringW &KeyName, CStringW &ResultString)
 
BOOL GetInt (const CStringW &KeyName, INT &iResult)
 
UINT GetSectionString (LPCWSTR Section, LPCWSTR Name, CStringW &Result)
 

Private Member Functions

void CacheINI ()
 
void ReadSection (CStringW &Buffer, const CStringW &Section, BOOL isArch)
 

Private Attributes

const CStringW szConfigPath
 
CSimpleMap< CStringW, CStringWm_Keys
 

Detailed Description

Definition at line 5 of file configparser.h.

Constructor & Destructor Documentation

◆ CConfigParser()

CConfigParser::CConfigParser ( const CStringW FilePath)

Definition at line 42 of file configparser.cpp.

43{
44 CacheINI();
45}
PCWSTR FilePath
const CStringW szConfigPath
Definition: configparser.h:7

Member Function Documentation

◆ CacheINI()

VOID CConfigParser::CacheINI ( )
private

Definition at line 105 of file configparser.cpp.

106{
107 // Cache section names
109 {
110 CString szLocaleID;
111 const INT cchLocaleSize = 5;
112
113 GetLocaleInfoW(GetUserDefaultLCID(), LOCALE_ILANGUAGE, szLocaleID.GetBuffer(cchLocaleSize), cchLocaleSize);
114 szLocaleID.ReleaseBuffer();
115 CString INISectionLocale = L"Section." + szLocaleID;
116
117 g_Names.ArchSpecific.Locale = INISectionLocale + L"." CurrentArchitecture;
118 g_Names.ArchNeutral.Locale = INISectionLocale;
119
120 // turn "Section.0c0a" into "Section.0a", keeping just the neutral lang part
121 if (szLocaleID.GetLength() >= 2)
122 {
123 g_Names.ArchSpecific.LocaleNeutral = L"Section." + szLocaleID.Right(2) + L"." CurrentArchitecture;
124 g_Names.ArchNeutral.LocaleNeutral = L"Section." + szLocaleID.Right(2);
125 }
126
127 g_Names.ArchSpecific.Section = L"Section." CurrentArchitecture;
128 g_Names.ArchNeutral.Section = L"Section";
129 }
130
131 // Use a shared buffer so that we don't have to re-allocate it every time
133
136 {
138 }
140
143 {
145 }
147}
bool IsEmpty() const noexcept
Definition: atlsimpstr.h:394
void ReleaseBuffer(_In_ int nNewLength=-1)
Definition: atlsimpstr.h:387
Definition: bufpool.h:45
void ReadSection(CStringW &Buffer, const CStringW &Section, BOOL isArch)
static CSectionNames g_Names
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
LCID WINAPI GetUserDefaultLCID(void)
Definition: locale.c:1210
INT WINAPI GetLocaleInfoW(LCID lcid, LCTYPE lctype, LPWSTR buffer, INT len)
Definition: locale.c:1665
#define L(x)
Definition: ntvdm.h:50
CStringW LocaleNeutral
CLocaleSections ArchSpecific
CLocaleSections ArchNeutral
int32_t INT
Definition: typedefs.h:58
#define LOCALE_ILANGUAGE
Definition: winnls.h:25

Referenced by CConfigParser().

◆ GetInt()

BOOL CConfigParser::GetInt ( const CStringW KeyName,
INT iResult 
)

Definition at line 164 of file configparser.cpp.

165{
167
168 iResult = 0;
169
170 // grab the text version of our entry
171 if (!GetString(KeyName, Buffer))
172 return FALSE;
173
174 if (Buffer.IsEmpty())
175 return FALSE;
176
177 // convert it to an actual integer
178 iResult = StrToIntW(Buffer.GetString());
179
180 // we only care about values > 0
181 return (iResult > 0);
182}
BOOL GetString(const CStringW &KeyName, CStringW &ResultString)
INT WINAPI StrToIntW(LPCWSTR lpString)
Definition: string.c:407
_Must_inspect_result_ _In_ WDFDEVICE _In_ PCUNICODE_STRING KeyName
Definition: wdfdevice.h:2699

Referenced by CAvailableApplicationInfo::CAvailableApplicationInfo(), CAppDB::EnumerateFiles(), CAvailableApplicationInfo::GetDownloadInfo(), and CAvailableApplicationInfo::LicenseString().

◆ GetSectionString()

UINT CConfigParser::GetSectionString ( LPCWSTR  Section,
LPCWSTR  Name,
CStringW Result 
)

Definition at line 185 of file configparser.cpp.

186{
187 HRESULT hr; // Return value; length of ini string or 0 on failure.
188 CStringW SecBuf;
189 WCHAR FullLoc[5], *NeutralLoc = FullLoc + 2;
191
192 SecBuf.Format(L"%s.%s.%s", Section, FullLoc, CurrentArchitecture);
193 if ((hr = ReadIniValue(szConfigPath, SecBuf, Name, Result)) > 0)
194 return hr;
195
196 if (*NeutralLoc)
197 {
198 SecBuf.Format(L"%s.%s.%s", Section, NeutralLoc, CurrentArchitecture);
199 if ((hr = ReadIniValue(szConfigPath, SecBuf, Name, Result)) > 0)
200 return hr;
201 }
202
203 SecBuf.Format(L"%s.%s", Section, CurrentArchitecture);
204 if ((hr = ReadIniValue(szConfigPath, SecBuf, Name, Result)) > 0)
205 return hr;
206
207 SecBuf.Format(L"%s.%s", Section, FullLoc);
208 if ((hr = ReadIniValue(szConfigPath, SecBuf, Name, Result)) > 0)
209 return hr;
210
211 if (*NeutralLoc)
212 {
213 SecBuf.Format(L"%s.%s", Section, NeutralLoc);
214 if ((hr = ReadIniValue(szConfigPath, SecBuf, Name, Result)) > 0)
215 return hr;
216 }
217
218 if ((hr = ReadIniValue(szConfigPath, Section, Name, Result)) > 0)
219 return hr;
220 return 0;
221}
void __cdecl Format(UINT nFormatID,...)
Definition: cstringt.h:818
HRESULT ReadIniValue(LPCWSTR File, LPCWSTR Section, LPCWSTR Name, CStringW &Output)
HRESULT hr
Definition: shlfolder.c:183
#define _countof(array)
Definition: sndvol32.h:70
_At_(*)(_In_ PWSK_CLIENT Client, _In_opt_ PUNICODE_STRING NodeName, _In_opt_ PUNICODE_STRING ServiceName, _In_opt_ ULONG NameSpace, _In_opt_ GUID *Provider, _In_opt_ PADDRINFOEXW Hints, _Outptr_ PADDRINFOEXW *Result, _In_opt_ PEPROCESS OwningProcess, _In_opt_ PETHREAD OwningThread, _Inout_ PIRP Irp Result)(Mem)) NTSTATUS(WSKAPI *PFN_WSK_GET_ADDRESS_INFO
Definition: wsk.h:409
__wchar_t WCHAR
Definition: xmlstorage.h:180

Referenced by GetGenerateString().

◆ GetString()

BOOL CConfigParser::GetString ( const CStringW KeyName,
CStringW ResultString 
)

Definition at line 150 of file configparser.cpp.

151{
152 int nIndex = m_Keys.FindKey(KeyName);
153 if (nIndex >= 0)
154 {
155 ResultString = m_Keys.GetValueAt(nIndex);
156 return TRUE;
157 }
158
159 ResultString.Empty();
160 return FALSE;
161}
TVal & GetValueAt(int nIndex)
Definition: atlsimpcoll.h:358
int FindKey(const TKey &key) const
Definition: atlsimpcoll.h:315
void Empty() noexcept
Definition: atlsimpstr.h:253
CSimpleMap< CStringW, CStringW > m_Keys
Definition: configparser.h:8

Referenced by CAvailableApplicationInfo::CAvailableApplicationInfo(), GetCommonString(), CAvailableApplicationInfo::GetDownloadInfo(), CAvailableApplicationInfo::GetInstallerType(), GetInt(), CAvailableApplicationInfo::InsertVersionInfo(), CAvailableApplicationInfo::LicenseString(), CAvailableApplicationInfo::RetrieveLanguages(), and CAvailableApplicationInfo::RetrieveScreenshot().

◆ ReadSection()

void CConfigParser::ReadSection ( CStringW Buffer,
const CStringW Section,
BOOL  isArch 
)
private

Definition at line 48 of file configparser.cpp.

49{
50 DWORD len = 512;
52
53 do
54 {
55 len *= 2;
56
58 Buffer.ReleaseBuffer(result);
59 } while (result == len - 2);
60
61 len = 0;
62 while (len < result)
63 {
64 // Explicitly use the null terminator!
65 CString tmp = Buffer.GetBuffer() + len;
66 if (tmp.GetLength() > 0)
67 {
68 len += tmp.GetLength() + 1;
69
70 int idx = tmp.Find('=');
71 if (idx >= 0)
72 {
73 CString key = tmp.Left(idx);
74
75#ifndef _M_IX86
76 // On non-x86 architecture we need the architecture specific URL
77 if (!isArch && key == "URLDownload")
78 {
79 continue;
80 }
81#endif
82
83 // Is this key already present from a more specific translation?
84 if (m_Keys.FindKey(key) >= 0)
85 {
86 continue;
87 }
88
89 CString value = tmp.Mid(idx + 1);
91 }
92 else
93 {
94 DPRINT1("ERROR: invalid key/value pair: '%S'\n", tmp.GetString());
95 }
96 }
97 else
98 {
99 break;
100 }
101 }
102}
#define DPRINT1
Definition: precomp.h:8
BOOL Add(const TKey &key, const TVal &val)
Definition: atlsimpcoll.h:309
PXSTR GetString() noexcept
Definition: atlsimpstr.h:367
int GetLength() const noexcept
Definition: atlsimpstr.h:362
CStringT Left(int nCount) const
Definition: cstringt.h:776
int Find(_In_ PCXSTR pszSub, _In_opt_ int iStart=0) const noexcept
Definition: cstringt.h:696
CStringT Mid(int iFirst, int nCount) const
Definition: cstringt.h:748
unsigned int idx
Definition: utils.c:41
INT WINAPI GetPrivateProfileSectionW(LPCWSTR section, LPWSTR buffer, DWORD len, LPCWSTR filename)
Definition: profile.c:1351
unsigned long DWORD
Definition: ntddk_ex.h:95
GLenum GLsizei len
Definition: glext.h:6722
GLuint64EXT * result
Definition: glext.h:11304
Definition: copy.c:22
Definition: pdh_main.c:94

Referenced by CacheINI().

Member Data Documentation

◆ m_Keys

CSimpleMap<CStringW, CStringW> CConfigParser::m_Keys
private

Definition at line 8 of file configparser.h.

Referenced by GetString(), and ReadSection().

◆ szConfigPath

const CStringW CConfigParser::szConfigPath
private

Definition at line 7 of file configparser.h.

Referenced by GetSectionString(), and ReadSection().


The documentation for this class was generated from the following files: