mirror of
https://github.com/sirjonasxx/G-Earth.git
synced 2024-11-26 18:30:52 +01:00
add static file of messages for now
This commit is contained in:
parent
d590664583
commit
96ee5e4b08
@ -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));
|
||||
// }
|
||||
});
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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)) {
|
||||
|
@ -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(
|
||||
|
@ -75,7 +75,7 @@
|
||||
<Insets right="10.0" />
|
||||
</FlowPane.margin>
|
||||
</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>
|
||||
<Insets right="10.0" />
|
||||
</FlowPane.margin>
|
||||
|
Loading…
Reference in New Issue
Block a user