diff --git a/.gitignore b/.gitignore index c51e7db9..8ad5768e 100644 --- a/.gitignore +++ b/.gitignore @@ -24,4 +24,5 @@ src/test/resources/War3x.w3x *.classpath /bin/ /.project -src/main/java/net/moonlightflower/wc3libs/antlr \ No newline at end of file +src/main/java/net/moonlightflower/wc3libs/antlr +.settings/ diff --git a/src/main/java/net/moonlightflower/wc3libs/misc/WinRegistryHandler.java b/src/main/java/net/moonlightflower/wc3libs/misc/WinRegistryHandler.java index c57a0325..12df27e8 100644 --- a/src/main/java/net/moonlightflower/wc3libs/misc/WinRegistryHandler.java +++ b/src/main/java/net/moonlightflower/wc3libs/misc/WinRegistryHandler.java @@ -4,6 +4,7 @@ import java.io.IOException; import java.io.InputStream; import java.io.StringWriter; +import java.util.Optional; import net.moonlightflower.wc3libs.misc.ProcCaller; import net.moonlightflower.wc3libs.port.Orient; @@ -37,6 +38,8 @@ private Entry(@Nonnull String dirS, @Nonnull String key, @Nonnull EntryType entr } } + /** A warcraft3-specific registry entry. Present on wc3 versions before 1.32 (reforged). */ + @Deprecated public static class Wc3Entry extends Entry { public final static String PREFIX = "HKCU\\Software\\Blizzard Entertainment\\Warcraft III"; @@ -257,6 +260,23 @@ public Wc3Entry(@Nonnull String key, @Nonnull EntryType entryType) { } } + /** A Warcraft 3 Reforged compatible registry entry. Installations as of 1.32 may be void of all `Wc3Entry`s. */ + public static class Wc3ReforgedEntry extends Entry { + public final static String PREFIX = "HKLM\\Software\\WOW6432Node\\Blizzard Entertainment\\Warcraft III\\Capabilities"; + + public Wc3ReforgedEntry(@Nonnull String key, @Nonnull EntryType entryType) { + super(PREFIX, key, entryType); + } + + /** Of the form `"C:\Program Files\Warcraft III\x86_64\Warcraft III.exe",0` */ + public final static Wc3ReforgedEntry APPLICATION_ICON = new Wc3ReforgedEntry("ApplicationIcon", EntryType.REG_SZ); + + /** Of the form `"C:\Program Files\Warcraft III\x86_64\Warcraft III.exe",0` */ + public final static Wc3ReforgedEntry INSTALL_PATH = APPLICATION_ICON; + } + + /** A warcraft3-specific registry entry. Present on wc3 versions before 1.32 (reforged). */ + @Deprecated public static class Wc3LocalMachineEntry extends Entry { public final static String PREFIX = "HKLM\\Software\\Blizzard Entertainment\\Warcraft III"; @@ -269,6 +289,8 @@ public Wc3LocalMachineEntry(@Nonnull File dir, @Nonnull String key, @Nonnull Ent } } + /** A warcraft3-specific registry entry. Present on wc3 versions before 1.32 (reforged). */ + @Deprecated public static class WorldEditEntry extends Entry { public final static String PREFIX = "HKCU\\Software\\Blizzard Entertainment\\WorldEdit"; @@ -281,24 +303,32 @@ public String get(@Nonnull File dir, @Nonnull String key) throws IOException { if (!Orient.isWindowsSystem()) throw new UnsupportedOperationException("not a windows system: " + Orient.getSystem()); ProcCaller proc = getQueryingProcCaller(dir, key); - + proc.exec(); - + String result = proc.getOutString(); - + result = result.replaceAll("\\p{Cntrl}", ""); - + String[] splits = result.split(" "); - if (splits.length < 4) return null;//throw new IOException("entry " + dir + ";" + key + " not found"); + if (splits.length < 4) return null; return splits[3]; } + public Optional maybeGet(@Nonnull String dirS, @Nonnull String key) { + try { + return Optional.ofNullable(get(dirS, key)); + } catch (IOException e) { + return Optional.empty(); + } + } + protected ProcCaller getQueryingProcCaller(@Nonnull File dir, @Nonnull String key) { return new ProcCaller("REG", "QUERY", dir.toString(), "/v", key); } - + public String get(@Nonnull String dirS, @Nonnull String key) throws IOException { return get(new File(dirS), key); }