Skip to content
This repository has been archived by the owner on Nov 20, 2024. It is now read-only.

Commit

Permalink
Fix updater problems
Browse files Browse the repository at this point in the history
  • Loading branch information
danieldieeins committed Apr 28, 2024
1 parent 9a99444 commit 6cdba2f
Showing 1 changed file with 29 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,21 @@ public class ApplicationLauncher {
public ApplicationLauncher(String[] args) {
Launcher.getLogger().log("[UPDATER] Checking defaults...");
config.checkEntry("updater.installed.info.version","0");
config.checkEntry("updater.installed.info.channel","null");
version = config.getString("updater.installed.info.version");
config.checkEntry("updater.settings.autoUpdate",true);
config.checkEntry("updater.settings.updateChannel","stable");
autoUpdate = config.getBoolean("updater.settings.autoUpdate");
updateChannel = config.getString("updater.settings.updateChannel");
boolean au = config.getBoolean("updater.settings.autoUpdate");
String uc = config.getString("updater.settings.updateChannel");
for(String arg:args) {
if(arg.startsWith("--channel:")) {
uc = arg.replace("--channel:", "");
} else if(arg.equalsIgnoreCase("--update")) {
au = true;
}
}
autoUpdate = au;
updateChannel = uc;
}

public String getVersion() {
Expand All @@ -56,22 +66,24 @@ public boolean automaticUpdates() {
private boolean validate() {
Launcher.getLogger().log("[UPDATER] Validating installed version...");
File folder = new File(libraries+"versions/");
if(!folder.mkdirs()) {
if(folder.exists()) {
if(folder.isDirectory()) {
Launcher.getLogger().log("[UPDATER] Found versions folder...");
for(File versions: Objects.requireNonNull(folder.listFiles())) {
if(versions.isDirectory()) {
if(Objects.requireNonNull(versions.listFiles()).length <= 3) {
for (File jar : Objects.requireNonNull(versions.listFiles())) {
Launcher.getLogger().log("[UPDATER] Found "+jar.getName());
if (jar.getName().contains("nexus-" + version + ".jar")) {
Launcher.getLogger().log("[UPDATER] Successfully validated installed version "+version+"!");
return true;
if(updateChannel.equals(config.getString("updater.installed.info.channel"))) {
if (!folder.mkdirs()) {
if (folder.exists()) {
if (folder.isDirectory()) {
Launcher.getLogger().log("[UPDATER] Found versions folder...");
for (File versions : Objects.requireNonNull(folder.listFiles())) {
if (versions.isDirectory()) {
if (Objects.requireNonNull(versions.listFiles()).length <= 3) {
for (File jar : Objects.requireNonNull(versions.listFiles())) {
Launcher.getLogger().log("[UPDATER] Found " + jar.getName());
if (jar.getName().contains("nexus-" + version + ".jar")) {
Launcher.getLogger().log("[UPDATER] Successfully validated installed version " + version + "!");
return true;
}
}
} else {
Launcher.getLogger().error("[UPDATER] Too many versions!");
}
} else {
Launcher.getLogger().error("[UPDATER] Too many versions!");
}
}
}
Expand Down Expand Up @@ -111,6 +123,7 @@ public boolean update(String updateChannelId, boolean overwrite) {
if(app != null) {
this.version = newVersion;
config.set("updater.installed.info.version", this.version);
config.set("updater.installed.info.channel", this.updateChannel);
return true;
} else {
Launcher.getLogger().error("[UPDATER] Couldn't download new version!");
Expand Down

0 comments on commit 6cdba2f

Please sign in to comment.