ReactOS 0.4.15-dev-7788-g1ad9096
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)
 

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 28 of file configparser.cpp.

29{
30 CacheINI();
31}
PCWSTR FilePath
const CStringW szConfigPath
Definition: configparser.h:7

Member Function Documentation

◆ CacheINI()

VOID CConfigParser::CacheINI ( )
private

Definition at line 91 of file configparser.cpp.

92{
93 // Cache section names
95 {
96 CString szLocaleID;
97 const INT cchLocaleSize = 5;
98
99 GetLocaleInfoW(GetUserDefaultLCID(), LOCALE_ILANGUAGE, szLocaleID.GetBuffer(cchLocaleSize), cchLocaleSize);
100 szLocaleID.ReleaseBuffer();
101 CString INISectionLocale = L"Section." + szLocaleID;
102
103 g_Names.ArchSpecific.Locale = INISectionLocale + L"." CurrentArchitecture;
104 g_Names.ArchNeutral.Locale = INISectionLocale;
105
106 // turn "Section.0c0a" into "Section.0a", keeping just the neutral lang part
107 if (szLocaleID.GetLength() >= 2)
108 {
109 g_Names.ArchSpecific.LocaleNeutral = L"Section." + szLocaleID.Right(2) + L"." CurrentArchitecture;
110 g_Names.ArchNeutral.LocaleNeutral = L"Section." + szLocaleID.Right(2);
111 }
112
113 g_Names.ArchSpecific.Section = L"Section." CurrentArchitecture;
114 g_Names.ArchNeutral.Section = L"Section";
115 }
116
117 // Use a shared buffer so that we don't have to re-allocate it every time
119
122 {
124 }
126
129 {
131 }
133}
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: lang.c:778
INT WINAPI GetLocaleInfoW(LCID lcid, LCTYPE lctype, LPWSTR buffer, INT len)
Definition: lang.c:1108
#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 150 of file configparser.cpp.

151{
153
154 iResult = 0;
155
156 // grab the text version of our entry
157 if (!GetString(KeyName, Buffer))
158 return FALSE;
159
160 if (Buffer.IsEmpty())
161 return FALSE;
162
163 // convert it to an actual integer
164 iResult = StrToIntW(Buffer.GetString());
165
166 // we only care about values > 0
167 return (iResult > 0);
168}
BOOL GetString(const CStringW &KeyName, CStringW &ResultString)
INT WINAPI StrToIntW(LPCWSTR lpString)
Definition: string.c:411
_Must_inspect_result_ _In_ WDFDEVICE _In_ PCUNICODE_STRING KeyName
Definition: wdfdevice.h:2699

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

◆ GetString()

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

Definition at line 136 of file configparser.cpp.

137{
138 int nIndex = m_Keys.FindKey(KeyName);
139 if (nIndex >= 0)
140 {
141 ResultString = m_Keys.GetValueAt(nIndex);
142 return TRUE;
143 }
144
145 ResultString.Empty();
146 return FALSE;
147}
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(), CAvailableApplicationInfo::GetDownloadInfo(), 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 34 of file configparser.cpp.

35{
36 DWORD len = 512;
38
39 do
40 {
41 len *= 2;
42
44 Buffer.ReleaseBuffer(result);
45 } while (result == len - 2);
46
47 len = 0;
48 while (len < result)
49 {
50 // Explicitly use the null terminator!
51 CString tmp = Buffer.GetBuffer() + len;
52 if (tmp.GetLength() > 0)
53 {
54 len += tmp.GetLength() + 1;
55
56 int idx = tmp.Find('=');
57 if (idx >= 0)
58 {
59 CString key = tmp.Left(idx);
60
61#ifndef _M_IX86
62 // On non-x86 architecture we need the architecture specific URL
63 if (!isArch && key == "URLDownload")
64 {
65 continue;
66 }
67#endif
68
69 // Is this key already present from a more specific translation?
70 if (m_Keys.FindKey(key) >= 0)
71 {
72 continue;
73 }
74
75 CString value = tmp.Mid(idx + 1);
77 }
78 else
79 {
80 DPRINT1("ERROR: invalid key/value pair: '%S'\n", tmp.GetString());
81 }
82 }
83 else
84 {
85 break;
86 }
87 }
88}
#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 ReadSection().


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