https://git.reactos.org/?p=reactos.git;a=commitdiff;h=209e9a7c1daa6a596202287a67799baefc73ff21
commit 209e9a7c1daa6a596202287a67799baefc73ff21 Author: Katayama Hirofumi MZ <katayama.hirofumi...@gmail.com> AuthorDate: Wed Dec 20 20:49:06 2023 +0900 Commit: Katayama Hirofumi MZ <katayama.hirofumi...@gmail.com> CommitDate: Wed Dec 20 20:49:21 2023 +0900 [SDK] Add <cicero/cicarray.h> and <cicero/cicreg.h> CORE-19360 --- sdk/include/reactos/cicero/cicarray.h | 100 +++++++++++++++++++++++++++ sdk/include/reactos/cicero/cicreg.h | 126 ++++++++++++++++++++++++++++++++++ 2 files changed, 226 insertions(+) diff --git a/sdk/include/reactos/cicero/cicarray.h b/sdk/include/reactos/cicero/cicarray.h new file mode 100644 index 00000000000..8767ac727f9 --- /dev/null +++ b/sdk/include/reactos/cicero/cicarray.h @@ -0,0 +1,100 @@ +/* + * PROJECT: ReactOS Cicero + * LICENSE: LGPL-2.1-or-later (https://spdx.org/licenses/LGPL-2.1-or-later) + * PURPOSE: Cicero dynamic array + * COPYRIGHT: Copyright 2023 Katayama Hirofumi MZ <katayama.hirofumi...@gmail.com> + */ + +#pragma once + +#include "cicbase.h" + +class CicArray +{ + LPVOID lpVtbl; + LPBYTE m_pb; + INT m_cItems; + INT m_cbItem; + INT m_cCapacity; + +public: + CicArray(INT cbItem); + virtual CicArray(); + + void Insert(INT iItem, INT cGrow); + void Append(INT cGrow); + void Remove(INT iItem, INT cRemove); +}; + +/******************************************************************************/ + +inline CicArray::CicArray(INT cbItem) +{ + m_cbItem = cbItem; + m_pb = NULL; + m_cItems = m_cCapacity = 0; +} + +inline CicArray::~CicArray() +{ + cicMemFree(m_pb); +} + +inline void CicArray::Append(INT cGrow) +{ + Insert(m_cItems, cGrow); +} + +inline void CicArray::Insert(INT iItem, INT cGrow) +{ + INT cNewCapacity = m_cItems + cGrow; + if (m_cCapacity < cNewCapacity) + { + if (cNewCapacity <= m_cItems + m_cItems / 2) + cNewCapacity = m_cItems + m_cItems / 2; + + BYTE *pbNew; + if (m_pb) + pbNew = (BYTE *)cicMemReAlloc(m_pb, cNewCapacity * m_cbItem); + else + pbNew = (BYTE *)cicMemAlloc(cNewCapacity * m_cbItem); + + if (!pbNew) + return; + + m_pb = pbNew; + m_cCapacity = cNewCapacity; + } + + if (iItem < m_cItems) + { + MoveMemory(&m_pb[(cGrow + iItem) * m_cbItem], + &m_pb[iItem * m_cbItem], + (m_cItems - iItem) * m_cbItem); + } + + m_cItems += cGrow; +} + +inline void CicArray::Remove(INT iItem, INT cRemove) +{ + if (iItem + cRemove < m_cItems) + { + MoveMemory(&m_pb[iItem * m_cbItem], + &m_pb[(iItem + cRemove) * m_cbItem], + (m_cItems - iItem - cRemove) * m_cbItem); + } + + m_cItems -= cRemove; + + INT cHalfCapacity = m_cCapacity / 2; + if (cHalfCapacity > m_cItems) + { + BYTE *pb = (BYTE *)cicMemReAlloc(m_pb, cHalfCapacity * m_cbItem); + if (pb) + { + m_pb = pb; + m_cCapacity = cHalfCapacity; + } + } +} diff --git a/sdk/include/reactos/cicero/cicreg.h b/sdk/include/reactos/cicero/cicreg.h new file mode 100644 index 00000000000..674d1d27ed2 --- /dev/null +++ b/sdk/include/reactos/cicero/cicreg.h @@ -0,0 +1,126 @@ +/* + * PROJECT: ReactOS Cicero + * LICENSE: LGPL-2.1-or-later (https://spdx.org/licenses/LGPL-2.1-or-later) + * PURPOSE: Cicero registry handling + * COPYRIGHT: Copyright 2023 Katayama Hirofumi MZ <katayama.hirofumi...@gmail.com> + */ + +#pragma once + +#include "cicbase.h" + +class CicRegKey +{ +public: + HKEY m_hKey; + + CicRegKey() : m_hKey(NULL) { } + ~CicRegKey() { Close(); } + + operator HKEY() { return m_hKey; } + + void Close(); + + LSTATUS Open( + HKEY hKey, + LPCWSTR lpSubKey, + REGSAM samDesired = KEY_READ); + + LSTATUS Create( + HKEY hKey, + LPCWSTR lpSubKey, + LPWSTR lpClass = NULL, + DWORD dwOptions = REG_OPTION_NON_VOLATILE, + REGSAM samDesired = KEY_ALL_ACCESS, + LPSECURITY_ATTRIBUTES lpSecurityAttributes = NULL, + LPDWORD pdwDisposition = NULL); + + LSTATUS QueryDword(LPCWSTR pszValueName, LPDWORD pdwValue) + { + DWORD cbData = sizeof(DWORD); + return ::RegQueryValueExW(m_hKey, pszValueName, 0, NULL, (LPBYTE)pdwValue, &cbData); + } + + LSTATUS SetDword(LPCWSTR pszValueName, DWORD dwValue) + { + return ::RegSetValueExW(m_hKey, pszValueName, 0, REG_DWORD, &dwValue, sizeof(dwValue)); + } + + LSTATUS QuerySz(LPCWSTR pszValueName, LPWSTR pszValue, DWORD cchValueMax); + + LSTATUS SetSz(LPCWSTR pszValueName, LPCWSTR pszValue) + { + DWORD cbValue = (lstrlenW(pszValue) + 1) * sizeof(WCHAR); + return ::RegSetValueExW(m_hKey, pszValueName, 0, REG_SZ, (LPBYTE)pszValue, cbValue); + } +}; + +/******************************************************************************/ + +inline void +CicRegKey::Close() +{ + if (!m_hKey) + return; + + ::RegCloseKey(m_hKey); + m_hKey = NULL; +} + +inline LSTATUS +CicRegKey::Open( + HKEY hKey, + LPCWSTR lpSubKey, + REGSAM samDesired) +{ + HKEY hNewKey = NULL; + LSTATUS error = ::RegOpenKeyExW(hKey, lpSubKey, 0, samDesired, &hNewKey); + if (error != ERROR_SUCCESS) + return error; + + Close(); + m_hKey = hNewKey; + return error; +} + +inline LSTATUS +CicRegKey::Create( + HKEY hKey, + LPCWSTR lpSubKey, + LPWSTR lpClass, + DWORD dwOptions, + REGSAM samDesired, + LPSECURITY_ATTRIBUTES lpSecurityAttributes, + LPDWORD pdwDisposition) +{ + HKEY hNewKey = NULL; + LSTATUS error = ::RegCreateKeyExW(hKey, + lpSubKey, + 0, + lpClass, + dwOptions, + samDesired, + lpSecurityAttributes, + &hNewKey, + pdwDisposition); + if (error != ERROR_SUCCESS) + return error; + + Close(); + m_hKey = hNewKey; + return error; +} + +inline LSTATUS +CicRegKey::QuerySz(LPCWSTR pszValueName, LPWSTR pszValue, DWORD cchValueMax) +{ + DWORD cchSaveMax = cchValueMax; + + cchValueMax *= sizeof(WCHAR); + LSTATUS error = ::RegQueryValueExW(m_hKey, pszValueName, 0, NULL, + (LPBYTE)pszValue, &cchValueMax); + if (cchSaveMax > 0) + pszValue[(error == ERROR_SUCCESS) ? (cchSaveMax - 1) : 0] = UNICODE_NULL; + + return error; +}