add RegistryKey.getMultiStringValue()

This commit is contained in:
Doug MacEachern 2007-03-03 18:25:02 +00:00
parent b0e7fd04f1
commit eda91e1e8a
2 changed files with 67 additions and 0 deletions

View File

@ -265,6 +265,62 @@ JNIEXPORT jstring SIGAR_JNI(win32_RegistryKey_RegQueryStringValue)
}
}
JNIEXPORT void SIGAR_JNI(win32_RegistryKey_RegQueryMultiStringValue)
(JNIEnv *env, jclass, jlong hkey, jstring jname, jobject obj)
{
LONG rc;
DWORD type, size;
LPBYTE value;
LPTSTR name =
(LPTSTR)env->GetStringChars(jname, NULL);
jclass cls =
env->GetObjectClass(obj);
jmethodID id =
env->GetMethodID(cls, "add",
"(Ljava/lang/Object;)"
"Z");
rc = RegQueryValueEx((HKEY)hkey,
name, NULL,
&type, NULL, &size);
if (type != REG_MULTI_SZ) {
rc = ERROR_SUCCESS - 1;
}
if (rc == ERROR_SUCCESS) {
value =
(LPBYTE)HeapAlloc(GetProcessHeap(),
HEAP_ZERO_MEMORY, size);
if (RegQueryValueEx((HKEY)hkey, name, NULL, NULL,
value, &size) == ERROR_SUCCESS)
{
PTSTR ptr = (PTSTR)value;
while (*ptr) {
int len = _tcslen(ptr);
jstring jval =
env->NewString((const jchar *)ptr, len);
env->CallBooleanMethod(obj, id, jval);
ptr += len + 1;
}
}
HeapFree(GetProcessHeap(), 0, value);
}
env->ReleaseStringChars(jname, (const jchar *)name);
if (rc != ERROR_SUCCESS) {
jclass cls =
env->FindClass(WIN32_PACKAGE "Win32Exception");
env->ThrowNew(cls, "");
}
}
JNIEXPORT jint SIGAR_JNI(win32_RegistryKey_RegSetIntValue)
(JNIEnv * env, jclass, jlong hkey, jstring valueName, jint value)
{

View File

@ -19,6 +19,7 @@
package org.hyperic.sigar.win32;
import java.util.Collection;
import java.util.List;
import java.util.Vector;
public class RegistryKey extends Win32
@ -175,6 +176,12 @@ public class RegistryKey extends Win32
return strResult;
}
public void getMultiStringValue(String name, List values)
throws Win32Exception
{
RegQueryMultiStringValue(this.m_hkey, name, values);
}
public String getStringValue(String name, String defaultValue)
{
String strResult;
@ -281,6 +288,10 @@ public class RegistryKey extends Win32
private static native String RegQueryStringValue(long hkey,
String valueName);
private static native void RegQueryMultiStringValue(long hkey,
String valueName,
List values);
private static native int RegSetIntValue(long hkey,
String valueName,
int value);