Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/kornelski/7z.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'CPP/Windows/Registry.cpp')
-rwxr-xr-xCPP/Windows/Registry.cpp81
1 files changed, 63 insertions, 18 deletions
diff --git a/CPP/Windows/Registry.cpp b/CPP/Windows/Registry.cpp
index 96cab0c2..8b25375d 100755
--- a/CPP/Windows/Registry.cpp
+++ b/CPP/Windows/Registry.cpp
@@ -16,24 +16,6 @@ namespace NRegistry {
#define MYASSERT(expr) // _ASSERTE(expr)
-CKey::~CKey()
-{
- Close();
-}
-
-HKEY CKey::Detach()
-{
- HKEY hKey = _object;
- _object = NULL;
- return hKey;
-}
-
-void CKey::Attach(HKEY hKey)
-{
- MYASSERT(_object == NULL);
- _object = hKey;
-}
-
LONG CKey::Create(HKEY parentKey, LPCTSTR keyName,
LPTSTR keyClass, DWORD options, REGSAM accessMask,
LPSECURITY_ATTRIBUTES securityAttributes, LPDWORD disposition)
@@ -224,6 +206,24 @@ LONG CKey::QueryValue(LPCTSTR name, bool &value)
return res;
}
+LONG CKey::GetValue_IfOk(LPCTSTR name, UInt32 &value)
+{
+ UInt32 newVal;
+ LONG res = QueryValue(name, newVal);
+ if (res == ERROR_SUCCESS)
+ value = newVal;
+ return res;
+}
+
+LONG CKey::GetValue_IfOk(LPCTSTR name, bool &value)
+{
+ bool newVal;
+ LONG res = QueryValue(name, newVal);
+ if (res == ERROR_SUCCESS)
+ value = newVal;
+ return res;
+}
+
LONG CKey::QueryValue(LPCTSTR name, LPTSTR value, UInt32 &count)
{
MYASSERT(count != NULL);
@@ -321,4 +321,49 @@ LONG CKey::EnumKeys(CSysStringVector &keyNames)
return ERROR_SUCCESS;
}
+LONG CKey::SetValue_Strings(LPCTSTR valueName, const UStringVector &strings)
+{
+ UInt32 numChars = 0;
+ int i;
+ for (i = 0; i < strings.Size(); i++)
+ numChars += strings[i].Length() + 1;
+ CBuffer<wchar_t> buffer;
+ buffer.SetCapacity(numChars);
+ int pos = 0;
+ for (i = 0; i < strings.Size(); i++)
+ {
+ const UString &s = strings[i];
+ MyStringCopy((wchar_t *)buffer + pos, (const wchar_t *)s);
+ pos += s.Length() + 1;
+ }
+ return SetValue(valueName, buffer, numChars * sizeof(wchar_t));
+}
+
+LONG CKey::GetValue_Strings(LPCTSTR valueName, UStringVector &strings)
+{
+ strings.Clear();
+ CByteBuffer buffer;
+ UInt32 dataSize;
+ LONG res = QueryValue(valueName, buffer, dataSize);
+ if (res != ERROR_SUCCESS)
+ return res;
+ if (dataSize % sizeof(wchar_t) != 0)
+ return E_FAIL;
+ const wchar_t *data = (const wchar_t *)(const Byte *)buffer;
+ int numChars = dataSize / sizeof(wchar_t);
+ UString s;
+ for (int i = 0; i < numChars; i++)
+ {
+ wchar_t c = data[i];
+ if (c == 0)
+ {
+ strings.Add(s);
+ s.Empty();
+ }
+ else
+ s += c;
+ }
+ return res;
+}
+
}}