add static file of messages for now

This commit is contained in:
sirjonasxx 2020-12-28 00:49:54 +01:00
parent d590664583
commit 96ee5e4b08
5 changed files with 23 additions and 14 deletions

View File

@ -6,6 +6,7 @@ import gearth.misc.harble_api.HarbleAPI;
import gearth.protocol.HMessage; import gearth.protocol.HMessage;
import gearth.protocol.HPacket; import gearth.protocol.HPacket;
import java.io.File;
import java.security.InvalidParameterException; import java.security.InvalidParameterException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
@ -30,7 +31,7 @@ public class HashSupport {
extension.onConnect((host, port, hotelversion, cachePath) -> { extension.onConnect((host, port, hotelversion, cachePath) -> {
// synchronized (lock) { // synchronized (lock) {
harbleAPI = new HarbleAPI(hotelversion, cachePath); harbleAPI = new HarbleAPI(new File(cachePath));
// } // }
}); });

View File

@ -71,7 +71,6 @@ public class HarbleAPI {
private boolean success = false; private boolean success = false;
private String fullPath = null; 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 * 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)) { if (Cacher.cacheFileExists(possibleCachedMessagesPath)) {
JSONObject object = Cacher.getCacheContents(possibleCachedMessagesPath); JSONObject object = Cacher.getCacheContents(possibleCachedMessagesPath);
success = true; success = true;
revision = hotelversion;
fullPath = Cacher.getCacheDir() + File.separator + possibleCachedMessagesPath; fullPath = Cacher.getCacheDir() + File.separator + possibleCachedMessagesPath;
parse(object); parse(object);
} }
} }
public HarbleAPI(String hotelversion, String path_to_file) { public HarbleAPI(File f) {
File f = new File(path_to_file);
if (f.exists() && !f.isDirectory()) { if (f.exists() && !f.isDirectory()) {
try { try {
String contents = String.join("\n", Files.readAllLines(f.toPath())); String contents = String.join("\n", Files.readAllLines(f.toPath()));
JSONObject object = new JSONObject(contents); JSONObject object = new JSONObject(contents);
success = true; success = true;
revision = hotelversion; fullPath = f.getAbsolutePath();
fullPath = path_to_file;
parse(object); parse(object);
} catch (IOException e) { } catch (IOException e) {
@ -219,10 +214,6 @@ public class HarbleAPI {
return nameToMessage.get(name); return nameToMessage.get(name);
} }
public String getRevision() {
return revision;
}
public String getPath() { public String getPath() {
if (success) { if (success) {
return fullPath; return fullPath;

View File

@ -1,11 +1,14 @@
package gearth.misc.harble_api; package gearth.misc.harble_api;
import gearth.Main;
import gearth.misc.Cacher; import gearth.misc.Cacher;
import gearth.protocol.HMessage; import gearth.protocol.HMessage;
import org.jsoup.Connection; import org.jsoup.Connection;
import org.jsoup.Jsoup; import org.jsoup.Jsoup;
import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.net.URISyntaxException;
/** /**
* Created by Jonas on 10/11/2018. * Created by Jonas on 10/11/2018.
@ -36,6 +39,20 @@ public class HarbleAPIFetcher {
public static HarbleAPI HARBLEAPI = null; public static HarbleAPI HARBLEAPI = null;
public synchronized static void fetch(String hotelversion) { 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; String cacheName = CACHE_PREFIX + hotelversion;
if (Cacher.cacheFileExists(cacheName)) { if (Cacher.cacheFileExists(cacheName)) {

View File

@ -96,7 +96,7 @@ public class UiLoggerController implements Initializable {
String expr = packet.toExpression(isIncoming ? HMessage.Direction.TOCLIENT : HMessage.Direction.TOSERVER); 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) { if ((viewMessageName || viewMessageHash) && HarbleAPIFetcher.HARBLEAPI != null) {
HarbleAPI api = HarbleAPIFetcher.HARBLEAPI; HarbleAPI api = HarbleAPIFetcher.HARBLEAPI;
HarbleAPI.HarbleMessage message = api.getHarbleMessageFromHeaderId( HarbleAPI.HarbleMessage message = api.getHarbleMessageFromHeaderId(

View File

@ -75,7 +75,7 @@
<Insets right="10.0" /> <Insets right="10.0" />
</FlowPane.margin> </FlowPane.margin>
</Label> </Label>
<Label fx:id="lblHarbleAPI" layoutX="283.0" layoutY="11.0" style="-fx-text-fill: black !important" text="HarbleAPI: False"> <Label fx:id="lblHarbleAPI" layoutX="283.0" layoutY="11.0" style="-fx-text-fill: black !important" text="Messages: False">
<FlowPane.margin> <FlowPane.margin>
<Insets right="10.0" /> <Insets right="10.0" />
</FlowPane.margin> </FlowPane.margin>