https://git.reactos.org/?p=reactos.git;a=commitdiff;h=ad83af36dd3312bc2d36a…
commit ad83af36dd3312bc2d36a60b8bfd80b7aee74f15
Author: Mark Jansen <mark.jansen(a)reactos.org>
AuthorDate: Tue Sep 21 19:00:21 2021 +0200
Commit: Mark Jansen <mark.jansen(a)reactos.org>
CommitDate: Tue Sep 21 19:00:21 2021 +0200
[RAPPS] Move the CConfigParser to a new file
---
base/applications/rapps/CMakeLists.txt | 14 +--
base/applications/rapps/configparser.cpp | 120 +++++++++++++++++++++++++
base/applications/rapps/include/available.h | 1 +
base/applications/rapps/include/configparser.h | 27 ++++++
base/applications/rapps/include/misc.h | 22 -----
base/applications/rapps/include/rapps.h | 1 +
base/applications/rapps/misc.cpp | 117 ------------------------
7 files changed, 157 insertions(+), 145 deletions(-)
diff --git a/base/applications/rapps/CMakeLists.txt
b/base/applications/rapps/CMakeLists.txt
index 4da7397229f..8a260cfb2e3 100644
--- a/base/applications/rapps/CMakeLists.txt
+++ b/base/applications/rapps/CMakeLists.txt
@@ -9,6 +9,7 @@ list(APPEND SOURCE
asyncinet.cpp
available.cpp
cabinet.cpp
+ configparser.cpp
gui.cpp
installed.cpp
integrity.cpp
@@ -16,23 +17,24 @@ list(APPEND SOURCE
misc.cpp
settings.cpp
settingsdlg.cpp
- winmain.cpp
unattended.cpp
- include/rapps.h
+ winmain.cpp
include/appview.h
include/asyncinet.h
include/available.h
+ include/configparser.h
+ include/crichedit.h
+ include/defines.h
include/dialogs.h
include/gui.h
include/installed.h
- include/crichedit.h
- include/defines.h
include/misc.h
- include/settings.h
+ include/rapps.h
include/resource.h
include/rosui.h
- include/winmain.h
+ include/settings.h
include/unattended.h
+ include/winmain.h
)
add_definitions(
diff --git a/base/applications/rapps/configparser.cpp
b/base/applications/rapps/configparser.cpp
new file mode 100644
index 00000000000..5e191da800b
--- /dev/null
+++ b/base/applications/rapps/configparser.cpp
@@ -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(a)reactos.org)
+ * Copyright 2015 Ismael Ferreras Morezuelas (swyterzone+ros(a)gmail.com)
+ * Copyright 2017 Alexander Shaposhnikov (sanchaez(a)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);
+}
diff --git a/base/applications/rapps/include/available.h
b/base/applications/rapps/include/available.h
index c478a898b82..92a846aa5e9 100644
--- a/base/applications/rapps/include/available.h
+++ b/base/applications/rapps/include/available.h
@@ -6,6 +6,7 @@
#include <atlcoll.h>
#include "misc.h"
+#include "configparser.h"
#define MAX_SCRNSHOT_NUM 16
diff --git a/base/applications/rapps/include/configparser.h
b/base/applications/rapps/include/configparser.h
new file mode 100644
index 00000000000..5df9150269c
--- /dev/null
+++ b/base/applications/rapps/include/configparser.h
@@ -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);
+};
+
diff --git a/base/applications/rapps/include/misc.h
b/base/applications/rapps/include/misc.h
index 7bb6afcecb5..1a00feeb526 100644
--- a/base/applications/rapps/include/misc.h
+++ b/base/applications/rapps/include/misc.h
@@ -41,28 +41,6 @@ BOOL ExtractFilesFromCab(const ATL::CStringW& szCabName,
const ATL::CStringW& szCabDir,
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 IsSystem64Bit();
diff --git a/base/applications/rapps/include/rapps.h
b/base/applications/rapps/include/rapps.h
index 43d8a5e8e0b..595cf24e76e 100644
--- a/base/applications/rapps/include/rapps.h
+++ b/base/applications/rapps/include/rapps.h
@@ -7,5 +7,6 @@
#include "installed.h"
#include "available.h"
#include "misc.h"
+#include "configparser.h"
#endif /* _RAPPS_H */
diff --git a/base/applications/rapps/misc.cpp b/base/applications/rapps/misc.cpp
index e8418869a21..0380705f4e3 100644
--- a/base/applications/rapps/misc.cpp
+++ b/base/applications/rapps/misc.cpp
@@ -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)