From c718f8d3f66ae6ca9c02b327e60525ab8a746432 Mon Sep 17 00:00:00 2001 From: crschnick Date: Fri, 20 Sep 2024 15:05:52 +0000 Subject: [PATCH] Expose reg query parser --- .../io/xpipe/app/util/WindowsRegistry.java | 30 +++++++++++-------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/app/src/main/java/io/xpipe/app/util/WindowsRegistry.java b/app/src/main/java/io/xpipe/app/util/WindowsRegistry.java index a2aca1d11..fc7f257b5 100644 --- a/app/src/main/java/io/xpipe/app/util/WindowsRegistry.java +++ b/app/src/main/java/io/xpipe/app/util/WindowsRegistry.java @@ -104,6 +104,22 @@ public abstract class WindowsRegistry { public static class Remote extends WindowsRegistry { + public static Optional readOutputValue(String original) { + // Output has the following format: + // \n\n\n\t\t + if (original.contains("\t")) { + String[] parsed = original.split("\t"); + return Optional.of(parsed[parsed.length - 1]); + } + + if (original.contains(" ")) { + String[] parsed = original.split(" "); + return Optional.of(parsed[parsed.length - 1]); + } + + return Optional.empty(); + } + private final ShellControl shellControl; public Remote(ShellControl shellControl) { @@ -150,19 +166,7 @@ public abstract class WindowsRegistry { return Optional.empty(); } - // Output has the following format: - // \n\n\n\t\t - if (output.get().contains("\t")) { - String[] parsed = output.get().split("\t"); - return Optional.of(parsed[parsed.length - 1]); - } - - if (output.get().contains(" ")) { - String[] parsed = output.get().split(" "); - return Optional.of(parsed[parsed.length - 1]); - } - - return Optional.empty(); + return readOutputValue(output.get()); } @Override