From a7aa63bacf4bcebf1b03c9a85e20a4fa863d479d Mon Sep 17 00:00:00 2001 From: Napoleon-x Date: Sun, 23 Jul 2023 17:30:16 +0100 Subject: [PATCH] Improve Windows compatibility by removing ICE_JNIRegistry.dll (and its java parts) and using a more efficient registry search method. Fixed another issue that caused an exception to be thrown at times. --- src/com/ice/jni/registry/HexNumberFormat.java | 140 -- .../ice/jni/registry/NoSuchKeyException.java | 56 - .../jni/registry/NoSuchValueException.java | 57 - src/com/ice/jni/registry/RegBinaryValue.java | 113 -- src/com/ice/jni/registry/RegDWordValue.java | 128 -- .../ice/jni/registry/RegMultiStringValue.java | 179 --- src/com/ice/jni/registry/RegStringValue.java | 115 -- src/com/ice/jni/registry/Registry.java | 1364 ----------------- .../ice/jni/registry/RegistryException.java | 75 - src/com/ice/jni/registry/RegistryKey.java | 697 --------- src/com/ice/jni/registry/RegistryValue.java | 164 -- src/com/ice/jni/registry/build.xml | 185 --- src/vlcskineditor/Main.java | 27 +- 13 files changed, 19 insertions(+), 3281 deletions(-) delete mode 100644 src/com/ice/jni/registry/HexNumberFormat.java delete mode 100644 src/com/ice/jni/registry/NoSuchKeyException.java delete mode 100644 src/com/ice/jni/registry/NoSuchValueException.java delete mode 100644 src/com/ice/jni/registry/RegBinaryValue.java delete mode 100644 src/com/ice/jni/registry/RegDWordValue.java delete mode 100644 src/com/ice/jni/registry/RegMultiStringValue.java delete mode 100644 src/com/ice/jni/registry/RegStringValue.java delete mode 100644 src/com/ice/jni/registry/Registry.java delete mode 100644 src/com/ice/jni/registry/RegistryException.java delete mode 100644 src/com/ice/jni/registry/RegistryKey.java delete mode 100644 src/com/ice/jni/registry/RegistryValue.java delete mode 100644 src/com/ice/jni/registry/build.xml diff --git a/src/com/ice/jni/registry/HexNumberFormat.java b/src/com/ice/jni/registry/HexNumberFormat.java deleted file mode 100644 index a2615f2..0000000 --- a/src/com/ice/jni/registry/HexNumberFormat.java +++ /dev/null @@ -1,140 +0,0 @@ -/* -** Java native interface to the Windows Registry API. -** -** Authored by Timothy Gerard Endres -** -** -** This work has been placed into the public domain. -** You may use this work in any way and for any purpose you wish. -** -** THIS SOFTWARE IS PROVIDED AS-IS WITHOUT WARRANTY OF ANY KIND, -** NOT EVEN THE IMPLIED WARRANTY OF MERCHANTABILITY. THE AUTHOR -** OF THIS SOFTWARE, ASSUMES _NO_ RESPONSIBILITY FOR ANY -** CONSEQUENCE RESULTING FROM THE USE, MODIFICATION, OR -** REDISTRIBUTION OF THIS SOFTWARE. -** -*/ - -package com.ice.jni.registry; - -import java.lang.*; -import java.text.*; -import java.util.*; - -/** - * The HexNumberFormat class implements the code necessary - * to format and parse Hexidecimal integer numbers. - * - * @version 3.1.3 - * - * @author Timothy Gerard Endres, time@ice.com. - * @see java.text.NumberFormat - */ - -public -class HexNumberFormat -extends Format - { - static public final String RCS_ID = "$Id: HexNumberFormat.java,v 1.1 2000/05/20 17:10:15 time Exp $"; - static public final String RCS_REV = "$Revision: 1.1 $"; - - private static char[] lowChars; - private static char[] uprChars; - - private int count; - private String pattern; - private static char[] hexChars; - - static - { - HexNumberFormat.lowChars = new char[20]; - HexNumberFormat.uprChars = new char[20]; - - HexNumberFormat.uprChars[0] = HexNumberFormat.lowChars[0] = '0'; - HexNumberFormat.uprChars[1] = HexNumberFormat.lowChars[1] = '1'; - HexNumberFormat.uprChars[2] = HexNumberFormat.lowChars[2] = '2'; - HexNumberFormat.uprChars[3] = HexNumberFormat.lowChars[3] = '3'; - HexNumberFormat.uprChars[4] = HexNumberFormat.lowChars[4] = '4'; - HexNumberFormat.uprChars[5] = HexNumberFormat.lowChars[5] = '5'; - HexNumberFormat.uprChars[6] = HexNumberFormat.lowChars[6] = '6'; - HexNumberFormat.uprChars[7] = HexNumberFormat.lowChars[7] = '7'; - HexNumberFormat.uprChars[8] = HexNumberFormat.lowChars[8] = '8'; - HexNumberFormat.uprChars[9] = HexNumberFormat.lowChars[9] = '9'; - HexNumberFormat.uprChars[10] = 'A'; HexNumberFormat.lowChars[10] = 'a'; - HexNumberFormat.uprChars[11] = 'B'; HexNumberFormat.lowChars[11] = 'b'; - HexNumberFormat.uprChars[12] = 'C'; HexNumberFormat.lowChars[12] = 'c'; - HexNumberFormat.uprChars[13] = 'D'; HexNumberFormat.lowChars[13] = 'd'; - HexNumberFormat.uprChars[14] = 'E'; HexNumberFormat.lowChars[14] = 'e'; - HexNumberFormat.uprChars[15] = 'F'; HexNumberFormat.lowChars[15] = 'f'; - } - - static public final HexNumberFormat - getInstance() - { - return new HexNumberFormat( "XXXXXXXX" ); - } - - public - HexNumberFormat( String pattern ) - { - super(); - this.pattern = pattern; - this.count = pattern.length(); - this.hexChars = - ( pattern.charAt(0) == 'X' - ? HexNumberFormat.uprChars - : HexNumberFormat.lowChars ); - } - - public String - format( int hexNum ) - throws IllegalArgumentException - { - FieldPosition pos = new FieldPosition(0); - StringBuffer hexBuf = new StringBuffer(8); - - this.format( new Integer( hexNum ), hexBuf, pos ); - - return hexBuf.toString(); - } - - public StringBuffer - format( Object hexInt, StringBuffer appendTo, FieldPosition fieldPos ) - throws IllegalArgumentException - { - char[] hexBuf = new char[16]; - - int end = fieldPos.getEndIndex(); - int beg = fieldPos.getBeginIndex(); - - int hexNum = ((Integer) hexInt).intValue(); - - for ( int i = 7 ; i >= 0 ; --i ) - { - hexBuf[i] = this.hexChars[ (hexNum & 0x0F) ]; - hexNum = hexNum >> 4; - } - - for ( int i = (8 - this.count) ; i < 8 ; ++i ) - { - appendTo.append( hexBuf[i] ); - } - - return appendTo; - } - - public int - parse( String source ) - throws ParseException - { - throw new ParseException( "unimplemented!", 0 ); - } - - public Object - parseObject( String source, ParsePosition pos ) - { - return null; - } - - } - diff --git a/src/com/ice/jni/registry/NoSuchKeyException.java b/src/com/ice/jni/registry/NoSuchKeyException.java deleted file mode 100644 index dbb009f..0000000 --- a/src/com/ice/jni/registry/NoSuchKeyException.java +++ /dev/null @@ -1,56 +0,0 @@ -/* -** Java native interface to the Windows Registry API. -** -** Authored by Timothy Gerard Endres -** -** -** This work has been placed into the public domain. -** You may use this work in any way and for any purpose you wish. -** -** THIS SOFTWARE IS PROVIDED AS-IS WITHOUT WARRANTY OF ANY KIND, -** NOT EVEN THE IMPLIED WARRANTY OF MERCHANTABILITY. THE AUTHOR -** OF THIS SOFTWARE, ASSUMES _NO_ RESPONSIBILITY FOR ANY -** CONSEQUENCE RESULTING FROM THE USE, MODIFICATION, OR -** REDISTRIBUTION OF THIS SOFTWARE. -** -*/ - -package com.ice.jni.registry; - -/** - * This exception is used to indicate that no such key exists in the registry. - * - * @version 3.1.3 - * - * @author Timothy Gerard Endres, - * time@ice.com. - */ - -public class -NoSuchKeyException extends RegistryException - { - static public final String RCS_ID = "$Id: NoSuchKeyException.java,v 1.1.1.1 1998/02/22 00:37:22 time Exp $"; - static public final String RCS_REV = "$Revision: 1.1.1.1 $"; - static public final String RCS_NAME = "$Name: $"; - - public - NoSuchKeyException() - { - super(); - } - - public - NoSuchKeyException( String msg ) - { - super( msg, Registry.ERROR_FILE_NOT_FOUND ); - } - - public - NoSuchKeyException( String msg, int regErr ) - { - super( msg, regErr ); - } - - } - - diff --git a/src/com/ice/jni/registry/NoSuchValueException.java b/src/com/ice/jni/registry/NoSuchValueException.java deleted file mode 100644 index 8c2ba46..0000000 --- a/src/com/ice/jni/registry/NoSuchValueException.java +++ /dev/null @@ -1,57 +0,0 @@ -/* -** Java native interface to the Windows Registry API. -** -** Authored by Timothy Gerard Endres -** -** -** This work has been placed into the public domain. -** You may use this work in any way and for any purpose you wish. -** -** THIS SOFTWARE IS PROVIDED AS-IS WITHOUT WARRANTY OF ANY KIND, -** NOT EVEN THE IMPLIED WARRANTY OF MERCHANTABILITY. THE AUTHOR -** OF THIS SOFTWARE, ASSUMES _NO_ RESPONSIBILITY FOR ANY -** CONSEQUENCE RESULTING FROM THE USE, MODIFICATION, OR -** REDISTRIBUTION OF THIS SOFTWARE. -** -*/ - -package com.ice.jni.registry; - -/** - * This exception is used to indicate that no such key exists in the registry. - * - * @version 3.1.3 - * - * @version $Revision: 1.1.1.1 $ - * @author Timothy Gerard Endres, - * time@ice.com. - */ - -public class -NoSuchValueException extends RegistryException - { - static public final String RCS_ID = "$Id: NoSuchValueException.java,v 1.1.1.1 1998/02/22 00:37:22 time Exp $"; - static public final String RCS_REV = "$Revision: 1.1.1.1 $"; - static public final String RCS_NAME = "$Name: $"; - - public - NoSuchValueException() - { - super(); - } - - public - NoSuchValueException( String msg ) - { - super( msg, Registry.ERROR_FILE_NOT_FOUND ); - } - - public - NoSuchValueException( String msg, int regErr ) - { - super( msg, regErr ); - } - - } - - diff --git a/src/com/ice/jni/registry/RegBinaryValue.java b/src/com/ice/jni/registry/RegBinaryValue.java deleted file mode 100644 index 75e34b5..0000000 --- a/src/com/ice/jni/registry/RegBinaryValue.java +++ /dev/null @@ -1,113 +0,0 @@ -/* -** Java native interface to the Windows Registry API. -** -** Authored by Timothy Gerard Endres -** -** -** This work has been placed into the public domain. -** You may use this work in any way and for any purpose you wish. -** -** THIS SOFTWARE IS PROVIDED AS-IS WITHOUT WARRANTY OF ANY KIND, -** NOT EVEN THE IMPLIED WARRANTY OF MERCHANTABILITY. THE AUTHOR -** OF THIS SOFTWARE, ASSUMES _NO_ RESPONSIBILITY FOR ANY -** CONSEQUENCE RESULTING FROM THE USE, MODIFICATION, OR -** REDISTRIBUTION OF THIS SOFTWARE. -** -*/ - -package com.ice.jni.registry; - -import java.io.OutputStreamWriter; -import java.io.PrintWriter; - - -/** - * The RegBinaryValue class represents a binary value in the - * registry (REG_BINARY). - * - * @version 3.1.3 - * - * @see com.ice.jni.registry.Registry - * @see com.ice.jni.registry.RegistryKey - */ - -public class -RegBinaryValue extends RegistryValue - { - byte[] data; - int dataLen; - - - public - RegBinaryValue( RegistryKey key, String name ) - { - super( key, name, RegistryValue.REG_BINARY ); - this.data = null; - this.dataLen = 0; - } - - public - RegBinaryValue( RegistryKey key, String name, int type ) - { - super( key, name, type ); - this.data = null; - this.dataLen = 0; - } - - public - RegBinaryValue( RegistryKey key, String name, byte[] data ) - { - super( key, name, RegistryValue.REG_BINARY ); - this.setData( data ); - } - - public byte[] - getData() - { - return this.data; - } - - public int - getLength() - { - return this.dataLen; - } - - public void - setData( byte[] data ) - { - this.data = data; - this.dataLen = data.length; - } - - public byte[] - getByteData() - { - return this.data; - } - - public int - getByteLength() - { - return this.dataLen; - } - - public void - setByteData( byte[] data ) - { - this.data = data; - this.dataLen = data.length; - } - - public void - export( PrintWriter out ) - { - out.println( "\"" + this.getName() + "\"=hex:\\" ); - RegistryValue.exportHexData( out, this.data ); - } - - } - - - - diff --git a/src/com/ice/jni/registry/RegDWordValue.java b/src/com/ice/jni/registry/RegDWordValue.java deleted file mode 100644 index 042729e..0000000 --- a/src/com/ice/jni/registry/RegDWordValue.java +++ /dev/null @@ -1,128 +0,0 @@ -/* -** Java native interface to the Windows Registry API. -** -** Authored by Timothy Gerard Endres -** -** -** This work has been placed into the public domain. -** You may use this work in any way and for any purpose you wish. -** -** THIS SOFTWARE IS PROVIDED AS-IS WITHOUT WARRANTY OF ANY KIND, -** NOT EVEN THE IMPLIED WARRANTY OF MERCHANTABILITY. THE AUTHOR -** OF THIS SOFTWARE, ASSUMES _NO_ RESPONSIBILITY FOR ANY -** CONSEQUENCE RESULTING FROM THE USE, MODIFICATION, OR -** REDISTRIBUTION OF THIS SOFTWARE. -** -*/ - -package com.ice.jni.registry; - -import java.io.PrintWriter; - - -/** - * The RegDWordValue class represents a double word, or - * integer, value in the registry (REG_DWORD). - * - * @see com.ice.jni.registry.Registry - * @see com.ice.jni.registry.RegistryKey - * - * @version 3.1.3 - * - */ - -public class -RegDWordValue extends RegistryValue - { - int data; - int dataLen; - - public - RegDWordValue( RegistryKey key, String name ) - { - super( key, name, RegistryValue.REG_DWORD ); - this.data = 0; - this.dataLen = 0; - } - - public - RegDWordValue( RegistryKey key, String name, int type ) - { - super( key, name, type ); - this.data = 0; - this.dataLen = 0; - } - - public - RegDWordValue( RegistryKey key, String name, int type, int data ) - { - super( key, name, RegistryValue.REG_DWORD ); - this.setData( data ); - } - - public int - getData() - { - return this.data; - } - - public int - getLength() - { - return this.dataLen; - } - - public void - setData( int data ) - { - this.data = data; - this.dataLen = 1; - } - - public byte[] - getByteData() - { - byte[] result = new byte[4]; - - result[0] = (byte) ( (this.data >> 24) & 255 ); - result[1] = (byte) ( (this.data >> 16) & 255 ); - result[2] = (byte) ( (this.data >> 8) & 255 ); - result[3] = (byte) ( this.data & 255 ); - - return result; - } - - public int - getByteLength() - { - return 4; - } - - public void - setByteData( byte[] data ) - { - int newValue = - ( (((int) data[0]) << 24) & 0xFF000000 ) - | ( (((int) data[1]) << 16) & 0x00FF0000 ) - | ( (((int) data[2]) << 8) & 0x0000FF00 ) - | ( ((int) data[3]) & 0x000000FF ); - - this.setData( newValue ); - } - - public void - export( PrintWriter out ) - { - out.print( "\"" + this.getName() + "\"=" ); - - HexNumberFormat nFmt = - new HexNumberFormat( "xxxxxxxx" ); - - out.println( "dword:" + nFmt.format( this.getData() ) ); - } - - } - - - - diff --git a/src/com/ice/jni/registry/RegMultiStringValue.java b/src/com/ice/jni/registry/RegMultiStringValue.java deleted file mode 100644 index cbd0c81..0000000 --- a/src/com/ice/jni/registry/RegMultiStringValue.java +++ /dev/null @@ -1,179 +0,0 @@ -/* -** Java native interface to the Windows Registry API. -** -** Authored by Timothy Gerard Endres -** -** -** This work has been placed into the public domain. -** You may use this work in any way and for any purpose you wish. -** -** THIS SOFTWARE IS PROVIDED AS-IS WITHOUT WARRANTY OF ANY KIND, -** NOT EVEN THE IMPLIED WARRANTY OF MERCHANTABILITY. THE AUTHOR -** OF THIS SOFTWARE, ASSUMES _NO_ RESPONSIBILITY FOR ANY -** CONSEQUENCE RESULTING FROM THE USE, MODIFICATION, OR -** REDISTRIBUTION OF THIS SOFTWARE. -** -*/ - -package com.ice.jni.registry; - -import java.io.PrintWriter; - - -/** - * The RegMultiStringValue class represents a multiple - * string, or string array, value in the registry - * (REG_MULTI_SZ). - * - * @version 3.1.3 - * - * @see com.ice.jni.registry.Registry - * @see com.ice.jni.registry.RegistryKey - */ - -public class -RegMultiStringValue extends RegistryValue - { - String[] data; - int dataLen; - - - public - RegMultiStringValue( RegistryKey key, String name ) - { - super( key, name, RegistryValue.REG_MULTI_SZ ); - this.data = null; - this.dataLen = 0; - } - - public - RegMultiStringValue( RegistryKey key, String name, int type ) - { - super( key, name, type ); - this.data = null; - this.dataLen = 0; - } - - public - RegMultiStringValue( RegistryKey key, String name, String[] data ) - { - super( key, name, RegistryValue.REG_MULTI_SZ ); - this.setData( data ); - } - - public String[] - getData() - { - return this.data; - } - - public int - getLength() - { - return this.dataLen; - } - - public void - setData( String[] data ) - { - this.data = data; - this.dataLen = data.length; - } - - public byte[] - getByteData() - { - int len = this.getByteLength(); - - int ri = 0; - byte[] result = new byte[len]; - for ( int i = 0 ; i < this.dataLen ; ++i ) - { - byte[] strBytes = this.data[i].getBytes(); - - for ( int j = 0 ; j < strBytes.length ; ++j ) - result[ri++] = strBytes[j]; - - result[ri++] = 0; - } - - return result; - } - - public int - getByteLength() - { - int len = 0; - for ( int i = 0 ; i < this.dataLen ; ++i ) - len += this.data[i].length() + 1; - - return len; - } - - public void - setByteData( byte[] data ) - { - int start; - int count = 0; - - for ( int i = 0 ; i < data.length ; ++i ) - { - if ( data[i] == 0 ) - count++; - } - - int si = 0; - String[] newData = new String[ count ]; - for ( int i = start = 0 ; i < data.length ; ++i ) - { - if ( data[i] == 0 ) - { - newData[si] = new String( data, start, (i - start) ); - start = si; - } - } - - this.setData( newData ); - } - - public void - export( PrintWriter out ) - { - byte[] hexData; - int dataLen = 0; - - out.println( "\"" + this.getName() + "\"=hex(7):\\" ); - - for ( int i = 0 ; i < this.data.length ; ++i ) - { - dataLen += this.data[i].length() + 1; - } - - ++dataLen; - - int idx = 0; - hexData = new byte[ dataLen ]; - - for ( int i = 0 ; i < this.data.length ; ++i ) - { - int strLen = this.data[i].length(); - byte[] strBytes = this.data[i].getBytes(); - - System.arraycopy - ( strBytes, 0, hexData, idx, strLen ); - - idx += strLen; - - hexData[ idx++ ] = 0; - } - - hexData[ idx++ ] = 0; - - RegistryValue.exportHexData( out, hexData ); - } - - } - - - - diff --git a/src/com/ice/jni/registry/RegStringValue.java b/src/com/ice/jni/registry/RegStringValue.java deleted file mode 100644 index 661203a..0000000 --- a/src/com/ice/jni/registry/RegStringValue.java +++ /dev/null @@ -1,115 +0,0 @@ -/* -** Java native interface to the Windows Registry API. -** -** Authored by Timothy Gerard Endres -** -** -** This work has been placed into the public domain. -** You may use this work in any way and for any purpose you wish. -** -** THIS SOFTWARE IS PROVIDED AS-IS WITHOUT WARRANTY OF ANY KIND, -** NOT EVEN THE IMPLIED WARRANTY OF MERCHANTABILITY. THE AUTHOR -** OF THIS SOFTWARE, ASSUMES _NO_ RESPONSIBILITY FOR ANY -** CONSEQUENCE RESULTING FROM THE USE, MODIFICATION, OR -** REDISTRIBUTION OF THIS SOFTWARE. -** -*/ - -package com.ice.jni.registry; - -import java.io.PrintWriter; - - -/** - * The RegStringValue class represents a string value in the - * registry (REG_SZ, and REG_EXPAND_SZ). - * - * @version 3.1.3 - * - * @see com.ice.jni.registry.Registry - * @see com.ice.jni.registry.RegistryKey - */ - -public class -RegStringValue extends RegistryValue - { - String data; - int dataLen; - - - public - RegStringValue( RegistryKey key, String name ) - { - super( key, name, RegistryValue.REG_SZ ); - this.data = null; - this.dataLen = 0; - } - - public - RegStringValue( RegistryKey key, String name, int type ) - { - super( key, name, type ); - this.data = null; - this.dataLen = 0; - } - - public - RegStringValue( RegistryKey key, String name, String data ) - { - super( key, name, RegistryValue.REG_SZ ); - this.setData( data ); - } - - public String - getData() - { - return this.data; - } - - public int - getLength() - { - return this.dataLen; - } - - public void - setData( String data ) - { - this.data = data; - this.dataLen = data.length(); - } - - public byte[] - getByteData() - { - return this.data.getBytes(); - } - - public int - getByteLength() - { - return this.dataLen; - } - - public void - setByteData( byte[] data ) - { - this.setData( new String( data ) ); - } - - public void - export( PrintWriter out ) - { - if ( this.getName().length() == 0 ) - out.print( "@=" ); - else - out.print( "\"" + this.getName() + "\"=" ); - - out.println( "\"" + this.getData() + "\"" ); - } - - } - - - - diff --git a/src/com/ice/jni/registry/Registry.java b/src/com/ice/jni/registry/Registry.java deleted file mode 100644 index 97d87e8..0000000 --- a/src/com/ice/jni/registry/Registry.java +++ /dev/null @@ -1,1364 +0,0 @@ -/* -** Java native interface to the Windows Registry API. -** -** Authored by Timothy Gerard Endres -** -** -** This work has been placed into the public domain. -** You may use this work in any way and for any purpose you wish. -** -** THIS SOFTWARE IS PROVIDED AS-IS WITHOUT WARRANTY OF ANY KIND, -** NOT EVEN THE IMPLIED WARRANTY OF MERCHANTABILITY. THE AUTHOR -** OF THIS SOFTWARE, ASSUMES _NO_ RESPONSIBILITY FOR ANY -** CONSEQUENCE RESULTING FROM THE USE, MODIFICATION, OR -** REDISTRIBUTION OF THIS SOFTWARE. -** - * Modified by Daniel Dreibrodt to compile safely with JDK 1.5+ - * -*/ - -package com.ice.jni.registry; - -import java.io.*; -import java.net.URL; -import java.util.*; - - -/** - * The Registry class provides is used to load the native - * library DLL, as well as a placeholder for the top level - * keys, error codes, and utility methods. - * - * @version 3.1.3.DD - * - */ - -public class -Registry - { - /** - * The following statics are the top level keys. - * Without these, there is no way to get "into" - * the registry, since the RegOpenSubkey() call - * requires an existing key which contains the - * subkey. - */ - public static RegistryKey HKEY_CLASSES_ROOT; - public static RegistryKey HKEY_CURRENT_USER; - public static RegistryKey HKEY_LOCAL_MACHINE; - public static RegistryKey HKEY_USERS; - public static RegistryKey HKEY_PERFORMANCE_DATA; - public static RegistryKey HKEY_CURRENT_CONFIG; - public static RegistryKey HKEY_DYN_DATA; - - /** - * This is a key for ICE's testing purposes. - */ - private static RegistryKey HKEY_ICE_TESTKEY = null; - /** - * These are predefined keys ($0-$9) used to make the - * testing program easier to use (less typing). - */ - private static String[] preDefines; - - /** - * These are the Registry API error codes, which can - * be returned via the RegistryException. - */ - public static final int ERROR_SUCCESS = 0; - public static final int ERROR_FILE_NOT_FOUND = 2; - public static final int ERROR_ACCESS_DENIED = 5; - public static final int ERROR_INVALID_HANDLE = 6; - public static final int ERROR_INVALID_PARAMETER = 87; - public static final int ERROR_CALL_NOT_IMPLEMENTED = 120; - public static final int ERROR_INSUFFICIENT_BUFFER = 122; - public static final int ERROR_LOCK_FAILED = 167; - public static final int ERROR_TRANSFER_TOO_LONG = 222; - public static final int ERROR_MORE_DATA = 234; - public static final int ERROR_NO_MORE_ITEMS = 259; - public static final int ERROR_BADDB = 1009; - public static final int ERROR_BADKEY = 1010; - public static final int ERROR_CANTOPEN = 1011; - public static final int ERROR_CANTREAD = 1012; - public static final int ERROR_CANTWRITE = 1013; - public static final int ERROR_REGISTRY_RECOVERED = 1014; - public static final int ERROR_REGISTRY_CORRUPT = 1015; - public static final int ERROR_REGISTRY_IO_FAILED = 1016; - public static final int ERROR_NOT_REGISTRY_FILE = 1017; - public static final int ERROR_KEY_DELETED = 1018; - - /** - * These are used by dumpHex(). - */ - private static final int ROW_BYTES = 16; - private static final int ROW_QTR1 = 3; - private static final int ROW_HALF = 7; - private static final int ROW_QTR2 = 11; - - - /** - * This is the last key used by the test program ($$). - */ - private static String saveKey = null; - /** - * This is a Hashtable which maps nams to the top level keys. - */ - private static Hashtable topLevelKeys = null; - - - /** - * If true, debug the fv parameters and computation. - */ - public boolean debugLevel; - - /** - * Loads the DLL needed for the native methods, creates the - * toplevel keys, fills the hashtable that maps various names - * to the toplevel keys. - */ - - static - { - try { - System.loadLibrary("ICE_JNIRegistry"); - } - catch ( UnsatisfiedLinkError e ) - { - System.err.println - ( "ERROR You have not installed the DLL named '" - + "ICE_JNIRegistry.DLL'.\n\t" + e.getMessage() ); - } - catch ( SecurityException e ) - { - System.err.println - ( "ERROR You do not have permission to load the DLL named '" - + "ICE_JNIRegistry.DLL'.\n\t" + e.getMessage() ); - } - - Registry.HKEY_CLASSES_ROOT = - new RegistryKey( 0x80000000, "HKEY_CLASSES_ROOT" ); - - Registry.HKEY_CURRENT_USER = - new RegistryKey( 0x80000001, "HKEY_CURRENT_USER" ); - - Registry.HKEY_LOCAL_MACHINE = - new RegistryKey( 0x80000002, "HKEY_LOCAL_MACHINE" ); - - Registry.HKEY_USERS = - new RegistryKey( 0x80000003, "HKEY_USERS" ); - - Registry.HKEY_PERFORMANCE_DATA = - new RegistryKey( 0x80000004, "HKEY_PERFORMANCE_DATA" ); - - Registry.HKEY_CURRENT_CONFIG = - new RegistryKey( 0x80000005, "HKEY_CURRENT_CONFIG" ); - - Registry.HKEY_DYN_DATA = - new RegistryKey( 0x80000006, "HKEY_DYN_DATA" ); - - - Registry.topLevelKeys = new Hashtable( 16 ); - - topLevelKeys.put( "HKCR", Registry.HKEY_CLASSES_ROOT ); - topLevelKeys.put( "HKEY_CLASSES_ROOT", Registry.HKEY_CLASSES_ROOT ); - - topLevelKeys.put( "HKCU", Registry.HKEY_CURRENT_USER ); - topLevelKeys.put( "HKEY_CURRENT_USER", Registry.HKEY_CURRENT_USER ); - - topLevelKeys.put( "HKLM", Registry.HKEY_LOCAL_MACHINE ); - topLevelKeys.put( "HKEY_LOCAL_MACHINE", Registry.HKEY_LOCAL_MACHINE ); - - topLevelKeys.put( "HKU", Registry.HKEY_USERS ); - topLevelKeys.put( "HKUS", Registry.HKEY_USERS ); - topLevelKeys.put( "HKEY_USERS", Registry.HKEY_USERS ); - - topLevelKeys.put( "HKPD", Registry.HKEY_PERFORMANCE_DATA ); - topLevelKeys.put( "HKEY_PERFORMANCE_DATA", Registry.HKEY_PERFORMANCE_DATA ); - - topLevelKeys.put( "HKCC", Registry.HKEY_PERFORMANCE_DATA ); - topLevelKeys.put( "HKEY_CURRENT_CONFIG", Registry.HKEY_PERFORMANCE_DATA ); - - topLevelKeys.put( "HKDD", Registry.HKEY_PERFORMANCE_DATA ); - topLevelKeys.put( "HKEY_DYN_DATA", Registry.HKEY_PERFORMANCE_DATA ); - } - - /** - * Get a top level key by name using the top level key Hashtable. - * - * @param keyName The name of the top level key. - * @return The top level RegistryKey, or null if unknown keyName. - */ - - public static RegistryKey - getTopLevelKey( String keyName ) - { - return (RegistryKey) - Registry.topLevelKeys.get( keyName ); - } - - /** - * Open a subkey of a given top level key. - * - * @param topKey The top level key containing the subkey. - * @param keyName The subkey's name. - * @param access The access flag for the newly opened key. - * @return The newly opened RegistryKey. - * - * @see RegistryKey - */ - - public static RegistryKey - openSubkey( RegistryKey topKey, String keyName, int access ) - { - RegistryKey subKey = null; - - try { subKey = topKey.openSubKey( keyName, access ); } - catch ( NoSuchKeyException ex ) - { - subKey = null; - } - catch ( RegistryException ex ) - { - subKey = null; - } - - return subKey; - } - - /** - * Get the description of a Registry error code. - * - * @param errCode The error code from a RegistryException - * @return The description of the error code. - */ - - public static String - getErrorMessage( int errCode ) - { - switch ( errCode ) - { - case ERROR_SUCCESS: return "success"; - case ERROR_FILE_NOT_FOUND: return "key or value not found"; - case ERROR_ACCESS_DENIED: return "access denied"; - case ERROR_INVALID_HANDLE: return "invalid handle"; - case ERROR_INVALID_PARAMETER: return "invalid parameter"; - case ERROR_CALL_NOT_IMPLEMENTED: return "call not implemented"; - case ERROR_INSUFFICIENT_BUFFER: return "insufficient buffer"; - case ERROR_LOCK_FAILED: return "lock failed"; - case ERROR_TRANSFER_TOO_LONG: return "transfer was too long"; - case ERROR_MORE_DATA: return "more data buffer needed"; - case ERROR_NO_MORE_ITEMS: return "no more items"; - case ERROR_BADDB: return "bad database"; - case ERROR_BADKEY: return "bad key"; - case ERROR_CANTOPEN: return "can not open"; - case ERROR_CANTREAD: return "can not read"; - case ERROR_CANTWRITE: return "can not write"; - case ERROR_REGISTRY_RECOVERED: return "registry recovered"; - case ERROR_REGISTRY_CORRUPT: return "registry corrupt"; - case ERROR_REGISTRY_IO_FAILED: return "registry IO failed"; - case ERROR_NOT_REGISTRY_FILE: return "not a registry file"; - case ERROR_KEY_DELETED: return "key has been deleted"; - } - - return "errCode=" + errCode; - } - - /** - * Export the textual definition for a registry key to a file. - * The resulting file can be re-loaded via RegEdit. - * - * @param pathName The pathname of the file into which to export. - * @param key The registry key definition to export. - * @param descend If true, descend and export all subkeys. - * - * @exception NoSuchKeyException Thrown by openSubKey(). - * @exception RegistryException Any other registry API error. - */ - - public static void - exportRegistryKey( String pathName, RegistryKey key, boolean descend ) - throws java.io.IOException, NoSuchKeyException, RegistryException - { - PrintWriter out = - new PrintWriter( - new FileWriter( pathName ) ); - - out.println( "REGEDIT4" ); - out.println( "" ); - - key.export( out, descend ); - - out.flush(); - out.close(); - } - - /** - * The main() method is used to test the Registry package. - */ - - public static void - main( String argv[] ) - { - Registry.preDefines = new String[10]; - - Registry.preDefines[0] = "HKLM\\System\\CurrentControlSet\\control"; - Registry.preDefines[1] = "HKLM\\Software"; - Registry.preDefines[2] = "HKLM\\Software\\Miscrosoft"; - Registry.preDefines[3] = "HKLM\\Software\\Microsoft\\Windows" - + "\\CurrentVersion"; - Registry.preDefines[4] = "HKLM\\Software\\Microsoft\\Windows" - + "\\CurrentVersion\\ProfileList"; - Registry.preDefines[5] = "HKCU\\Software"; - Registry.preDefines[6] = "HKCU\\Software\\Microsoft"; - Registry.preDefines[7] = "HKCU\\AppEvents"; - Registry.preDefines[8] = "HKCU\\AppEvents\\Schemes"; - Registry.preDefines[9] = "HKCU\\AppEvents\\Schemes"; - - try { - Registry.HKEY_ICE_TESTKEY = - Registry.HKEY_CURRENT_USER.openSubKey - ( "Software\\ICE Engineering\\test" ); - } - catch ( NoSuchKeyException ex ) - { - } - catch ( RegistryException ex ) - { - } - - if ( argv.length > 0 ) - { - Registry.subMain( argv ); - } - else - { - String inLine; - String saveLine = null; - BufferedReader input = - new BufferedReader - ( new InputStreamReader( System.in ) ); - - for ( ; ; ) - { - System.out.print( "command: " ); - System.out.flush(); - - try { inLine = input.readLine(); } - catch ( IOException ex ) - { inLine = null; } - - if ( inLine == null || inLine.length() == 0 ) - break; - - if ( inLine.equalsIgnoreCase( "help" ) ) - { - Registry.usage( null ); - continue; - } - - String[] subArgs; - if ( inLine.equals( "!!" ) && saveLine != null ) - { - subArgs = - Registry.parseArgumentString( saveLine ); - } - else - { - subArgs = - Registry.parseArgumentString( inLine ); - saveLine = inLine; - } - - Registry.subMain( subArgs ); - } - } - } - - /** - * Print the usage/help information. - */ - - public static void - usage( String message ) - { - if ( message != null ) - System.err.println( message ); - - System.err.println - ( "keys regKey -- print the key names" ); - System.err.println - ( "values regKey -- print the value names" ); - System.err.println - ( "data regKey subKey -- print the key's data" ); - System.err.println - ( "string regKey subKey -- print REG_SZ key's string" ); - System.err.println - ( "setbin regKey subKey binaryString -- set REG_BINARY" ); - System.err.println - ( "setdw regKey subKey int -- set REG_DWORD" ); - System.err.println - ( "setstr regKey subKey string -- set REG_SZ" ); - System.err.println - ( "setmulti regKey subKey semiColonString -- set REG_MULTI_SZ" ); - System.err.println - ( "delkey regKey subKey -- delete key 'subKey' of regKey" ); - System.err.println - ( "delval regKey subKey -- delete value 'subKey' of regKey" ); - System.err.println - ( "export regKey fileName -- export registry key to fileName" ); - System.err.println - ( "expand regKey valueName -- expand string value" ); - - System.err.println( "" ); - - System.err.println - ( "!! -- repeats last command" ); - System.err.println - ( "$$ -- re-uses previous keyname" ); - System.err.println - ( "Predefined Key Prefixes: (e.g. $0-9)" ); - for ( int idx = 0 ; idx < Registry.preDefines.length ; ++idx ) - System.err.println - ( " $" + idx + "=" + Registry.preDefines[idx] ); - } - - /** - * The actual main method, which is called for each command. - */ - - public static void - subMain( String argv[] ) - { - int index; - RegistryKey key; - RegistryKey subKey; - RegistryKey topKey = null; - boolean isRemote = false; - String topKeyName = null; - String hostName = null; - - if ( argv.length < 1 || argv[0].equals( "help" ) ) - { - Registry.usage( null ); - return; - } - - if ( argv.length < 2 ) - { - Registry.usage( null ); - return; - } - - String keyName = argv[1]; - - if ( Registry.saveKey != null - && keyName.equals( "$$" ) ) - { - keyName = Registry.saveKey; - } - else if ( keyName.equals( "@@" ) ) - { - keyName = "HKCU\\Software\\ICE Engineering\\test"; - } - else - { - char ch1 = keyName.charAt(0); - char ch2 = keyName.charAt(1); - - if ( ch1 == '$' && ch2 >= '0' && ch2 <= '9' ) - { - int pIdx = (ch2 - '0'); - if ( Registry.preDefines[ pIdx ] != null ) - { - if ( keyName.length() < 3 ) - keyName = Registry.preDefines[ pIdx ]; - else - keyName = - Registry.preDefines[ pIdx ] - + keyName.substring( 2 ); - } - else - { - System.err.println - ( "Predefine '" + keyName + "' not defined." ); - return; - } - } - else - { - Registry.saveKey = argv[1]; - } - } - - if ( keyName.startsWith( "\\\\" ) ) - { - isRemote = true; - index = keyName.indexOf( '\\', 2 ); - hostName = keyName.substring( 2, index ); - keyName = keyName.substring( index + 1 ); - } - - index = keyName.indexOf( '\\' ); - - if ( index < 0 ) - { - // - // "topLevelKeyname" - // - topKeyName = keyName; - keyName = null; - } - else if ( index < 4 ) - { - // - // INVALID KEYNAME, topLevelName too short - // - System.err.println - ( "Invalid key '" + keyName - + "', top level key name too short." ); - return; - } - else - { - // - // "topLevelKeyname\subKey\subKey\..." - // - topKeyName = keyName.substring( 0, index ); - - if ( (index + 1) >= keyName.length() ) - keyName = null; - else - keyName = keyName.substring( index + 1 ); - } - - topKey = Registry.getTopLevelKey( topKeyName ); - if ( topKey == null ) - { - System.err.println - ( "ERROR, toplevel key '" + topKeyName - + "' not resolved!" ); - return; - } - - if ( isRemote ) - { - System.err.println - ( "REMOTE Key host='" + hostName + "'" ); - - RegistryKey remoteKey = null; - - try { - remoteKey = topKey.connectRegistry( hostName ); - } - catch ( NoSuchKeyException ex ) - { - System.err.println - ( "ERROR No such key connecting to '" - + hostName + "', " + ex.getMessage() ); - return; - } - catch ( RegistryException ex ) - { - System.err.println - ( "ERROR errCode=" + ex.getErrorCode() - + "' connecting to '" + hostName - + "', " + ex.getMessage() ); - return; - } - - if ( remoteKey != null ) - { - topKey = remoteKey; - } - } - - - // - // P R O C E S S C O M M A N D S - // - - if ( argv[0].equalsIgnoreCase( "create" ) ) - { - Registry.createCommand( topKey, keyName ); - } - else if ( argv[0].equalsIgnoreCase( "setbin" ) ) - { - Registry.setBinaryCommand - ( topKey, keyName, argv[2], argv[3] ); - } - else if ( argv[0].equalsIgnoreCase( "setdw" ) ) - { - Registry.setBinaryCommand - ( topKey, keyName, argv[2], argv[3] ); - } - else if ( argv[0].equalsIgnoreCase( "setstr" ) ) - { - Registry.setStringCommand - ( topKey, keyName, argv[2], argv[3] ); - } - else if ( argv[0].equalsIgnoreCase( "setmulti" ) ) - { - Registry.setMultiStringCommand - ( topKey, keyName, argv[2], argv[3] ); - } - else if ( argv[0].equalsIgnoreCase( "keys" ) ) - { - Registry.listKeysCommand( topKey, keyName ); - } - else if ( argv[0].equalsIgnoreCase( "values" ) ) - { - Registry.listValuesCommand( topKey, keyName ); - } - else if ( argv[0].equalsIgnoreCase( "delkey" ) ) - { - Registry.deleteKeyCommand( topKey, keyName, argv[2] ); - } - else if ( argv[0].equalsIgnoreCase( "delval" ) ) - { - Registry.deleteValueCommand( topKey, keyName, argv[2] ); - } - else if ( argv[0].equalsIgnoreCase( "data" ) ) - { - Registry.getDataCommand( topKey, keyName, argv[2] ); - } - else if ( argv[0].equalsIgnoreCase( "string" ) ) - { - Registry.getStringCommand( topKey, keyName, argv[2] ); - } - else if ( argv[0].equalsIgnoreCase( "export" ) ) - { - Registry.exportKeyCommand( topKey, keyName, argv[2] ); - } - else if ( argv[0].equalsIgnoreCase( "expand" ) ) - { - Registry.expandStringCommand( topKey, keyName, argv[2] ); - } - } - - private static void - exportKeyCommand( - RegistryKey topKey, String keyName, String pathName ) - { - RegistryKey subKey = - Registry.openSubKeyVerbose - ( topKey, keyName, RegistryKey.ACCESS_READ ); - - if ( subKey == null ) - return; - - try { Registry.exportRegistryKey( pathName, subKey, true ); } - catch ( IOException ex ) - { - System.err.println - ( "IO Exception: '" + ex.getMessage() + "'" ); - } - catch ( NoSuchKeyException ex ) - { - System.err.println - ( "Error, encountered non-existent key during export." ); - } - catch ( RegistryException ex ) - { - System.err.println - ( "ERROR registry error=" + ex.getErrorCode() - + ", " + ex.getMessage() ); - } - } - - private static void - getDataCommand( - RegistryKey topKey, String keyName, String valueName ) - { - RegistryKey subKey = - Registry.openSubKeyVerbose - ( topKey, keyName, RegistryKey.ACCESS_READ ); - - if ( subKey == null ) - return; - - RegistryValue data = null; - - try { data = subKey.getValue( valueName ); } - catch ( NoSuchValueException ex ) - { - System.err.println - ( "Value '" + valueName + "' does not exist." ); - return; - } - catch ( RegistryException ex ) - { - System.err.println - ( "ERROR registry error=" + ex.getErrorCode() - + ", " + ex.getMessage() ); - return; - } - - System.err.println - ( "Value '" + valueName + "' is " + data.toString() ); - - if ( data instanceof RegStringValue ) - { - RegStringValue val = (RegStringValue) data; - System.err.println( "REG_SZ '" + val.getData() + "'" ); - } - else if ( data instanceof RegMultiStringValue ) - { - RegMultiStringValue val = (RegMultiStringValue) data; - String[] args = val.getData(); - for ( int idx = 0 ; idx < args.length ; ++idx ) - System.err.println - ( "REG_MULTI_SZ[" + idx + "] '" - + args[idx] + "'" ); - } - else if ( data instanceof RegDWordValue ) - { - RegDWordValue val = (RegDWordValue) data; - - HexNumberFormat xFmt = - new HexNumberFormat( "XXXXXXXX" ); - - System.err.println( - "REG_DWORD" - + ( (RegistryValue.REG_DWORD_BIG_ENDIAN - == val.getType()) - ? "_BIG_ENDIAN" : "" ) - + " '" + val.getData() + "' [x" - + xFmt.format( val.getData() ) + "]" ); - } - else - { - RegBinaryValue val = (RegBinaryValue) data; - /* - System.err.println( "BINARY: len=" + val.getLength() ); - System.err.println( "BINARY: [0]=" + val.getData()[0] ); - System.err.println( "BINARY: [1]=" + val.getData()[1] ); - System.err.println( "BINARY: [2]=" + val.getData()[2] ); - System.err.println( "BINARY: [3]=" + val.getData()[3] ); - */ - Registry.dumpHexData - ( System.err, - "REG_BINARY '" + val.getName() - + "', len=" + val.getLength(), - val.getData(), val.getLength() ); - } - } - - private static void - getStringCommand( - RegistryKey topKey, String keyName, String valueName ) - { - RegistryKey subKey = - Registry.openSubKeyVerbose - ( topKey, keyName, RegistryKey.ACCESS_READ ); - - if ( subKey == null ) - return; - - try { - String value = subKey.getStringValue( valueName ); - System.err.println - ( "String Value " + valueName + "='" + value + "'" ); - } - catch ( RegistryException ex ) - { - System.err.println - ( "ERROR getting value '" + valueName + "', " - + ex.getMessage() ); - return; - } - } - - private static void - expandStringCommand( - RegistryKey topKey, String keyName, String valueName ) - { - RegistryKey subKey = - Registry.openSubKeyVerbose - ( topKey, keyName, RegistryKey.ACCESS_READ ); - - if ( subKey == null ) - return; - - try { - String value = subKey.getStringValue( valueName ); - System.err.println - ( "String Value " + valueName + "='" + value + "'" ); - value = RegistryKey.expandEnvStrings( value ); - System.err.println - ( "Expanded Value " + valueName + "='" + value + "'" ); - } - catch ( RegistryException ex ) - { - System.err.println - ( "ERROR getting value '" + valueName + "', " - + ex.getMessage() ); - return; - } - } - - private static void - deleteKeyCommand( - RegistryKey topKey, String keyName, String deleteKeyName ) - { - RegistryKey subKey = - Registry.openSubKeyVerbose - ( topKey, keyName, RegistryKey.ACCESS_WRITE ); - - if ( subKey == null ) - return; - - try { subKey.deleteSubKey( deleteKeyName ); } - catch ( NoSuchKeyException ex ) - { - System.err.println - ( "Key '" + keyName + "\\" - + deleteKeyName + "' does not exist." ); - return; - } - catch ( RegistryException ex ) - { - System.err.println - ( "ERROR deleting key '" + keyName - + "', " + ex.getMessage() ); - return; - } - } - - private static void - deleteValueCommand( - RegistryKey topKey, String keyName, String valueName ) - { - RegistryKey subKey = - Registry.openSubKeyVerbose - ( topKey, keyName, RegistryKey.ACCESS_WRITE ); - - if ( subKey == null ) - return; - - try { subKey.deleteValue( valueName ); } - catch ( NoSuchValueException ex ) - { - System.err.println - ( "Value '" + valueName + "' does not exist." ); - return; - } - catch ( RegistryException ex ) - { - System.err.println - ( "ERROR deleting value '" + valueName - + "', " + ex.getMessage() ); - return; - } - } - - private static void - listKeysCommand( RegistryKey topKey, String keyName ) - { - RegistryKey subKey = - Registry.openSubKeyVerbose - ( topKey, keyName, RegistryKey.ACCESS_READ ); - - if ( subKey == null ) - return; - - try { - Enumeration enum_var = subKey.keyElements(); - for ( int kIdx = 0 ; enum_var.hasMoreElements() ; ++kIdx ) - { - String keyStr = (String) enum_var.nextElement(); - System.err.println - ( "Subkey[" + kIdx + "] = '" + keyStr + "'" ); - } - } - catch ( RegistryException ex ) - { - System.err.println - ( "ERROR getting key enum_varerator, " - + ex.getMessage() ); - return; - } - } - - private static void - listValuesCommand( RegistryKey topKey, String keyName ) - { - RegistryKey subKey = - Registry.openSubKeyVerbose - ( topKey, keyName, RegistryKey.ACCESS_READ ); - - if ( subKey == null ) - return; - - try { - Enumeration enum_var = subKey.valueElements(); - for ( int kIdx = 0 ; enum_var.hasMoreElements() ; ++kIdx ) - { - String name = (String) enum_var.nextElement(); - System.err.println - ( "Value Name[" + kIdx + "] = '" + name + "'" ); - } - } - catch ( RegistryException ex ) - { - System.err.println - ( "ERROR getting value enum_varerator, " - + ex.getMessage() ); - return; - } - } - - private static void - setDWordCommand( - RegistryKey topKey, String keyName, - String valueName, String data ) - { - RegistryKey subKey = - Registry.openSubKeyVerbose - ( topKey, keyName, RegistryKey.ACCESS_WRITE ); - - if ( subKey == null ) - return; - - int anInt; - try { anInt = Integer.parseInt( data ); } - catch ( NumberFormatException ex ) - { - System.err.println - ( "ERROR bad int: '" + ex.getMessage() + "'" ); - return; - } - - RegDWordValue val = new RegDWordValue( subKey, valueName ); - val.setData( anInt ); - - Registry.setValue( subKey, val ); - } - - private static void - setMultiStringCommand( - RegistryKey topKey, String keyName, - String valueName, String data ) - { - RegistryKey subKey = - Registry.openSubKeyVerbose - ( topKey, keyName, RegistryKey.ACCESS_WRITE ); - - if ( subKey == null ) - return; - - String[] strArray = - Registry.splitString( data, ";" ); - - RegMultiStringValue val = - new RegMultiStringValue - ( subKey, valueName, strArray ); - - Registry.setValue( subKey, val ); - } - - private static void - setStringCommand( - RegistryKey topKey, String keyName, - String valueName, String data ) - { - RegistryKey subKey = - Registry.openSubKeyVerbose - ( topKey, keyName, RegistryKey.ACCESS_WRITE ); - - if ( subKey == null ) - return; - - RegStringValue val = - new RegStringValue( subKey, valueName, data ); - - Registry.setValue( subKey, val ); - } - - private static void - setBinaryCommand( - RegistryKey topKey, String keyName, - String valueName, String data ) - { - RegistryKey subKey = - Registry.openSubKeyVerbose - ( topKey, keyName, RegistryKey.ACCESS_WRITE ); - - if ( subKey == null ) - return; - - byte[] binData = data.getBytes(); - - RegBinaryValue val = - new RegBinaryValue( subKey, valueName, binData ); - - Registry.setValue( subKey, val ); - } - - private static void - createCommand( RegistryKey topKey, String keyName ) - { - RegistryKey subKey; - - try { - subKey = - topKey.createSubKey - ( keyName, "", RegistryKey.ACCESS_WRITE ); - } - catch ( RegistryException ex ) - { - subKey = null; - System.err.println - ( "ERROR creating subKey: " + ex.getMessage() ); - } - - if ( subKey != null ) - { - try { - subKey.flushKey(); - subKey.closeKey(); - } - catch ( RegistryException ex ) - { - subKey = null; - System.err.println - ( "ERROR flushing and closing key: " - + ex.getMessage() ); - } - } - - if ( subKey != null ) - { - System.err.println - ( "SUCCEEDED " - + ( subKey.wasCreated() - ? "Creating" : "Opening via create" ) - + " Key '" + keyName + "'" ); - } - else - { - System.err.println - ( "FAILED Creating Key '" + keyName + "'" ); - } - } - - private static RegistryKey - openSubKeyVerbose( RegistryKey topKey, String keyName, int access ) - { - RegistryKey subKey = null; - - try { subKey = topKey.openSubKey( keyName, access ); } - catch ( NoSuchKeyException ex ) - { - subKey = null; - System.err.println - ( "Key '" + keyName + "' does not exist." ); - } - catch ( RegistryException ex ) - { - subKey = null; - System.err.println - ( "ERROR registry error=" + ex.getErrorCode() - + ", " + ex.getMessage() ); - } - - return subKey; - } - - private static void - setValue( RegistryKey subKey, RegistryValue value ) - { - try { - subKey.setValue( value ); - subKey.flushKey(); - } - catch ( RegistryException ex ) - { - System.err.println - ( "ERROR setting MULTI_SZ value '" - + value.getName() + "', " + ex.getMessage() ); - } - } - - public static void - dumpHexData( PrintStream out, String title, byte[] buf, int numBytes ) - { - PrintWriter wrtr = - new PrintWriter( new OutputStreamWriter( out ) ); - - Registry.dumpHexData( wrtr, title, buf, 0, numBytes ); - } - - public static void - dumpHexData( - PrintWriter out, String title, - byte[] buf, int offset, int numBytes ) - { - int rows, residue, i, j; - byte[] save_buf= new byte[ ROW_BYTES+2 ]; - char[] hex_buf = new char[ 4 ]; - char[] idx_buf = new char[ 8 ]; - char[] hex_chars = new char[20]; - - hex_chars[0] = '0'; - hex_chars[1] = '1'; - hex_chars[2] = '2'; - hex_chars[3] = '3'; - hex_chars[4] = '4'; - hex_chars[5] = '5'; - hex_chars[6] = '6'; - hex_chars[7] = '7'; - hex_chars[8] = '8'; - hex_chars[9] = '9'; - hex_chars[10] = 'A'; - hex_chars[11] = 'B'; - hex_chars[12] = 'C'; - hex_chars[13] = 'D'; - hex_chars[14] = 'E'; - hex_chars[15] = 'F'; - - out.println( title + " - " + numBytes + " bytes." ); - - rows = (numBytes + (ROW_BYTES-1)) / ROW_BYTES; - residue = (numBytes % ROW_BYTES); - - for ( i = 0 ; i < rows ; i++ ) - { - int hexVal = (i * ROW_BYTES); - idx_buf[0] = hex_chars[ ((hexVal >> 12) & 15) ]; - idx_buf[1] = hex_chars[ ((hexVal >> 8) & 15) ]; - idx_buf[2] = hex_chars[ ((hexVal >> 4) & 15) ]; - idx_buf[3] = hex_chars[ (hexVal & 15) ]; - - String idxStr = new String( idx_buf, 0, 4 ); - out.print( idxStr + ": " ); - - for ( j = 0 ; j < ROW_BYTES ; j++ ) - { - if ( i == (rows - 1) && j >= residue ) - { - save_buf[j] = ' '; - out.print( " " ); - if ( j == ROW_QTR1 || j == ROW_HALF || j == ROW_QTR2 ) - out.print( ' ' ); - } - else - { - save_buf[j] = buf[ offset + (i * ROW_BYTES) + j ]; - - hex_buf[0] = hex_chars[ (save_buf[j] >> 4) & 0x0F ]; - hex_buf[1] = hex_chars[ save_buf[j] & 0x0F ]; - - out.print( hex_buf[0] ); - out.print( hex_buf[1] ); - out.print( ' ' ); - - if ( j == ROW_QTR1 || j == ROW_HALF || j == ROW_QTR2 ) - out.print( ' ' ); - - if ( save_buf[j] < 0x20 || save_buf[j] > 0x7E ) - save_buf[j] = (byte) '.'; - } - } - - String saveStr = new String( save_buf, 0, j ); - out.println( " | " + saveStr + " |" ); - } - - out.flush(); - } - - /** - * Split a string into a string array containing the substrings - * between the delimiters. - * - * NOTE This method WILL NOT return an empty - * token at the end of the array that is returned, if the string - * ends with the delimiter. If you wish to have a property string - * array that ends with the delimiter return an empty string at - * the end of the array, use vectorString(). - */ - - static public String[] - splitString( String splitStr, String delim ) - { - int i, count; - String[] result; - StringTokenizer toker; - - toker = new StringTokenizer( splitStr, delim ); - - count = toker.countTokens(); - - result = new String[ count ]; - - for ( i = 0 ; i < count ; ++i ) - { - try { result[i] = toker.nextToken(); } - catch ( NoSuchElementException ex ) - { - result = null; - break; - } - } - - return result; - } - - public static String[] - parseArgumentString( String argStr ) - { - String[] result = null; - - Vector vector = Registry.parseArgumentVector( argStr ); - - if ( vector != null && vector.size() > 0 ) - { - result = new String[ vector.size() ]; - vector.copyInto( result ); - } - - return result; - } - - public static Vector - parseArgumentVector( String argStr ) - { - Vector result = new Vector(); - StringBuffer argBuf = new StringBuffer(); - - boolean backSlash = false; - boolean matchSglQuote = false; - boolean matchDblQuote = false; - - for ( int cIdx = 0 ; cIdx < argStr.length() ; ++cIdx ) - { - char ch = argStr.charAt( cIdx ); - - switch ( ch ) - { - // - // W H I T E S P A C E - // - case ' ': - case '\t': - case '\n': - case '\r': - if ( backSlash ) - { - argBuf.append( ch ); - backSlash = false; - } - else if ( matchSglQuote || matchDblQuote ) - { - argBuf.append( ch ); - } - else if ( argBuf.length() > 0 ) - { - result.addElement( argBuf.toString() ); - argBuf.setLength( 0 ); - } - break; - - case '\\': - if ( backSlash ) - { - argBuf.append( "\\" ); - } - backSlash = ! backSlash; - break; - - case '\'': - if ( backSlash ) - { - argBuf.append( "'" ); - backSlash = false; - } - else if ( matchSglQuote ) - { - result.addElement( argBuf.toString() ); - argBuf.setLength( 0 ); - matchSglQuote = false; - } - else if ( ! matchDblQuote ) - { - matchSglQuote = true; - } - break; - - case '"': - if ( backSlash ) - { - argBuf.append( "\"" ); - backSlash = false; - } - else if ( matchDblQuote ) - { - result.addElement( argBuf.toString() ); - argBuf.setLength( 0 ); - matchDblQuote = false; - } - else if ( ! matchSglQuote ) - { - matchDblQuote = true; - } - break; - - default: - if ( backSlash ) - { - switch ( ch ) - { - case 'b': argBuf.append( '\b' ); break; - case 'f': argBuf.append( '\f' ); break; - case 'n': argBuf.append( '\n' ); break; - case 'r': argBuf.append( '\r' ); break; - case 't': argBuf.append( '\t' ); break; - - default: - char ch2 = argStr.charAt( cIdx+1 ); - char ch3 = argStr.charAt( cIdx+2 ); - if ( (ch >= '0' && ch <= '7') - && (ch2 >= '0' && ch2 <= '7') - && (ch3 >= '0' && ch3 <= '7') ) - { - int octal = - ( ( (ch - '0') * 64 ) - + ( (ch2 - '0') * 8 ) - + (ch3 - '0') ); - argBuf.append( (char) octal ); - cIdx += 2; - } - else if ( ch == '0' ) - { - argBuf.append( '\0' ); - } - else - { - argBuf.append( ch ); - } - break; - } - } - else - { - argBuf.append( ch ); - } - - backSlash = false; - break; - } - } - - if ( argBuf.length() > 0 ) - { - result.addElement( argBuf.toString() ); - } - - return result; - } - - } - - - - diff --git a/src/com/ice/jni/registry/RegistryException.java b/src/com/ice/jni/registry/RegistryException.java deleted file mode 100644 index 783a732..0000000 --- a/src/com/ice/jni/registry/RegistryException.java +++ /dev/null @@ -1,75 +0,0 @@ -/* -** Java native interface to the Windows Registry API. -** -** Authored by Timothy Gerard Endres -** -** -** This work has been placed into the public domain. -** You may use this work in any way and for any purpose you wish. -** -** THIS SOFTWARE IS PROVIDED AS-IS WITHOUT WARRANTY OF ANY KIND, -** NOT EVEN THE IMPLIED WARRANTY OF MERCHANTABILITY. THE AUTHOR -** OF THIS SOFTWARE, ASSUMES _NO_ RESPONSIBILITY FOR ANY -** CONSEQUENCE RESULTING FROM THE USE, MODIFICATION, OR -** REDISTRIBUTION OF THIS SOFTWARE. -** -*/ - -package com.ice.jni.registry; - -/** - * This exception is used to indicate that no such key exists in the registry. - * - * - * @version 3.1.3 - * - * @author Timothy Gerard Endres, - * time@ice.com. - */ - -public class -RegistryException extends Exception - { - static public final String RCS_ID = "$Id: RegistryException.java,v 1.1.1.1 1998/02/22 00:37:22 time Exp $"; - static public final String RCS_REV = "$Revision: 1.1.1.1 $"; - static public final String RCS_NAME = "$Name: $"; - - private int errorCode; - - - public - RegistryException() - { - super(); - this.errorCode = -1; - } - - public - RegistryException( String msg ) - { - super( msg ); - this.errorCode = -1; - } - - public - RegistryException( String msg, int regErr ) - { - super( msg ); - this.errorCode = regErr; - } - - public int - getErrorCode() - { - return this.errorCode; - } - - public void - setErrorCode( int errorCode ) - { - this.errorCode = errorCode; - } - - } - - diff --git a/src/com/ice/jni/registry/RegistryKey.java b/src/com/ice/jni/registry/RegistryKey.java deleted file mode 100644 index 0101a69..0000000 --- a/src/com/ice/jni/registry/RegistryKey.java +++ /dev/null @@ -1,697 +0,0 @@ -/* -** Java native interface to the Windows Registry API. -** -** Authored by Timothy Gerard Endres -** -** -** This work has been placed into the public domain. -** You may use this work in any way and for any purpose you wish. -** -** THIS SOFTWARE IS PROVIDED AS-IS WITHOUT WARRANTY OF ANY KIND, -** NOT EVEN THE IMPLIED WARRANTY OF MERCHANTABILITY. THE AUTHOR -** OF THIS SOFTWARE, ASSUMES _NO_ RESPONSIBILITY FOR ANY -** CONSEQUENCE RESULTING FROM THE USE, MODIFICATION, OR -** REDISTRIBUTION OF THIS SOFTWARE. -** -*/ - -package com.ice.jni.registry; - -import java.io.PrintWriter; -import java.util.*; - -/** - * The RegistryKey class represents a key in the registry. - * The class also provides all of the native interface calls. - * - * You should refer to the Windows Registry API documentation - * for the details of any of the native methods. The native - * implementation performs almost no processing before or after - * a given call, so their behavior should match the API's - * documented behavior precisely. - * - * Note that you can not open a subkey without an existing - * open RegistryKey. Thus, you need to start with one of the - * top level keys defined in the Registry class and open - * relative to that. - * - * @version 3.1.3 - * - * @see com.ice.jni.registry.Registry - * @see com.ice.jni.registry.RegistryValue - */ - - -public class -RegistryKey - { - /** - * Constants used to determine the access level for - * newly opened keys. - */ - public static final int ACCESS_DEFAULT = 0; - public static final int ACCESS_READ = 1; - public static final int ACCESS_WRITE = 2; - public static final int ACCESS_EXECUTE = 3; - public static final int ACCESS_ALL = 4; - - /** - * This is the actual DWORD key that is returned from the - * Registry API. This value is totally opaque - * and should never be referenced. - */ - protected int hKey; - - /** - * The full pathname of this key. - */ - protected String name; - - /** - * Used to indicate whether or not the key was created - * when method createSubKey() is called, otherwise false. - */ - protected boolean created; - - - public - RegistryKey( int hKey, String name ) - { - this.hKey = hKey; - this.name = name; - this.created = false; - } - - public - RegistryKey( int hKey, String name, boolean created ) - { - this.hKey = hKey; - this.name = name; - this.created = created; - } - - /** - * The finalize() override checks to be sure the key is closed. - */ - public void - finalize() - { - // Never close a top level key... - if ( this.name.indexOf( "\\" ) > 0 ) - { - // REVIEW should we have an "open/closed" flag - // to avoid double closes? Or is it better to - // lazily not call closeKey() and let finalize() - // do it all the time? - // - try { this.closeKey(); } - catch ( RegistryException ex ) - { } - } - } - - /** - * Get the name of this key. This is not fully - * qualified, which means that the name will not contain - * any backslashes. - * - * @return The relative name of this key. - */ - - public String - getName() - { - int index = this.name.lastIndexOf( "\\" ); - - if ( index < 0 ) - return this.name; - else - return this.name.substring( index + 1 ); - } - - /** - * Get the full name of the key, from the top level down. - * - * @return The full name of the key. - */ - - public String - getFullName() - { - return this.name; - } - - /** - * Determine if this key was opened or created and opened. - * The result can only be true if createSubKey() was called - * and the key did not exist, and the creation of the new - * subkey succeeded. - * - * @return True if the key was created new, else false. - */ - - public boolean - wasCreated() - { - return this.created; - } - - /** - * Used to set the created state of this key. - * - * @param created The new created state. - */ - - public void - setCreated( boolean created ) - { - this.created = created; - } - - /** - * Open a Registry subkey of this key with READ access. - * - * @param subkey The name of the subkey to open. - * @return The newly opened RegistryKey. - * - * @exception NoSuchKeyException If the subkey does not exist. - * @exception RegistryException Any other registry API error. - */ - - public RegistryKey - openSubKey( String subkey ) - throws NoSuchKeyException, RegistryException - { - return this.openSubKey( subkey, ACCESS_READ ); - } - - /** - * Create, and open, a Registry subkey of this key with WRITE access. - * If the key already exists, it is opened, otherwise it is first - * created and then opened. - * - * @param subkey The name of the subkey to create. - * @param className The className of the created subkey. - * @return The newly created and opened RegistryKey. - * - * @exception RegistryException Any valid registry API error. - */ - - public RegistryKey - createSubKey( String subkey, String className ) - throws RegistryException - { - return this.createSubKey( subkey, "", ACCESS_WRITE ); - } - - /** - * Set the value of this RegistryKey. - * - * @param value The value to set, including the value name. - * - * @exception RegistryException Any valid registry API error. - */ - - public void - setValue( RegistryValue value ) - throws RegistryException - { - this.setValue( value.getName(), value ); - } - - - // - // N A T I V E M E T H O D S - // - - /** - * Open a Registry subkey of this key with the specified access. - * - * @param subKey The name of the subkey to open. - * @param access The access level for the open. - * @return The newly opened RegistryKey. - * - * @exception NoSuchKeyException If the subkey does not exist. - * @exception RegistryException Any other registry API error. - */ - - public native RegistryKey - openSubKey( String subKey, int access ) - throws NoSuchKeyException, RegistryException; - - /** - * Connect to the remote registry on hostName. - * This method will only work when invoked on a toplevel - * key. The returned value will be the same toplevel key - * opened from the remote host's registry. - * - * @param hostName The remote computer's hostname. - * @return The remote top level key identical to this top level key. - * - * @exception NoSuchKeyException If the subkey does not exist. - * @exception RegistryException Any other registry API error. - */ - public native RegistryKey - connectRegistry( String hostName ) - throws NoSuchKeyException, RegistryException; - - /** - * Create a new subkey, or open the existing one. You can - * determine if the subkey was created, or whether an - * existing subkey was opened, via the wasCreated() method. - * - * @param subKey The name of the subkey to create/open. - * @param className The key's class name, or null. - * @param access The access level of the opened subkey. - * @return The newly created or opened subkey. - * - * @exception RegistryException Any valid registry API error. - */ - - public native RegistryKey - createSubKey( String subKey, String className, int access ) - throws RegistryException; - - /** - * Closes this subkey. You may chose to let the finalize() - * method do the close. - * - * @exception RegistryException Any valid registry API error. - */ - - public native void - closeKey() - throws RegistryException; - - /** - * Delete a named subkey. - * - * @param subKey The name of the subkey to delete. - * - * @exception NoSuchKeyException If the subkey does not exist. - * @exception RegistryException Any other registry API error. - */ - - public native void - deleteSubKey( String subKey ) - throws NoSuchKeyException, RegistryException; - - /** - * Delete a named value. - * - * @param valueName The name of the value to delete. - * - * @exception NoSuchValueException If the value does not exist. - * @exception RegistryException Any other registry API error. - */ - - public native void - deleteValue( String valueName ) - throws NoSuchValueException, RegistryException; - - /** - * Guarentees that this key is written to disk. This - * method should be called only when needed, as it has - * a huge performance cost. - * - * @exception RegistryException Any valid registry API error. - */ - - public native void - flushKey() - throws RegistryException; - - /** - * Set the name value to the given data. - * - * @param valueName The name of the value to set. - * @param value The data to set the named value. - * - * @exception RegistryException Any valid registry API error. - */ - - public native void - setValue( String valueName, RegistryValue value ) - throws RegistryException; - - /** - * Get the data of a named value. - * - * @param valueName The name of the value to get. - * @return The data of the named value. - * - * @exception NoSuchValueException If the value does not exist. - * @exception RegistryException Any other registry API error. - */ - - public native RegistryValue - getValue( String valueName ) - throws NoSuchValueException, RegistryException; - - /** - * Get the value of a REG_SZ or REG_EXPAND_SZ value. - * - * @param valueName The name of the value to get. - * @return The string data of the named value. - * - * @exception NoSuchValueException If the value does not exist. - * @exception RegistryException Any other registry API error. - */ - - public native String - getStringValue( String valueName ) - throws NoSuchValueException, RegistryException; - - /** - * Get the data from the default value. - * - * @return The string data of the default value. - * - * @exception NoSuchValueException If the value does not exist. - * @exception RegistryException Any other registry API error. - */ - - public native String - getDefaultValue() - throws NoSuchValueException, RegistryException; - - /** - * Determines if this key has a default value. - * - * @return True if there is a default value, else false. - * - * @exception RegistryException Any valid registry API error. - */ - - public native boolean - hasDefaultValue() - throws RegistryException; - - /** - * Determines if this key has only a default value. - * - * @return True if there is only a default value, else false. - * - * @exception RegistryException Any valid registry API error. - */ - - public native boolean - hasOnlyDefaultValue() - throws RegistryException; - - /** - * Obtains the number of subkeys that this key contains. - * - * @return The number of subkeys that this key contains. - * - * @exception RegistryException Any valid registry API error. - */ - - public native int - getNumberSubkeys() - throws RegistryException; - - /** - * Obtains the maximum length of all of the subkey names. - * - * @return The maximum length of all of the subkey names. - * - * @exception RegistryException Any valid registry API error. - */ - - public native int - getMaxSubkeyLength() - throws RegistryException; - - /** - * Obtains an enum_varerator for the subkeys of this key. - * - * @return The key enum_varerator. - * - * @exception RegistryException Any valid registry API error. - */ - - public native String - regEnumKey( int index ) - throws RegistryException; - - /** - * Obtains the number of values that this key contains. - * - * @return The number of values that this key contains. - * - * @exception RegistryException Any valid registry API error. - */ - - public native int - getNumberValues() - throws RegistryException; - - /** - * Obtains the maximum length of all of the value data. - * - * @return The maximum length of all of the value data. - * - * @exception RegistryException Any valid registry API error. - */ - - public native int - getMaxValueDataLength() - throws RegistryException; - - /** - * Obtains the maximum length of all of the value names. - * - * @return The maximum length of all of the value names. - * - * @exception RegistryException Any valid registry API error. - */ - - public native int - getMaxValueNameLength() - throws RegistryException; - - /** - * Obtains an enum_varerator for the values of this key. - * - * @return The value enum_varerator. - * - * @exception RegistryException Any valid registry API error. - */ - - public native String - regEnumValue( int index ) - throws RegistryException; - - // - // Convenience routines - // - - /** - * This method will increment the value of a REG_DWORD value. - * - * @param valueName The name of the value to increment. - * - * @exception NoSuchValueException If the value does not exist. - * @exception RegistryException Any other registry API error. - */ - - public native int - incrDoubleWord( String valueName ) - throws NoSuchValueException, RegistryException; - - /** - * This method will decrement the value of a REG_DWORD value. - * - * @param valueName The name of the value to increment. - * - * @exception NoSuchValueException If the value does not exist. - * @exception RegistryException Any other registry API error. - */ - - public native int - decrDoubleWord( String valueName ) - throws NoSuchValueException, RegistryException; - - /** - * This method will expand a string to include the definitions - * of System environment variables that are referenced via the - * %variable% construct. This method invokes EnvExpandStrings(). - * - * @param exString The name of the value to increment. - */ - - public static native String - expandEnvStrings( String exString ); - - /** - * Returns a new Enumeration that will enum_varerate the - * names of the subkeys of this key, - * - * @return A new Enumeration to enum_varerate subkey names. - * - * @exception RegistryException Any valid registry API error. - */ - - public Enumeration - keyElements() - throws RegistryException - { - return this.new RegistryKeyEnumerator( this ); - } - - /** - * Returns a new Enumeration that will enum_varerate the - * names of the values of this key, - * - * @return A new Enumeration to enum_varerate value names. - * - * @exception RegistryException Any valid registry API error. - */ - - public Enumeration - valueElements() - throws RegistryException - { - return this.new RegistryValueEnumerator( this ); - } - - /** - * A RegistryKey enum_varerator class. This enum_varerator - * is used to enum_varerate the names of this key's subkeys. - * - * This class should remain opaque to the client, - * which will use the Enumeration interface. - */ - class - RegistryKeyEnumerator implements Enumeration - { - RegistryKey key; - int currIndex; - int numSubKeys; - - public - RegistryKeyEnumerator( RegistryKey key ) - throws RegistryException - { - this.key = key; - this.currIndex = 0; - this.numSubKeys = key.getNumberSubkeys(); - } - - public boolean hasMoreElements() - { - return ( this.currIndex < this.numSubKeys ); - } - - public Object - nextElement() - { - Object result = null; - - try { result = this.key.regEnumKey( this.currIndex++ ); } - catch ( RegistryException ex ) - { - throw new NoSuchElementException( ex.getMessage() ); - } - - return result; - } - } - - /** - * A RegistryValue enum_varerator class. This enum_varerator - * is used to enum_varerate the names of this key's values. - * This will return the default value name as an empty string. - * - * This class should remain opaque to the client. - * It will use the Enumeration interface. - */ - - class - RegistryValueEnumerator implements Enumeration - { - RegistryKey key; - int currIndex; - int numValues; - - public - RegistryValueEnumerator( RegistryKey key ) - throws RegistryException - { - this.key = key; - this.currIndex = 0; - this.numValues = key.getNumberValues(); - } - - public boolean hasMoreElements() - { - return ( this.currIndex < this.numValues ); - } - - public Object - nextElement() - { - Object result = null; - - try { result = this.key.regEnumValue( this.currIndex++ ); } - catch ( RegistryException ex ) - { - throw new NoSuchElementException( ex.getMessage() ); - } - - return result; - } - } - - /** - * Export this key's definition to the provided PrintWriter. - * The resulting file can be imported via RegEdit. - * - * @exception NoSuchKeyException Thrown by openSubKey(). - * @exception NoSuchValueException Thrown by getValue(). - * @exception RegistryException Any other registry API error. - */ - - public void - export( PrintWriter out, boolean descend ) - throws NoSuchKeyException, RegistryException - { - Enumeration enum_var; - - out.println( "[" + this.getFullName() + "]" ); - - enum_var = this.valueElements(); - - for ( int idx = 0 ; enum_var.hasMoreElements() ; ++idx ) - { - String valueName = (String) enum_var.nextElement(); - - RegistryValue value = this.getValue( valueName ); - - value.export( out ); - } - - out.println( "" ); - - if ( descend ) - { - enum_var = this.keyElements(); - - for ( int idx = 0 ; enum_var.hasMoreElements() ; ++idx ) - { - String keyName = (String) enum_var.nextElement(); - - RegistryKey subKey = this.openSubKey( keyName ); - - subKey.export( out, descend ); - - subKey.closeKey(); - } - } - } - - } - - - diff --git a/src/com/ice/jni/registry/RegistryValue.java b/src/com/ice/jni/registry/RegistryValue.java deleted file mode 100644 index 01bd883..0000000 --- a/src/com/ice/jni/registry/RegistryValue.java +++ /dev/null @@ -1,164 +0,0 @@ -/* -** Java native interface to the Windows Registry API. -** -** Authored by Timothy Gerard Endres -** -** -** This work has been placed into the public domain. -** You may use this work in any way and for any purpose you wish. -** -** THIS SOFTWARE IS PROVIDED AS-IS WITHOUT WARRANTY OF ANY KIND, -** NOT EVEN THE IMPLIED WARRANTY OF MERCHANTABILITY. THE AUTHOR -** OF THIS SOFTWARE, ASSUMES _NO_ RESPONSIBILITY FOR ANY -** CONSEQUENCE RESULTING FROM THE USE, MODIFICATION, OR -** REDISTRIBUTION OF THIS SOFTWARE. -** -*/ - -package com.ice.jni.registry; - -import java.io.PrintWriter; - -/** - * The RegistryValue class represents a value in the registry. - * This class is abstract, so it can not be instantiated. The - * class is a superclass to all value classes. The common - * abstract methods for getting and setting data must be defined - * by the subclass, but subclasses will almost always provide - * additional methods that get and set the value using the data - * type of the subclass. - * - * @version 3.1.3 - * - * @see com.ice.jni.registry.Registry - * @see com.ice.jni.registry.RegistryKey - */ - -abstract public class -RegistryValue - { - public static final int REG_NONE = 0; - public static final int REG_SZ = 1; - public static final int REG_EXPAND_SZ = 2; - public static final int REG_BINARY = 3; - public static final int REG_DWORD = 4; - public static final int REG_DWORD_LITTLE_ENDIAN = 4; - public static final int REG_DWORD_BIG_ENDIAN = 5; - public static final int REG_LINK = 6; - public static final int REG_MULTI_SZ = 7; - public static final int REG_RESOURCE_LIST = 8; - public static final int REG_FULL_RESOURCE_DESCRIPTOR = 9; - public static final int REG_RESOURCE_REQUIREMENTS_LIST = 10; - - protected static char[] hexChars; - - int type; - String name; - RegistryKey key; - - static - { - RegistryValue.hexChars = new char[20]; - - RegistryValue.hexChars[0] = '0'; - RegistryValue.hexChars[1] = '1'; - RegistryValue.hexChars[2] = '2'; - RegistryValue.hexChars[3] = '3'; - RegistryValue.hexChars[4] = '4'; - RegistryValue.hexChars[5] = '5'; - RegistryValue.hexChars[6] = '6'; - RegistryValue.hexChars[7] = '7'; - RegistryValue.hexChars[8] = '8'; - RegistryValue.hexChars[9] = '9'; - RegistryValue.hexChars[10] = 'a'; - RegistryValue.hexChars[11] = 'b'; - RegistryValue.hexChars[12] = 'c'; - RegistryValue.hexChars[13] = 'd'; - RegistryValue.hexChars[14] = 'e'; - RegistryValue.hexChars[15] = 'f'; - } - - public - RegistryValue( RegistryKey key, String name, int type ) - { - this.key = key; - this.name = name; - this.type = type; - } - - public RegistryKey - getKey() - { - return this.key; - } - - public String - getName() - { - return this.name; - } - - public int - getType() - { - return this.type; - } - - public void - export( PrintWriter out ) - { - out.print( "\"" + this.getName() + "\"=" ); - out.println( "\"ERROR called RegistryValue.export()!\"" ); - } - - public String - toString() - { - return "[type=" + this.type + ",name=" + this.name + "]"; - } - - public static void - exportHexData( PrintWriter out, byte[] data ) - { - int i, cnt; - char ch1, ch2; - int len = data.length; - - for ( i = 0, cnt = 0 ; i < len ; ++i ) - { - byte dByte = data[i]; - - ch2 = RegistryValue.hexChars[ (dByte & 0x0F) ]; - ch1 = RegistryValue.hexChars[ ((dByte >> 4) & 0x0F) ]; - - if ( cnt == 0 ) out.print( " " ); - - out.print( ch1 ); - out.print( ch2 ); - - if ( i < (len - 1) ) - out.print( "," ); - - if ( ++cnt > 15 ) - { - cnt = 0; - if ( i < (len-1) ) - out.println( "\\" ); - } - } - - out.println( "" ); - } - - abstract public byte[] - getByteData(); - - abstract public int - getByteLength(); - - abstract public void - setByteData( byte[] data ); - - } - - diff --git a/src/com/ice/jni/registry/build.xml b/src/com/ice/jni/registry/build.xml deleted file mode 100644 index 57a157b..0000000 --- a/src/com/ice/jni/registry/build.xml +++ /dev/null @@ -1,185 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/vlcskineditor/Main.java b/src/vlcskineditor/Main.java index 593716b..49e8a04 100644 --- a/src/vlcskineditor/Main.java +++ b/src/vlcskineditor/Main.java @@ -35,7 +35,6 @@ import java.util.zip.*; import vlcskineditor.items.*; import com.ice.tar.*; -import com.ice.jni.registry.*; import javax.swing.plaf.basic.BasicToolBarUI; import javax.swing.plaf.metal.*; import vlcskineditor.history.*; @@ -707,13 +706,22 @@ private void getVLCdirectory() { vlc_dir = f.getPath(); vlc_skins_dir = new File(f, "skins").getPath(); } else { - try { - RegistryKey vlc_key = Registry.openSubkey(Registry.HKEY_LOCAL_MACHINE,"Software\\VideoLAN\\VLC",RegistryKey.ACCESS_READ); - String installDir = vlc_key.getStringValue("InstallDir"); - vlc_dir = installDir+File.separator; - vlc_skins_dir = vlc_dir+"skins\\"; - } - catch (Exception e) { + try { + // An improvement upon the unnecessary ICE_JNIRegistry.dll which may not work on all Windows systems (yikes!) + Process regProcess = Runtime.getRuntime().exec("REG QUERY \"HKEY_LOCAL_MACHINE\\Software\\VideoLAN\\VLC\" /v InstallDir"); + BufferedReader reader = new BufferedReader(new InputStreamReader(regProcess.getInputStream())); + String cmdLine; + while((cmdLine=reader.readLine()) !=null) { + if(cmdLine.contains("InstallDir")) { + int index = cmdLine.lastIndexOf("REG_SZ"); + if(index !=-1) { + vlc_dir = cmdLine.substring(index+6).trim(); + vlc_skins_dir = vlc_dir+"skins\\"; + break; + } + } + } + } catch (Exception e) { System.err.println("Could not read VLC installation directory from Registry. VLC might not be properly installed."); e.printStackTrace(); } @@ -847,6 +855,9 @@ private void openFile() { opening = true; String[] exts = { "xml","vlt" }; if(System.getProperty("os.name").indexOf("Mac")==-1) { + if(base_fc == null) { + base_fc = new JFileChooser(); // Initialize base_fc if it's null + } base_fc.setFileFilter(new CustomFileFilter(base_fc,exts,"*.xml (VLC XML-Skin), *.vlt (VLC Theme)",false,vlc_dir)); int returnVal = base_fc.showOpenDialog(this); if(returnVal == JFileChooser.APPROVE_OPTION) {