From 0a7da856c278056c23921323e7681f28dc4d82a2 Mon Sep 17 00:00:00 2001 From: sirjonasxx <36828922+sirjonasxx@users.noreply.github.com> Date: Tue, 22 Jan 2019 17:58:18 +0100 Subject: [PATCH] might as well do this --- .../gearth/misc/harble_api/HarbleAPI.java | 34 ++++++++++++++++--- 1 file changed, 30 insertions(+), 4 deletions(-) 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 18fff31..5a16db9 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 @@ -6,6 +6,8 @@ import org.json.JSONArray; import org.json.JSONObject; import java.io.File; +import java.io.IOException; +import java.nio.file.Files; import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -68,7 +70,8 @@ public class HarbleAPI { private Map nameToMessage_outgoing = new HashMap<>(); private boolean success = false; - private String cachedMessagesPath; + 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 @@ -89,11 +92,30 @@ public class HarbleAPI { if (Cacher.cacheFileExists(possibleCachedMessagesPath)) { JSONObject object = Cacher.getCacheContents(possibleCachedMessagesPath); success = true; - cachedMessagesPath = possibleCachedMessagesPath; + 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); + 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; + parse(object); + + } catch (IOException e) { + e.printStackTrace(); + } + } + } + private void addMessage(HMessage.Side side, JSONObject object) { String name; try { @@ -196,10 +218,14 @@ public class HarbleAPI { return nameToMessage.get(name); } + public String getRevision() { + return revision; + } + @Override public String toString() { - if (Cacher.cacheFileExists(cachedMessagesPath)) { - return Cacher.getCacheDir() + File.separator + cachedMessagesPath; + if (success) { + return fullPath; } return "null"; }