Initial git commit

This commit is contained in:
2019-04-14 12:18:58 +02:00
commit e1c1b51c90
113 changed files with 2646 additions and 0 deletions

View File

@@ -0,0 +1,88 @@
package update;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.Socket;
import java.net.UnknownHostException;
import guis.MainGui;
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();
}
}
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();
} catch (IOException e) {
e.printStackTrace();
}
}
}

View File

@@ -0,0 +1,50 @@
package update;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.StandardCopyOption;
import manager.SettingManager;
public class UpdateThread implements Runnable {
File sq;
File qlN;
File fMark;
public UpdateThread(){
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(){
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
e.printStackTrace();
}
if(sq.exists()){
if(fMark.exists()){
sq.delete();
fMark.delete();
}
else{
try {
Files.copy(sq.toPath(), qlN.toPath(),StandardCopyOption.REPLACE_EXISTING);
fMark.createNewFile();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
}

View File

@@ -0,0 +1,94 @@
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;
import java.util.Optional;
import guis.MainGui;
import javafx.scene.control.Alert;
import javafx.scene.control.Alert.AlertType;
import javafx.scene.control.ButtonType;
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,
"There is a newer version of QuickLaunch available\nDownload now?",
ButtonType.YES,
ButtonType.NO);
updateAlert.setTitle("Update available!");
Optional<ButtonType> 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");
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){
}
}
private void cleanDirectory(){
File squirrel = new File(SettingManager.getJarDirectory()+File.separator+"Squirrel.jar");
if(squirrel.exists()){
squirrel.delete();
}
File fMark = new File(SettingManager.getJarDirectory()+File.separator+"f.MARK");
if(fMark.exists()){
fMark.delete();
}
}
}