ReactOS  0.4.15-dev-4934-gfd1e799
CConfigParser Class Reference

#include <configparser.h>

Collaboration diagram for CConfigParser:

Public Member Functions

 CConfigParser (const ATL::CStringW &FileName)
 
BOOL GetString (const ATL::CStringW &KeyName, ATL::CStringW &ResultString)
 
BOOL GetInt (const ATL::CStringW &KeyName, INT &iResult)
 

Private Member Functions

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

Private Attributes

const ATL::CStringW szConfigPath
 
CSimpleMap< CStringW, CStringWm_Keys
 

Detailed Description

Definition at line 6 of file configparser.h.

Constructor & Destructor Documentation

◆ CConfigParser()

CConfigParser::CConfigParser ( const ATL::CStringW FileName)

Definition at line 40 of file configparser.cpp.

42 {
43  CacheINI();
44 }
static ATL::CStringW GetINIFullPath(const ATL::CStringW &FileName)
const ATL::CStringW szConfigPath
Definition: configparser.h:8

Member Function Documentation

◆ CacheINI()

VOID CConfigParser::CacheINI ( )
private

Definition at line 102 of file configparser.cpp.

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

Referenced by CConfigParser().

◆ GetInt()

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

Definition at line 160 of file configparser.cpp.

161 {
163 
164  iResult = 0;
165 
166  // grab the text version of our entry
167  if (!GetString(KeyName, Buffer))
168  return FALSE;
169 
170  if (Buffer.IsEmpty())
171  return FALSE;
172 
173  // convert it to an actual integer
174  iResult = StrToIntW(Buffer.GetString());
175 
176  // we only care about values > 0
177  return (iResult > 0);
178 }
IN BOOLEAN OUT PSTR Buffer
Definition: progress.h:34
#define FALSE
Definition: types.h:117
Definition: bufpool.h:45
_Must_inspect_result_ _In_ WDFDEVICE _In_ PCUNICODE_STRING KeyName
Definition: wdfdevice.h:2697
BOOL GetString(const ATL::CStringW &KeyName, ATL::CStringW &ResultString)
INT WINAPI StrToIntW(LPCWSTR lpString)
Definition: string.c:411

Referenced by CAvailableApplicationInfo::RetrieveGeneralInfo(), CAvailableApplicationInfo::RetrieveLicenseType(), and CAvailableApplicationInfo::RetrieveSize().

◆ GetString()

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

Definition at line 147 of file configparser.cpp.

148 {
149  int nIndex = m_Keys.FindKey(KeyName);
150  if (nIndex >= 0)
151  {
152  ResultString = m_Keys.GetValueAt(nIndex);
153  return TRUE;
154  }
155 
156  ResultString.Empty();
157  return FALSE;
158 }
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
_Must_inspect_result_ _In_ WDFDEVICE _In_ PCUNICODE_STRING KeyName
Definition: wdfdevice.h:2697
CSimpleMap< CStringW, CStringW > m_Keys
Definition: configparser.h:9
TVal & GetValueAt(int nIndex)
Definition: atlsimpcoll.h:358
int FindKey(const TKey &key) const
Definition: atlsimpcoll.h:315

Referenced by GetInt(), CAvailableApplicationInfo::GetString(), and CAvailableApplicationInfo::RetrieveLanguages().

◆ ReadSection()

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

Definition at line 46 of file configparser.cpp.

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

Referenced by CacheINI().

Member Data Documentation

◆ m_Keys

CSimpleMap<CStringW, CStringW> CConfigParser::m_Keys
private

Definition at line 9 of file configparser.h.

Referenced by GetString(), and ReadSection().

◆ szConfigPath

const ATL::CStringW CConfigParser::szConfigPath
private

Definition at line 8 of file configparser.h.

Referenced by ReadSection().


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