added auto updater

This commit is contained in:
Niklas 2020-03-30 02:46:25 +02:00
parent c4fbe48055
commit e7501013fc
11 changed files with 1208 additions and 24 deletions

View File

@ -2053,7 +2053,7 @@
<properties/> <properties/>
<border type="none"/> <border type="none"/>
<children> <children>
<grid id="98919" layout-manager="GridLayoutManager" row-count="3" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1"> <grid id="98919" layout-manager="GridLayoutManager" row-count="4" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/> <margin top="0" left="0" bottom="0" right="0"/>
<constraints> <constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/> <grid row="0" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
@ -2083,7 +2083,7 @@
<grid id="80ce0" layout-manager="GridLayoutManager" row-count="2" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1"> <grid id="80ce0" layout-manager="GridLayoutManager" row-count="2" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/> <margin top="0" left="0" bottom="0" right="0"/>
<constraints> <constraints>
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/> <grid row="3" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints> </constraints>
<properties/> <properties/>
<border type="none"/> <border type="none"/>
@ -2123,6 +2123,14 @@
</component> </component>
</children> </children>
</grid> </grid>
<component id="3ba42" class="javax.swing.JButton" binding="updateButton">
<constraints>
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text resource-bundle="lang" key="update_now"/>
</properties>
</component>
</children> </children>
</grid> </grid>
<grid id="e5ad4" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1"> <grid id="e5ad4" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">

File diff suppressed because it is too large Load Diff

View File

@ -2,6 +2,7 @@ package de.mc8051.arma3launcher.objects;
import de.mc8051.arma3launcher.ArmA3Launcher; import de.mc8051.arma3launcher.ArmA3Launcher;
import de.mc8051.arma3launcher.utils.FileUtils; import de.mc8051.arma3launcher.utils.FileUtils;
import de.mc8051.arma3launcher.utils.URLUtils;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
@ -105,12 +106,12 @@ public class ModFile implements AbstractMod {
public String getRemoteFile() { public String getRemoteFile() {
String s = ArmA3Launcher.config.getString("sync.url"); String s = ArmA3Launcher.config.getString("sync.url");
if (parent == null || parent.isEmpty()) { if (parent == null || parent.isEmpty()) {
return s + "/" + encodeToURL(getName()); return s + "/" + URLUtils.encodeToURL(getName());
} }
s += "/" + encodeToURL(parent); s += "/" + URLUtils.encodeToURL(parent);
for (String seg : getPath()) { for (String seg : getPath()) {
s += "/" + encodeToURL(seg); s += "/" + URLUtils.encodeToURL(seg);
} }
return s; return s;
} }
@ -118,13 +119,4 @@ public class ModFile implements AbstractMod {
public String getParent() { public String getParent() {
return parent; return parent;
} }
private String encodeToURL(String s) {
try {
return URLEncoder.encode(s, StandardCharsets.UTF_8.name()).replace("+", "%20").replace("@", "%40");
} catch (UnsupportedEncodingException e) {
Logger.getLogger(getClass().getName()).log(Level.SEVERE, null, e);
}
return "";
}
} }

View File

@ -2,16 +2,75 @@ package de.mc8051.arma3launcher.repo;
import de.mc8051.arma3launcher.ArmA3Launcher; import de.mc8051.arma3launcher.ArmA3Launcher;
import de.mc8051.arma3launcher.utils.Callback; import de.mc8051.arma3launcher.utils.Callback;
import de.mc8051.arma3launcher.utils.URLUtils;
import java.io.File;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardCopyOption;
import java.util.logging.Level;
import java.util.logging.Logger;
/** /**
* Created by gurkengewuerz.de on 29.03.2020. * Created by gurkengewuerz.de on 29.03.2020.
*/ */
public class Updater { public class Updater {
private boolean canPatch = false; private File patcherFile = new File(ArmA3Launcher.APPLICATION_PATH + File.separator + "patcher.jar");
private File me;
private long lastCheck = 0;
private Version newestVersion = null;
private String newFile = "";
public void update() { public Updater() {
try {
me = new File(Updater.class.getProtectionDomain().getCodeSource().getLocation().toURI());
} catch (URISyntaxException ignored) {}
}
public void update() throws IOException {
if (!me.exists() || !me.isFile()) throw new IOException("Own jar not exists. Are you running in dev?");
if (!patcherFile.exists()) throw new IOException("Patcher does not exists");
Runtime.getRuntime().exec(
"\"" + System.getProperty("java.home") + File.separator + "bin" + File.separator + "java\"" +
" -jar \"" + patcherFile.getAbsolutePath() + "\"" +
" \"" + ArmA3Launcher.config.getString("sync.url") + "/.sync/" + URLUtils.encodeToURL(newFile) + "\"" +
" \"" + me.getAbsolutePath() + "\""
);
}
public void downloadPatcher() {
if(patcherFile.exists()) {
Logger.getLogger(getClass().getName()).log(Level.INFO, "Patcher already exists. Skip.");
return;
}
try {
HttpClient client = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder()
.uri(new URI(ArmA3Launcher.config.getString("sync.url") + "/.sync/patcher.jar"))
.GET()
.build();
Path tempFile = Files.createTempFile("patcher", "jar");
client.sendAsync(request, HttpResponse.BodyHandlers.ofFile(tempFile)).thenAccept((r) -> {
if (r.statusCode() != 200) return;
try {
Files.copy(tempFile, patcherFile.toPath(), StandardCopyOption.REPLACE_EXISTING);
Logger.getLogger(getClass().getName()).log(Level.INFO, "Patcher copied to " + patcherFile.getAbsolutePath());
} catch (IOException e) {
Logger.getLogger(getClass().getName()).log(Level.SEVERE, "Copy patcher failed", e);
}
});
} catch (IOException | URISyntaxException e) {
Logger.getLogger(getClass().getName()).log(Level.SEVERE, null, e);
}
} }
public void getNewestVersion(Callback.HttpCallback callback) { public void getNewestVersion(Callback.HttpCallback callback) {
@ -20,13 +79,26 @@ public class Updater {
public void needUpdate(Callback.NeedUpdateCallback callback) { public void needUpdate(Callback.NeedUpdateCallback callback) {
final Version currentVersion = new Version(ArmA3Launcher.VERSION); final Version currentVersion = new Version(ArmA3Launcher.VERSION);
if(lastCheck != 0 && System.currentTimeMillis() - lastCheck < 2 * 60 * 1000) {
callback.response(currentVersion.compareTo(newestVersion) < 0, newestVersion);
lastCheck = System.currentTimeMillis();
return;
}
getNewestVersion(new Callback.HttpCallback() { getNewestVersion(new Callback.HttpCallback() {
@Override @Override
public void response(Response r) { public void response(Response r) {
if (!r.isSuccessful()) callback.response(false, null); if (!r.isSuccessful()) callback.response(false, null);
final String[] split = r.getBody().split(":"); final String[] split = r.getBody().split(":");
final Version newestVersion = new Version(r.getBody().split(":")[0]); newestVersion = new Version(split[0]);
callback.response((currentVersion.compareTo(newestVersion) < 0), newestVersion); newFile = split[1].replace("\n", "").replace("\r","").trim();
final boolean needUpdate = currentVersion.compareTo(newestVersion) < 0;
if(needUpdate) downloadPatcher();
lastCheck = System.currentTimeMillis();
callback.response(needUpdate, newestVersion);
} }
}); });
} }

View File

@ -0,0 +1,22 @@
package de.mc8051.arma3launcher.utils;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
* Created by gurkengewuerz.de on 29.03.2020.
*/
public class URLUtils {
public static String encodeToURL(String s) {
try {
return URLEncoder.encode(s, StandardCharsets.UTF_8.name()).replace("+", "%20").replace("@", "%40");
} catch (UnsupportedEncodingException e) {
Logger.getLogger(URLUtils.class.getName()).log(Level.SEVERE, null, e);
}
return "";
}
}

View File

@ -101,7 +101,7 @@ follow_on_twitter=Folgt und auf Twitter
star_on_github="Star us" auf GitHub star_on_github="Star us" auf GitHub
client_up_to_date=Client ist aktuell client_up_to_date=Client ist aktuell
client_outdated=Neue Client Version verfügbar client_outdated=Neue Client Version verfügbar
please_update=Bitte führe ein Update durch please_update=Bitte führe ein Update durch. Gehe in den Tab "Über" und führe das Update durch.
developer_page=Entwickler-Seite developer_page=Entwickler-Seite
project_page=Projektseite project_page=Projektseite
fast_check=Schnelle Prüfung fast_check=Schnelle Prüfung
@ -112,3 +112,4 @@ clone_preset=Vorlage klonen
new_modset_name=Modsset Name new_modset_name=Modsset Name
modset_exists_msg=Bitte wähle ein anderen Namen für deine Vorlage. modset_exists_msg=Bitte wähle ein anderen Namen für deine Vorlage.
modset_exists=Preset mit diesen Namen existiert bereits modset_exists=Preset mit diesen Namen existiert bereits
update_now=Jetzt updaten!

View File

@ -99,7 +99,7 @@ follow_on_twitter=Follow us on Twitter
star_on_github=Star us on GitHub star_on_github=Star us on GitHub
client_up_to_date=Client is up to date client_up_to_date=Client is up to date
client_outdated=New client version available client_outdated=New client version available
please_update=Please do an update please_update=Please do an update. Go to the Tab "About" and run the update.
developer_page=Developer page developer_page=Developer page
project_page=Project page project_page=Project page
new_modset_name=Modsset name new_modset_name=Modsset name

View File

0
linux/.sync/patcher.jar Normal file
View File

1
linux/.sync/version.txt Normal file
View File

@ -0,0 +1 @@
0.1.1000:arma3launcher.jar

View File

@ -25,6 +25,7 @@
package de.mc8051.arma3launcher; package de.mc8051.arma3launcher;
import javax.swing.*; import javax.swing.*;
import java.awt.*;
/** /**
* Created by gurkengewuerz.de on 29.03.2020. * Created by gurkengewuerz.de on 29.03.2020.
@ -32,4 +33,59 @@ import javax.swing.*;
public class Patcher { public class Patcher {
public JPanel mainpanel; public JPanel mainpanel;
public JProgressBar progressBar1; public JProgressBar progressBar1;
{
// GUI initializer generated by IntelliJ IDEA GUI Designer
// >>> IMPORTANT!! <<<
// DO NOT EDIT OR ADD ANY CODE HERE!
$$$setupUI$$$();
}
/**
* Method generated by IntelliJ IDEA GUI Designer
* >>> IMPORTANT!! <<<
* DO NOT edit this method OR call it in your code!
*
* @noinspection ALL
*/
private void $$$setupUI$$$() {
mainpanel = new JPanel();
mainpanel.setLayout(new BorderLayout(0, 0));
progressBar1 = new JProgressBar();
progressBar1.setMinimumSize(new Dimension(10, 4));
progressBar1.setString("");
progressBar1.setValue(0);
mainpanel.add(progressBar1, BorderLayout.CENTER);
final JLabel label1 = new JLabel();
Font label1Font = this.$$$getFont$$$(null, Font.BOLD, 16, label1.getFont());
if (label1Font != null) label1.setFont(label1Font);
label1.setText("Launcher Updater");
mainpanel.add(label1, BorderLayout.NORTH);
}
/**
* @noinspection ALL
*/
private Font $$$getFont$$$(String fontName, int style, int size, Font currentFont) {
if (currentFont == null) return null;
String resultName;
if (fontName == null) {
resultName = currentFont.getName();
} else {
Font testFont = new Font(fontName, Font.PLAIN, 10);
if (testFont.canDisplay('a') && testFont.canDisplay('1')) {
resultName = fontName;
} else {
resultName = currentFont.getName();
}
}
return new Font(resultName, style >= 0 ? style : currentFont.getStyle(), size >= 0 ? size : currentFont.getSize());
}
/**
* @noinspection ALL
*/
public JComponent $$$getRootComponent$$$() {
return mainpanel;
}
} }