Simplified and changed updated process to be more versatile and flexible

This commit is contained in:
ChococookieOS 2019-04-15 10:20:43 +02:00
parent 3c9ef9c987
commit 141374eee3
17 changed files with 106 additions and 158 deletions

Binary file not shown.

Binary file not shown.

View File

@ -1,4 +1,4 @@
#Sat Oct 06 17:21:25 CEST 2018 #Sun Apr 14 19:07:39 CEST 2019
Load-File-on-startup=true Load-File-on-startup=true
key2=44 key2=44
key1=29 key1=29

View File

@ -29,7 +29,6 @@ public class BasicGuiApp extends Application{
public static Stage mainStage; public static Stage mainStage;
public static Scene mainScene; public static Scene mainScene;
public static KeyChecker listener; public static KeyChecker listener;
public static Updater up = new Updater();
public BasicGuiApp(){ public BasicGuiApp(){
@ -78,8 +77,13 @@ public class BasicGuiApp extends Application{
primaryStage.show(); primaryStage.show();
if(SettingManager.isCheckUptdateOnBoot()){ if(SettingManager.isCheckUptdateOnBoot()){
new Thread(new Runnable() {
public void run() {
Updater up = new Updater();
up.checkForUpdate(); up.checkForUpdate();
}
}).start();
} }
} }

View File

@ -23,18 +23,23 @@ public class ResourceManager {
fontBig = Font.loadFont(ResourceManager.class.getResourceAsStream("/LiberationSerif-Regular.ttf"), 40); fontBig = Font.loadFont(ResourceManager.class.getResourceAsStream("/LiberationSerif-Regular.ttf"), 40);
fontSmall = Font.loadFont(ResourceManager.class.getResourceAsStream("/LiberationSerif-Regular.ttf"), 17); 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.setFitWidth(32);
addImage.setFitHeight(32); addImage.setFitHeight(32);
addImage.setPreserveRatio(true); addImage.setPreserveRatio(true);
backImage = new ImageView(new Image(ResourceManager.class.getResourceAsStream("/back.png"), 32, 32 ,true, false)); backImage = loadIcon("/back.png");
editImage = new ImageView(new Image(ResourceManager.class.getResourceAsStream("/edit.png"),32 ,32, true, false)); editImage = loadIcon("/edit.png");
lockImage = new ImageView(new Image(ResourceManager.class.getResourceAsStream("/lock.png"), 32, 32, true, false)); lockImage = loadIcon("/lock.png");
saveImage = new ImageView(new Image(ResourceManager.class.getResourceAsStream("/save.png"), 32, 32 ,true, false)); saveImage = loadIcon("/save.png");
unsavedImage = new ImageView(new Image(ResourceManager.class.getResourceAsStream("/unsaved.png"), 32, 32, true, false)); 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() { public static Font getFontBig() {
@ -65,8 +70,6 @@ public class ResourceManager {
return lockImage; return lockImage;
} }
public static ImageView getSaveImage() { public static ImageView getSaveImage() {
return saveImage; return saveImage;
} }

View File

@ -21,13 +21,8 @@ public class SettingManager {
private static int key1 = -1,key2 = -1; private static int key1 = -1,key2 = -1;
private static OperatingSystem currentOS = null; private static OperatingSystem currentOS = null;
private static String jarDirectory = ""; private static String jarDirectory = "";
public SettingManager(){ public SettingManager(){
if(System.getProperty("os.name").toLowerCase().contains("nux")){ if(System.getProperty("os.name").toLowerCase().contains("nux")){
currentOS = OperatingSystem.LINUX; currentOS = OperatingSystem.LINUX;
@ -57,10 +52,10 @@ public class SettingManager {
try{ try{
input = new FileInputStream(settingFile); input = new FileInputStream(settingFile);
prop.load(input); prop.load(input);
loadFileOnBoot = Boolean.parseBoolean(prop.getProperty("Load-File-on-startup")); loadFileOnBoot = Boolean.parseBoolean(prop.getProperty("Load-File-on-startup", "true"));
checkUptdateOnBoot = Boolean.parseBoolean(prop.getProperty("Check-for-updates-on-startup")); checkUptdateOnBoot = Boolean.parseBoolean(prop.getProperty("Check-for-updates-on-startup", "true"));
key1 = Integer.parseInt(prop.getProperty("key1")); key1 = Integer.parseInt(prop.getProperty("key1", "-1"));
key2 = Integer.parseInt(prop.getProperty("key2")); key2 = Integer.parseInt(prop.getProperty("key2", "-1"));
}catch (IOException e) { }catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
}finally{ }finally{

View File

@ -17,6 +17,7 @@ import javafx.stage.StageStyle;
import main.Start; import main.Start;
import manager.SettingManager; import manager.SettingManager;
import scenes.SettingScene; import scenes.SettingScene;
import update.Updater;
public class QuickLaunch extends BasicMod { public class QuickLaunch extends BasicMod {
@ -94,7 +95,13 @@ public class QuickLaunch extends BasicMod {
} }
private void checkForUpdates() { 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 { private void loadFile() throws IOException {

View File

@ -6,81 +6,42 @@ import java.io.IOException;
import java.net.InetAddress; import java.net.InetAddress;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
import java.net.Socket; import java.net.Socket;
import java.net.UnknownHostException; import java.util.HashMap;
public class UpdateChecker { public class UpdateChecker {
Socket socket; HashMap<String, String> serverData = new HashMap<>();
DataInputStream in;
DataOutputStream out; public void requestServerData(){
String ip;
int port;
float feedback = -1;
String linkToFile = "";
public UpdateChecker(String ip, int port){
this.ip = ip;
this.port = port;
try { try {
socket = new Socket(); Socket socket = new Socket();
socket.connect(new InetSocketAddress(InetAddress.getByName("cookiestudios.org"), port), 700); socket.connect(new InetSocketAddress(InetAddress.getByName("cookiestudios.org"), 9999), 700);
in = new DataInputStream(socket.getInputStream()); DataInputStream in = new DataInputStream(socket.getInputStream());
out = new DataOutputStream(socket.getOutputStream()); DataOutputStream out = new DataOutputStream(socket.getOutputStream());
} catch (UnknownHostException e) {
e.printStackTrace(); StringBuilder data = new StringBuilder();
} catch (IOException e) { data.append(System.getProperty("os.name")).append(";");
e.printStackTrace(); data.append(System.getProperty("os.version")).append(";");
data.append(System.getProperty("os.arch")).append(";");
data.append(System.getProperty("java.version"));
out.writeUTF(data.toString());
String[] response = in.readUTF().split(";");
for(String str: response) {
String[] keyValue = str.split("=");
serverData.put(keyValue[0], keyValue[1]);
} }
}
public float getCurrentVersion(){
try {
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"));
return feedback;
} catch (IOException e) {
e.printStackTrace();
return feedback;
}
}
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(); socket.close();
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }
} }
public float getLatestVersion() {
if(serverData.containsKey("VERSION")) {
return Float.parseFloat(serverData.get("VERSION"));
}
return -1;
}
} }

View File

@ -7,23 +7,22 @@ import java.nio.file.StandardCopyOption;
import manager.SettingManager; import manager.SettingManager;
public class UpdateThread implements Runnable { public class UpdateFileHandler {
File sq; File sq;
File qlN; File qlN;
File fMark; File fMark;
public UpdateThread(){ public UpdateFileHandler(){
sq = new File(SettingManager.getJarDirectory()+File.separator+"Squirrel.jar"); sq = new File(SettingManager.getJarDirectory()+File.separator+"Squirrel.jar");
qlN = new File(SettingManager.getJarDirectory()+File.separator+"QuickLaunch.jar"); qlN = new File(SettingManager.getJarDirectory()+File.separator+"QuickLaunch.jar");
fMark = new File(SettingManager.getJarDirectory()+File.separator+"f.MARK"); fMark = new File(SettingManager.getJarDirectory()+File.separator+"f.MARK");
} }
public void run(){ public void launch(){
try { try {
Thread.sleep(2000); Thread.sleep(2000);
} catch (InterruptedException e) { } catch (InterruptedException e) {
e.printStackTrace(); e.printStackTrace();
} }
if(sq.exists()){ if(sq.exists()){
@ -35,16 +34,11 @@ public class UpdateThread implements Runnable {
try { try {
Files.copy(sq.toPath(), qlN.toPath(),StandardCopyOption.REPLACE_EXISTING); Files.copy(sq.toPath(), qlN.toPath(),StandardCopyOption.REPLACE_EXISTING);
fMark.createNewFile(); fMark.createNewFile();
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }
} }
} }
} }
} }

View File

@ -1,10 +1,8 @@
package update; package update;
import java.io.File; import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL; import java.net.URL;
import java.nio.channels.Channels; import java.nio.channels.Channels;
import java.nio.channels.ReadableByteChannel; import java.nio.channels.ReadableByteChannel;
@ -19,16 +17,12 @@ import manager.SettingManager;
public class Updater { public class Updater {
Thread uT;
public void checkForUpdate(){ public void checkForUpdate(){
try{ UpdateChecker uc = new UpdateChecker();
UpdateChecker uc = new UpdateChecker("cookiestudios.org", 9999); uc.requestServerData();
float tmpversion = uc.getCurrentVersion(); System.out.println("got version: " + uc.getLatestVersion());
System.out.println("got version: " + tmpversion); if(uc.getLatestVersion() > Start.VERSION){
String dl = "https://cookiestudios.org/software/QuickLaunch/QuickLaunch.jar";
if(tmpversion > Start.VERSION){
String dl = uc.getDownloadLink();
Alert updateAlert = new Alert(AlertType.INFORMATION, Alert updateAlert = new Alert(AlertType.INFORMATION,
"There is a newer version of QuickLaunch available\nDownload now?", "There is a newer version of QuickLaunch available\nDownload now?",
ButtonType.YES, ButtonType.YES,
@ -44,39 +38,29 @@ public class Updater {
FileOutputStream fos = new FileOutputStream(SettingManager.getJarDirectory()+File.separator+"Squirrel.jar"); FileOutputStream fos = new FileOutputStream(SettingManager.getJarDirectory()+File.separator+"Squirrel.jar");
fos.getChannel().transferFrom(rbc, 0, Integer.MAX_VALUE); fos.getChannel().transferFrom(rbc, 0, Integer.MAX_VALUE);
fos.close(); fos.close();
System.out.println("Done");
try { try {
ProcessBuilder pb = new ProcessBuilder("java","-jar",SettingManager.getJarDirectory()+File.separator+"Squirrel.jar"); ProcessBuilder pb = new ProcessBuilder("java","-jar",SettingManager.getJarDirectory()+File.separator+"Squirrel.jar");
pb.directory(new File(SettingManager.getJarDirectory())); pb.directory(new File(SettingManager.getJarDirectory()));
pb.redirectErrorStream(true); pb.redirectErrorStream(true);
pb.redirectOutput(ProcessBuilder.Redirect.INHERIT); pb.redirectOutput(ProcessBuilder.Redirect.INHERIT);
pb.start(); pb.start();
}catch(Exception e) { }catch(Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
System.out.println("started newer version");
System.exit(0); 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) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
MainGui.addNotification("Couldn´t reach update server", 2); MainGui.addNotification("Couldn't download update", 2);
} }
} }
} else{
if(uc.getLatestVersion() == Start.VERSION){
MainGui.addNotification("QuickLaunch is up to date", 2);
} }
else { else {
uc.upToDate(); MainGui.addNotification("Update server unavailable", 2);
MainGui.addNotification("QuickLaunch is up to date", 2);
uT = new Thread(new UpdateThread());
uT.start();
} }
uc.close(); new UpdateFileHandler().launch();
}catch(Exception e){
} }
} }