Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDoug Schaefer2007-05-24 04:08:08 +0000
committerDoug Schaefer2007-05-24 04:08:08 +0000
commit4082f4efa89e412ae5a4b4ae79abd1ba71f64702 (patch)
treede0b160c8bd10173a2e7f84736d91d131003a0fb
parent0eb470fd43d86b67fab896f55f7ffcd6551e0ddc (diff)
downloadorg.eclipse.cdt-4082f4efa89e412ae5a4b4ae79abd1ba71f64702.tar.gz
org.eclipse.cdt-4082f4efa89e412ae5a4b4ae79abd1ba71f64702.tar.xz
org.eclipse.cdt-4082f4efa89e412ae5a4b4ae79abd1ba71f64702.zip
Added support for HKEY_CURRENT_USER to the registry access routines.
-rw-r--r--core/org.eclipse.cdt.core.win32/library/winreg/winreg.cpp85
-rw-r--r--core/org.eclipse.cdt.core.win32/os/win32/x86/winreg.dllbin16949 -> 17909 bytes
-rw-r--r--core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/WindowsRegistry.java36
3 files changed, 94 insertions, 27 deletions
diff --git a/core/org.eclipse.cdt.core.win32/library/winreg/winreg.cpp b/core/org.eclipse.cdt.core.win32/library/winreg/winreg.cpp
index c10d37a253..e5c284d943 100644
--- a/core/org.eclipse.cdt.core.win32/library/winreg/winreg.cpp
+++ b/core/org.eclipse.cdt.core.win32/library/winreg/winreg.cpp
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005, 2006 QNX Software Systems
+ * Copyright (c) 2005, 2007 QNX Software Systems
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -12,25 +12,22 @@
#include <jni.h>
#include <string.h>
-extern "C"
-JNIEXPORT jstring JNICALL Java_org_eclipse_cdt_utils_WindowsRegistry_getLocalMachineValue(
- JNIEnv * env, jobject obj, jstring subkey, jstring name)
-{
+static jstring getValue(JNIEnv * env, HKEY key, jstring subkey, jstring name) {
const jchar * csubkey = env->GetStringChars(subkey, NULL);
const jchar * cname = env->GetStringChars(name, NULL);
jstring result = NULL;
- HKEY key;
- LONG rc = RegOpenKeyEx(HKEY_LOCAL_MACHINE, (const wchar_t *)csubkey, 0, KEY_READ, &key);
+ HKEY skey;
+ LONG rc = RegOpenKeyEx(key, (const wchar_t *)csubkey, 0, KEY_READ, &skey);
if (rc == ERROR_SUCCESS) {
DWORD type;
wchar_t buffer[256];
DWORD len = sizeof(buffer);
- rc = RegQueryValueEx(key, (const wchar_t *)cname, NULL, &type, (BYTE *)&buffer, &len);
+ rc = RegQueryValueEx(skey, (const wchar_t *)cname, NULL, &type, (BYTE *)&buffer, &len);
if (rc == ERROR_SUCCESS) {
result = env->NewString((jchar *)buffer, wcslen(buffer));
}
- RegCloseKey(key);
+ RegCloseKey(skey);
}
env->ReleaseStringChars(subkey, csubkey);
@@ -39,28 +36,39 @@ JNIEXPORT jstring JNICALL Java_org_eclipse_cdt_utils_WindowsRegistry_getLocalMac
return result;
}
+extern "C"
+JNIEXPORT jstring JNICALL Java_org_eclipse_cdt_utils_WindowsRegistry_getLocalMachineValue(
+ JNIEnv * env, jobject obj, jstring subkey, jstring name)
+{
+ return getValue(env, HKEY_LOCAL_MACHINE, subkey, name);
+}
+
+extern "C"
+JNIEXPORT jstring JNICALL Java_org_eclipse_cdt_utils_WindowsRegistry_getCurrentUserValue(
+ JNIEnv * env, jobject obj, jstring subkey, jstring name)
+{
+ return getValue(env, HKEY_CURRENT_USER, subkey, name);
+}
+
/*
* Given a subkey (string) under HKEY_LOCAL_MACHINE, and an index (starting from 0)
* to the key's array of values, return the name of the indexed value.
* The return value is null on any error or when the index is invalid.
*/
-
-extern "C"
-JNIEXPORT jstring JNICALL Java_org_eclipse_cdt_utils_WindowsRegistry_getLocalMachineValueName(
- JNIEnv * env, jobject obj, jstring subkey, jint index)
-{
+
+static jstring getValueName(JNIEnv * env, HKEY key, jstring subkey, jint index) {
const jchar * csubkey = env->GetStringChars(subkey, NULL);
jstring result = NULL;
- HKEY key;
- LONG rc = RegOpenKeyEx(HKEY_LOCAL_MACHINE, (const wchar_t *)csubkey, 0, KEY_READ, &key);
+ HKEY skey;
+ LONG rc = RegOpenKeyEx(key, (const wchar_t *)csubkey, 0, KEY_READ, &skey);
if (rc != ERROR_SUCCESS)
return NULL;
wchar_t valueName[256];
DWORD nameSize = sizeof(valueName) + 2;
- rc = RegEnumValue(key, index,
+ rc = RegEnumValue(skey, index,
valueName, // UNICODE string
&nameSize,
NULL, NULL,
@@ -72,35 +80,46 @@ JNIEXPORT jstring JNICALL Java_org_eclipse_cdt_utils_WindowsRegistry_getLocalMac
result = env->NewString((jchar *)valueName, nameSize);
}
- RegCloseKey(key);
+ RegCloseKey(skey);
env->ReleaseStringChars(subkey, csubkey);
return result;
}
+extern "C"
+JNIEXPORT jstring JNICALL Java_org_eclipse_cdt_utils_WindowsRegistry_getLocalMachineValueName(
+ JNIEnv * env, jobject obj, jstring subkey, jint index)
+{
+ return getValueName(env, HKEY_LOCAL_MACHINE, subkey, index);
+}
+
+extern "C"
+JNIEXPORT jstring JNICALL Java_org_eclipse_cdt_utils_WindowsRegistry_getCurrentUserValueName(
+ JNIEnv * env, jobject obj, jstring subkey, jint index)
+{
+ return getValueName(env, HKEY_CURRENT_USER, subkey, index);
+}
+
/*
* Given a subkey (string) under HKEY_LOCAL_MACHINE, and an index (starting from 0)
* to the key's array of keys, return the name of the indexed key.
* The return value is null on any error or when the index is invalid.
*/
-extern "C"
-JNIEXPORT jstring JNICALL Java_org_eclipse_cdt_utils_WindowsRegistry_getLocalMachineKeyName(
- JNIEnv * env, jobject obj, jstring subkey, jint index)
-{
+static jstring getKeyName(JNIEnv * env, HKEY key, jstring subkey, jint index) {
const jchar * csubkey = env->GetStringChars(subkey, NULL);
jstring result = NULL;
- HKEY key;
- LONG rc = RegOpenKeyEx(HKEY_LOCAL_MACHINE, (const wchar_t *)csubkey, 0, KEY_READ, &key);
+ HKEY skey;
+ LONG rc = RegOpenKeyEx(HKEY_LOCAL_MACHINE, (const wchar_t *)csubkey, 0, KEY_READ, &skey);
if (rc != ERROR_SUCCESS)
return NULL;
wchar_t keyName[256];
DWORD nameSize = sizeof(keyName) + 2;
- rc = RegEnumKeyEx(key, index,
+ rc = RegEnumKeyEx(skey, index,
keyName, // UNICODE string
&nameSize,
NULL, NULL,
@@ -112,9 +131,23 @@ JNIEXPORT jstring JNICALL Java_org_eclipse_cdt_utils_WindowsRegistry_getLocalMac
result = env->NewString((jchar *)keyName, nameSize);
}
- RegCloseKey(key);
+ RegCloseKey(skey);
env->ReleaseStringChars(subkey, csubkey);
return result;
}
+
+extern "C"
+JNIEXPORT jstring JNICALL Java_org_eclipse_cdt_utils_WindowsRegistry_getLocalMachineKeyName(
+ JNIEnv * env, jobject obj, jstring subkey, jint index)
+{
+ return getKeyName(env, HKEY_LOCAL_MACHINE, subkey, index);
+}
+
+extern "C"
+JNIEXPORT jstring JNICALL Java_org_eclipse_cdt_utils_WindowsRegistry_getCurrentUserKeyName(
+ JNIEnv * env, jobject obj, jstring subkey, jint index)
+{
+ return getKeyName(env, HKEY_CURRENT_USER, subkey, index);
+}
diff --git a/core/org.eclipse.cdt.core.win32/os/win32/x86/winreg.dll b/core/org.eclipse.cdt.core.win32/os/win32/x86/winreg.dll
index 0d613301f7..d80166ce1d 100644
--- a/core/org.eclipse.cdt.core.win32/os/win32/x86/winreg.dll
+++ b/core/org.eclipse.cdt.core.win32/os/win32/x86/winreg.dll
Binary files differ
diff --git a/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/WindowsRegistry.java b/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/WindowsRegistry.java
index ce05a273be..ad9ccb0c42 100644
--- a/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/WindowsRegistry.java
+++ b/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/WindowsRegistry.java
@@ -72,10 +72,44 @@ public class WindowsRegistry {
* The return value is null on any error or when the index is invalid.
* The key name can be used in the above getLocalMachineValueName()
* to retrieve value names.
- * @param subkey subkey of HKEY_LOCAL_MACHINE
+ * @param subkey subkey of HKEY_CURRENT_USER
* @param index index to the subkey's array of values, starting from 0.
* @return name of registry value or null if not found
*/
public native String getLocalMachineKeyName(String subkey, int index);
+
+ /**
+ * Gets the registry value for the subkey of HKEY_CURRENT_USER with the
+ * given name. If problems occur, like the name is not found, null is returned.
+ *
+ * @param subkey subkey of HKEY_CURRENT_USER
+ * @param name name of the registry value
+ * @return registry value or null if not found
+ */
+ public native String getCurrentUserValue(String subkey, String name);
+
+ /**
+ * Given a subkey of HKEY_CURRENT_USER, and an index (starting from 0)
+ * to the key's array of values, return the name of the indexed value.
+ * The return value is null on any error or when the index is invalid.
+ * The value name can be used in the above getCurrentUserValue() to retrieve
+ * the value data.
+ * @param subkey subkey of HKEY_CURRENT_USER
+ * @param index index to the subkey's array of values, starting from 0.
+ * @return name of registry value or null if not found
+ */
+ public native String getCurrentUserValueName(String subkey, int index);
+
+ /**
+ * Given a subkey of HKEY_CURRENT_USER, and an index (starting from 0)
+ * to the key's array of sub keys, return the name of the indexed key.
+ * The return value is null on any error or when the index is invalid.
+ * The key name can be used in the above getCurrentUserValueName()
+ * to retrieve value names.
+ * @param subkey subkey of HKEY_CURRENT_USER
+ * @param index index to the subkey's array of values, starting from 0.
+ * @return name of registry value or null if not found
+ */
+ public native String getCurrentUserKeyName(String subkey, int index);
}

Back to the top