From 4e7220c9246e740e6fff8a346dd72f359d732eb2 Mon Sep 17 00:00:00 2001 From: Elbandi Date: Thu, 17 Nov 2011 01:20:09 +0100 Subject: [PATCH] valueExists use the same code as getValue --- .../java/hudson/util/jna/RegistryKey.java | 28 +++++++++++++------ 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/core/src/main/java/hudson/util/jna/RegistryKey.java b/core/src/main/java/hudson/util/jna/RegistryKey.java index 95ae2c2772..18dc4f8d99 100644 --- a/core/src/main/java/hudson/util/jna/RegistryKey.java +++ b/core/src/main/java/hudson/util/jna/RegistryKey.java @@ -156,14 +156,26 @@ public class RegistryKey { * Does a specified value exist? */ public boolean valueExists(String name) { - int r = Advapi32.INSTANCE.RegQueryValueEx(handle, name, null, new IntByReference(), new byte[1], new IntByReference()); - switch(r) { - case WINERROR.ERROR_FILE_NOT_FOUND: - return false; - case WINERROR.ERROR_SUCCESS: - return true; - default: - throw new JnaException(r); + IntByReference pType, lpcbData; + byte[] lpData = new byte[1]; + + pType = new IntByReference(); + lpcbData = new IntByReference(); + + OUTER: + while(true) { + int r = Advapi32.INSTANCE.RegQueryValueEx(handle, name, null, pType, lpData, lpcbData); + switch(r) { + case WINERROR.ERROR_MORE_DATA: + lpData = new byte[lpcbData.getValue()]; + continue OUTER; + case WINERROR.ERROR_FILE_NOT_FOUND: + return false; + case WINERROR.ERROR_SUCCESS: + return true; + default: + throw new JnaException(r); + } } }