Package org.openstreetmap.josm.tools
Class WinRegistry
- java.lang.Object
-
- org.openstreetmap.josm.tools.WinRegistry
-
public final class WinRegistry extends Object
Utility class to access Window registry (read access only). As the implementation relies on internal JDK classjava.util.prefs.WindowsPreferences
and its native JNI methodJava_java_util_prefs_WindowsPreferences_WindowsRegQueryValueEx
, only String values (REG_SZ) are supported. Adapted from StackOverflow.- Since:
- 12217
-
-
Field Summary
Fields Modifier and Type Field Description static int
HKEY_CURRENT_USER
Registry entries subordinate to this key define the preferences of the current user.static int
HKEY_LOCAL_MACHINE
Registry entries subordinate to this key define the physical state of the computer, including data about the bus type, system memory, and installed hardware and software.private static boolean
java11
private static int
KEY_READ
private static long
REG_SUCCESS
private static Method
regCloseKey
private static Method
regEnumKeyEx
private static Method
regEnumValue
private static Method
regOpenKey
private static Method
regQueryInfoKey
private static Method
regQueryValueEx
private static Preferences
systemRoot
private static Class<? extends Preferences>
userClass
private static Preferences
userRoot
-
Constructor Summary
Constructors Modifier Constructor Description private
WinRegistry()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description private static Method
getDeclaredMethod(String name, Class<?>... parameterTypes)
private static Number
getNumber(Object array, int index)
private static Number
hkey(int key)
static String
readString(int hkey, String key, String valueName)
Read a value from key and value nameprivate static String
readString(Preferences root, int hkey, String key, String value)
static List<String>
readStringSubKeys(int hkey, String key)
Read the value name(s) from a given keyprivate static List<String>
readStringSubKeys(Preferences root, int hkey, String key)
static Map<String,String>
readStringValues(int hkey, String key)
Read value(s) and value name(s) form given keyprivate static Map<String,String>
readStringValues(Preferences root, int hkey, String key)
private static byte[]
toCstr(String str)
-
-
-
Field Detail
-
HKEY_CURRENT_USER
public static final int HKEY_CURRENT_USER
Registry entries subordinate to this key define the preferences of the current user. These preferences include the settings of environment variables, data about program groups, colors, printers, network connections, and application preferences. See Predefined Keys- See Also:
- Constant Field Values
-
HKEY_LOCAL_MACHINE
public static final int HKEY_LOCAL_MACHINE
Registry entries subordinate to this key define the physical state of the computer, including data about the bus type, system memory, and installed hardware and software. It contains subkeys that hold current configuration data, including Plug and Play information (the Enum branch, which includes a complete list of all hardware that has ever been on the system), network logon preferences, network security information, software-related information (such as server names and the location of the server), and other system information. See Predefined Keys- See Also:
- Constant Field Values
-
REG_SUCCESS
private static final long REG_SUCCESS
- See Also:
- Constant Field Values
-
KEY_READ
private static final int KEY_READ
- See Also:
- Constant Field Values
-
userRoot
private static final Preferences userRoot
-
systemRoot
private static final Preferences systemRoot
-
userClass
private static final Class<? extends Preferences> userClass
-
regOpenKey
private static final Method regOpenKey
-
regCloseKey
private static final Method regCloseKey
-
regQueryValueEx
private static final Method regQueryValueEx
-
regEnumValue
private static final Method regEnumValue
-
regQueryInfoKey
private static final Method regQueryInfoKey
-
regEnumKeyEx
private static final Method regEnumKeyEx
-
java11
private static boolean java11
-
-
Constructor Detail
-
WinRegistry
private WinRegistry()
-
-
Method Detail
-
getDeclaredMethod
private static Method getDeclaredMethod(String name, Class<?>... parameterTypes)
-
readString
public static String readString(int hkey, String key, String valueName) throws IllegalAccessException, InvocationTargetException
Read a value from key and value name- Parameters:
hkey
- HKEY_CURRENT_USER/HKEY_LOCAL_MACHINEkey
- key namevalueName
- value name- Returns:
- the value
- Throws:
IllegalArgumentException
- if hkey not HKEY_CURRENT_USER/HKEY_LOCAL_MACHINEIllegalAccessException
- if Java language access control is enforced and the underlying method is inaccessibleInvocationTargetException
- if the underlying method throws an exception
-
readStringValues
public static Map<String,String> readStringValues(int hkey, String key) throws IllegalAccessException, InvocationTargetException
Read value(s) and value name(s) form given key- Parameters:
hkey
- HKEY_CURRENT_USER/HKEY_LOCAL_MACHINEkey
- key name- Returns:
- the value name(s) plus the value(s)
- Throws:
IllegalArgumentException
- if hkey not HKEY_CURRENT_USER/HKEY_LOCAL_MACHINEIllegalAccessException
- if Java language access control is enforced and the underlying method is inaccessibleInvocationTargetException
- if the underlying method throws an exception
-
readStringSubKeys
public static List<String> readStringSubKeys(int hkey, String key) throws IllegalAccessException, InvocationTargetException
Read the value name(s) from a given key- Parameters:
hkey
- HKEY_CURRENT_USER/HKEY_LOCAL_MACHINEkey
- key name- Returns:
- the value name(s)
- Throws:
IllegalArgumentException
- if hkey not HKEY_CURRENT_USER/HKEY_LOCAL_MACHINEIllegalAccessException
- if Java language access control is enforced and the underlying method is inaccessibleInvocationTargetException
- if the underlying method throws an exception
-
readString
private static String readString(Preferences root, int hkey, String key, String value) throws IllegalAccessException, InvocationTargetException
-
readStringValues
private static Map<String,String> readStringValues(Preferences root, int hkey, String key) throws IllegalAccessException, InvocationTargetException
-
readStringSubKeys
private static List<String> readStringSubKeys(Preferences root, int hkey, String key) throws IllegalAccessException, InvocationTargetException
-
-