Changed Server to new protocol on port 9999 with only one String based

communication exchange
This commit is contained in:
ChococookieOS 2019-04-15 11:14:06 +02:00
parent 141374eee3
commit c4ed32689d
14 changed files with 36 additions and 48 deletions

Binary file not shown.

View File

@ -1,4 +1,4 @@
#Sun Apr 14 19:07:39 CEST 2019
#Mon Apr 15 11:05:55 CEST 2019
Load-File-on-startup=true
key2=44
key1=29

View File

@ -31,7 +31,6 @@ public class BasicGuiApp extends Application{
public static KeyChecker listener;
public BasicGuiApp(){
ModLoader ml = new ModLoader();
ml.init();
ml.addMods();
@ -45,7 +44,6 @@ public class BasicGuiApp extends Application{
}
listener = new KeyChecker();
LogManager.getLogManager().reset();
Logger logger = Logger.getLogger(GlobalScreen.class.getPackage().getName());
logger.setLevel(Level.OFF);
GlobalScreen.addNativeKeyListener(listener);

View File

@ -14,7 +14,7 @@ public class UpdateChecker {
public void requestServerData(){
try {
Socket socket = new Socket();
socket.connect(new InetSocketAddress(InetAddress.getByName("cookiestudios.org"), 9999), 700);
socket.connect(new InetSocketAddress(InetAddress.getByName("cookiestudios.org"), 9999), 2000);
DataInputStream in = new DataInputStream(socket.getInputStream());
DataOutputStream out = new DataOutputStream(socket.getOutputStream());
@ -30,7 +30,6 @@ public class UpdateChecker {
String[] keyValue = str.split("=");
serverData.put(keyValue[0], keyValue[1]);
}
socket.close();
} catch (IOException e) {
e.printStackTrace();

View File

@ -9,6 +9,7 @@ import java.nio.channels.ReadableByteChannel;
import java.util.Optional;
import guis.MainGui;
import javafx.application.Platform;
import javafx.scene.control.Alert;
import javafx.scene.control.Alert.AlertType;
import javafx.scene.control.ButtonType;
@ -22,37 +23,42 @@ public class Updater {
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,
Platform.runLater(new Runnable() {
@Override
public void run() {
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<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();
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();
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();
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 (IOException e) {
e.printStackTrace();
MainGui.addNotification("Couldn't download update", 2);
}
}
System.exit(0);
} 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);

View File

@ -15,7 +15,6 @@ implements Runnable {
this.PORT = port;
}
boolean updateNeeded = true;
ServerSocket ses;
Socket s;
DataOutputStream out;
@ -25,25 +24,14 @@ implements Runnable {
do {
try {
do {
updateNeeded = true;
ses = new ServerSocket(this.PORT);
s = ses.accept();
System.out.println("Connected with: " + s.getInetAddress());
out = new DataOutputStream(s.getOutputStream());
in = new DataInputStream(s.getInputStream());
out.writeFloat(Start.version);
System.out.println(in.readUTF());
out.writeUTF("VERSION="+Start.version);
System.out.println(in.readUTF());
System.out.println(in.readUTF());
System.out.println(in.readUTF());
System.out.println(in.readUTF());
updateNeeded = in.readBoolean();
if (updateNeeded) {
System.out.println("Update needed, Download link was send");
out.writeUTF(Start.download);
}
out.close();
in.close();
s.close();

View File

@ -6,7 +6,6 @@ import run.UpdateThread;
public class Start {
public static float version = -1.0f;
public static String download = "";
private static final int PORT = 9999;
@ -14,7 +13,6 @@ public class Start {
public static void main(String[] args) {
version = Float.parseFloat(JOptionPane.showInputDialog("QuickLaunch version:"));
download = JOptionPane.showInputDialog("Link to downloadable");
Thread ut = new Thread(new UpdateThread());
ut.start();
System.out.println("Update thread started");

View File

@ -9,7 +9,6 @@ implements Runnable {
public void run() {
do {
Start.version = Float.parseFloat(JOptionPane.showInputDialog("QuickLaunch version (" + Start.version + "): "));
Start.download = JOptionPane.showInputDialog("Link to downloadable:");
} while (true);
}
}