mirror of
https://github.com/reactos/reactos.git
synced 2025-08-01 21:33:25 +00:00
[RAPPS] Move the CConfigParser to a new file
This commit is contained in:
parent
982ee872dd
commit
ad83af36dd
7 changed files with 157 additions and 145 deletions
|
@ -313,121 +313,6 @@ BOOL GetInstalledVersion(ATL::CStringW *pszVersion, const ATL::CStringW &szRegNa
|
|||
|| GetInstalledVersion_WowUser(pszVersion, szRegName, FALSE, KEY_WOW64_64KEY)));
|
||||
}
|
||||
|
||||
// CConfigParser
|
||||
|
||||
CConfigParser::CConfigParser(const ATL::CStringW& FileName) : szConfigPath(GetINIFullPath(FileName))
|
||||
{
|
||||
CacheINILocale();
|
||||
}
|
||||
|
||||
ATL::CStringW CConfigParser::GetINIFullPath(const ATL::CStringW& FileName)
|
||||
{
|
||||
ATL::CStringW szDir;
|
||||
ATL::CStringW szBuffer;
|
||||
|
||||
GetStorageDirectory(szDir);
|
||||
szBuffer.Format(L"%ls\\rapps\\%ls", szDir.GetString(), FileName.GetString());
|
||||
|
||||
return szBuffer;
|
||||
}
|
||||
|
||||
VOID CConfigParser::CacheINILocale()
|
||||
{
|
||||
// TODO: Set default locale if call fails
|
||||
// find out what is the current system lang code (e.g. "0a") and append it to SectionLocale
|
||||
GetLocaleInfoW(GetUserDefaultLCID(), LOCALE_ILANGUAGE,
|
||||
m_szLocaleID.GetBuffer(m_cchLocaleSize), m_cchLocaleSize);
|
||||
|
||||
m_szLocaleID.ReleaseBuffer();
|
||||
m_szCachedINISectionLocale = L"Section." + m_szLocaleID;
|
||||
|
||||
// turn "Section.0c0a" into "Section.0a", keeping just the neutral lang part
|
||||
if (m_szLocaleID.GetLength() >= 2)
|
||||
m_szCachedINISectionLocaleNeutral = L"Section." + m_szLocaleID.Right(2);
|
||||
else
|
||||
m_szCachedINISectionLocaleNeutral = m_szCachedINISectionLocale;
|
||||
}
|
||||
|
||||
BOOL CConfigParser::GetStringWorker(const ATL::CStringW& KeyName, PCWSTR Suffix, ATL::CStringW& ResultString)
|
||||
{
|
||||
DWORD dwResult;
|
||||
|
||||
LPWSTR ResultStringBuffer = ResultString.GetBuffer(MAX_PATH);
|
||||
// 1st - find localized strings (e.g. "Section.0c0a")
|
||||
dwResult = GetPrivateProfileStringW((m_szCachedINISectionLocale + Suffix).GetString(),
|
||||
KeyName.GetString(),
|
||||
NULL,
|
||||
ResultStringBuffer,
|
||||
MAX_PATH,
|
||||
szConfigPath.GetString());
|
||||
|
||||
if (!dwResult)
|
||||
{
|
||||
// 2nd - if they weren't present check for neutral sub-langs/ generic translations (e.g. "Section.0a")
|
||||
dwResult = GetPrivateProfileStringW((m_szCachedINISectionLocaleNeutral + Suffix).GetString(),
|
||||
KeyName.GetString(),
|
||||
NULL,
|
||||
ResultStringBuffer,
|
||||
MAX_PATH,
|
||||
szConfigPath.GetString());
|
||||
if (!dwResult)
|
||||
{
|
||||
// 3rd - if they weren't present fallback to standard english strings (just "Section")
|
||||
dwResult = GetPrivateProfileStringW((ATL::CStringW(L"Section") + Suffix).GetString(),
|
||||
KeyName.GetString(),
|
||||
NULL,
|
||||
ResultStringBuffer,
|
||||
MAX_PATH,
|
||||
szConfigPath.GetString());
|
||||
}
|
||||
}
|
||||
|
||||
ResultString.ReleaseBuffer();
|
||||
return (dwResult != 0 ? TRUE : FALSE);
|
||||
}
|
||||
|
||||
BOOL CConfigParser::GetString(const ATL::CStringW& KeyName, ATL::CStringW& ResultString)
|
||||
{
|
||||
/* First try */
|
||||
if (GetStringWorker(KeyName, L"." CurrentArchitecture, ResultString))
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
#ifndef _M_IX86
|
||||
/* On non-x86 architecture we need the architecture specific URL */
|
||||
if (KeyName == L"URLDownload")
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Fall back to default */
|
||||
return GetStringWorker(KeyName, L"", ResultString);
|
||||
}
|
||||
|
||||
BOOL CConfigParser::GetInt(const ATL::CStringW& KeyName, INT& iResult)
|
||||
{
|
||||
ATL::CStringW Buffer;
|
||||
|
||||
iResult = 0;
|
||||
|
||||
// grab the text version of our entry
|
||||
if (!GetString(KeyName, Buffer))
|
||||
return FALSE;
|
||||
|
||||
if (Buffer.IsEmpty())
|
||||
return FALSE;
|
||||
|
||||
// convert it to an actual integer
|
||||
iResult = StrToIntW(Buffer.GetString());
|
||||
|
||||
// we only care about values > 0
|
||||
return (iResult > 0);
|
||||
}
|
||||
// CConfigParser
|
||||
|
||||
|
||||
BOOL PathAppendNoDirEscapeW(LPWSTR pszPath, LPCWSTR pszMore)
|
||||
{
|
||||
WCHAR pszPathBuffer[MAX_PATH]; // buffer to store result
|
||||
|
@ -473,8 +358,6 @@ BOOL PathAppendNoDirEscapeW(LPWSTR pszPath, LPCWSTR pszMore)
|
|||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
|
||||
BOOL IsSystem64Bit()
|
||||
{
|
||||
if (bIsSys64ResultCached)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue