diff --git a/build.gradle b/build.gradle index 19f902b4..e917bd0e 100644 --- a/build.gradle +++ b/build.gradle @@ -1,5 +1,5 @@ plugins { - id 'org.jreleaser' version '1.2.0' + id 'org.jreleaser' version '1.3.1' } if(project == rootProject) { diff --git a/deps b/deps index 23936c9a..d0578cfb 160000 --- a/deps +++ b/deps @@ -1 +1 @@ -Subproject commit 23936c9a6a2ec35f0ca71266debb93d06144df9d +Subproject commit d0578cfb68e7668423988fafa96659eaae219a0e diff --git a/extension/build.gradle b/extension/build.gradle index 3943894d..6ad8fcbb 100644 --- a/extension/build.gradle +++ b/extension/build.gradle @@ -24,6 +24,8 @@ dependencies { api group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: "2.13.0" api group: 'com.fasterxml.jackson.core', name: 'jackson-annotations', version: "2.13.0" + compileOnly 'net.java.dev.jna:jna-jpms:5.12.1' + compileOnly 'net.java.dev.jna:jna-platform-jpms:5.12.1' compileOnly group: 'org.kordamp.ikonli', name: 'ikonli-javafx', version: "12.2.0" compileOnly group: 'org.fxmisc.richtext', name: 'richtextfx', version: '0.10.9' compileOnly 'net.synedra:validatorfx:0.3.1' diff --git a/extension/src/main/java/io/xpipe/extension/util/WindowsRegistry.java b/extension/src/main/java/io/xpipe/extension/util/WindowsRegistry.java index dfc89167..cdcfe8a1 100644 --- a/extension/src/main/java/io/xpipe/extension/util/WindowsRegistry.java +++ b/extension/src/main/java/io/xpipe/extension/util/WindowsRegistry.java @@ -1,60 +1,25 @@ package io.xpipe.extension.util; -import java.io.IOException; -import java.io.InputStream; -import java.io.StringWriter; +import com.sun.jna.platform.win32.Advapi32Util; +import com.sun.jna.platform.win32.WinReg; + import java.util.Optional; public class WindowsRegistry { - public static Optional readRegistry(String location, String key) { - try { - Process process = - Runtime.getRuntime().exec("reg query " + '"' + location + "\"" + (key != null ? " /v " + key : " /ve")); + public static final int HKEY_CURRENT_USER = 0x80000001; + public static final int HKEY_LOCAL_MACHINE = 0x80000002; - StreamReader reader = new StreamReader(process.getInputStream()); - reader.start(); - process.waitFor(); - reader.join(); - String output = reader.getResult(); - - // Output has the following format: - // \n\n\n\t\t - if (output.contains("\t")) { - String[] parsed = output.split("\t"); - return Optional.of(parsed[parsed.length - 1]); - } - - if (output.contains(" ")) { - String[] parsed = output.split(" "); - return Optional.of(parsed[parsed.length - 1].substring(0, parsed[parsed.length - 1].length() - 4)); - } - - return Optional.empty(); - } catch (Exception e) { - return Optional.empty(); - } + public static Optional readString(int hkey, String key) { + return readString(hkey,key, null); } - static class StreamReader extends Thread { - private final InputStream is; - private final StringWriter sw = new StringWriter(); - - public StreamReader(InputStream is) { - this.is = is; + public static Optional readString(int hkey, String key, String valueName) { + if (!Advapi32Util.registryValueExists(hkey == HKEY_LOCAL_MACHINE ? WinReg.HKEY_LOCAL_MACHINE : WinReg.HKEY_CURRENT_USER, key, valueName)) { + return Optional.empty(); } - public void run() { - try { - int c; - while ((c = is.read()) != -1) sw.write(c); - } catch (IOException e) { - System.err.println(e.toString()); - } - } - - public String getResult() { - return sw.toString(); - } + return Optional.ofNullable(Advapi32Util.registryGetStringValue( + hkey == HKEY_LOCAL_MACHINE ? WinReg.HKEY_LOCAL_MACHINE : WinReg.HKEY_CURRENT_USER, key, valueName)); } } \ No newline at end of file diff --git a/extension/src/main/java/module-info.java b/extension/src/main/java/module-info.java index 8dab653b..66afbdff 100644 --- a/extension/src/main/java/module-info.java +++ b/extension/src/main/java/module-info.java @@ -18,6 +18,8 @@ open module io.xpipe.extension { requires io.xpipe.beacon; requires io.xpipe.api; requires com.fasterxml.jackson.databind; + requires static com.sun.jna; + requires static com.sun.jna.platform; requires static org.junit.jupiter.api; requires static org.apache.commons.lang3; requires static javafx.base; diff --git a/jreleaser.gradle b/jreleaser.gradle index c3617b4b..87bf2264 100644 --- a/jreleaser.gradle +++ b/jreleaser.gradle @@ -18,7 +18,7 @@ jreleaser { java { groupId = 'io.xpipe' - version = '17' + version = '19' multiProject = true } }