Quicklaunch/QuickLaunch/src/update/UpdateChecker.java

87 lines
1.8 KiB
Java
Raw Normal View History

2019-04-14 10:18:58 +00:00
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;
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();
}
}
}