mirror of
https://github.com/openjdk/jdk.git
synced 2025-09-23 12:34:32 +02:00
8198899: Compilation errors in java.prefs with VS 2017
Change Java level representation of HKEY from int to long Reviewed-by: alanb, rriggs, psandoz
This commit is contained in:
parent
605827c671
commit
4ee1b63881
2 changed files with 279 additions and 279 deletions
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
|
@ -172,22 +172,22 @@ class WindowsPreferences extends AbstractPreferences {
|
||||||
/**
|
/**
|
||||||
* Java wrapper for Windows registry API RegOpenKey()
|
* Java wrapper for Windows registry API RegOpenKey()
|
||||||
*/
|
*/
|
||||||
private static native int[] WindowsRegOpenKey(int hKey, byte[] subKey,
|
private static native long[] WindowsRegOpenKey(long hKey, byte[] subKey,
|
||||||
int securityMask);
|
int securityMask);
|
||||||
/**
|
/**
|
||||||
* Retries RegOpenKey() MAX_ATTEMPTS times before giving up.
|
* Retries RegOpenKey() MAX_ATTEMPTS times before giving up.
|
||||||
*/
|
*/
|
||||||
private static int[] WindowsRegOpenKey1(int hKey, byte[] subKey,
|
private static long[] WindowsRegOpenKey1(long hKey, byte[] subKey,
|
||||||
int securityMask) {
|
int securityMask) {
|
||||||
int[] result = WindowsRegOpenKey(hKey, subKey, securityMask);
|
long[] result = WindowsRegOpenKey(hKey, subKey, securityMask);
|
||||||
if (result[ERROR_CODE] == ERROR_SUCCESS) {
|
if (result[ERROR_CODE] == ERROR_SUCCESS) {
|
||||||
return result;
|
return result;
|
||||||
} else if (result[ERROR_CODE] == ERROR_FILE_NOT_FOUND) {
|
} else if (result[ERROR_CODE] == ERROR_FILE_NOT_FOUND) {
|
||||||
logger().warning("Trying to recreate Windows registry node " +
|
logger().warning("Trying to recreate Windows registry node " +
|
||||||
byteArrayToString(subKey) + " at root 0x" +
|
byteArrayToString(subKey) + " at root 0x" +
|
||||||
Integer.toHexString(hKey) + ".");
|
Long.toHexString(hKey) + ".");
|
||||||
// Try recreation
|
// Try recreation
|
||||||
int handle = WindowsRegCreateKeyEx(hKey, subKey)[NATIVE_HANDLE];
|
long handle = WindowsRegCreateKeyEx(hKey, subKey)[NATIVE_HANDLE];
|
||||||
WindowsRegCloseKey(handle);
|
WindowsRegCloseKey(handle);
|
||||||
return WindowsRegOpenKey(hKey, subKey, securityMask);
|
return WindowsRegOpenKey(hKey, subKey, securityMask);
|
||||||
} else if (result[ERROR_CODE] != ERROR_ACCESS_DENIED) {
|
} else if (result[ERROR_CODE] != ERROR_ACCESS_DENIED) {
|
||||||
|
@ -211,18 +211,18 @@ class WindowsPreferences extends AbstractPreferences {
|
||||||
/**
|
/**
|
||||||
* Java wrapper for Windows registry API RegCloseKey()
|
* Java wrapper for Windows registry API RegCloseKey()
|
||||||
*/
|
*/
|
||||||
private static native int WindowsRegCloseKey(int hKey);
|
private static native int WindowsRegCloseKey(long hKey);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Java wrapper for Windows registry API RegCreateKeyEx()
|
* Java wrapper for Windows registry API RegCreateKeyEx()
|
||||||
*/
|
*/
|
||||||
private static native int[] WindowsRegCreateKeyEx(int hKey, byte[] subKey);
|
private static native long[] WindowsRegCreateKeyEx(long hKey, byte[] subKey);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retries RegCreateKeyEx() MAX_ATTEMPTS times before giving up.
|
* Retries RegCreateKeyEx() MAX_ATTEMPTS times before giving up.
|
||||||
*/
|
*/
|
||||||
private static int[] WindowsRegCreateKeyEx1(int hKey, byte[] subKey) {
|
private static long[] WindowsRegCreateKeyEx1(long hKey, byte[] subKey) {
|
||||||
int[] result = WindowsRegCreateKeyEx(hKey, subKey);
|
long[] result = WindowsRegCreateKeyEx(hKey, subKey);
|
||||||
if (result[ERROR_CODE] == ERROR_SUCCESS) {
|
if (result[ERROR_CODE] == ERROR_SUCCESS) {
|
||||||
return result;
|
return result;
|
||||||
} else {
|
} else {
|
||||||
|
@ -245,17 +245,17 @@ class WindowsPreferences extends AbstractPreferences {
|
||||||
/**
|
/**
|
||||||
* Java wrapper for Windows registry API RegDeleteKey()
|
* Java wrapper for Windows registry API RegDeleteKey()
|
||||||
*/
|
*/
|
||||||
private static native int WindowsRegDeleteKey(int hKey, byte[] subKey);
|
private static native int WindowsRegDeleteKey(long hKey, byte[] subKey);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Java wrapper for Windows registry API RegFlushKey()
|
* Java wrapper for Windows registry API RegFlushKey()
|
||||||
*/
|
*/
|
||||||
private static native int WindowsRegFlushKey(int hKey);
|
private static native int WindowsRegFlushKey(long hKey);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retries RegFlushKey() MAX_ATTEMPTS times before giving up.
|
* Retries RegFlushKey() MAX_ATTEMPTS times before giving up.
|
||||||
*/
|
*/
|
||||||
private static int WindowsRegFlushKey1(int hKey) {
|
private static int WindowsRegFlushKey1(long hKey) {
|
||||||
int result = WindowsRegFlushKey(hKey);
|
int result = WindowsRegFlushKey(hKey);
|
||||||
if (result == ERROR_SUCCESS) {
|
if (result == ERROR_SUCCESS) {
|
||||||
return result;
|
return result;
|
||||||
|
@ -280,17 +280,17 @@ class WindowsPreferences extends AbstractPreferences {
|
||||||
/**
|
/**
|
||||||
* Java wrapper for Windows registry API RegQueryValueEx()
|
* Java wrapper for Windows registry API RegQueryValueEx()
|
||||||
*/
|
*/
|
||||||
private static native byte[] WindowsRegQueryValueEx(int hKey,
|
private static native byte[] WindowsRegQueryValueEx(long hKey,
|
||||||
byte[] valueName);
|
byte[] valueName);
|
||||||
/**
|
/**
|
||||||
* Java wrapper for Windows registry API RegSetValueEx()
|
* Java wrapper for Windows registry API RegSetValueEx()
|
||||||
*/
|
*/
|
||||||
private static native int WindowsRegSetValueEx(int hKey, byte[] valueName,
|
private static native int WindowsRegSetValueEx(long hKey, byte[] valueName,
|
||||||
byte[] value);
|
byte[] value);
|
||||||
/**
|
/**
|
||||||
* Retries RegSetValueEx() MAX_ATTEMPTS times before giving up.
|
* Retries RegSetValueEx() MAX_ATTEMPTS times before giving up.
|
||||||
*/
|
*/
|
||||||
private static int WindowsRegSetValueEx1(int hKey, byte[] valueName,
|
private static int WindowsRegSetValueEx1(long hKey, byte[] valueName,
|
||||||
byte[] value) {
|
byte[] value) {
|
||||||
int result = WindowsRegSetValueEx(hKey, valueName, value);
|
int result = WindowsRegSetValueEx(hKey, valueName, value);
|
||||||
if (result == ERROR_SUCCESS) {
|
if (result == ERROR_SUCCESS) {
|
||||||
|
@ -316,18 +316,18 @@ class WindowsPreferences extends AbstractPreferences {
|
||||||
/**
|
/**
|
||||||
* Java wrapper for Windows registry API RegDeleteValue()
|
* Java wrapper for Windows registry API RegDeleteValue()
|
||||||
*/
|
*/
|
||||||
private static native int WindowsRegDeleteValue(int hKey, byte[] valueName);
|
private static native int WindowsRegDeleteValue(long hKey, byte[] valueName);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Java wrapper for Windows registry API RegQueryInfoKey()
|
* Java wrapper for Windows registry API RegQueryInfoKey()
|
||||||
*/
|
*/
|
||||||
private static native int[] WindowsRegQueryInfoKey(int hKey);
|
private static native long[] WindowsRegQueryInfoKey(long hKey);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retries RegQueryInfoKey() MAX_ATTEMPTS times before giving up.
|
* Retries RegQueryInfoKey() MAX_ATTEMPTS times before giving up.
|
||||||
*/
|
*/
|
||||||
private static int[] WindowsRegQueryInfoKey1(int hKey) {
|
private static long[] WindowsRegQueryInfoKey1(long hKey) {
|
||||||
int[] result = WindowsRegQueryInfoKey(hKey);
|
long[] result = WindowsRegQueryInfoKey(hKey);
|
||||||
if (result[ERROR_CODE] == ERROR_SUCCESS) {
|
if (result[ERROR_CODE] == ERROR_SUCCESS) {
|
||||||
return result;
|
return result;
|
||||||
} else {
|
} else {
|
||||||
|
@ -351,13 +351,13 @@ class WindowsPreferences extends AbstractPreferences {
|
||||||
/**
|
/**
|
||||||
* Java wrapper for Windows registry API RegEnumKeyEx()
|
* Java wrapper for Windows registry API RegEnumKeyEx()
|
||||||
*/
|
*/
|
||||||
private static native byte[] WindowsRegEnumKeyEx(int hKey, int subKeyIndex,
|
private static native byte[] WindowsRegEnumKeyEx(long hKey, int subKeyIndex,
|
||||||
int maxKeyLength);
|
int maxKeyLength);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retries RegEnumKeyEx() MAX_ATTEMPTS times before giving up.
|
* Retries RegEnumKeyEx() MAX_ATTEMPTS times before giving up.
|
||||||
*/
|
*/
|
||||||
private static byte[] WindowsRegEnumKeyEx1(int hKey, int subKeyIndex,
|
private static byte[] WindowsRegEnumKeyEx1(long hKey, int subKeyIndex,
|
||||||
int maxKeyLength) {
|
int maxKeyLength) {
|
||||||
byte[] result = WindowsRegEnumKeyEx(hKey, subKeyIndex, maxKeyLength);
|
byte[] result = WindowsRegEnumKeyEx(hKey, subKeyIndex, maxKeyLength);
|
||||||
if (result != null) {
|
if (result != null) {
|
||||||
|
@ -383,12 +383,12 @@ class WindowsPreferences extends AbstractPreferences {
|
||||||
/**
|
/**
|
||||||
* Java wrapper for Windows registry API RegEnumValue()
|
* Java wrapper for Windows registry API RegEnumValue()
|
||||||
*/
|
*/
|
||||||
private static native byte[] WindowsRegEnumValue(int hKey, int valueIndex,
|
private static native byte[] WindowsRegEnumValue(long hKey, int valueIndex,
|
||||||
int maxValueNameLength);
|
int maxValueNameLength);
|
||||||
/**
|
/**
|
||||||
* Retries RegEnumValueEx() MAX_ATTEMPTS times before giving up.
|
* Retries RegEnumValueEx() MAX_ATTEMPTS times before giving up.
|
||||||
*/
|
*/
|
||||||
private static byte[] WindowsRegEnumValue1(int hKey, int valueIndex,
|
private static byte[] WindowsRegEnumValue1(long hKey, int valueIndex,
|
||||||
int maxValueNameLength) {
|
int maxValueNameLength) {
|
||||||
byte[] result = WindowsRegEnumValue(hKey, valueIndex,
|
byte[] result = WindowsRegEnumValue(hKey, valueIndex,
|
||||||
maxValueNameLength);
|
maxValueNameLength);
|
||||||
|
@ -421,18 +421,18 @@ class WindowsPreferences extends AbstractPreferences {
|
||||||
*/
|
*/
|
||||||
private WindowsPreferences(WindowsPreferences parent, String name) {
|
private WindowsPreferences(WindowsPreferences parent, String name) {
|
||||||
super(parent, name);
|
super(parent, name);
|
||||||
int parentNativeHandle = parent.openKey(KEY_CREATE_SUB_KEY, KEY_READ);
|
long parentNativeHandle = parent.openKey(KEY_CREATE_SUB_KEY, KEY_READ);
|
||||||
if (parentNativeHandle == NULL_NATIVE_HANDLE) {
|
if (parentNativeHandle == NULL_NATIVE_HANDLE) {
|
||||||
// if here, openKey failed and logged
|
// if here, openKey failed and logged
|
||||||
isBackingStoreAvailable = false;
|
isBackingStoreAvailable = false;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
int[] result =
|
long[] result =
|
||||||
WindowsRegCreateKeyEx1(parentNativeHandle, toWindowsName(name));
|
WindowsRegCreateKeyEx1(parentNativeHandle, toWindowsName(name));
|
||||||
if (result[ERROR_CODE] != ERROR_SUCCESS) {
|
if (result[ERROR_CODE] != ERROR_SUCCESS) {
|
||||||
logger().warning("Could not create windows registry node " +
|
logger().warning("Could not create windows registry node " +
|
||||||
byteArrayToString(windowsAbsolutePath()) +
|
byteArrayToString(windowsAbsolutePath()) +
|
||||||
" at root 0x" + Integer.toHexString(rootNativeHandle()) +
|
" at root 0x" + Long.toHexString(rootNativeHandle()) +
|
||||||
". Windows RegCreateKeyEx(...) returned error code " +
|
". Windows RegCreateKeyEx(...) returned error code " +
|
||||||
result[ERROR_CODE] + ".");
|
result[ERROR_CODE] + ".");
|
||||||
isBackingStoreAvailable = false;
|
isBackingStoreAvailable = false;
|
||||||
|
@ -451,14 +451,14 @@ class WindowsPreferences extends AbstractPreferences {
|
||||||
* @param rootNativeHandle Native handle to one of Windows top level keys.
|
* @param rootNativeHandle Native handle to one of Windows top level keys.
|
||||||
* @param rootDirectory Path to root directory, as a byte-encoded string.
|
* @param rootDirectory Path to root directory, as a byte-encoded string.
|
||||||
*/
|
*/
|
||||||
private WindowsPreferences(int rootNativeHandle, byte[] rootDirectory) {
|
private WindowsPreferences(long rootNativeHandle, byte[] rootDirectory) {
|
||||||
super(null, "");
|
super(null, "");
|
||||||
int[] result =
|
long[] result =
|
||||||
WindowsRegCreateKeyEx1(rootNativeHandle, rootDirectory);
|
WindowsRegCreateKeyEx1(rootNativeHandle, rootDirectory);
|
||||||
if (result[ERROR_CODE] != ERROR_SUCCESS) {
|
if (result[ERROR_CODE] != ERROR_SUCCESS) {
|
||||||
logger().warning("Could not open/create prefs root node " +
|
logger().warning("Could not open/create prefs root node " +
|
||||||
byteArrayToString(windowsAbsolutePath()) +
|
byteArrayToString(windowsAbsolutePath()) +
|
||||||
" at root 0x" + Integer.toHexString(rootNativeHandle()) +
|
" at root 0x" + Long.toHexString(rootNativeHandle()) +
|
||||||
". Windows RegCreateKeyEx(...) returned error code " +
|
". Windows RegCreateKeyEx(...) returned error code " +
|
||||||
result[ERROR_CODE] + ".");
|
result[ERROR_CODE] + ".");
|
||||||
isBackingStoreAvailable = false;
|
isBackingStoreAvailable = false;
|
||||||
|
@ -497,7 +497,7 @@ class WindowsPreferences extends AbstractPreferences {
|
||||||
* @see #openKey(int, byte[], int)
|
* @see #openKey(int, byte[], int)
|
||||||
* @see #closeKey(int)
|
* @see #closeKey(int)
|
||||||
*/
|
*/
|
||||||
private int openKey(int securityMask) {
|
private long openKey(int securityMask) {
|
||||||
return openKey(securityMask, securityMask);
|
return openKey(securityMask, securityMask);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -511,7 +511,7 @@ class WindowsPreferences extends AbstractPreferences {
|
||||||
* @see #openKey(int, byte[], int)
|
* @see #openKey(int, byte[], int)
|
||||||
* @see #closeKey(int)
|
* @see #closeKey(int)
|
||||||
*/
|
*/
|
||||||
private int openKey(int mask1, int mask2) {
|
private long openKey(int mask1, int mask2) {
|
||||||
return openKey(windowsAbsolutePath(), mask1, mask2);
|
return openKey(windowsAbsolutePath(), mask1, mask2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -527,11 +527,11 @@ class WindowsPreferences extends AbstractPreferences {
|
||||||
* @see #openKey(int, byte[],int)
|
* @see #openKey(int, byte[],int)
|
||||||
* @see #closeKey(int)
|
* @see #closeKey(int)
|
||||||
*/
|
*/
|
||||||
private int openKey(byte[] windowsAbsolutePath, int mask1, int mask2) {
|
private long openKey(byte[] windowsAbsolutePath, int mask1, int mask2) {
|
||||||
/* Check if key's path is short enough be opened at once
|
/* Check if key's path is short enough be opened at once
|
||||||
otherwise use a path-splitting procedure */
|
otherwise use a path-splitting procedure */
|
||||||
if (windowsAbsolutePath.length <= MAX_WINDOWS_PATH_LENGTH + 1) {
|
if (windowsAbsolutePath.length <= MAX_WINDOWS_PATH_LENGTH + 1) {
|
||||||
int[] result = WindowsRegOpenKey1(rootNativeHandle(),
|
long[] result = WindowsRegOpenKey1(rootNativeHandle(),
|
||||||
windowsAbsolutePath, mask1);
|
windowsAbsolutePath, mask1);
|
||||||
if (result[ERROR_CODE] == ERROR_ACCESS_DENIED && mask2 != mask1)
|
if (result[ERROR_CODE] == ERROR_ACCESS_DENIED && mask2 != mask1)
|
||||||
result = WindowsRegOpenKey1(rootNativeHandle(),
|
result = WindowsRegOpenKey1(rootNativeHandle(),
|
||||||
|
@ -541,7 +541,7 @@ class WindowsPreferences extends AbstractPreferences {
|
||||||
logger().warning("Could not open windows registry node " +
|
logger().warning("Could not open windows registry node " +
|
||||||
byteArrayToString(windowsAbsolutePath()) +
|
byteArrayToString(windowsAbsolutePath()) +
|
||||||
" at root 0x" +
|
" at root 0x" +
|
||||||
Integer.toHexString(rootNativeHandle()) +
|
Long.toHexString(rootNativeHandle()) +
|
||||||
". Windows RegOpenKey(...) returned error code " +
|
". Windows RegOpenKey(...) returned error code " +
|
||||||
result[ERROR_CODE] + ".");
|
result[ERROR_CODE] + ".");
|
||||||
result[NATIVE_HANDLE] = NULL_NATIVE_HANDLE;
|
result[NATIVE_HANDLE] = NULL_NATIVE_HANDLE;
|
||||||
|
@ -550,7 +550,7 @@ class WindowsPreferences extends AbstractPreferences {
|
||||||
"Could not open windows registry node " +
|
"Could not open windows registry node " +
|
||||||
byteArrayToString(windowsAbsolutePath()) +
|
byteArrayToString(windowsAbsolutePath()) +
|
||||||
" at root 0x" +
|
" at root 0x" +
|
||||||
Integer.toHexString(rootNativeHandle()) +
|
Long.toHexString(rootNativeHandle()) +
|
||||||
": Access denied");
|
": Access denied");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -573,11 +573,11 @@ class WindowsPreferences extends AbstractPreferences {
|
||||||
* @see #openKey(byte[],int)
|
* @see #openKey(byte[],int)
|
||||||
* @see #closeKey(int)
|
* @see #closeKey(int)
|
||||||
*/
|
*/
|
||||||
private int openKey(int nativeHandle, byte[] windowsRelativePath,
|
private long openKey(long nativeHandle, byte[] windowsRelativePath,
|
||||||
int mask1, int mask2) {
|
int mask1, int mask2) {
|
||||||
/* If the path is short enough open at once. Otherwise split the path */
|
/* If the path is short enough open at once. Otherwise split the path */
|
||||||
if (windowsRelativePath.length <= MAX_WINDOWS_PATH_LENGTH + 1 ) {
|
if (windowsRelativePath.length <= MAX_WINDOWS_PATH_LENGTH + 1 ) {
|
||||||
int[] result = WindowsRegOpenKey1(nativeHandle,
|
long[] result = WindowsRegOpenKey1(nativeHandle,
|
||||||
windowsRelativePath, mask1);
|
windowsRelativePath, mask1);
|
||||||
if (result[ERROR_CODE] == ERROR_ACCESS_DENIED && mask2 != mask1)
|
if (result[ERROR_CODE] == ERROR_ACCESS_DENIED && mask2 != mask1)
|
||||||
result = WindowsRegOpenKey1(nativeHandle,
|
result = WindowsRegOpenKey1(nativeHandle,
|
||||||
|
@ -586,7 +586,7 @@ class WindowsPreferences extends AbstractPreferences {
|
||||||
if (result[ERROR_CODE] != ERROR_SUCCESS) {
|
if (result[ERROR_CODE] != ERROR_SUCCESS) {
|
||||||
logger().warning("Could not open windows registry node " +
|
logger().warning("Could not open windows registry node " +
|
||||||
byteArrayToString(windowsAbsolutePath()) +
|
byteArrayToString(windowsAbsolutePath()) +
|
||||||
" at root 0x" + Integer.toHexString(nativeHandle) +
|
" at root 0x" + Long.toHexString(nativeHandle) +
|
||||||
". Windows RegOpenKey(...) returned error code " +
|
". Windows RegOpenKey(...) returned error code " +
|
||||||
result[ERROR_CODE] + ".");
|
result[ERROR_CODE] + ".");
|
||||||
result[NATIVE_HANDLE] = NULL_NATIVE_HANDLE;
|
result[NATIVE_HANDLE] = NULL_NATIVE_HANDLE;
|
||||||
|
@ -610,12 +610,12 @@ class WindowsPreferences extends AbstractPreferences {
|
||||||
separatorPosition - 1];
|
separatorPosition - 1];
|
||||||
System.arraycopy(windowsRelativePath, separatorPosition+1,
|
System.arraycopy(windowsRelativePath, separatorPosition+1,
|
||||||
nextRelativePath, 0, nextRelativePath.length);
|
nextRelativePath, 0, nextRelativePath.length);
|
||||||
int nextNativeHandle = openKey(nativeHandle, nextRelativeRoot,
|
long nextNativeHandle = openKey(nativeHandle, nextRelativeRoot,
|
||||||
mask1, mask2);
|
mask1, mask2);
|
||||||
if (nextNativeHandle == NULL_NATIVE_HANDLE) {
|
if (nextNativeHandle == NULL_NATIVE_HANDLE) {
|
||||||
return NULL_NATIVE_HANDLE;
|
return NULL_NATIVE_HANDLE;
|
||||||
}
|
}
|
||||||
int result = openKey(nextNativeHandle, nextRelativePath,
|
long result = openKey(nextNativeHandle, nextRelativePath,
|
||||||
mask1,mask2);
|
mask1,mask2);
|
||||||
closeKey(nextNativeHandle);
|
closeKey(nextNativeHandle);
|
||||||
return result;
|
return result;
|
||||||
|
@ -630,13 +630,13 @@ class WindowsPreferences extends AbstractPreferences {
|
||||||
* @see #openKey(byte[],int)
|
* @see #openKey(byte[],int)
|
||||||
* @see #openKey(int, byte[],int)
|
* @see #openKey(int, byte[],int)
|
||||||
*/
|
*/
|
||||||
private void closeKey(int nativeHandle) {
|
private void closeKey(long nativeHandle) {
|
||||||
int result = WindowsRegCloseKey(nativeHandle);
|
int result = WindowsRegCloseKey(nativeHandle);
|
||||||
if (result != ERROR_SUCCESS) {
|
if (result != ERROR_SUCCESS) {
|
||||||
logger().warning("Could not close windows registry node " +
|
logger().warning("Could not close windows registry node " +
|
||||||
byteArrayToString(windowsAbsolutePath()) +
|
byteArrayToString(windowsAbsolutePath()) +
|
||||||
" at root 0x" +
|
" at root 0x" +
|
||||||
Integer.toHexString(rootNativeHandle()) +
|
Long.toHexString(rootNativeHandle()) +
|
||||||
". Windows RegCloseKey(...) returned error code " +
|
". Windows RegCloseKey(...) returned error code " +
|
||||||
result + ".");
|
result + ".");
|
||||||
}
|
}
|
||||||
|
@ -649,7 +649,7 @@ class WindowsPreferences extends AbstractPreferences {
|
||||||
* @see #getSpi(String)
|
* @see #getSpi(String)
|
||||||
*/
|
*/
|
||||||
protected void putSpi(String javaName, String value) {
|
protected void putSpi(String javaName, String value) {
|
||||||
int nativeHandle = openKey(KEY_SET_VALUE);
|
long nativeHandle = openKey(KEY_SET_VALUE);
|
||||||
if (nativeHandle == NULL_NATIVE_HANDLE) {
|
if (nativeHandle == NULL_NATIVE_HANDLE) {
|
||||||
isBackingStoreAvailable = false;
|
isBackingStoreAvailable = false;
|
||||||
return;
|
return;
|
||||||
|
@ -662,7 +662,7 @@ class WindowsPreferences extends AbstractPreferences {
|
||||||
" at Windows registry node " +
|
" at Windows registry node " +
|
||||||
byteArrayToString(windowsAbsolutePath()) +
|
byteArrayToString(windowsAbsolutePath()) +
|
||||||
" at root 0x" +
|
" at root 0x" +
|
||||||
Integer.toHexString(rootNativeHandle()) +
|
Long.toHexString(rootNativeHandle()) +
|
||||||
". Windows RegSetValueEx(...) returned error code " +
|
". Windows RegSetValueEx(...) returned error code " +
|
||||||
result + ".");
|
result + ".");
|
||||||
isBackingStoreAvailable = false;
|
isBackingStoreAvailable = false;
|
||||||
|
@ -677,7 +677,7 @@ class WindowsPreferences extends AbstractPreferences {
|
||||||
* @see #putSpi(String, String)
|
* @see #putSpi(String, String)
|
||||||
*/
|
*/
|
||||||
protected String getSpi(String javaName) {
|
protected String getSpi(String javaName) {
|
||||||
int nativeHandle = openKey(KEY_QUERY_VALUE);
|
long nativeHandle = openKey(KEY_QUERY_VALUE);
|
||||||
if (nativeHandle == NULL_NATIVE_HANDLE) {
|
if (nativeHandle == NULL_NATIVE_HANDLE) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -699,7 +699,7 @@ class WindowsPreferences extends AbstractPreferences {
|
||||||
* been deleted.
|
* been deleted.
|
||||||
*/
|
*/
|
||||||
protected void removeSpi(String key) {
|
protected void removeSpi(String key) {
|
||||||
int nativeHandle = openKey(KEY_SET_VALUE);
|
long nativeHandle = openKey(KEY_SET_VALUE);
|
||||||
if (nativeHandle == NULL_NATIVE_HANDLE) {
|
if (nativeHandle == NULL_NATIVE_HANDLE) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -709,7 +709,7 @@ class WindowsPreferences extends AbstractPreferences {
|
||||||
logger().warning("Could not delete windows registry value " +
|
logger().warning("Could not delete windows registry value " +
|
||||||
byteArrayToString(windowsAbsolutePath()) + "\\" +
|
byteArrayToString(windowsAbsolutePath()) + "\\" +
|
||||||
toWindowsName(key) + " at root 0x" +
|
toWindowsName(key) + " at root 0x" +
|
||||||
Integer.toHexString(rootNativeHandle()) +
|
Long.toHexString(rootNativeHandle()) +
|
||||||
". Windows RegDeleteValue(...) returned error code " +
|
". Windows RegDeleteValue(...) returned error code " +
|
||||||
result + ".");
|
result + ".");
|
||||||
isBackingStoreAvailable = false;
|
isBackingStoreAvailable = false;
|
||||||
|
@ -725,27 +725,27 @@ class WindowsPreferences extends AbstractPreferences {
|
||||||
*/
|
*/
|
||||||
protected String[] keysSpi() throws BackingStoreException{
|
protected String[] keysSpi() throws BackingStoreException{
|
||||||
// Find out the number of values
|
// Find out the number of values
|
||||||
int nativeHandle = openKey(KEY_QUERY_VALUE);
|
long nativeHandle = openKey(KEY_QUERY_VALUE);
|
||||||
if (nativeHandle == NULL_NATIVE_HANDLE) {
|
if (nativeHandle == NULL_NATIVE_HANDLE) {
|
||||||
throw new BackingStoreException(
|
throw new BackingStoreException(
|
||||||
"Could not open windows registry node " +
|
"Could not open windows registry node " +
|
||||||
byteArrayToString(windowsAbsolutePath()) +
|
byteArrayToString(windowsAbsolutePath()) +
|
||||||
" at root 0x" +
|
" at root 0x" +
|
||||||
Integer.toHexString(rootNativeHandle()) + ".");
|
Long.toHexString(rootNativeHandle()) + ".");
|
||||||
}
|
}
|
||||||
int[] result = WindowsRegQueryInfoKey1(nativeHandle);
|
long[] result = WindowsRegQueryInfoKey1(nativeHandle);
|
||||||
if (result[ERROR_CODE] != ERROR_SUCCESS) {
|
if (result[ERROR_CODE] != ERROR_SUCCESS) {
|
||||||
String info = "Could not query windows registry node " +
|
String info = "Could not query windows registry node " +
|
||||||
byteArrayToString(windowsAbsolutePath()) +
|
byteArrayToString(windowsAbsolutePath()) +
|
||||||
" at root 0x" +
|
" at root 0x" +
|
||||||
Integer.toHexString(rootNativeHandle()) +
|
Long.toHexString(rootNativeHandle()) +
|
||||||
". Windows RegQueryInfoKeyEx(...) returned error code " +
|
". Windows RegQueryInfoKeyEx(...) returned error code " +
|
||||||
result[ERROR_CODE] + ".";
|
result[ERROR_CODE] + ".";
|
||||||
logger().warning(info);
|
logger().warning(info);
|
||||||
throw new BackingStoreException(info);
|
throw new BackingStoreException(info);
|
||||||
}
|
}
|
||||||
int maxValueNameLength = result[MAX_VALUE_NAME_LENGTH];
|
int maxValueNameLength = (int)result[MAX_VALUE_NAME_LENGTH];
|
||||||
int valuesNumber = result[VALUES_NUMBER];
|
int valuesNumber = (int)result[VALUES_NUMBER];
|
||||||
if (valuesNumber == 0) {
|
if (valuesNumber == 0) {
|
||||||
closeKey(nativeHandle);
|
closeKey(nativeHandle);
|
||||||
return new String[0];
|
return new String[0];
|
||||||
|
@ -759,7 +759,7 @@ class WindowsPreferences extends AbstractPreferences {
|
||||||
String info =
|
String info =
|
||||||
"Could not enumerate value #" + i + " of windows node " +
|
"Could not enumerate value #" + i + " of windows node " +
|
||||||
byteArrayToString(windowsAbsolutePath()) + " at root 0x" +
|
byteArrayToString(windowsAbsolutePath()) + " at root 0x" +
|
||||||
Integer.toHexString(rootNativeHandle()) + ".";
|
Long.toHexString(rootNativeHandle()) + ".";
|
||||||
logger().warning(info);
|
logger().warning(info);
|
||||||
throw new BackingStoreException(info);
|
throw new BackingStoreException(info);
|
||||||
}
|
}
|
||||||
|
@ -777,27 +777,27 @@ class WindowsPreferences extends AbstractPreferences {
|
||||||
*/
|
*/
|
||||||
protected String[] childrenNamesSpi() throws BackingStoreException {
|
protected String[] childrenNamesSpi() throws BackingStoreException {
|
||||||
// Open key
|
// Open key
|
||||||
int nativeHandle = openKey(KEY_ENUMERATE_SUB_KEYS | KEY_QUERY_VALUE);
|
long nativeHandle = openKey(KEY_ENUMERATE_SUB_KEYS | KEY_QUERY_VALUE);
|
||||||
if (nativeHandle == NULL_NATIVE_HANDLE) {
|
if (nativeHandle == NULL_NATIVE_HANDLE) {
|
||||||
throw new BackingStoreException(
|
throw new BackingStoreException(
|
||||||
"Could not open windows registry node " +
|
"Could not open windows registry node " +
|
||||||
byteArrayToString(windowsAbsolutePath()) +
|
byteArrayToString(windowsAbsolutePath()) +
|
||||||
" at root 0x" +
|
" at root 0x" +
|
||||||
Integer.toHexString(rootNativeHandle()) + ".");
|
Long.toHexString(rootNativeHandle()) + ".");
|
||||||
}
|
}
|
||||||
// Get number of children
|
// Get number of children
|
||||||
int[] result = WindowsRegQueryInfoKey1(nativeHandle);
|
long[] result = WindowsRegQueryInfoKey1(nativeHandle);
|
||||||
if (result[ERROR_CODE] != ERROR_SUCCESS) {
|
if (result[ERROR_CODE] != ERROR_SUCCESS) {
|
||||||
String info = "Could not query windows registry node " +
|
String info = "Could not query windows registry node " +
|
||||||
byteArrayToString(windowsAbsolutePath()) +
|
byteArrayToString(windowsAbsolutePath()) +
|
||||||
" at root 0x" + Integer.toHexString(rootNativeHandle()) +
|
" at root 0x" + Long.toHexString(rootNativeHandle()) +
|
||||||
". Windows RegQueryInfoKeyEx(...) returned error code " +
|
". Windows RegQueryInfoKeyEx(...) returned error code " +
|
||||||
result[ERROR_CODE] + ".";
|
result[ERROR_CODE] + ".";
|
||||||
logger().warning(info);
|
logger().warning(info);
|
||||||
throw new BackingStoreException(info);
|
throw new BackingStoreException(info);
|
||||||
}
|
}
|
||||||
int maxKeyLength = result[MAX_KEY_LENGTH];
|
int maxKeyLength = (int)result[MAX_KEY_LENGTH];
|
||||||
int subKeysNumber = result[SUBKEYS_NUMBER];
|
int subKeysNumber = (int)result[SUBKEYS_NUMBER];
|
||||||
if (subKeysNumber == 0) {
|
if (subKeysNumber == 0) {
|
||||||
closeKey(nativeHandle);
|
closeKey(nativeHandle);
|
||||||
return new String[0];
|
return new String[0];
|
||||||
|
@ -812,7 +812,7 @@ class WindowsPreferences extends AbstractPreferences {
|
||||||
String info =
|
String info =
|
||||||
"Could not enumerate key #" + i + " of windows node " +
|
"Could not enumerate key #" + i + " of windows node " +
|
||||||
byteArrayToString(windowsAbsolutePath()) + " at root 0x" +
|
byteArrayToString(windowsAbsolutePath()) + " at root 0x" +
|
||||||
Integer.toHexString(rootNativeHandle()) + ". ";
|
Long.toHexString(rootNativeHandle()) + ". ";
|
||||||
logger().warning(info);
|
logger().warning(info);
|
||||||
throw new BackingStoreException(info);
|
throw new BackingStoreException(info);
|
||||||
}
|
}
|
||||||
|
@ -839,20 +839,20 @@ class WindowsPreferences extends AbstractPreferences {
|
||||||
throw new BackingStoreException(
|
throw new BackingStoreException(
|
||||||
"flush(): Backing store not available.");
|
"flush(): Backing store not available.");
|
||||||
}
|
}
|
||||||
int nativeHandle = openKey(KEY_READ);
|
long nativeHandle = openKey(KEY_READ);
|
||||||
if (nativeHandle == NULL_NATIVE_HANDLE) {
|
if (nativeHandle == NULL_NATIVE_HANDLE) {
|
||||||
throw new BackingStoreException(
|
throw new BackingStoreException(
|
||||||
"Could not open windows registry node " +
|
"Could not open windows registry node " +
|
||||||
byteArrayToString(windowsAbsolutePath()) +
|
byteArrayToString(windowsAbsolutePath()) +
|
||||||
" at root 0x" +
|
" at root 0x" +
|
||||||
Integer.toHexString(rootNativeHandle()) + ".");
|
Long.toHexString(rootNativeHandle()) + ".");
|
||||||
}
|
}
|
||||||
int result = WindowsRegFlushKey1(nativeHandle);
|
int result = WindowsRegFlushKey1(nativeHandle);
|
||||||
if (result != ERROR_SUCCESS) {
|
if (result != ERROR_SUCCESS) {
|
||||||
String info = "Could not flush windows registry node " +
|
String info = "Could not flush windows registry node " +
|
||||||
byteArrayToString(windowsAbsolutePath()) +
|
byteArrayToString(windowsAbsolutePath()) +
|
||||||
" at root 0x" +
|
" at root 0x" +
|
||||||
Integer.toHexString(rootNativeHandle()) +
|
Long.toHexString(rootNativeHandle()) +
|
||||||
". Windows RegFlushKey(...) returned error code " +
|
". Windows RegFlushKey(...) returned error code " +
|
||||||
result + ".";
|
result + ".";
|
||||||
logger().warning(info);
|
logger().warning(info);
|
||||||
|
@ -891,21 +891,21 @@ class WindowsPreferences extends AbstractPreferences {
|
||||||
* is not available.
|
* is not available.
|
||||||
*/
|
*/
|
||||||
public void removeNodeSpi() throws BackingStoreException {
|
public void removeNodeSpi() throws BackingStoreException {
|
||||||
int parentNativeHandle =
|
long parentNativeHandle =
|
||||||
((WindowsPreferences)parent()).openKey(DELETE);
|
((WindowsPreferences)parent()).openKey(DELETE);
|
||||||
if (parentNativeHandle == NULL_NATIVE_HANDLE) {
|
if (parentNativeHandle == NULL_NATIVE_HANDLE) {
|
||||||
throw new BackingStoreException(
|
throw new BackingStoreException(
|
||||||
"Could not open parent windows registry node of " +
|
"Could not open parent windows registry node of " +
|
||||||
byteArrayToString(windowsAbsolutePath()) +
|
byteArrayToString(windowsAbsolutePath()) +
|
||||||
" at root 0x" +
|
" at root 0x" +
|
||||||
Integer.toHexString(rootNativeHandle()) + ".");
|
Long.toHexString(rootNativeHandle()) + ".");
|
||||||
}
|
}
|
||||||
int result =
|
int result =
|
||||||
WindowsRegDeleteKey(parentNativeHandle, toWindowsName(name()));
|
WindowsRegDeleteKey(parentNativeHandle, toWindowsName(name()));
|
||||||
if (result != ERROR_SUCCESS) {
|
if (result != ERROR_SUCCESS) {
|
||||||
String info = "Could not delete windows registry node " +
|
String info = "Could not delete windows registry node " +
|
||||||
byteArrayToString(windowsAbsolutePath()) +
|
byteArrayToString(windowsAbsolutePath()) +
|
||||||
" at root 0x" + Integer.toHexString(rootNativeHandle()) +
|
" at root 0x" + Long.toHexString(rootNativeHandle()) +
|
||||||
". Windows RegDeleteKeyEx(...) returned error code " +
|
". Windows RegDeleteKeyEx(...) returned error code " +
|
||||||
result + ".";
|
result + ".";
|
||||||
logger().warning(info);
|
logger().warning(info);
|
||||||
|
@ -1089,7 +1089,7 @@ class WindowsPreferences extends AbstractPreferences {
|
||||||
if ((ch < 0x0020) || (ch > 0x007f)){
|
if ((ch < 0x0020) || (ch > 0x007f)){
|
||||||
// write \udddd
|
// write \udddd
|
||||||
windowsName.append("/u");
|
windowsName.append("/u");
|
||||||
String hex = Integer.toHexString(javaName.charAt(i));
|
String hex = Long.toHexString(javaName.charAt(i));
|
||||||
StringBuilder hex4 = new StringBuilder(hex);
|
StringBuilder hex4 = new StringBuilder(hex);
|
||||||
hex4.reverse();
|
hex4.reverse();
|
||||||
int len = 4 - hex4.length();
|
int len = 4 - hex4.length();
|
||||||
|
@ -1115,7 +1115,7 @@ class WindowsPreferences extends AbstractPreferences {
|
||||||
/**
|
/**
|
||||||
* Returns native handle for the top Windows node for this node.
|
* Returns native handle for the top Windows node for this node.
|
||||||
*/
|
*/
|
||||||
private int rootNativeHandle() {
|
private long rootNativeHandle() {
|
||||||
return (isUserNode()
|
return (isUserNode()
|
||||||
? USER_ROOT_NATIVE_HANDLE
|
? USER_ROOT_NATIVE_HANDLE
|
||||||
: SYSTEM_ROOT_NATIVE_HANDLE);
|
: SYSTEM_ROOT_NATIVE_HANDLE);
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
|
@ -37,90 +37,91 @@ extern "C" {
|
||||||
*/
|
*/
|
||||||
DEF_STATIC_JNI_OnLoad
|
DEF_STATIC_JNI_OnLoad
|
||||||
|
|
||||||
JNIEXPORT jintArray JNICALL Java_java_util_prefs_WindowsPreferences_WindowsRegOpenKey
|
JNIEXPORT jlongArray JNICALL
|
||||||
(JNIEnv* env, jclass this_class, jint hKey, jbyteArray lpSubKey, jint securityMask) {
|
Java_java_util_prefs_WindowsPreferences_WindowsRegOpenKey(JNIEnv* env,
|
||||||
HKEY handle;
|
jclass this_class, jlong hKey, jbyteArray lpSubKey, jint securityMask) {
|
||||||
char* str;
|
char* str = (*env)->GetByteArrayElements(env, lpSubKey, NULL);
|
||||||
int tmp[2];
|
|
||||||
int errorCode=-1;
|
|
||||||
jintArray result;
|
|
||||||
str = (*env)->GetByteArrayElements(env, lpSubKey, NULL);
|
|
||||||
CHECK_NULL_RETURN(str, NULL);
|
CHECK_NULL_RETURN(str, NULL);
|
||||||
errorCode = RegOpenKeyEx((HKEY)hKey, str, 0, securityMask, &handle);
|
|
||||||
|
HKEY handle;
|
||||||
|
int errorCode = RegOpenKeyEx((HKEY) hKey, str, 0, securityMask, &handle);
|
||||||
(*env)->ReleaseByteArrayElements(env, lpSubKey, str, 0);
|
(*env)->ReleaseByteArrayElements(env, lpSubKey, str, 0);
|
||||||
tmp[0]= (int) handle;
|
|
||||||
tmp[1]= errorCode;
|
jlong tmp[2];
|
||||||
result = (*env)->NewIntArray(env,2);
|
tmp[0] = (jlong) handle;
|
||||||
|
tmp[1] = errorCode;
|
||||||
|
jlongArray result = (*env)->NewLongArray(env, 2);
|
||||||
if (result != NULL) {
|
if (result != NULL) {
|
||||||
(*env)->SetIntArrayRegion(env, result, 0, 2, tmp);
|
(*env)->SetLongArrayRegion(env, result, 0, 2, tmp);
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
JNIEXPORT jint JNICALL Java_java_util_prefs_WindowsPreferences_WindowsRegCloseKey
|
JNIEXPORT jint JNICALL
|
||||||
(JNIEnv* env, jclass this_class, jint hKey) {
|
Java_java_util_prefs_WindowsPreferences_WindowsRegCloseKey(JNIEnv* env,
|
||||||
|
jclass this_class, jlong hKey) {
|
||||||
return (jint) RegCloseKey((HKEY) hKey);
|
return (jint) RegCloseKey((HKEY) hKey);
|
||||||
};
|
};
|
||||||
|
|
||||||
JNIEXPORT jintArray JNICALL Java_java_util_prefs_WindowsPreferences_WindowsRegCreateKeyEx
|
JNIEXPORT jlongArray JNICALL
|
||||||
(JNIEnv* env, jclass this_class, jint hKey, jbyteArray lpSubKey) {
|
Java_java_util_prefs_WindowsPreferences_WindowsRegCreateKeyEx(JNIEnv* env,
|
||||||
HKEY handle;
|
jclass this_class, jlong hKey, jbyteArray lpSubKey) {
|
||||||
char* str;
|
char* str = (*env)->GetByteArrayElements(env, lpSubKey, NULL);
|
||||||
int tmp[3];
|
|
||||||
DWORD lpdwDisposition;
|
|
||||||
int errorCode;
|
|
||||||
jintArray result = NULL;
|
|
||||||
str = (*env)->GetByteArrayElements(env, lpSubKey, NULL);
|
|
||||||
CHECK_NULL_RETURN(str, NULL);
|
CHECK_NULL_RETURN(str, NULL);
|
||||||
errorCode = RegCreateKeyEx((HKEY)hKey, str, 0, NULL,
|
|
||||||
|
HKEY handle;
|
||||||
|
DWORD lpdwDisposition;
|
||||||
|
int errorCode = RegCreateKeyEx((HKEY) hKey, str, 0, NULL,
|
||||||
REG_OPTION_NON_VOLATILE, KEY_READ,
|
REG_OPTION_NON_VOLATILE, KEY_READ,
|
||||||
NULL, &handle, &lpdwDisposition);
|
NULL, &handle, &lpdwDisposition);
|
||||||
(*env)->ReleaseByteArrayElements(env, lpSubKey, str, 0);
|
(*env)->ReleaseByteArrayElements(env, lpSubKey, str, 0);
|
||||||
tmp[0]= (int) handle;
|
|
||||||
tmp[1]= errorCode;
|
jlong tmp[3];
|
||||||
tmp[2]= lpdwDisposition;
|
tmp[0] = (jlong) handle;
|
||||||
result = (*env)->NewIntArray(env,3);
|
tmp[1] = errorCode;
|
||||||
|
tmp[2] = lpdwDisposition;
|
||||||
|
jlongArray result = (*env)->NewLongArray(env, 3);
|
||||||
if (result != NULL) {
|
if (result != NULL) {
|
||||||
(*env)->SetIntArrayRegion(env, result, 0, 3, tmp);
|
(*env)->SetLongArrayRegion(env, result, 0, 3, tmp);
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
JNIEXPORT jint JNICALL Java_java_util_prefs_WindowsPreferences_WindowsRegDeleteKey
|
JNIEXPORT jint JNICALL
|
||||||
(JNIEnv* env, jclass this_class, jint hKey, jbyteArray lpSubKey) {
|
Java_java_util_prefs_WindowsPreferences_WindowsRegDeleteKey(JNIEnv* env,
|
||||||
char* str;
|
jclass this_class, jlong hKey, jbyteArray lpSubKey) {
|
||||||
int result;
|
char* str = (*env)->GetByteArrayElements(env, lpSubKey, NULL);
|
||||||
str = (*env)->GetByteArrayElements(env, lpSubKey, NULL);
|
|
||||||
CHECK_NULL_RETURN(str, -1);
|
CHECK_NULL_RETURN(str, -1);
|
||||||
result = RegDeleteKey((HKEY)hKey, str);
|
|
||||||
|
int result = RegDeleteKey((HKEY) hKey, str);
|
||||||
(*env)->ReleaseByteArrayElements(env, lpSubKey, str, 0);
|
(*env)->ReleaseByteArrayElements(env, lpSubKey, str, 0);
|
||||||
return result;
|
return result;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
JNIEXPORT jint JNICALL Java_java_util_prefs_WindowsPreferences_WindowsRegFlushKey
|
JNIEXPORT jint JNICALL
|
||||||
(JNIEnv* env, jclass this_class, jint hKey) {
|
Java_java_util_prefs_WindowsPreferences_WindowsRegFlushKey(JNIEnv* env,
|
||||||
return RegFlushKey ((HKEY)hKey);
|
jclass this_class, jlong hKey) {
|
||||||
}
|
return RegFlushKey((HKEY) hKey);
|
||||||
|
}
|
||||||
|
|
||||||
|
JNIEXPORT jbyteArray JNICALL
|
||||||
|
Java_java_util_prefs_WindowsPreferences_WindowsRegQueryValueEx(JNIEnv* env,
|
||||||
|
jclass this_class, jlong hKey, jbyteArray valueName) {
|
||||||
|
char* valueNameStr = (*env)->GetByteArrayElements(env, valueName, NULL);
|
||||||
|
CHECK_NULL_RETURN(valueNameStr, NULL);
|
||||||
|
|
||||||
JNIEXPORT jbyteArray JNICALL Java_java_util_prefs_WindowsPreferences_WindowsRegQueryValueEx
|
|
||||||
(JNIEnv* env, jclass this_class, jint hKey, jbyteArray valueName) {
|
|
||||||
char* valueNameStr;
|
|
||||||
char* buffer;
|
|
||||||
jbyteArray result;
|
|
||||||
DWORD valueType;
|
DWORD valueType;
|
||||||
DWORD valueSize;
|
DWORD valueSize;
|
||||||
valueNameStr = (*env)->GetByteArrayElements(env, valueName, NULL);
|
if (RegQueryValueEx((HKEY) hKey, valueNameStr, NULL, &valueType, NULL,
|
||||||
CHECK_NULL_RETURN(valueNameStr, NULL);
|
|
||||||
if (RegQueryValueEx((HKEY)hKey, valueNameStr, NULL, &valueType, NULL,
|
|
||||||
&valueSize) != ERROR_SUCCESS) {
|
&valueSize) != ERROR_SUCCESS) {
|
||||||
(*env)->ReleaseByteArrayElements(env, valueName, valueNameStr, 0);
|
(*env)->ReleaseByteArrayElements(env, valueName, valueNameStr, 0);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
buffer = (char*)malloc(valueSize);
|
char* buffer = (char*) malloc(valueSize);
|
||||||
if (buffer != NULL) {
|
if (buffer != NULL) {
|
||||||
if (RegQueryValueEx((HKEY)hKey, valueNameStr, NULL, &valueType, buffer,
|
if (RegQueryValueEx((HKEY) hKey, valueNameStr, NULL, &valueType, buffer,
|
||||||
&valueSize) != ERROR_SUCCESS) {
|
&valueSize) != ERROR_SUCCESS) {
|
||||||
free(buffer);
|
free(buffer);
|
||||||
(*env)->ReleaseByteArrayElements(env, valueName, valueNameStr, 0);
|
(*env)->ReleaseByteArrayElements(env, valueName, valueNameStr, 0);
|
||||||
|
@ -132,6 +133,7 @@ DEF_STATIC_JNI_OnLoad
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
jbyteArray result;
|
||||||
if (valueType == REG_SZ) {
|
if (valueType == REG_SZ) {
|
||||||
result = (*env)->NewByteArray(env, valueSize);
|
result = (*env)->NewByteArray(env, valueSize);
|
||||||
if (result != NULL) {
|
if (result != NULL) {
|
||||||
|
@ -143,116 +145,114 @@ DEF_STATIC_JNI_OnLoad
|
||||||
free(buffer);
|
free(buffer);
|
||||||
(*env)->ReleaseByteArrayElements(env, valueName, valueNameStr, 0);
|
(*env)->ReleaseByteArrayElements(env, valueName, valueNameStr, 0);
|
||||||
return result;
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
JNIEXPORT jint JNICALL
|
||||||
|
Java_java_util_prefs_WindowsPreferences_WindowsRegSetValueEx(JNIEnv* env,
|
||||||
|
jclass this_class, jlong hKey, jbyteArray valueName, jbyteArray data) {
|
||||||
|
if ((valueName == NULL) || (data == NULL)) {
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
|
int size = (*env)->GetArrayLength(env, data);
|
||||||
|
char* dataStr = (*env)->GetByteArrayElements(env, data, NULL);
|
||||||
|
|
||||||
|
|
||||||
JNIEXPORT jint JNICALL Java_java_util_prefs_WindowsPreferences_WindowsRegSetValueEx
|
|
||||||
(JNIEnv* env, jclass this_class, jint hKey, jbyteArray valueName, jbyteArray data) {
|
|
||||||
char* valueNameStr;
|
|
||||||
char* dataStr;
|
|
||||||
int size = -1;
|
|
||||||
int nameSize = -1;
|
|
||||||
int error_code = -1;
|
|
||||||
if ((valueName == NULL)||(data == NULL)) {return -1;}
|
|
||||||
size = (*env)->GetArrayLength(env, data);
|
|
||||||
dataStr = (*env)->GetByteArrayElements(env, data, NULL);
|
|
||||||
CHECK_NULL_RETURN(dataStr, -1);
|
CHECK_NULL_RETURN(dataStr, -1);
|
||||||
valueNameStr = (*env)->GetByteArrayElements(env, valueName, NULL);
|
|
||||||
|
char* valueNameStr = (*env)->GetByteArrayElements(env, valueName, NULL);
|
||||||
|
int error_code = -1;
|
||||||
if (valueNameStr != NULL) {
|
if (valueNameStr != NULL) {
|
||||||
error_code = RegSetValueEx((HKEY)hKey, valueNameStr, 0,
|
error_code = RegSetValueEx((HKEY) hKey, valueNameStr, 0,
|
||||||
REG_SZ, dataStr, size);
|
REG_SZ, dataStr, size);
|
||||||
(*env)->ReleaseByteArrayElements(env, valueName, valueNameStr, 0);
|
(*env)->ReleaseByteArrayElements(env, valueName, valueNameStr, 0);
|
||||||
}
|
}
|
||||||
(*env)->ReleaseByteArrayElements(env, data, dataStr, 0);
|
(*env)->ReleaseByteArrayElements(env, data, dataStr, 0);
|
||||||
return error_code;
|
return error_code;
|
||||||
}
|
}
|
||||||
|
|
||||||
JNIEXPORT jint JNICALL Java_java_util_prefs_WindowsPreferences_WindowsRegDeleteValue
|
JNIEXPORT jint JNICALL
|
||||||
(JNIEnv* env, jclass this_class, jint hKey, jbyteArray valueName) {
|
Java_java_util_prefs_WindowsPreferences_WindowsRegDeleteValue(JNIEnv* env,
|
||||||
char* valueNameStr;
|
jclass this_class, jlong hKey, jbyteArray valueName) {
|
||||||
int error_code = -1;
|
if (valueName == NULL) {
|
||||||
if (valueName == NULL) {return -1;}
|
return -1;
|
||||||
valueNameStr = (*env)->GetByteArrayElements(env, valueName, NULL);
|
}
|
||||||
|
char* valueNameStr = (*env)->GetByteArrayElements(env, valueName, NULL);
|
||||||
CHECK_NULL_RETURN(valueNameStr, -1);
|
CHECK_NULL_RETURN(valueNameStr, -1);
|
||||||
error_code = RegDeleteValue((HKEY)hKey, valueNameStr);
|
|
||||||
|
int error_code = RegDeleteValue((HKEY) hKey, valueNameStr);
|
||||||
(*env)->ReleaseByteArrayElements(env, valueName, valueNameStr, 0);
|
(*env)->ReleaseByteArrayElements(env, valueName, valueNameStr, 0);
|
||||||
return error_code;
|
return error_code;
|
||||||
}
|
}
|
||||||
|
|
||||||
JNIEXPORT jintArray JNICALL Java_java_util_prefs_WindowsPreferences_WindowsRegQueryInfoKey
|
JNIEXPORT jlongArray JNICALL
|
||||||
(JNIEnv* env, jclass this_class, jint hKey) {
|
Java_java_util_prefs_WindowsPreferences_WindowsRegQueryInfoKey(JNIEnv* env,
|
||||||
jintArray result = NULL;
|
jclass this_class, jlong hKey) {
|
||||||
int tmp[5];
|
int subKeysNumber;
|
||||||
int valuesNumber = -1;
|
int maxSubKeyLength;
|
||||||
int maxValueNameLength = -1;
|
int valuesNumber;
|
||||||
int maxSubKeyLength = -1;
|
int maxValueNameLength;
|
||||||
int subKeysNumber = -1;
|
int errorCode = RegQueryInfoKey((HKEY) hKey, NULL, NULL, NULL,
|
||||||
int errorCode = -1;
|
|
||||||
errorCode = RegQueryInfoKey((HKEY)hKey, NULL, NULL, NULL,
|
|
||||||
&subKeysNumber, &maxSubKeyLength, NULL,
|
&subKeysNumber, &maxSubKeyLength, NULL,
|
||||||
&valuesNumber, &maxValueNameLength,
|
&valuesNumber, &maxValueNameLength,
|
||||||
NULL, NULL, NULL);
|
NULL, NULL, NULL);
|
||||||
tmp[0]= subKeysNumber;
|
|
||||||
tmp[1]= (int)errorCode;
|
jlong tmp[5];
|
||||||
tmp[2]= valuesNumber;
|
tmp[0] = subKeysNumber;
|
||||||
tmp[3]= maxSubKeyLength;
|
tmp[1] = errorCode;
|
||||||
tmp[4]= maxValueNameLength;
|
tmp[2] = valuesNumber;
|
||||||
result = (*env)->NewIntArray(env,5);
|
tmp[3] = maxSubKeyLength;
|
||||||
|
tmp[4] = maxValueNameLength;
|
||||||
|
jintArray result = (*env)->NewLongArray(env, 5);
|
||||||
if (result != NULL) {
|
if (result != NULL) {
|
||||||
(*env)->SetIntArrayRegion(env, result, 0, 5, tmp);
|
(*env)->SetLongArrayRegion(env, result, 0, 5, tmp);
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
JNIEXPORT jbyteArray JNICALL Java_java_util_prefs_WindowsPreferences_WindowsRegEnumKeyEx
|
JNIEXPORT jbyteArray JNICALL
|
||||||
(JNIEnv* env, jclass this_class, jint hKey , jint subKeyIndex, jint maxKeyLength) {
|
Java_java_util_prefs_WindowsPreferences_WindowsRegEnumKeyEx(JNIEnv* env,
|
||||||
|
jclass this_class, jlong hKey, jint subKeyIndex, jint maxKeyLength) {
|
||||||
int size = maxKeyLength;
|
int size = maxKeyLength;
|
||||||
jbyteArray result;
|
char* buffer = (char*) malloc(maxKeyLength);
|
||||||
char* buffer = NULL;
|
|
||||||
buffer = (char*)malloc(maxKeyLength);
|
|
||||||
if (buffer == NULL) {
|
if (buffer == NULL) {
|
||||||
JNU_ThrowOutOfMemoryError(env, "native memory allocation failed");
|
JNU_ThrowOutOfMemoryError(env, "native memory allocation failed");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
if (RegEnumKeyEx((HKEY) hKey, subKeyIndex, buffer, &size, NULL, NULL,
|
if (RegEnumKeyEx((HKEY) hKey, subKeyIndex, buffer, &size, NULL, NULL,
|
||||||
NULL, NULL) != ERROR_SUCCESS){
|
NULL, NULL) != ERROR_SUCCESS) {
|
||||||
free(buffer);
|
free(buffer);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
result = (*env)->NewByteArray(env, size + 1);
|
|
||||||
|
jbyteArray result = (*env)->NewByteArray(env, size + 1);
|
||||||
if (result != NULL) {
|
if (result != NULL) {
|
||||||
(*env)->SetByteArrayRegion(env, result, 0, size + 1, buffer);
|
(*env)->SetByteArrayRegion(env, result, 0, size + 1, buffer);
|
||||||
}
|
}
|
||||||
free(buffer);
|
free(buffer);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
JNIEXPORT jbyteArray JNICALL Java_java_util_prefs_WindowsPreferences_WindowsRegEnumValue
|
JNIEXPORT jbyteArray JNICALL
|
||||||
(JNIEnv* env, jclass this_class, jint hKey , jint valueIndex, jint maxValueNameLength){
|
Java_java_util_prefs_WindowsPreferences_WindowsRegEnumValue(JNIEnv* env,
|
||||||
|
jclass this_class, jlong hKey, jint valueIndex, jint maxValueNameLength) {
|
||||||
int size = maxValueNameLength;
|
int size = maxValueNameLength;
|
||||||
jbyteArray result;
|
char* buffer = (char*) malloc(maxValueNameLength);
|
||||||
char* buffer = NULL;
|
|
||||||
int error_code;
|
|
||||||
buffer = (char*)malloc(maxValueNameLength);
|
|
||||||
if (buffer == NULL) {
|
if (buffer == NULL) {
|
||||||
JNU_ThrowOutOfMemoryError(env, "native memory allocation failed");
|
JNU_ThrowOutOfMemoryError(env, "native memory allocation failed");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
error_code = RegEnumValue((HKEY) hKey, valueIndex, buffer,
|
|
||||||
|
int error_code = RegEnumValue((HKEY) hKey, valueIndex, buffer,
|
||||||
&size, NULL, NULL, NULL, NULL);
|
&size, NULL, NULL, NULL, NULL);
|
||||||
if (error_code!= ERROR_SUCCESS){
|
if (error_code != ERROR_SUCCESS) {
|
||||||
free(buffer);
|
free(buffer);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
result = (*env)->NewByteArray(env, size + 1);
|
jbyteArray result = (*env)->NewByteArray(env, size + 1);
|
||||||
if (result != NULL) {
|
if (result != NULL) {
|
||||||
(*env)->SetByteArrayRegion(env, result, 0, size + 1, buffer);
|
(*env)->SetByteArrayRegion(env, result, 0, size + 1, buffer);
|
||||||
}
|
}
|
||||||
free(buffer);
|
free(buffer);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue