diff options
| author | Matthias Becker | 2018-11-30 08:46:37 +0000 |
|---|---|---|
| committer | Matthias Becker | 2018-12-12 15:58:31 +0000 |
| commit | c6ee3fcc6ae6ce51c7ce2fca1751e86876bfdc7d (patch) | |
| tree | 90f863800edfd66cce401147e3bf9d9d4904a862 | |
| parent | fa4beed101319433e7524ae312e6287d38b6b277 (diff) | |
| download | eclipse.platform.ui-c6ee3fcc6ae6ce51c7ce2fca1751e86876bfdc7d.tar.gz eclipse.platform.ui-c6ee3fcc6ae6ce51c7ce2fca1751e86876bfdc7d.tar.xz eclipse.platform.ui-c6ee3fcc6ae6ce51c7ce2fca1751e86876bfdc7d.zip | |
Bug 541653: Simplify CodeY20181212-2200I20181212-1800
Change-Id: Ic79c6ccb50e01e8d1be3bccd47491ba4e66290d0
Signed-off-by: Matthias Becker <ma.becker@sap.com>
| -rw-r--r-- | bundles/org.eclipse.urischeme/src/org/eclipse/urischeme/internal/registration/WinRegistry.java | 22 |
1 files changed, 9 insertions, 13 deletions
diff --git a/bundles/org.eclipse.urischeme/src/org/eclipse/urischeme/internal/registration/WinRegistry.java b/bundles/org.eclipse.urischeme/src/org/eclipse/urischeme/internal/registration/WinRegistry.java index 86175f0a0cd..cdbee8014c9 100644 --- a/bundles/org.eclipse.urischeme/src/org/eclipse/urischeme/internal/registration/WinRegistry.java +++ b/bundles/org.eclipse.urischeme/src/org/eclipse/urischeme/internal/registration/WinRegistry.java @@ -25,6 +25,7 @@ import org.eclipse.core.runtime.Path; * */ public class WinRegistry implements IWinRegistry { + private static final Preferences USER_ROOT = Preferences.userRoot(); private static final int KEY_READ = 1; private static final int KEY_SET = 2; private static final int KEY_DELETE = 0x10000; @@ -40,7 +41,7 @@ public class WinRegistry implements IWinRegistry { static { // method handles are cached for performance reasons try { - Class<?> prefClass = Preferences.userRoot().getClass(); + Class<?> prefClass = USER_ROOT.getClass(); METHOD_stringToByteArray = prefClass.getDeclaredMethod("stringToByteArray", String.class); //$NON-NLS-1$ METHOD_toJavaValueString = prefClass.getDeclaredMethod("toJavaValueString", byte[].class); //$NON-NLS-1$ METHOD_openKey = prefClass.getDeclaredMethod("openKey", byte[].class, int.class, int.class); //$NON-NLS-1$ @@ -70,13 +71,11 @@ public class WinRegistry implements IWinRegistry { @Override public void setValueForKey(String key, String attribute, String value) throws WinRegistryException { - final Preferences user = Preferences.userRoot(); - final Preferences systemRoot = Preferences.systemRoot(); try { - Object handle = METHOD_openKey.invoke(user, toByteArray(key), KEY_SET, KEY_SET); + Object handle = METHOD_openKey.invoke(USER_ROOT, toByteArray(key), KEY_SET, KEY_SET); int result = (Integer) METHOD_WinRegSetValueEx1.invoke(null, handle, toByteArray(attribute), toByteArray(value)); - METHOD_closeKey.invoke(systemRoot, handle); + METHOD_closeKey.invoke(USER_ROOT, handle); if (result != 0) { throw new WinRegistryException("Unable to write to registry. Key = " + key + attribute + //$NON-NLS-1$ ", value: " + value); //$NON-NLS-1$ @@ -89,13 +88,11 @@ public class WinRegistry implements IWinRegistry { @Override public String getValueForKey(String key, String attribute) throws WinRegistryException { - final Preferences user = Preferences.userRoot(); - final Preferences systemRoot = Preferences.systemRoot(); try { - Object handle = METHOD_openKey.invoke(user, toByteArray(key), KEY_READ, KEY_READ); + Object handle = METHOD_openKey.invoke(USER_ROOT, toByteArray(key), KEY_READ, KEY_READ); byte[] valb = (byte[]) METHOD_WinRegQueryValueEx.invoke(null, handle, toByteArray(attribute)); + METHOD_closeKey.invoke(USER_ROOT, handle); String vals = (valb != null ? toString(valb) : null); - METHOD_closeKey.invoke(systemRoot, handle); return vals; } catch (Exception e) { throw new WinRegistryException(e.getMessage(), e); @@ -104,14 +101,13 @@ public class WinRegistry implements IWinRegistry { @Override public void deleteKey(String key) throws WinRegistryException { - final Preferences userRoot = Preferences.userRoot(); - IPath keyPath = new Path(key); try { + IPath keyPath = new Path(key); String parent = keyPath.removeLastSegments(1).toOSString(); String child = keyPath.lastSegment(); - Object parentHandle = METHOD_openKey.invoke(userRoot, toByteArray(parent), KEY_DELETE, KEY_DELETE); + Object parentHandle = METHOD_openKey.invoke(USER_ROOT, toByteArray(parent), KEY_DELETE, KEY_DELETE); int result = (Integer) METHOD_WinRegDeleteKey.invoke(null, parentHandle, toByteArray(child)); - METHOD_closeKey.invoke(userRoot, parentHandle); + METHOD_closeKey.invoke(USER_ROOT, parentHandle); if (result != 0) { throw new WinRegistryException("Unable to delete key = " + keyPath); //$NON-NLS-1$ } |
