diff options
author | Stephan Bergmann <sbergman@redhat.com> | 2020-12-03 08:12:23 +0100 |
---|---|---|
committer | Stephan Bergmann <sbergman@redhat.com> | 2020-12-03 15:01:00 +0100 |
commit | 01241113947fc7bd7f7b765dd897bb023c8ca99c (patch) | |
tree | c224f9afa42e961d9b22fd66530276ed7b7ae410 /odk | |
parent | 8e3dc5b81d1a7486a6787afef918e9d2b74542ef (diff) |
Replace unowinreg.dll with execution of `reg QUERY`
The SDK's <https://wiki.openoffice.org/wiki/Documentation/DevGuide/ProUNO/Java/
Transparent_Use_of_Office_UNO_Components> on all platforms included the Windows-
specific unowinreg.dll in generated jars (so that those jars, when distributed
to a Windows environment, would find a LO installation by inspecting the Windows
registry). That unowinreg.dll was originally built as a 32-bit DLL (though when
building a 64-bit Windows LO, it happened to be built as a 64-bit DLL). For
non-Windows LO builds, it could either be built locally with a MinGW toolchain
(--enable-build-unowinreg) or downloaded from dev-www.libreoffice.org.
However, that had various issues:
For one, unowinreg.dll was not necessarily available in a distributed jar as a
64-bit DLL for use with a 64-bit JRE on Windows. (Theoretically, running such a
jar with a 32-bit JRE to access a 64-bit LO installation's URE jars could have
worked. But practically, those URE jars in turn require native DLLs, which
would then not have been available as 32-bit DLLs for use in the 32-bit JRE.)
For another, at least the unowinreg.dll resulting from --enable-build-unowinreg
on Fedora 33 would have had a dependency on libgcc_s_dw2-1.dll that would
generally not have been available in a target Windows environment.
There appears to be no pure Java way to read the Windows registry, but instead
of using a native code DLL for that, it appears to work just as well to call out
to reg.exe and parse its output.
This removes the --enable-build-unowinreg and --with-mingw-cross-compiler
configuration options. (The sole use of the MinGW toolchain in LO was for
building unowinreg.dll.)
Change-Id: I3283ea38c884d3221a205e5ab6ec99a2691ef474
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/107140
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
Tested-by: Jenkins
Diffstat (limited to 'odk')
-rw-r--r-- | odk/CustomTarget_check.mk | 3 | ||||
-rw-r--r-- | odk/CustomTarget_unowinreg.mk | 26 | ||||
-rw-r--r-- | odk/Library_unowinreg.mk | 36 | ||||
-rw-r--r-- | odk/Module_odk.mk | 3 | ||||
-rw-r--r-- | odk/Package_unowinreg.mk | 28 | ||||
-rw-r--r-- | odk/examples/DevelopersGuide/FirstSteps/build_FirstUnoContact.xml | 1 | ||||
-rw-r--r-- | odk/settings/std.mk | 3 | ||||
-rw-r--r-- | odk/source/com/sun/star/lib/loader/InstallationFinder.java | 10 | ||||
-rw-r--r-- | odk/source/com/sun/star/lib/loader/WinRegKey.java | 199 | ||||
-rw-r--r-- | odk/source/com/sun/star/lib/loader/WinRegKeyException.java | 4 | ||||
-rw-r--r-- | odk/source/unowinreg/win/unowinreg.cxx | 170 |
11 files changed, 47 insertions, 436 deletions
diff --git a/odk/CustomTarget_check.mk b/odk/CustomTarget_check.mk index 69b99a9e4ce8..74331955be9b 100644 --- a/odk/CustomTarget_check.mk +++ b/odk/CustomTarget_check.mk @@ -38,8 +38,7 @@ $(call gb_CustomTarget_get_workdir,odk/check)/checkbin : \ $(call gb_Package_get_target,odk_html) \ $(if $(ENABLE_JAVA),$(call gb_GeneratedPackage_get_target,odk_javadoc)) \ $(call gb_Package_get_target,odk_settings) \ - $(call gb_Package_get_target,odk_settings_generated) \ - $(if $(ENABLE_JAVA),$(call gb_Package_get_target,odk_unowinreg)) + $(call gb_Package_get_target,odk_settings_generated) ifneq ($(gb_SUPPRESS_TESTS),) @true else diff --git a/odk/CustomTarget_unowinreg.mk b/odk/CustomTarget_unowinreg.mk deleted file mode 100644 index 3a46ddfd6860..000000000000 --- a/odk/CustomTarget_unowinreg.mk +++ /dev/null @@ -1,26 +0,0 @@ -# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*- -# -# This file is part of the LibreOffice project. -# -# This Source Code Form is subject to the terms of the Mozilla Public -# License, v. 2.0. If a copy of the MPL was not distributed with this -# file, You can obtain one at http://mozilla.org/MPL/2.0/. -# - -$(eval $(call gb_CustomTarget_CustomTarget,odk/unowinreg)) - -$(eval $(call gb_CustomTarget_register_target,odk/unowinreg,unowinreg.dll)) - -$(call gb_CustomTarget_get_workdir,odk/unowinreg)/unowinreg.dll : \ - $(SRCDIR)/odk/source/unowinreg/win/unowinreg.cxx - $(MINGWCXX) -Wall -D_JNI_IMPLEMENTATION_ \ - -I$(JAVA_HOME)/include \ - $(if $(filter LINUX,$(OS)),-I$(JAVA_HOME)/include/linux,\ - $(if $(filter FREEBSD,$(OS)),-I$(JAVA_HOME)/include/freebsd \ - -I$(JAVA_HOME)/include/bsd -I$(JAVA_HOME)/include/linux,\ - $(if $(filter NETBSD,$(OS)),-I$(JAVA_HOME)/include/netbsd))) \ - -shared -o $@ $< \ - -Wl,--kill-at -lkernel32 -ladvapi32 && \ - $(MINGWSTRIP) $@ - -# vim: set noet sw=4 ts=4: diff --git a/odk/Library_unowinreg.mk b/odk/Library_unowinreg.mk deleted file mode 100644 index a514168cdca0..000000000000 --- a/odk/Library_unowinreg.mk +++ /dev/null @@ -1,36 +0,0 @@ -# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*- -# -# This file is part of the LibreOffice project. -# -# This Source Code Form is subject to the terms of the Mozilla Public -# License, v. 2.0. If a copy of the MPL was not distributed with this -# file, You can obtain one at http://mozilla.org/MPL/2.0/. -# - -$(eval $(call gb_Library_Library,unowinreg)) - -ifeq ($(COM),GCC) -$(eval $(call gb_Library_add_libs,unowinreg,\ - -lstdc++ \ - -lgcc_eh \ - -lgcc \ - -lmingw32 \ - -lmoldname \ - -lmsvcrt \ -)) -else -$(eval $(call gb_Library_add_ldflags,unowinreg,\ - /MANIFEST:NO \ -)) -endif - -$(eval $(call gb_Library_add_exception_objects,unowinreg,\ - odk/source/unowinreg/win/unowinreg \ -)) - -$(eval $(call gb_Library_use_system_win32_libs,unowinreg,\ - kernel32 \ - advapi32 \ -)) - -# vim: set noet sw=4 ts=4: diff --git a/odk/Module_odk.mk b/odk/Module_odk.mk index 120d8a4c01bf..693885322115 100644 --- a/odk/Module_odk.mk +++ b/odk/Module_odk.mk @@ -41,13 +41,10 @@ endif ifneq ($(ENABLE_JAVA),) $(eval $(call gb_Module_add_targets,odk,\ - $(if $(and $(BUILD_UNOWINREG),$(filter GCC,$(COM))),CustomTarget_unowinreg)\ CustomTarget_classes \ CustomTarget_javadoc \ GeneratedPackage_odk_javadoc \ GeneratedPackage_uno_loader_classes \ - $(if $(filter WNT,$(OS)),Library_unowinreg) \ - Package_unowinreg \ )) endif diff --git a/odk/Package_unowinreg.mk b/odk/Package_unowinreg.mk deleted file mode 100644 index 189967eac22b..000000000000 --- a/odk/Package_unowinreg.mk +++ /dev/null @@ -1,28 +0,0 @@ -# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*- -# -# This file is part of the LibreOffice project. -# -# This Source Code Form is subject to the terms of the Mozilla Public -# License, v. 2.0. If a copy of the MPL was not distributed with this -# file, You can obtain one at http://mozilla.org/MPL/2.0/. -# - -ifneq ($(BUILD_UNOWINREG),) -ifeq ($(COM),MSC) -odk_unowinreg_DIR := $(WORKDIR)/LinkTarget/Library -else -odk_unowinreg_DIR := $(call gb_CustomTarget_get_workdir,odk/unowinreg) -endif -odk_unowinreg_FILE := unowinreg.dll -else # !BUILD_UNOWINREG -odk_unowinreg_DIR := $(TARFILE_LOCATION) -odk_unowinreg_FILE := $(UNOWINREG_DLL) -endif - -$(eval $(call gb_Package_Package,odk_unowinreg,$(odk_unowinreg_DIR))) - -$(eval $(call gb_Package_set_outdir,odk_unowinreg,$(INSTDIR))) - -$(eval $(call gb_Package_add_file,odk_unowinreg,$(SDKDIRNAME)/classes/win/unowinreg.dll,$(odk_unowinreg_FILE))) - -# vim: set noet sw=4 ts=4: diff --git a/odk/examples/DevelopersGuide/FirstSteps/build_FirstUnoContact.xml b/odk/examples/DevelopersGuide/FirstSteps/build_FirstUnoContact.xml index 4dec9aa7ee7c..ec0eba70ade7 100644 --- a/odk/examples/DevelopersGuide/FirstSteps/build_FirstUnoContact.xml +++ b/odk/examples/DevelopersGuide/FirstSteps/build_FirstUnoContact.xml @@ -34,7 +34,6 @@ <fileset id="bootstrap.glue.code" dir="${OO_SDK_HOME}/classes"> <patternset> <include name="com/sun/star/lib/loader/*.class"/> - <include name="win/unowinreg.dll"/> </patternset> </fileset> diff --git a/odk/settings/std.mk b/odk/settings/std.mk index dfa01e66fa82..0923a2798761 100644 --- a/odk/settings/std.mk +++ b/odk/settings/std.mk @@ -94,5 +94,4 @@ JAVAMAKER="$(OO_SDK_HOME)/bin/javamaker" REGMERGE="$(OO_SDK_URE_BIN_DIR)/regmerge" SDK_JAVA_UNO_BOOTSTRAP_FILES=\ - -C $(CLASSES_DIR) $(SQM)com/sun/star/lib/loader/$(SQM) \ - -C $(CLASSES_DIR) $(SQM)win/unowinreg.dll$(SQM) + -C $(CLASSES_DIR) $(SQM)com/sun/star/lib/loader/$(SQM) diff --git a/odk/source/com/sun/star/lib/loader/InstallationFinder.java b/odk/source/com/sun/star/lib/loader/InstallationFinder.java index 77c0424f5e4a..8178e0670781 100644 --- a/odk/source/com/sun/star/lib/loader/InstallationFinder.java +++ b/odk/source/com/sun/star/lib/loader/InstallationFinder.java @@ -189,20 +189,20 @@ final class InstallationFinder { */ private static String getPathFromWindowsRegistry() { - final String SUBKEYNAME = "Software\\LibreOffice\\UNO\\InstallPath"; + final String SUBKEYNAME = "\\Software\\LibreOffice\\UNO\\InstallPath"; String path = null; try { // read the key's default value from HKEY_CURRENT_USER - WinRegKey key = new WinRegKey( "HKEY_CURRENT_USER", SUBKEYNAME ); - path = key.getStringValue( "" ); // default + WinRegKey key = new WinRegKey( "HKEY_CURRENT_USER" + SUBKEYNAME ); + path = key.getStringValue(); } catch ( WinRegKeyException e ) { try { // read the key's default value from HKEY_LOCAL_MACHINE - WinRegKey key = new WinRegKey( "HKEY_LOCAL_MACHINE", + WinRegKey key = new WinRegKey( "HKEY_LOCAL_MACHINE" + SUBKEYNAME ); - path = key.getStringValue( "" ); // default + path = key.getStringValue(); } catch ( WinRegKeyException we ) { System.err.println( "com.sun.star.lib.loader." + "InstallationFinder::getPathFromWindowsRegistry: " + diff --git a/odk/source/com/sun/star/lib/loader/WinRegKey.java b/odk/source/com/sun/star/lib/loader/WinRegKey.java index 12cfc45ba293..bdbcced68afa 100644 --- a/odk/source/com/sun/star/lib/loader/WinRegKey.java +++ b/odk/source/com/sun/star/lib/loader/WinRegKey.java @@ -19,185 +19,62 @@ package com.sun.star.lib.loader; -import java.io.BufferedInputStream; -import java.io.BufferedOutputStream; -import java.io.File; -import java.io.FileOutputStream; -import java.io.InputStream; - +import java.io.BufferedReader; +import java.io.InputStreamReader; +import java.util.regex.Matcher; +import java.util.regex.Pattern; /** * This class provides functionality for reading string values from the - * Windows Registry. It requires the native library unowinreg.dll. + * Windows Registry. */ final class WinRegKey { - private final String m_rootKeyName; - private final String m_subKeyName; - - // native methods to access the windows registry - private static native boolean winreg_RegOpenClassesRoot( long[] hkresult ); - private static native boolean winreg_RegOpenCurrentConfig( - long[] hkresult ); - private static native boolean winreg_RegOpenCurrentUser( long[] hkresult ); - private static native boolean winreg_RegOpenLocalMachine( long[] hkresult ); - private static native boolean winreg_RegOpenUsers( long[] hkresult ); - private static native boolean winreg_RegOpenKeyEx( long parent, String name, - long[] hkresult ); - private static native boolean winreg_RegCloseKey( long hkey ); - private static native boolean winreg_RegQueryValueEx( - long hkey, String value, long[] type, - byte[] data, long[] size ); - private static native boolean winreg_RegQueryInfoKey( - long hkey, long[] subkeys, long[] maxSubkeyLen, - long[] values, long[] maxValueNameLen, - long[] maxValueLen, long[] secDescriptor ); - - // load the native library unowinreg.dll - static { - try { - ClassLoader cl = WinRegKey.class.getClassLoader(); - InputStream is = cl.getResourceAsStream( "win/unowinreg.dll" ); - if ( is != null ) { - // generate a temporary name for lib file and write to temp - // location - File libfile; - BufferedInputStream istream = null; - BufferedOutputStream ostream = null; - try { - istream = new BufferedInputStream( is ); - libfile = File.createTempFile( "unowinreg", ".dll" ); - libfile.deleteOnExit(); // ensure deletion - ostream = new BufferedOutputStream( - new FileOutputStream( libfile ) ); - int bsize = 2048; int n = 0; - byte[] buffer = new byte[bsize]; - while ( ( n = istream.read( buffer, 0, bsize ) ) != -1 ) { - ostream.write( buffer, 0, n ); - } - } finally { - if (istream != null) { - istream.close(); - } - if (ostream != null) { - ostream.close(); - } - } - // load library - System.load( libfile.getPath() ); - } else { - // If the library cannot be found as a class loader resource, - // try the global System.loadLibrary(). The JVM will look for - // it in the java.library.path. - System.loadLibrary( "unowinreg" ); - } - } catch ( java.lang.Exception e ) { - System.err.println( "com.sun.star.lib.loader.WinRegKey: " + - "loading of native library failed!" + e ); - } - } + private final String m_keyName; /** * Constructs a <code>WinRegKey</code>. */ - public WinRegKey( String rootKeyName, String subKeyName ) { - m_rootKeyName = rootKeyName; - m_subKeyName = subKeyName; - } - - /** - * Reads a string value for the specified value name. - */ - public String getStringValue( String valueName ) throws WinRegKeyException { - byte[] data = getValue( valueName ); - // remove terminating null character - return new String( data, 0, data.length - 1 ); + public WinRegKey( String keyName ) { + m_keyName = keyName; } /** - * Reads a value for the specified value name. + * Reads the default string value. */ - private byte[] getValue( String valueName ) throws WinRegKeyException { - - byte[] result = null; - long[] hkey = {0}; - - // open the specified registry key - boolean bRet = false; - long[] hroot = {0}; - if ( m_rootKeyName.equals( "HKEY_CLASSES_ROOT" ) ) { - bRet = winreg_RegOpenClassesRoot( hroot ); - } else if ( m_rootKeyName.equals( "HKEY_CURRENT_CONFIG" ) ) { - bRet = winreg_RegOpenCurrentConfig( hroot ); - } else if ( m_rootKeyName.equals( "HKEY_CURRENT_USER" ) ) { - bRet = winreg_RegOpenCurrentUser( hroot ); - } else if ( m_rootKeyName.equals( "HKEY_LOCAL_MACHINE" ) ) { - bRet = winreg_RegOpenLocalMachine( hroot ); - } else if ( m_rootKeyName.equals( "HKEY_USERS" ) ) { - bRet = winreg_RegOpenUsers( hroot ); - } else { - throw new WinRegKeyException( "unknown root registry key!"); - } - if ( !bRet ) { - throw new WinRegKeyException( "opening root registry key " + - "failed!" ); - } - if ( !winreg_RegOpenKeyEx( hroot[0], m_subKeyName, hkey ) ) { - if ( !winreg_RegCloseKey( hroot[0] ) ) { - throw new WinRegKeyException( "opening registry key and " + - "releasing root registry key handle failed!" ); + public String getStringValue() throws WinRegKeyException { + try { + Process p = Runtime.getRuntime().exec(new String[]{"reg", "QUERY", m_keyName}); + BufferedReader r = new BufferedReader(new InputStreamReader(p.getInputStream())); + String v = null; + Pattern pt = Pattern.compile("\\s+\\(Default\\)\\s+REG_SZ\\s+(.+)"); + for (;;) { + String s = r.readLine(); + if (s == null) { + break; + } + Matcher m = pt.matcher(s); + if (m.matches()) { + if (v != null) { + throw new WinRegKeyException("reg QUERY did not provided expected output"); + } + v = m.group(1); + } } - throw new WinRegKeyException( "opening registry key failed!" ); - } - - // get the size of the longest data component among the key's values - long[] subkeys = {0}; - long[] maxSubkeyLen = {0}; - long[] values = {0}; - long[] maxValueNameLen = {0}; - long[] maxValueLen = {0}; - long[] secDescriptor = {0}; - if ( !winreg_RegQueryInfoKey( hkey[0], subkeys, maxSubkeyLen, - values, maxValueNameLen, maxValueLen, secDescriptor ) ) { - if ( !winreg_RegCloseKey( hkey[0] ) || - !winreg_RegCloseKey( hroot[0] ) ) { - throw new WinRegKeyException( "retrieving information about " + - "the registry key and releasing registry key handles " + - "failed!" ); + p.waitFor(); + int e = p.exitValue(); + if (e != 0) { + throw new WinRegKeyException("reg QUERY exited with " + e); } - throw new WinRegKeyException( "retrieving information about " + - "the registry key failed!" ); - } - - // get the data for the specified value name - byte[] buffer = new byte[ (int) maxValueLen[0] ]; - long[] size = new long[1]; - size[0] = buffer.length; - long[] type = new long[1]; - type[0] = 0; - if ( !winreg_RegQueryValueEx( hkey[0], valueName, type, buffer, - size ) ) { - if ( !winreg_RegCloseKey( hkey[0] ) || - !winreg_RegCloseKey( hroot[0] ) ) { - throw new WinRegKeyException( "retrieving data for the " + - "specified value name and releasing registry key handles " + - "failed!" ); + if (v == null) { + throw new WinRegKeyException("reg QUERY did not provided expected output"); } - throw new WinRegKeyException( "retrieving data for the " + - "specified value name failed!" ); + return v; + } catch (WinRegKeyException e) { + throw e; + } catch (Exception e) { + throw new WinRegKeyException(e); } - - // release registry key handles - if ( !winreg_RegCloseKey( hkey[0] ) || - !winreg_RegCloseKey( hroot[0] ) ) { - throw new WinRegKeyException( "releasing registry key handles " + - "failed!" ); - } - - result = new byte[ (int) size[0] ]; - System.arraycopy( buffer, 0, result, 0, (int)size[0] ); - - return result; } } diff --git a/odk/source/com/sun/star/lib/loader/WinRegKeyException.java b/odk/source/com/sun/star/lib/loader/WinRegKeyException.java index aee93c06ee85..56abc7536062 100644 --- a/odk/source/com/sun/star/lib/loader/WinRegKeyException.java +++ b/odk/source/com/sun/star/lib/loader/WinRegKeyException.java @@ -27,8 +27,8 @@ final class WinRegKeyException extends java.lang.Exception { /** * Constructs a <code>WinRegKeyException</code>. */ - public WinRegKeyException() { - super(); + public WinRegKeyException(Throwable cause) { + super(cause); } /** diff --git a/odk/source/unowinreg/win/unowinreg.cxx b/odk/source/unowinreg/win/unowinreg.cxx deleted file mode 100644 index ba28809bfd78..000000000000 --- a/odk/source/unowinreg/win/unowinreg.cxx +++ /dev/null @@ -1,170 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * This file is part of the LibreOffice project. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * This file incorporates work covered by the following license notice: - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed - * with this work for additional information regarding copyright - * ownership. The ASF licenses this file to you under the Apache - * License, Version 2.0 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.apache.org/licenses/LICENSE-2.0 . - */ - - -#if !defined WIN32_LEAN_AND_MEAN -# define WIN32_LEAN_AND_MEAN -#endif -#include <windows.h> - -#include <jni.h> - -extern "C" BOOL __stdcall _DllMainCRTStartup(HINSTANCE, DWORD, LPVOID) -{ - return TRUE; -} - -extern "C" JNIEXPORT jboolean JNICALL - Java_com_sun_star_lib_loader_WinRegKey_winreg_1RegOpenClassesRoot( - JNIEnv *env, jclass, jlongArray hkresult) -{ - bool ret = JNI_FALSE; - auto phkey = env->GetLongArrayElements(hkresult, nullptr); - if (RegOpenKeyEx(HKEY_CLASSES_ROOT, nullptr, 0, KEY_READ, reinterpret_cast<PHKEY>(phkey)) - == ERROR_SUCCESS) - ret = JNI_TRUE; - env->ReleaseLongArrayElements(hkresult, phkey, 0); - return ret; -} - -extern "C" JNIEXPORT jboolean JNICALL - Java_com_sun_star_lib_loader_WinRegKey_winreg_1RegOpenCurrentConfig( - JNIEnv *env, jclass, jlongArray hkresult) -{ - bool ret = JNI_FALSE; - auto phkey = env->GetLongArrayElements(hkresult, nullptr); - if (RegOpenKeyEx(HKEY_CURRENT_CONFIG, nullptr, 0, KEY_READ, reinterpret_cast<PHKEY>(phkey)) - == ERROR_SUCCESS) - ret = JNI_TRUE; - env->ReleaseLongArrayElements(hkresult, phkey, 0); - return ret; -} - -extern "C" JNIEXPORT jboolean JNICALL - Java_com_sun_star_lib_loader_WinRegKey_winreg_1RegOpenCurrentUser( - JNIEnv *env, jclass, jlongArray hkresult) -{ - bool ret = JNI_FALSE; - auto phkey = env->GetLongArrayElements(hkresult, nullptr); - if (RegOpenKeyEx(HKEY_CURRENT_USER, nullptr, 0, KEY_READ, reinterpret_cast<PHKEY>(phkey)) - == ERROR_SUCCESS) - ret = JNI_TRUE; - env->ReleaseLongArrayElements(hkresult, phkey, 0); - return ret; -} - -extern "C" JNIEXPORT jboolean JNICALL - Java_com_sun_star_lib_loader_WinRegKey_winreg_1RegOpenLocalMachine( - JNIEnv *env, jclass, jlongArray hkresult) -{ - bool ret = JNI_FALSE; - auto phkey = env->GetLongArrayElements(hkresult, nullptr); - if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, nullptr, 0, KEY_READ, reinterpret_cast<PHKEY>(phkey)) - == ERROR_SUCCESS) - ret = JNI_TRUE; - env->ReleaseLongArrayElements(hkresult, phkey, 0); - return ret; -} - -extern "C" JNIEXPORT jboolean JNICALL - Java_com_sun_star_lib_loader_WinRegKey_winreg_1RegOpenUsers( - JNIEnv *env, jclass, jlongArray hkresult) -{ - bool ret = JNI_FALSE; - auto phkey = env->GetLongArrayElements(hkresult, nullptr); - if (RegOpenKeyEx(HKEY_USERS, nullptr, 0, KEY_READ, reinterpret_cast<PHKEY>(phkey)) == ERROR_SUCCESS) - ret = JNI_TRUE; - env->ReleaseLongArrayElements(hkresult, phkey, 0); - return ret; -} - -extern "C" JNIEXPORT jboolean JNICALL - Java_com_sun_star_lib_loader_WinRegKey_winreg_1RegOpenKeyEx( - JNIEnv *env, jclass, jlong parent, jstring name, jlongArray hkresult) -{ - bool ret = JNI_FALSE; - const char *namestr = env->GetStringUTFChars(name, nullptr); - auto phkey = env->GetLongArrayElements(hkresult, nullptr); - if (RegOpenKeyEx(reinterpret_cast<HKEY>(parent), namestr, 0, KEY_READ, reinterpret_cast<PHKEY>(phkey)) - == ERROR_SUCCESS) - ret = JNI_TRUE; - env->ReleaseStringUTFChars(name, namestr); - env->ReleaseLongArrayElements(hkresult, phkey, 0); - return ret; -} - - -extern "C" JNIEXPORT jboolean JNICALL - Java_com_sun_star_lib_loader_WinRegKey_winreg_1RegCloseKey( - JNIEnv *, jclass, jlong hkey) -{ - bool ret = JNI_FALSE; - if (RegCloseKey(reinterpret_cast<HKEY>(hkey)) == ERROR_SUCCESS) - ret = JNI_TRUE; - return ret; -} - -extern "C" JNIEXPORT jboolean - JNICALL Java_com_sun_star_lib_loader_WinRegKey_winreg_1RegQueryValueEx( - JNIEnv *env, jclass, jlong hkey, jstring value, jlongArray type, - jbyteArray data, jlongArray size) -{ - bool ret = JNI_FALSE; - const char* valuestr = env->GetStringUTFChars(value, nullptr); - auto ptype = env->GetLongArrayElements(type, nullptr); - auto pdata = env->GetByteArrayElements(data, nullptr); - auto psize = env->GetLongArrayElements(size, nullptr); - if (RegQueryValueEx(reinterpret_cast<HKEY>(hkey), valuestr, nullptr, reinterpret_cast<LPDWORD>(ptype), reinterpret_cast<LPBYTE>(pdata), reinterpret_cast<LPDWORD>(psize)) - == ERROR_SUCCESS) - ret = JNI_TRUE; - env->ReleaseStringUTFChars(value, valuestr); - env->ReleaseLongArrayElements(type, ptype, 0); - env->ReleaseByteArrayElements(data, pdata, 0); - env->ReleaseLongArrayElements(size, psize, 0); - return ret; -} - -extern "C" JNIEXPORT jboolean JNICALL - Java_com_sun_star_lib_loader_WinRegKey_winreg_1RegQueryInfoKey( - JNIEnv *env, jclass, jlong hkey, jlongArray subkeys, - jlongArray maxSubkeyLen, jlongArray values, jlongArray maxValueNameLen, - jlongArray maxValueLen, jlongArray secDescriptor) -{ - bool ret = JNI_FALSE; - auto psubkeys = env->GetLongArrayElements(subkeys, nullptr); - auto pmaxSubkeyLen = env->GetLongArrayElements(maxSubkeyLen, nullptr); - auto pvalues = env->GetLongArrayElements(values, nullptr); - auto pmaxValueNameLen = env->GetLongArrayElements(maxValueNameLen, nullptr); - auto pmaxValueLen = env->GetLongArrayElements(maxValueLen, nullptr); - auto psecDescriptor = env->GetLongArrayElements(secDescriptor, nullptr); - FILETIME ft; - if (RegQueryInfoKey(reinterpret_cast<HKEY>(hkey), nullptr, nullptr, nullptr, reinterpret_cast<LPDWORD>(psubkeys), reinterpret_cast<LPDWORD>(pmaxSubkeyLen), - nullptr, reinterpret_cast<LPDWORD>(pvalues), reinterpret_cast<LPDWORD>(pmaxValueNameLen), reinterpret_cast<LPDWORD>(pmaxValueLen), - reinterpret_cast<LPDWORD>(psecDescriptor), &ft) == ERROR_SUCCESS) - ret = JNI_TRUE; - env->ReleaseLongArrayElements(subkeys, psubkeys, 0); - env->ReleaseLongArrayElements(maxSubkeyLen, pmaxSubkeyLen, 0); - env->ReleaseLongArrayElements(values, pvalues, 0); - env->ReleaseLongArrayElements(maxValueNameLen, pmaxValueNameLen, 0); - env->ReleaseLongArrayElements(maxValueLen, pmaxValueLen, 0); - env->ReleaseLongArrayElements(secDescriptor, psecDescriptor, 0); - return ret; -} - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |