diff --git a/QuickLaunch/bin/basics/BasicGuiApp$1.class b/QuickLaunch/bin/basics/BasicGuiApp$1.class index f263721..4b94953 100644 Binary files a/QuickLaunch/bin/basics/BasicGuiApp$1.class and b/QuickLaunch/bin/basics/BasicGuiApp$1.class differ diff --git a/QuickLaunch/bin/basics/BasicGuiApp.class b/QuickLaunch/bin/basics/BasicGuiApp.class index d376be1..c11e0d0 100644 Binary files a/QuickLaunch/bin/basics/BasicGuiApp.class and b/QuickLaunch/bin/basics/BasicGuiApp.class differ diff --git a/QuickLaunch/bin/main/Start.class b/QuickLaunch/bin/main/Start.class index 5142a84..4537986 100644 Binary files a/QuickLaunch/bin/main/Start.class and b/QuickLaunch/bin/main/Start.class differ diff --git a/QuickLaunch/bin/manager/ResourceManager.class b/QuickLaunch/bin/manager/ResourceManager.class index 09f2bf3..60948de 100644 Binary files a/QuickLaunch/bin/manager/ResourceManager.class and b/QuickLaunch/bin/manager/ResourceManager.class differ diff --git a/QuickLaunch/bin/manager/SettingManager.class b/QuickLaunch/bin/manager/SettingManager.class index f5caf7b..8bd1b12 100644 Binary files a/QuickLaunch/bin/manager/SettingManager.class and b/QuickLaunch/bin/manager/SettingManager.class differ diff --git a/QuickLaunch/bin/mod_quicklaunch/QuickLaunch.class b/QuickLaunch/bin/mod_quicklaunch/QuickLaunch.class index caf39d4..07f45cf 100644 Binary files a/QuickLaunch/bin/mod_quicklaunch/QuickLaunch.class and b/QuickLaunch/bin/mod_quicklaunch/QuickLaunch.class differ diff --git a/QuickLaunch/bin/update/UpdateChecker.class b/QuickLaunch/bin/update/UpdateChecker.class index 456a3aa..67e0ea2 100644 Binary files a/QuickLaunch/bin/update/UpdateChecker.class and b/QuickLaunch/bin/update/UpdateChecker.class differ diff --git a/QuickLaunch/bin/update/UpdateThread.class b/QuickLaunch/bin/update/UpdateThread.class deleted file mode 100644 index 31a7280..0000000 Binary files a/QuickLaunch/bin/update/UpdateThread.class and /dev/null differ diff --git a/QuickLaunch/bin/update/Updater.class b/QuickLaunch/bin/update/Updater.class index 8f4b6d7..c28f1ad 100644 Binary files a/QuickLaunch/bin/update/Updater.class and b/QuickLaunch/bin/update/Updater.class differ diff --git a/QuickLaunch/settings.properties b/QuickLaunch/settings.properties index d0401d2..75f37c9 100644 --- a/QuickLaunch/settings.properties +++ b/QuickLaunch/settings.properties @@ -1,5 +1,5 @@ -#Sat Oct 06 17:21:25 CEST 2018 -Load-File-on-startup=true -key2=44 -key1=29 -Check-for-updates-on-startup=true +#Sun Apr 14 19:07:39 CEST 2019 +Load-File-on-startup=true +key2=44 +key1=29 +Check-for-updates-on-startup=true diff --git a/QuickLaunch/src/basics/BasicGuiApp.java b/QuickLaunch/src/basics/BasicGuiApp.java index 69919ab..a9dbfd5 100644 --- a/QuickLaunch/src/basics/BasicGuiApp.java +++ b/QuickLaunch/src/basics/BasicGuiApp.java @@ -29,7 +29,6 @@ public class BasicGuiApp extends Application{ public static Stage mainStage; public static Scene mainScene; public static KeyChecker listener; - public static Updater up = new Updater(); public BasicGuiApp(){ @@ -78,8 +77,13 @@ public class BasicGuiApp extends Application{ primaryStage.show(); if(SettingManager.isCheckUptdateOnBoot()){ - up.checkForUpdate(); - + new Thread(new Runnable() { + + public void run() { + Updater up = new Updater(); + up.checkForUpdate(); + } + }).start(); } } diff --git a/QuickLaunch/src/manager/ResourceManager.java b/QuickLaunch/src/manager/ResourceManager.java index aa49d1b..4f8fe13 100644 --- a/QuickLaunch/src/manager/ResourceManager.java +++ b/QuickLaunch/src/manager/ResourceManager.java @@ -23,20 +23,25 @@ public class ResourceManager { fontBig = Font.loadFont(ResourceManager.class.getResourceAsStream("/LiberationSerif-Regular.ttf"), 40); fontSmall = Font.loadFont(ResourceManager.class.getResourceAsStream("/LiberationSerif-Regular.ttf"), 17); - addImage = new ImageView(new Image(ResourceManager.class.getResourceAsStream("/plus.png"), 32, 32, true, false)); + addImage = loadIcon("/plus.png"); addImage.setFitWidth(32); addImage.setFitHeight(32); addImage.setPreserveRatio(true); - backImage = new ImageView(new Image(ResourceManager.class.getResourceAsStream("/back.png"), 32, 32 ,true, false)); - editImage = new ImageView(new Image(ResourceManager.class.getResourceAsStream("/edit.png"),32 ,32, true, false)); - lockImage = new ImageView(new Image(ResourceManager.class.getResourceAsStream("/lock.png"), 32, 32, true, false)); - saveImage = new ImageView(new Image(ResourceManager.class.getResourceAsStream("/save.png"), 32, 32 ,true, false)); - unsavedImage = new ImageView(new Image(ResourceManager.class.getResourceAsStream("/unsaved.png"), 32, 32, true, false)); + backImage = loadIcon("/back.png"); + editImage = loadIcon("/edit.png"); + lockImage = loadIcon("/lock.png"); + saveImage = loadIcon("/save.png"); + unsavedImage = loadIcon("/unsaved.png"); - trashImage = new ImageView(new Image(ResourceManager.class.getResourceAsStream("/trash.png"), 32, 32 ,true, false)); + trashImage = loadIcon("/trash.png"); } + + private static ImageView loadIcon(String path) { + return new ImageView(new Image(ResourceManager.class.getResourceAsStream(path), 32, 32,true , false)); + } + public static Font getFontBig() { return fontBig; } @@ -65,8 +70,6 @@ public class ResourceManager { return lockImage; } - - public static ImageView getSaveImage() { return saveImage; } diff --git a/QuickLaunch/src/manager/SettingManager.java b/QuickLaunch/src/manager/SettingManager.java index 613afc5..a2c3c63 100644 --- a/QuickLaunch/src/manager/SettingManager.java +++ b/QuickLaunch/src/manager/SettingManager.java @@ -21,13 +21,8 @@ public class SettingManager { private static int key1 = -1,key2 = -1; private static OperatingSystem currentOS = null; - private static String jarDirectory = ""; - - - - public SettingManager(){ if(System.getProperty("os.name").toLowerCase().contains("nux")){ currentOS = OperatingSystem.LINUX; @@ -57,10 +52,10 @@ public class SettingManager { try{ input = new FileInputStream(settingFile); prop.load(input); - loadFileOnBoot = Boolean.parseBoolean(prop.getProperty("Load-File-on-startup")); - checkUptdateOnBoot = Boolean.parseBoolean(prop.getProperty("Check-for-updates-on-startup")); - key1 = Integer.parseInt(prop.getProperty("key1")); - key2 = Integer.parseInt(prop.getProperty("key2")); + loadFileOnBoot = Boolean.parseBoolean(prop.getProperty("Load-File-on-startup", "true")); + checkUptdateOnBoot = Boolean.parseBoolean(prop.getProperty("Check-for-updates-on-startup", "true")); + key1 = Integer.parseInt(prop.getProperty("key1", "-1")); + key2 = Integer.parseInt(prop.getProperty("key2", "-1")); }catch (IOException e) { e.printStackTrace(); }finally{ diff --git a/QuickLaunch/src/mod_quicklaunch/QuickLaunch.java b/QuickLaunch/src/mod_quicklaunch/QuickLaunch.java index 1c9341a..cb7ae6b 100644 --- a/QuickLaunch/src/mod_quicklaunch/QuickLaunch.java +++ b/QuickLaunch/src/mod_quicklaunch/QuickLaunch.java @@ -17,6 +17,7 @@ import javafx.stage.StageStyle; import main.Start; import manager.SettingManager; import scenes.SettingScene; +import update.Updater; public class QuickLaunch extends BasicMod { @@ -94,7 +95,13 @@ public class QuickLaunch extends BasicMod { } private void checkForUpdates() { - BasicGuiApp.up.checkForUpdate(); + new Thread(new Runnable() { + + public void run() { + Updater up = new Updater(); + up.checkForUpdate(); + } + }).start(); } private void loadFile() throws IOException { diff --git a/QuickLaunch/src/update/UpdateChecker.java b/QuickLaunch/src/update/UpdateChecker.java index 5eee88b..b77b34f 100644 --- a/QuickLaunch/src/update/UpdateChecker.java +++ b/QuickLaunch/src/update/UpdateChecker.java @@ -6,81 +6,42 @@ import java.io.IOException; import java.net.InetAddress; import java.net.InetSocketAddress; import java.net.Socket; -import java.net.UnknownHostException; +import java.util.HashMap; public class UpdateChecker { - Socket socket; - DataInputStream in; - DataOutputStream out; - String ip; - int port; - float feedback = -1; - String linkToFile = ""; - public UpdateChecker(String ip, int port){ - this.ip = ip; - this.port = port; - try { - socket = new Socket(); - socket.connect(new InetSocketAddress(InetAddress.getByName("cookiestudios.org"), port), 700); - in = new DataInputStream(socket.getInputStream()); - out = new DataOutputStream(socket.getOutputStream()); - } catch (UnknownHostException e) { - e.printStackTrace(); - } catch (IOException e) { - e.printStackTrace(); - } - - - } + HashMap serverData = new HashMap<>(); - - public float getCurrentVersion(){ + public void requestServerData(){ try { + Socket socket = new Socket(); + socket.connect(new InetSocketAddress(InetAddress.getByName("cookiestudios.org"), 9999), 700); + DataInputStream in = new DataInputStream(socket.getInputStream()); + DataOutputStream out = new DataOutputStream(socket.getOutputStream()); - feedback = in.readFloat(); - out.writeUTF(System.getProperty("os.name")); - out.writeUTF(System.getProperty("os.version")); - out.writeUTF(System.getProperty("os.arch")); - out.writeUTF(System.getProperty("java.version")); + StringBuilder data = new StringBuilder(); + data.append(System.getProperty("os.name")).append(";"); + data.append(System.getProperty("os.version")).append(";"); + data.append(System.getProperty("os.arch")).append(";"); + data.append(System.getProperty("java.version")); - return feedback; - } catch (IOException e) { - e.printStackTrace(); - return feedback; + out.writeUTF(data.toString()); + String[] response = in.readUTF().split(";"); + for(String str: response) { + String[] keyValue = str.split("="); + serverData.put(keyValue[0], keyValue[1]); + } - } - } - - public String getDownloadLink(){ - try { - out.writeBoolean(true); - linkToFile = in.readUTF(); - } catch (IOException e) { - - e.printStackTrace(); - } - - return linkToFile; - - } - - public void upToDate() { - try { - out.writeBoolean(false); - } catch (IOException e) { - e.printStackTrace(); - } - } - - public void close(){ - try { - out.writeBoolean(false); - in.close(); - out.close(); socket.close(); } catch (IOException e) { - e.printStackTrace(); } } + + + public float getLatestVersion() { + if(serverData.containsKey("VERSION")) { + return Float.parseFloat(serverData.get("VERSION")); + } + return -1; + } } diff --git a/QuickLaunch/src/update/UpdateThread.java b/QuickLaunch/src/update/UpdateFileHandler.java similarity index 80% rename from QuickLaunch/src/update/UpdateThread.java rename to QuickLaunch/src/update/UpdateFileHandler.java index 456def7..0f0b1f2 100644 --- a/QuickLaunch/src/update/UpdateThread.java +++ b/QuickLaunch/src/update/UpdateFileHandler.java @@ -7,23 +7,22 @@ import java.nio.file.StandardCopyOption; import manager.SettingManager; -public class UpdateThread implements Runnable { +public class UpdateFileHandler { File sq; File qlN; File fMark; - public UpdateThread(){ + public UpdateFileHandler(){ sq = new File(SettingManager.getJarDirectory()+File.separator+"Squirrel.jar"); qlN = new File(SettingManager.getJarDirectory()+File.separator+"QuickLaunch.jar"); fMark = new File(SettingManager.getJarDirectory()+File.separator+"f.MARK"); } - public void run(){ + public void launch(){ try { Thread.sleep(2000); } catch (InterruptedException e) { - e.printStackTrace(); } if(sq.exists()){ @@ -34,17 +33,12 @@ public class UpdateThread implements Runnable { else{ try { Files.copy(sq.toPath(), qlN.toPath(),StandardCopyOption.REPLACE_EXISTING); - fMark.createNewFile(); - + fMark.createNewFile(); } catch (IOException e) { - e.printStackTrace(); } } - } - - } } diff --git a/QuickLaunch/src/update/Updater.java b/QuickLaunch/src/update/Updater.java index 3b9505a..51e23c9 100644 --- a/QuickLaunch/src/update/Updater.java +++ b/QuickLaunch/src/update/Updater.java @@ -1,10 +1,8 @@ package update; import java.io.File; -import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; -import java.net.MalformedURLException; import java.net.URL; import java.nio.channels.Channels; import java.nio.channels.ReadableByteChannel; @@ -18,66 +16,52 @@ import main.Start; import manager.SettingManager; public class Updater { - - Thread uT; public void checkForUpdate(){ - try{ - UpdateChecker uc = new UpdateChecker("cookiestudios.org", 9999); - float tmpversion = uc.getCurrentVersion(); - System.out.println("got version: " + tmpversion); - - if(tmpversion > Start.VERSION){ - String dl = uc.getDownloadLink(); - Alert updateAlert = new Alert(AlertType.INFORMATION, + UpdateChecker uc = new UpdateChecker(); + uc.requestServerData(); + System.out.println("got version: " + uc.getLatestVersion()); + if(uc.getLatestVersion() > Start.VERSION){ + String dl = "https://cookiestudios.org/software/QuickLaunch/QuickLaunch.jar"; + Alert updateAlert = new Alert(AlertType.INFORMATION, "There is a newer version of QuickLaunch available\nDownload now?", ButtonType.YES, ButtonType.NO); - updateAlert.setTitle("Update available!"); - Optional result = updateAlert.showAndWait(); - if(result.isPresent() && result.get() == ButtonType.YES){ - try { - System.out.println("here"); - cleanDirectory(); - URL website = new URL(dl); - ReadableByteChannel rbc = Channels.newChannel(website.openStream()); - FileOutputStream fos = new FileOutputStream(SettingManager.getJarDirectory()+File.separator+"Squirrel.jar"); - fos.getChannel().transferFrom(rbc, 0, Integer.MAX_VALUE); - fos.close(); - System.out.println("Done"); - try { - ProcessBuilder pb = new ProcessBuilder("java","-jar",SettingManager.getJarDirectory()+File.separator+"Squirrel.jar"); - pb.directory(new File(SettingManager.getJarDirectory())); - pb.redirectErrorStream(true); - pb.redirectOutput(ProcessBuilder.Redirect.INHERIT); - pb.start(); - - }catch(Exception e) { - e.printStackTrace(); - } - System.out.println("started newer version"); + updateAlert.setTitle("Update available!"); + Optional result = updateAlert.showAndWait(); + if(result.isPresent() && result.get() == ButtonType.YES){ + try { + System.out.println("here"); + cleanDirectory(); + URL website = new URL(dl); + ReadableByteChannel rbc = Channels.newChannel(website.openStream()); + FileOutputStream fos = new FileOutputStream(SettingManager.getJarDirectory()+File.separator+"Squirrel.jar"); + fos.getChannel().transferFrom(rbc, 0, Integer.MAX_VALUE); + fos.close(); + try { + ProcessBuilder pb = new ProcessBuilder("java","-jar",SettingManager.getJarDirectory()+File.separator+"Squirrel.jar"); + pb.directory(new File(SettingManager.getJarDirectory())); + pb.redirectErrorStream(true); + pb.redirectOutput(ProcessBuilder.Redirect.INHERIT); + pb.start(); + }catch(Exception e) { + e.printStackTrace(); + } System.exit(0); - } catch (MalformedURLException e) { - e.printStackTrace(); - MainGui.addNotification("Couldn´t reach update server", 2); - } catch (FileNotFoundException e) { - e.printStackTrace(); - MainGui.addNotification("Couldn´t reach update server", 2); - } catch (IOException e) { - e.printStackTrace(); - MainGui.addNotification("Couldn´t reach update server", 2); - } - } - } - else{ - uc.upToDate(); - MainGui.addNotification("QuickLaunch is up to date", 2); - uT = new Thread(new UpdateThread()); - uT.start(); - } - uc.close(); - }catch(Exception e){ - } + } catch (IOException e) { + e.printStackTrace(); + MainGui.addNotification("Couldn't download update", 2); + } + } + } else{ + if(uc.getLatestVersion() == Start.VERSION){ + MainGui.addNotification("QuickLaunch is up to date", 2); + } + else { + MainGui.addNotification("Update server unavailable", 2); + } + new UpdateFileHandler().launch(); + } } private void cleanDirectory(){