-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
better auto updates
- Loading branch information
Showing
5 changed files
with
97 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package net.kore.managers; | ||
|
||
import moe.nea.libautoupdate.CurrentVersion; | ||
import moe.nea.libautoupdate.UpdateContext; | ||
import moe.nea.libautoupdate.UpdateSource; | ||
import moe.nea.libautoupdate.UpdateTarget; | ||
import net.kore.Kore; | ||
|
||
import java.util.concurrent.CompletableFuture; | ||
import java.util.Base64; | ||
|
||
public class UpdateManager { | ||
private boolean checked = false; | ||
private UpdateContext updateContext; | ||
private boolean updateAvailable = false; | ||
private String stream = "upstream"; | ||
|
||
public UpdateManager() { | ||
// Auto Updater (Licensed only) | ||
updateContext = new UpdateContext( | ||
UpdateSource.gistSource("valekatoz","83a452dad0b31823d77f3b37e6a5ff3b"), | ||
UpdateTarget.deleteAndSaveInTheSameFolder(Kore.class), | ||
CurrentVersion.of(Integer.parseInt(Kore.VERSION_NUMBER)), | ||
Base64.getEncoder().encodeToString(Kore.MOD_ID.getBytes()) | ||
); | ||
updateContext.cleanup(); | ||
} | ||
|
||
public void update() { | ||
updateContext.checkUpdate(stream).thenCompose(it -> { | ||
if(it.isUpdateAvailable()) { | ||
updateAvailable = false; | ||
} | ||
|
||
return it.launchUpdate(); | ||
}).join(); | ||
} | ||
|
||
public boolean checkUpdate() { | ||
updateContext.checkUpdate(stream).thenCompose(it -> { | ||
if(it.isUpdateAvailable()) { | ||
updateAvailable = true; | ||
} | ||
|
||
return CompletableFuture.completedFuture(null); | ||
}).join(); | ||
|
||
return updateAvailable; | ||
} | ||
|
||
public boolean hasChecked() { | ||
return checked; | ||
} | ||
|
||
public void setChecked(boolean hasChecked) { | ||
this.checked = hasChecked; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters