From 24fd7c6ed29dfc066e8eede660fa215eff805a07 Mon Sep 17 00:00:00 2001 From: Wirlaburla Date: Mon, 9 Jan 2023 01:07:53 -0600 Subject: [PATCH] strip away the version and update checks --- .../worlio/WorldsOrganizer/ConfigManager.java | 2 - .../org/worlio/WorldsOrganizer/Dialog.java | 39 ------ .../java/org/worlio/WorldsOrganizer/Main.java | 117 +----------------- .../WorldsOrganizer/VersionManager.java | 71 ----------- 4 files changed, 2 insertions(+), 227 deletions(-) delete mode 100644 src/main/java/org/worlio/WorldsOrganizer/VersionManager.java diff --git a/src/main/java/org/worlio/WorldsOrganizer/ConfigManager.java b/src/main/java/org/worlio/WorldsOrganizer/ConfigManager.java index 20c2282..c2eab01 100644 --- a/src/main/java/org/worlio/WorldsOrganizer/ConfigManager.java +++ b/src/main/java/org/worlio/WorldsOrganizer/ConfigManager.java @@ -25,7 +25,6 @@ enum ToolBarPosition { } enum ConfigEntry { - updateURL("update-url"), iconSize("icon-size"), fileBackup("file-backup"), darkMode("dark-mode"), @@ -55,7 +54,6 @@ public class ConfigManager { private void initialize() { mapper = new ObjectMapper(); Console.print("Initializing default config values", 1, ConsoleType.INFO); - defaultConfiguration.put(ConfigEntry.updateURL.name(), "https://worlio.com/WorldsOrganizer.json"); defaultConfiguration.put(ConfigEntry.iconSize.name(), 24); defaultConfiguration.put(ConfigEntry.fileBackup.name(), true); defaultConfiguration.put(ConfigEntry.darkMode.name(), false); diff --git a/src/main/java/org/worlio/WorldsOrganizer/Dialog.java b/src/main/java/org/worlio/WorldsOrganizer/Dialog.java index 2a2687f..0f3626d 100644 --- a/src/main/java/org/worlio/WorldsOrganizer/Dialog.java +++ b/src/main/java/org/worlio/WorldsOrganizer/Dialog.java @@ -114,45 +114,6 @@ public class Dialog { } } - public static void showUpdate(Version newVer) { - Alert alert = new Alert(Alert.AlertType.INFORMATION); - assert Main.verMan != null; - alert.setTitle("Update Dialog"); - alert.setHeaderText("A new version (v" + newVer.get() + ") of Organizer is available for download.\nYou are currently on v" + Console.getVersion() + "."); - alert.initOwner(Main.mainStage); - - ButtonType updateButton = new ButtonType("Open"); - ButtonType buttonTypeCancel = new ButtonType("Cancel", ButtonBar.ButtonData.CANCEL_CLOSE); - - Label label = new Label("View Changelog"); - - TextArea textArea = new TextArea(Console.changelogify(Main.verMan.getChangelog(newVer))); - textArea.setEditable(false); - textArea.setWrapText(true); - - textArea.setMaxWidth(Double.MAX_VALUE); - textArea.setMaxHeight(Double.MAX_VALUE); - GridPane.setVgrow(textArea, Priority.ALWAYS); - GridPane.setHgrow(textArea, Priority.ALWAYS); - - GridPane expContent = new GridPane(); - expContent.setMaxWidth(Double.MAX_VALUE); - expContent.add(label, 0, 0); - expContent.add(textArea, 0, 1); - - alert.getDialogPane().setExpandableContent(expContent); - alert.getButtonTypes().setAll(updateButton, buttonTypeCancel); - - alert.getDialogPane().setMinSize(200,200); - Optional result = alert.showAndWait(); - if (result.get() == updateButton) { - Console.print("Displaying webpage in native browser.", 1, ConsoleType.INFO); - Main.hostServices.showDocument(Main.verMan.url.replace("{ver}", newVer.get())); - } else { - alert.close(); - } - } - public static void process() { Alert alert = new Alert(Alert.AlertType.INFORMATION); alert.setTitle("Message"); diff --git a/src/main/java/org/worlio/WorldsOrganizer/Main.java b/src/main/java/org/worlio/WorldsOrganizer/Main.java index 8eae93c..0c0a0dd 100644 --- a/src/main/java/org/worlio/WorldsOrganizer/Main.java +++ b/src/main/java/org/worlio/WorldsOrganizer/Main.java @@ -31,7 +31,6 @@ public class Main extends Application { static int debugMode = 0; static ConfigManager configManager; - static VersionManager verMan; static List startFiles = new ArrayList<>(); static List tabs = new ArrayList<>(); @@ -49,13 +48,6 @@ public class Main extends Application { configManager = new ConfigManager(new File((Console.getParent() + "/config.json"))); - try { - verMan = new VersionManager(); - } catch (IOException e) { - Console.print("An IOException was encountered attempting to obtain the version.", 1, ConsoleType.ERROR); - e.printStackTrace(); - } - if (debugMode < 1) debugMode = configManager.getBooleanValue(ConfigEntry.debug) ? 1 : 0; Console.print("Initializing main application.", ConsoleType.INFO); @@ -248,20 +240,6 @@ public class Main extends Application { // General Tab - Label channelName = new Label("Update Channel"); - channelName.setFont(Font.font("Verdana", FontWeight.BOLD, FontPosture.REGULAR, 12)); - Label channelInfo = new Label("Channel to use for update checks and links: 'stable' will provide tested " + - "build updates while 'beta' is more of an experimental bug-finding experience."); - channelInfo.setWrapText(true); - - ObservableList channels = - FXCollections.observableArrayList(ConfigManager.channels); - - ComboBox channelOption = new ComboBox(channels); - channelOption.getSelectionModel().select(configManager.getStringValue(ConfigEntry.channel)); - HBox.setHgrow(channelOption, Priority.ALWAYS); - - // Appearance Tab Label darkName = new Label("Use Dark Mode"); @@ -348,7 +326,6 @@ public class Main extends Application { applyButton.setDefaultButton(true); applyButton.addEventFilter(MouseEvent.MOUSE_CLICKED, a -> { configManager.setValue(ConfigEntry.toolbarPos, toolPosOption.getValue()); - configManager.setValue(ConfigEntry.channel, channelOption.getValue()); configManager.setValue(ConfigEntry.iconSize, (int)iconSizeSlider.getValue()); configManager.write(); toggleDark(scene); @@ -358,7 +335,6 @@ public class Main extends Application { Button okButton = new Button("Ok"); okButton.addEventFilter(MouseEvent.MOUSE_CLICKED, a -> { configManager.setValue(ConfigEntry.toolbarPos, toolPosOption.getValue()); - configManager.setValue(ConfigEntry.channel, channelOption.getValue()); configManager.setValue(ConfigEntry.iconSize, (int)iconSizeSlider.getValue()); configManager.write(); toggleDark(scene); @@ -374,14 +350,6 @@ public class Main extends Application { // Tabbing every option into their own VBox so we can have them split off in their own containers. // This makes it easier to add to tabs because it's just a simple declare. Also good for design. - VBox vGeneral = new VBox(channelName, channelInfo, channelOption); - ScrollPane general = new ScrollPane(vGeneral); - general.setFitToWidth(true); - Tab generalTab = new Tab("General", general); - VBox.setVgrow(general, Priority.ALWAYS); - vGeneral.setPadding(new Insets(10, 10, 10, 10)); - vGeneral.setSpacing(10); - VBox vSkin = new VBox(darkName, darkInfo, darkOption, statusName, statusInfo, statusOption, toolName, toolInfo, toolPosOption, sizeName, sizeInfo, iconSizeSlider); ScrollPane skin = new ScrollPane(vSkin); @@ -399,11 +367,10 @@ public class Main extends Application { vAdvance.setPadding(new Insets(10, 10, 10, 10)); vAdvance.setSpacing(10); - TabPane prefPane = new TabPane(generalTab, skinTab, advanceTab); + TabPane prefPane = new TabPane(skinTab, advanceTab); VBox.setVgrow(prefPane, Priority.ALWAYS); prefPane.setTabClosingPolicy(TabPane.TabClosingPolicy.UNAVAILABLE); - general.maxWidthProperty().bind(prefPane.widthProperty()); skin.maxWidthProperty().bind(prefPane.widthProperty()); advance.maxWidthProperty().bind(prefPane.widthProperty()); @@ -489,87 +456,7 @@ public class Main extends Application { logoView.fitHeightProperty().bind(mainBox.heightProperty().multiply(0.5)); mainBox.setAlignment(Pos.CENTER); - Button updateButton = new Button("Check for Updates"); - updateButton.addEventFilter(MouseEvent.MOUSE_CLICKED, a -> { - boolean isUpdatable; - try { - // Simply restarting the manager so it gets everything fresh. - // Simple yet effective at what we want, without issues. - verMan = new VersionManager(); - isUpdatable = verMan.hasUpdate(); - if (isUpdatable) { - Console.print("Update detected! Showing dialog.", ConsoleType.INFO); - verMan.pushUpdate(); - } else Console.print("No updates available.", ConsoleType.INFO); - } catch (IOException e) { - Console.print("Could not check for updates!", ConsoleType.ERROR); - isUpdatable = false; - } - if (!isUpdatable) Dialog.showError("Update Check", "No new updates are available."); - }); - - Button changelogButton = new Button("What's new?"); - changelogButton.addEventFilter(MouseEvent.MOUSE_CLICKED, a -> { - Stage changelogStage = new Stage(); - changelogStage.initOwner(mainStage); - changelogStage.setTitle("What's new?"); - - VBox changesBox = new VBox(); - - // Reading the json file remotely, and then looking through every single value in the list. - // It's simple text, so it makes it easy to parse and style. - - for (Map.Entry vC : ((Map)((Map)verMan.json.get("versions")).get(configManager.getStringValue(ConfigEntry.channel))).entrySet()) { - - // UPDATES UPDATES UPDATES - if (new Version((String)vC.getKey()).equals(new Version(Console.getVersion()))) { - Text channel = new Text("Current Version"); - channel.setFont(Font.font("Verdana", FontWeight.LIGHT, FontPosture.ITALIC, 12)); - changesBox.getChildren().add(channel); - } - - Text version = new Text((String)vC.getKey()); - version.setFont(Font.font("Verdana", FontWeight.BOLD, FontPosture.REGULAR, 14)); - changesBox.getChildren().add(version); - for (String line : verMan.getChangelog(new Version((String)vC.getKey()))) { - Text lineTxt = new Text(" - " + line); - lineTxt.wrappingWidthProperty().bind(changesBox.prefWidthProperty().multiply(0.95)); - changesBox.getChildren().add(lineTxt); - } - changesBox.getChildren().add(new Separator()); - } - changesBox.setPadding(new Insets(10, 10, 10, 10)); - - // Organize it nicely within a small ScrollPane. - // It took forever to get the text to wrap so this works. - ScrollPane changesPane = new ScrollPane(changesBox); - VBox.setVgrow(changesPane, Priority.ALWAYS); - changesPane.prefWidthProperty().bind(changelogStage.widthProperty()); - changesPane.setFitToWidth(true); - - changesBox.prefWidthProperty().bind(changesPane.widthProperty()); - - Button cancelButton = new Button("Close"); - cancelButton.setCancelButton(true); - cancelButton.addEventFilter(MouseEvent.MOUSE_CLICKED, (e) -> changelogStage.close()); - - ButtonBar bBar = new ButtonBar(); - bBar.getButtons().addAll(cancelButton); - bBar.setPadding(new Insets(10, 10, 10, 10)); - - changelogStage.setMinWidth(450); - changelogStage.setMinHeight(400); - - changelogStage.setScene(new Scene(new VBox(changesPane, bBar), 450, 400)); - changelogStage.show(); - }); - - HBox bBar = new HBox(changelogButton, updateButton); - bBar.setAlignment(Pos.CENTER); - bBar.setSpacing(10); - bBar.setPadding(new Insets(10, 10, 10, 10)); - - mainBox.getChildren().addAll(logoView, nameTxt, buildTxt, devTxt, bBar); + mainBox.getChildren().addAll(logoView, nameTxt, buildTxt, devTxt); return new Tab("Start Page", mainBox); } diff --git a/src/main/java/org/worlio/WorldsOrganizer/VersionManager.java b/src/main/java/org/worlio/WorldsOrganizer/VersionManager.java deleted file mode 100644 index 174a455..0000000 --- a/src/main/java/org/worlio/WorldsOrganizer/VersionManager.java +++ /dev/null @@ -1,71 +0,0 @@ -package org.worlio.WorldsOrganizer; - -import com.fasterxml.jackson.databind.json.JsonMapper; - -import java.io.*; -import java.net.URL; -import java.nio.charset.StandardCharsets; -import java.util.ArrayList; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; - -public class VersionManager { - - String url; - public Version currentVersion = new Version(Console.getVersion()); - public Version newVersion; - static JsonMapper mapper = new JsonMapper(); - Map json; - int format; - - private boolean isValid() { - return format == 2; - } - - VersionManager() throws IOException { - json = readJsonFromUrl(Main.configManager.getStringValue(ConfigEntry.updateURL)); - format = (int)json.get("format"); - if (!isValid()) throw new IOException("Invalid JSON Update format: Format Version is not 2"); - url = (String) json.get("url"); - Map updates = (Map) json.get("versions"); - LinkedHashMap ver = (LinkedHashMap) updates.get(Main.configManager.getStringValue(ConfigEntry.channel)); - newVersion = new Version((String)ver.keySet().toArray()[0]); - } - - public boolean hasUpdate() { - if (!isValid()) return false; - return newVersion.compareTo(currentVersion) >= 1; - } - - public void pushUpdate() { - if (hasUpdate() && isValid()) { - Dialog.showUpdate(newVersion); - } else Console.print("No new updates available."); - } - - public List getChangelog(Version ver) { - if (!isValid()) return new ArrayList<>(); - - // God is horrified, and he has every right to be. - return (List)((LinkedHashMap) ((Map)json.get("versions")).get(Main.configManager.getStringValue(ConfigEntry.channel))).get(ver.get()); - } - - private static String readAll(Reader rd) throws IOException { - StringBuilder sb = new StringBuilder(); - int cp; - while ((cp = rd.read()) != -1) { - sb.append((char) cp); - } - return sb.toString(); - } - - public static Map readJsonFromUrl(String url) throws IOException { - try (InputStream is = new URL(url).openStream()) { - BufferedReader rd = new BufferedReader(new InputStreamReader(is, StandardCharsets.UTF_8)); - String jsonText = readAll(rd); - return mapper.readValue(jsonText, Map.class); - } - } - -}