From 96ee5e4b08c8010b53bdfb6ad0607cfbd365fa65 Mon Sep 17 00:00:00 2001 From: sirjonasxx <36828922+sirjonasxx@users.noreply.github.com> Date: Mon, 28 Dec 2020 00:49:54 +0100 Subject: [PATCH] add static file of messages for now --- .../extensions/extra/harble/HashSupport.java | 3 ++- .../java/gearth/misc/harble_api/HarbleAPI.java | 13 ++----------- .../misc/harble_api/HarbleAPIFetcher.java | 17 +++++++++++++++++ .../uilogger/UiLoggerController.java | 2 +- .../gearth/ui/logger/uilogger/UiLogger.fxml | 2 +- 5 files changed, 23 insertions(+), 14 deletions(-) diff --git a/G-Earth/src/main/java/gearth/extensions/extra/harble/HashSupport.java b/G-Earth/src/main/java/gearth/extensions/extra/harble/HashSupport.java index 842fbc5..f507f44 100644 --- a/G-Earth/src/main/java/gearth/extensions/extra/harble/HashSupport.java +++ b/G-Earth/src/main/java/gearth/extensions/extra/harble/HashSupport.java @@ -6,6 +6,7 @@ import gearth.misc.harble_api.HarbleAPI; import gearth.protocol.HMessage; import gearth.protocol.HPacket; +import java.io.File; import java.security.InvalidParameterException; import java.util.ArrayList; import java.util.HashMap; @@ -30,7 +31,7 @@ public class HashSupport { extension.onConnect((host, port, hotelversion, cachePath) -> { // synchronized (lock) { - harbleAPI = new HarbleAPI(hotelversion, cachePath); + harbleAPI = new HarbleAPI(new File(cachePath)); // } }); diff --git a/G-Earth/src/main/java/gearth/misc/harble_api/HarbleAPI.java b/G-Earth/src/main/java/gearth/misc/harble_api/HarbleAPI.java index a265e68..8333483 100644 --- a/G-Earth/src/main/java/gearth/misc/harble_api/HarbleAPI.java +++ b/G-Earth/src/main/java/gearth/misc/harble_api/HarbleAPI.java @@ -71,7 +71,6 @@ public class HarbleAPI { private boolean success = false; private String fullPath = null; - private String revision = null; /** * cache file must be generated first within G-Earth, inb4 20 extensions requesting it at the same time @@ -92,22 +91,18 @@ public class HarbleAPI { if (Cacher.cacheFileExists(possibleCachedMessagesPath)) { JSONObject object = Cacher.getCacheContents(possibleCachedMessagesPath); success = true; - revision = hotelversion; fullPath = Cacher.getCacheDir() + File.separator + possibleCachedMessagesPath; parse(object); } } - public HarbleAPI(String hotelversion, String path_to_file) { - - File f = new File(path_to_file); + public HarbleAPI(File f) { if (f.exists() && !f.isDirectory()) { try { String contents = String.join("\n", Files.readAllLines(f.toPath())); JSONObject object = new JSONObject(contents); success = true; - revision = hotelversion; - fullPath = path_to_file; + fullPath = f.getAbsolutePath(); parse(object); } catch (IOException e) { @@ -219,10 +214,6 @@ public class HarbleAPI { return nameToMessage.get(name); } - public String getRevision() { - return revision; - } - public String getPath() { if (success) { return fullPath; diff --git a/G-Earth/src/main/java/gearth/misc/harble_api/HarbleAPIFetcher.java b/G-Earth/src/main/java/gearth/misc/harble_api/HarbleAPIFetcher.java index c99d942..08beed3 100644 --- a/G-Earth/src/main/java/gearth/misc/harble_api/HarbleAPIFetcher.java +++ b/G-Earth/src/main/java/gearth/misc/harble_api/HarbleAPIFetcher.java @@ -1,11 +1,14 @@ package gearth.misc.harble_api; +import gearth.Main; import gearth.misc.Cacher; import gearth.protocol.HMessage; import org.jsoup.Connection; import org.jsoup.Jsoup; +import java.io.File; import java.io.IOException; +import java.net.URISyntaxException; /** * Created by Jonas on 10/11/2018. @@ -36,6 +39,20 @@ public class HarbleAPIFetcher { public static HarbleAPI HARBLEAPI = null; public synchronized static void fetch(String hotelversion) { + // if unity + if (!(hotelversion.toLowerCase().contains("production") || hotelversion.toLowerCase().contains("release"))) { + try { + HARBLEAPI = new HarbleAPI( + new File(new File(Main.class.getProtectionDomain().getCodeSource().getLocation().toURI()) + .getParentFile(), "messages.json" + ) + ); + } catch (URISyntaxException e) { + HARBLEAPI = null; + } + return; + } + String cacheName = CACHE_PREFIX + hotelversion; if (Cacher.cacheFileExists(cacheName)) { diff --git a/G-Earth/src/main/java/gearth/ui/logger/loggerdisplays/uilogger/UiLoggerController.java b/G-Earth/src/main/java/gearth/ui/logger/loggerdisplays/uilogger/UiLoggerController.java index 064d6c0..6f1ad87 100644 --- a/G-Earth/src/main/java/gearth/ui/logger/loggerdisplays/uilogger/UiLoggerController.java +++ b/G-Earth/src/main/java/gearth/ui/logger/loggerdisplays/uilogger/UiLoggerController.java @@ -96,7 +96,7 @@ public class UiLoggerController implements Initializable { String expr = packet.toExpression(isIncoming ? HMessage.Direction.TOCLIENT : HMessage.Direction.TOSERVER); - lblHarbleAPI.setText("HarbleAPI: " + (HarbleAPIFetcher.HARBLEAPI == null ? "False" : "True")); + lblHarbleAPI.setText("Messages: " + (HarbleAPIFetcher.HARBLEAPI == null ? "False" : "True")); if ((viewMessageName || viewMessageHash) && HarbleAPIFetcher.HARBLEAPI != null) { HarbleAPI api = HarbleAPIFetcher.HARBLEAPI; HarbleAPI.HarbleMessage message = api.getHarbleMessageFromHeaderId( diff --git a/G-Earth/src/main/resources/gearth/ui/logger/uilogger/UiLogger.fxml b/G-Earth/src/main/resources/gearth/ui/logger/uilogger/UiLogger.fxml index c159ab2..1299ca7 100644 --- a/G-Earth/src/main/resources/gearth/ui/logger/uilogger/UiLogger.fxml +++ b/G-Earth/src/main/resources/gearth/ui/logger/uilogger/UiLogger.fxml @@ -75,7 +75,7 @@ -