ReactOS 0.4.15-dev-8058-ga7cbb60
configparser.cpp
Go to the documentation of this file.
1/*
2 * PROJECT: ReactOS Applications Manager
3 * LICENSE: GPL-2.0-or-later (https://spdx.org/licenses/GPL-2.0-or-later)
4 * PURPOSE: Config parser
5 * COPYRIGHT: Copyright 2009 Dmitry Chapyshev (dmitry@reactos.org)
6 * Copyright 2015 Ismael Ferreras Morezuelas (swyterzone+ros@gmail.com)
7 * Copyright 2017 Alexander Shaposhnikov (sanchaez@reactos.org)
8 * Copyright 2021 Mark Jansen <mark.jansen@reactos.org>
9 */
10
11#include "rapps.h"
12#include <debug.h>
13
15{
19};
20
22{
25};
27
29{
30 CacheINI();
31}
32
33void
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}
89
90VOID
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}
134
135BOOL
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}
148
149BOOL
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}
PCWSTR FilePath
#define DPRINT1
Definition: precomp.h:8
TVal & GetValueAt(int nIndex)
Definition: atlsimpcoll.h:358
int FindKey(const TKey &key) const
Definition: atlsimpcoll.h:315
BOOL Add(const TKey &key, const TVal &val)
Definition: atlsimpcoll.h:309
bool IsEmpty() const noexcept
Definition: atlsimpstr.h:394
void ReleaseBuffer(_In_ int nNewLength=-1)
Definition: atlsimpstr.h:387
PXSTR GetString() noexcept
Definition: atlsimpstr.h:367
int GetLength() const noexcept
Definition: atlsimpstr.h:362
void Empty() noexcept
Definition: atlsimpstr.h:253
CStringT Right(int nCount) const
Definition: cstringt.h:788
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
Definition: bufpool.h:45
CSimpleMap< CStringW, CStringW > m_Keys
Definition: configparser.h:8
CConfigParser(const CStringW &FilePath)
const CStringW szConfigPath
Definition: configparser.h:7
BOOL GetString(const CStringW &KeyName, CStringW &ResultString)
BOOL GetInt(const CStringW &KeyName, INT &iResult)
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
unsigned int idx
Definition: utils.c:41
INT WINAPI StrToIntW(LPCWSTR lpString)
Definition: string.c:411
INT WINAPI GetPrivateProfileSectionW(LPCWSTR section, LPWSTR buffer, DWORD len, LPCWSTR filename)
Definition: profile.c:1351
LCID WINAPI GetUserDefaultLCID(void)
Definition: locale.c:1210
INT WINAPI GetLocaleInfoW(LCID lcid, LCTYPE lctype, LPWSTR buffer, INT len)
Definition: locale.c:1665
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
GLenum GLsizei len
Definition: glext.h:6722
GLuint64EXT * result
Definition: glext.h:11304
#define L(x)
Definition: ntvdm.h:50
CStringW LocaleNeutral
CLocaleSections ArchSpecific
CLocaleSections ArchNeutral
Definition: copy.c:22
int32_t INT
Definition: typedefs.h:58
Definition: pdh_main.c:94
_Must_inspect_result_ _In_ WDFDEVICE _In_ PCUNICODE_STRING KeyName
Definition: wdfdevice.h:2699
#define LOCALE_ILANGUAGE
Definition: winnls.h:25