Add automatic updater with config option
This commit is contained in:
parent
42d168ca21
commit
a19e8c8533
@ -5,7 +5,7 @@ plugins {
|
|||||||
}
|
}
|
||||||
|
|
||||||
group 'tech.nevets.jaml'
|
group 'tech.nevets.jaml'
|
||||||
version '0.8.0'
|
version '0.8.1'
|
||||||
def build = 'dev'
|
def build = 'dev'
|
||||||
|
|
||||||
repositories {
|
repositories {
|
||||||
|
@ -42,6 +42,7 @@ Name: "desktopicon"; Description: "{cm:CreateDesktopIcon}"; GroupDescription: "{
|
|||||||
[Files]
|
[Files]
|
||||||
Source: "./build/launch4j/{#MyAppExeName}"; DestDir: "{app}"; Flags: ignoreversion
|
Source: "./build/launch4j/{#MyAppExeName}"; DestDir: "{app}"; Flags: ignoreversion
|
||||||
Source: "./jre/*"; DestDir: "{app}"; Flags: ignoreversion recursesubdirs createallsubdirs
|
Source: "./jre/*"; DestDir: "{app}"; Flags: ignoreversion recursesubdirs createallsubdirs
|
||||||
|
Source: "./JAML-Updater.jar"; Flags: ignoreversion
|
||||||
; NOTE: Don't use "Flags: ignoreversion" on any shared system files
|
; NOTE: Don't use "Flags: ignoreversion" on any shared system files
|
||||||
|
|
||||||
[Registry]
|
[Registry]
|
||||||
|
@ -1,4 +1,29 @@
|
|||||||
package tech.nevets.jaml;
|
package tech.nevets.jaml;
|
||||||
|
|
||||||
|
import com.google.gson.Gson;
|
||||||
|
import com.google.gson.JsonElement;
|
||||||
|
import tech.nevets.jaml.gui.StartupGui;
|
||||||
|
import tech.nevets.jaml.util.HttpUtils;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.net.URI;
|
||||||
|
import java.net.URISyntaxException;
|
||||||
|
import java.util.HashMap;
|
||||||
|
|
||||||
public class AutoUpdater {
|
public class AutoUpdater {
|
||||||
|
|
||||||
|
public static void checkForUpdate() {
|
||||||
|
try {
|
||||||
|
String version = HttpUtils.get(new URI("https://api.nevets.tech/jaml/version.json"), new HashMap<>());
|
||||||
|
JsonElement versionJson = new Gson().fromJson(version, JsonElement.class);
|
||||||
|
|
||||||
|
if (versionJson.getAsJsonObject().get("version").toString().replace("\"", "").equalsIgnoreCase(Config.CONFIG.getString("launcher.version"))) {
|
||||||
|
String command = JAML.path + "\\jre\\bin\\javaw.exe -jar " + JAML.path + "\\JAML-Updater.jar";
|
||||||
|
Runtime.getRuntime().exec(command);
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (URISyntaxException | IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -57,6 +57,8 @@ public class Config {
|
|||||||
YML_FILE.setComment("launcher.keep-open", "Keeps the launcher open after launching the game");
|
YML_FILE.setComment("launcher.keep-open", "Keeps the launcher open after launching the game");
|
||||||
YML_FILE.addDefault("launcher.first-launch", true);
|
YML_FILE.addDefault("launcher.first-launch", true);
|
||||||
YML_FILE.setComment("launcher.first-launch", "Do Not Change, will regenerate files");
|
YML_FILE.setComment("launcher.first-launch", "Do Not Change, will regenerate files");
|
||||||
|
YML_FILE.addDefault("launcher.auto-update", true);
|
||||||
|
YML_FILE.setComment("launcher.auto-update", "Enables a simple automatic updates system.");
|
||||||
YML_FILE.addDefault("launcher.verbose", false);
|
YML_FILE.addDefault("launcher.verbose", false);
|
||||||
YML_FILE.setComment("launcher.verbose", "If true, will print out all the messages");
|
YML_FILE.setComment("launcher.verbose", "If true, will print out all the messages");
|
||||||
YML_FILE.addDefault("launcher.version", JAML.VERSION);
|
YML_FILE.addDefault("launcher.version", JAML.VERSION);
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package tech.nevets.jaml.gui;
|
package tech.nevets.jaml.gui;
|
||||||
|
|
||||||
|
import tech.nevets.jaml.AutoUpdater;
|
||||||
import tech.nevets.jaml.Config;
|
import tech.nevets.jaml.Config;
|
||||||
import tech.nevets.jaml.JAML;
|
import tech.nevets.jaml.JAML;
|
||||||
import tech.nevets.jaml.gui.panels.CustomProgressBarPanel;
|
import tech.nevets.jaml.gui.panels.CustomProgressBarPanel;
|
||||||
@ -10,14 +11,13 @@ import tech.nevets.jaml.util.VersionUtils;
|
|||||||
|
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
import javax.swing.border.EmptyBorder;
|
import javax.swing.border.EmptyBorder;
|
||||||
import java.io.IOException;
|
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
|
|
||||||
public class StartupGui extends JFrame {
|
public class StartupGui extends JFrame {
|
||||||
JPanel contentPane;
|
JPanel contentPane;
|
||||||
private static JLabel currentTaskLabel;
|
private static JLabel currentTaskLabel;
|
||||||
private static CustomProgressBarPanel progressBar;
|
private static CustomProgressBarPanel progressBar;
|
||||||
private static final int TASKS = 7;
|
private static final int TASKS = 8;
|
||||||
private static int task = 0;
|
private static int task = 0;
|
||||||
|
|
||||||
public StartupGui() {
|
public StartupGui() {
|
||||||
@ -73,6 +73,13 @@ public class StartupGui extends JFrame {
|
|||||||
Config.loadConfig();
|
Config.loadConfig();
|
||||||
smoothIncrease();
|
smoothIncrease();
|
||||||
|
|
||||||
|
task++;
|
||||||
|
if (Config.CONFIG.getBoolean("launcher.auto-update")) {
|
||||||
|
currentTaskLabel.setText("Checking for updates...");
|
||||||
|
AutoUpdater.checkForUpdate();
|
||||||
|
}
|
||||||
|
smoothIncrease();
|
||||||
|
|
||||||
currentTaskLabel.setText("Downloading Version List...");
|
currentTaskLabel.setText("Downloading Version List...");
|
||||||
task++;
|
task++;
|
||||||
VersionUtils.downloadList();
|
VersionUtils.downloadList();
|
||||||
@ -115,7 +122,7 @@ public class StartupGui extends JFrame {
|
|||||||
currentTaskLabel.setText(currentTask);
|
currentTaskLabel.setText(currentTask);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void makeDirs() {
|
public static void makeDirs() {
|
||||||
if (System.getenv("JAML_HOME") == null) {
|
if (System.getenv("JAML_HOME") == null) {
|
||||||
JAML.path = Path.of(System.getenv("APPDATA") + "\\.jaml\\");
|
JAML.path = Path.of(System.getenv("APPDATA") + "\\.jaml\\");
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
Reference in New Issue
Block a user