mirror of
https://github.com/reactos/reactos.git
synced 2025-08-04 09:25:44 +00:00
[SDK] Add <cicero/cicarray.h> and <cicero/cicreg.h>
CORE-19360
This commit is contained in:
parent
9d495475f0
commit
209e9a7c1d
2 changed files with 226 additions and 0 deletions
100
sdk/include/reactos/cicero/cicarray.h
Normal file
100
sdk/include/reactos/cicero/cicarray.h
Normal file
|
@ -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.mz@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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
126
sdk/include/reactos/cicero/cicreg.h
Normal file
126
sdk/include/reactos/cicero/cicreg.h
Normal file
|
@ -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.mz@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;
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue