mirror of
https://github.com/reactos/reactos.git
synced 2025-07-04 06:21:23 +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
|
@ -9,6 +9,7 @@ list(APPEND SOURCE
|
||||||
asyncinet.cpp
|
asyncinet.cpp
|
||||||
available.cpp
|
available.cpp
|
||||||
cabinet.cpp
|
cabinet.cpp
|
||||||
|
configparser.cpp
|
||||||
gui.cpp
|
gui.cpp
|
||||||
installed.cpp
|
installed.cpp
|
||||||
integrity.cpp
|
integrity.cpp
|
||||||
|
@ -16,23 +17,24 @@ list(APPEND SOURCE
|
||||||
misc.cpp
|
misc.cpp
|
||||||
settings.cpp
|
settings.cpp
|
||||||
settingsdlg.cpp
|
settingsdlg.cpp
|
||||||
winmain.cpp
|
|
||||||
unattended.cpp
|
unattended.cpp
|
||||||
include/rapps.h
|
winmain.cpp
|
||||||
include/appview.h
|
include/appview.h
|
||||||
include/asyncinet.h
|
include/asyncinet.h
|
||||||
include/available.h
|
include/available.h
|
||||||
|
include/configparser.h
|
||||||
|
include/crichedit.h
|
||||||
|
include/defines.h
|
||||||
include/dialogs.h
|
include/dialogs.h
|
||||||
include/gui.h
|
include/gui.h
|
||||||
include/installed.h
|
include/installed.h
|
||||||
include/crichedit.h
|
|
||||||
include/defines.h
|
|
||||||
include/misc.h
|
include/misc.h
|
||||||
include/settings.h
|
include/rapps.h
|
||||||
include/resource.h
|
include/resource.h
|
||||||
include/rosui.h
|
include/rosui.h
|
||||||
include/winmain.h
|
include/settings.h
|
||||||
include/unattended.h
|
include/unattended.h
|
||||||
|
include/winmain.h
|
||||||
)
|
)
|
||||||
|
|
||||||
add_definitions(
|
add_definitions(
|
||||||
|
|
120
base/applications/rapps/configparser.cpp
Normal file
120
base/applications/rapps/configparser.cpp
Normal file
|
@ -0,0 +1,120 @@
|
||||||
|
/*
|
||||||
|
* PROJECT: ReactOS Applications Manager
|
||||||
|
* LICENSE: GPL-2.0-or-later (https://spdx.org/licenses/GPL-2.0-or-later)
|
||||||
|
* PURPOSE: Config parser
|
||||||
|
* COPYRIGHT: Copyright 2009 Dmitry Chapyshev (dmitry@reactos.org)
|
||||||
|
* Copyright 2015 Ismael Ferreras Morezuelas (swyterzone+ros@gmail.com)
|
||||||
|
* Copyright 2017 Alexander Shaposhnikov (sanchaez@reactos.org)
|
||||||
|
*/
|
||||||
|
#include "rapps.h"
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
|
@ -6,6 +6,7 @@
|
||||||
#include <atlcoll.h>
|
#include <atlcoll.h>
|
||||||
|
|
||||||
#include "misc.h"
|
#include "misc.h"
|
||||||
|
#include "configparser.h"
|
||||||
|
|
||||||
|
|
||||||
#define MAX_SCRNSHOT_NUM 16
|
#define MAX_SCRNSHOT_NUM 16
|
||||||
|
|
27
base/applications/rapps/include/configparser.h
Normal file
27
base/applications/rapps/include/configparser.h
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <windef.h>
|
||||||
|
#include <atlstr.h>
|
||||||
|
|
||||||
|
class CConfigParser
|
||||||
|
{
|
||||||
|
// Locale names cache
|
||||||
|
const static INT m_cchLocaleSize = 5;
|
||||||
|
|
||||||
|
ATL::CStringW m_szLocaleID;
|
||||||
|
ATL::CStringW m_szCachedINISectionLocale;
|
||||||
|
ATL::CStringW m_szCachedINISectionLocaleNeutral;
|
||||||
|
|
||||||
|
const ATL::CStringW szConfigPath;
|
||||||
|
|
||||||
|
ATL::CStringW GetINIFullPath(const ATL::CStringW& FileName);
|
||||||
|
VOID CacheINILocale();
|
||||||
|
BOOL GetStringWorker(const ATL::CStringW& KeyName, PCWSTR Suffix, ATL::CStringW& ResultString);
|
||||||
|
|
||||||
|
public:
|
||||||
|
CConfigParser(const ATL::CStringW& FileName);
|
||||||
|
|
||||||
|
BOOL GetString(const ATL::CStringW& KeyName, ATL::CStringW& ResultString);
|
||||||
|
BOOL GetInt(const ATL::CStringW& KeyName, INT& iResult);
|
||||||
|
};
|
||||||
|
|
|
@ -41,28 +41,6 @@ BOOL ExtractFilesFromCab(const ATL::CStringW& szCabName,
|
||||||
const ATL::CStringW& szCabDir,
|
const ATL::CStringW& szCabDir,
|
||||||
const ATL::CStringW& szOutputDir);
|
const ATL::CStringW& szOutputDir);
|
||||||
|
|
||||||
class CConfigParser
|
|
||||||
{
|
|
||||||
// Locale names cache
|
|
||||||
const static INT m_cchLocaleSize = 5;
|
|
||||||
|
|
||||||
ATL::CStringW m_szLocaleID;
|
|
||||||
ATL::CStringW m_szCachedINISectionLocale;
|
|
||||||
ATL::CStringW m_szCachedINISectionLocaleNeutral;
|
|
||||||
|
|
||||||
const ATL::CStringW szConfigPath;
|
|
||||||
|
|
||||||
ATL::CStringW GetINIFullPath(const ATL::CStringW& FileName);
|
|
||||||
VOID CacheINILocale();
|
|
||||||
BOOL GetStringWorker(const ATL::CStringW& KeyName, PCWSTR Suffix, ATL::CStringW& ResultString);
|
|
||||||
|
|
||||||
public:
|
|
||||||
CConfigParser(const ATL::CStringW& FileName = "");
|
|
||||||
|
|
||||||
BOOL GetString(const ATL::CStringW& KeyName, ATL::CStringW& ResultString);
|
|
||||||
BOOL GetInt(const ATL::CStringW& KeyName, INT& iResult);
|
|
||||||
};
|
|
||||||
|
|
||||||
BOOL PathAppendNoDirEscapeW(LPWSTR pszPath, LPCWSTR pszMore);
|
BOOL PathAppendNoDirEscapeW(LPWSTR pszPath, LPCWSTR pszMore);
|
||||||
|
|
||||||
BOOL IsSystem64Bit();
|
BOOL IsSystem64Bit();
|
||||||
|
|
|
@ -7,5 +7,6 @@
|
||||||
#include "installed.h"
|
#include "installed.h"
|
||||||
#include "available.h"
|
#include "available.h"
|
||||||
#include "misc.h"
|
#include "misc.h"
|
||||||
|
#include "configparser.h"
|
||||||
|
|
||||||
#endif /* _RAPPS_H */
|
#endif /* _RAPPS_H */
|
||||||
|
|
|
@ -313,121 +313,6 @@ BOOL GetInstalledVersion(ATL::CStringW *pszVersion, const ATL::CStringW &szRegNa
|
||||||
|| GetInstalledVersion_WowUser(pszVersion, szRegName, FALSE, KEY_WOW64_64KEY)));
|
|| 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)
|
BOOL PathAppendNoDirEscapeW(LPWSTR pszPath, LPCWSTR pszMore)
|
||||||
{
|
{
|
||||||
WCHAR pszPathBuffer[MAX_PATH]; // buffer to store result
|
WCHAR pszPathBuffer[MAX_PATH]; // buffer to store result
|
||||||
|
@ -473,8 +358,6 @@ BOOL PathAppendNoDirEscapeW(LPWSTR pszPath, LPCWSTR pszMore)
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
BOOL IsSystem64Bit()
|
BOOL IsSystem64Bit()
|
||||||
{
|
{
|
||||||
if (bIsSys64ResultCached)
|
if (bIsSys64ResultCached)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue