the updater now uses gitea
This commit is contained in:
parent
3f6eeece7d
commit
38421599a3
|
@ -44,16 +44,16 @@ import javafx.application.Platform;
|
||||||
public class UpdateController implements Runnable {
|
public class UpdateController implements Runnable {
|
||||||
|
|
||||||
private MainWindowController mainWindowController;
|
private MainWindowController mainWindowController;
|
||||||
private String buildNumber;
|
private int buildNumber;
|
||||||
|
private int updateBuildNumber; // tag_name from gitea
|
||||||
private String apiOutput;
|
private String apiOutput;
|
||||||
private String updateBuildNumber; // tag_name from Github
|
@SuppressWarnings("unused")
|
||||||
// private String updateName;
|
private String updateName;
|
||||||
// private String updateChanges;
|
@SuppressWarnings("unused")
|
||||||
|
private String updateChanges;
|
||||||
private String browserDownloadUrl; // update download link
|
private String browserDownloadUrl; // update download link
|
||||||
private String githubApiRelease = "https://api.github.com/repos/Seil0/cemu_UI/releases/latest";
|
private String giteaApiRelease = "https://git.mosad.xyz/api/v1/repos/Seil0/cemu_UI/releases";
|
||||||
private String githubApiBeta = "https://api.github.com/repos/Seil0/cemu_UI/releases";
|
private URL giteaApiUrl;
|
||||||
|
|
||||||
private URL githubApiUrl;
|
|
||||||
private boolean useBeta;
|
private boolean useBeta;
|
||||||
private static final Logger LOGGER = LogManager.getLogger(UpdateController.class.getName());
|
private static final Logger LOGGER = LogManager.getLogger(UpdateController.class.getName());
|
||||||
|
|
||||||
|
@ -62,7 +62,7 @@ public class UpdateController implements Runnable {
|
||||||
*/
|
*/
|
||||||
public UpdateController(MainWindowController mwc, String buildNumber, boolean useBeta) {
|
public UpdateController(MainWindowController mwc, String buildNumber, boolean useBeta) {
|
||||||
mainWindowController = mwc;
|
mainWindowController = mwc;
|
||||||
this.buildNumber = buildNumber;
|
this.buildNumber = Integer.parseInt(buildNumber);
|
||||||
this.useBeta = useBeta;
|
this.useBeta = useBeta;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -74,15 +74,9 @@ public class UpdateController implements Runnable {
|
||||||
});
|
});
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
giteaApiUrl = new URL(giteaApiRelease);
|
||||||
|
|
||||||
if (useBeta) {
|
BufferedReader ina = new BufferedReader(new InputStreamReader(giteaApiUrl.openStream()));
|
||||||
githubApiUrl = new URL(githubApiBeta);
|
|
||||||
} else {
|
|
||||||
githubApiUrl = new URL(githubApiRelease);
|
|
||||||
}
|
|
||||||
|
|
||||||
// URL githubApiUrl = new URL(githubApiRelease);
|
|
||||||
BufferedReader ina = new BufferedReader(new InputStreamReader(githubApiUrl.openStream()));
|
|
||||||
apiOutput = ina.readLine();
|
apiOutput = ina.readLine();
|
||||||
ina.close();
|
ina.close();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
|
@ -91,40 +85,31 @@ public class UpdateController implements Runnable {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (useBeta) {
|
JsonArray objectArray = Json.parse("{\"items\": " + apiOutput + "}").asObject().get("items").asArray();
|
||||||
JsonArray objectArray = Json.parse("{\"items\": " + apiOutput + "}").asObject().get("items").asArray();
|
JsonValue object = objectArray.get(0).asObject(); // set to the latest release as default
|
||||||
JsonValue object = objectArray.get(0);
|
JsonObject objectAsset = object.asObject().get("assets").asArray().get(0).asObject();
|
||||||
JsonArray objectAssets = object.asObject().get("assets").asArray();
|
|
||||||
|
|
||||||
updateBuildNumber = object.asObject().getString("tag_name", "");
|
|
||||||
// updateName = object.asObject().getString("name", "");
|
|
||||||
// updateChanges = object.asObject().getString("body", "");
|
|
||||||
|
|
||||||
for (JsonValue asset : objectAssets) {
|
|
||||||
browserDownloadUrl = asset.asObject().getString("browser_download_url", "");
|
|
||||||
}
|
|
||||||
|
|
||||||
} else {
|
|
||||||
JsonObject object = Json.parse(apiOutput).asObject();
|
|
||||||
JsonArray objectAssets = Json.parse(apiOutput).asObject().get("assets").asArray();
|
|
||||||
|
|
||||||
updateBuildNumber = object.getString("tag_name", "");
|
|
||||||
// updateName = object.getString("name", "");
|
|
||||||
// updateChanges = object.getString("body", "");
|
|
||||||
for (JsonValue asset : objectAssets) {
|
|
||||||
browserDownloadUrl = asset.asObject().getString("browser_download_url", "");
|
|
||||||
|
|
||||||
|
for(JsonValue objectIt : objectArray) {
|
||||||
|
// TODO note this will download still the pre-release if there's a more recent stable version
|
||||||
|
if(objectIt.asObject().getBoolean("prerelease", false) == useBeta) {
|
||||||
|
// we found the needed release either beta or not
|
||||||
|
object = objectIt;
|
||||||
|
objectAsset = objectIt.asObject().get("assets").asArray().get(0).asObject();
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
updateBuildNumber = Integer.parseInt(object.asObject().getString("tag_name", ""));
|
||||||
|
updateName = object.asObject().getString("name", "");
|
||||||
|
updateChanges = object.asObject().getString("body", "");
|
||||||
|
|
||||||
LOGGER.info("Build: " + buildNumber + ", Update: " + updateBuildNumber);
|
LOGGER.info("Build: " + buildNumber + ", Update: " + updateBuildNumber);
|
||||||
|
|
||||||
// Compares the program BuildNumber with the current BuildNumber if program
|
/**
|
||||||
// BuildNumber < current BuildNumber then perform a update
|
* Compare the program BuildNumber with the current BuildNumber
|
||||||
int iversion = Integer.parseInt(buildNumber);
|
* if buildNumber < updateBuildNumber then perform a update
|
||||||
int iaktVersion = Integer.parseInt(updateBuildNumber.replace(".", ""));
|
*/
|
||||||
|
if (buildNumber >= updateBuildNumber) {
|
||||||
if (iversion >= iaktVersion) {
|
|
||||||
Platform.runLater(() -> {
|
Platform.runLater(() -> {
|
||||||
mainWindowController.getUpdateBtn().setText(mainWindowController.getBundle().getString("updateBtnNoUpdateAvailable"));
|
mainWindowController.getUpdateBtn().setText(mainWindowController.getBundle().getString("updateBtnNoUpdateAvailable"));
|
||||||
});
|
});
|
||||||
|
@ -134,6 +119,7 @@ public class UpdateController implements Runnable {
|
||||||
mainWindowController.getUpdateBtn().setText(mainWindowController.getBundle().getString("updateBtnUpdateAvailable"));
|
mainWindowController.getUpdateBtn().setText(mainWindowController.getBundle().getString("updateBtnUpdateAvailable"));
|
||||||
});
|
});
|
||||||
LOGGER.info("update available");
|
LOGGER.info("update available");
|
||||||
|
browserDownloadUrl = objectAsset.getString("browser_download_url", "");
|
||||||
LOGGER.info("download link: " + browserDownloadUrl);
|
LOGGER.info("download link: " + browserDownloadUrl);
|
||||||
try {
|
try {
|
||||||
// open new Http connection, ProgressMonitorInputStream for downloading the data
|
// open new Http connection, ProgressMonitorInputStream for downloading the data
|
||||||
|
@ -148,7 +134,7 @@ public class UpdateController implements Runnable {
|
||||||
org.apache.commons.io.FileUtils.copyFile(new File("cemu_UI_update.jar"), new File("cemu_UI.jar"));
|
org.apache.commons.io.FileUtils.copyFile(new File("cemu_UI_update.jar"), new File("cemu_UI.jar"));
|
||||||
org.apache.commons.io.FileUtils.deleteQuietly(new File("cemu_UI_update.jar")); // delete update
|
org.apache.commons.io.FileUtils.deleteQuietly(new File("cemu_UI_update.jar")); // delete update
|
||||||
new ProcessBuilder("java", "-jar", "cemu_UI.jar").start(); // start the new application
|
new ProcessBuilder("java", "-jar", "cemu_UI.jar").start(); // start the new application
|
||||||
System.exit(0); // finishes itself
|
System.exit(0); // close the current application
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
Platform.runLater(() -> {
|
Platform.runLater(() -> {
|
||||||
LOGGER.info("could not download update files", e);
|
LOGGER.info("could not download update files", e);
|
||||||
|
|
|
@ -18,10 +18,10 @@ fullscreenToggleBtn = start game in fullscreen
|
||||||
cemu_UISettingsLbl = cemu_UI Settings
|
cemu_UISettingsLbl = cemu_UI Settings
|
||||||
cemuDirectoryLbl = cemu directory
|
cemuDirectoryLbl = cemu directory
|
||||||
romDirectoryLbl = ROM directory
|
romDirectoryLbl = ROM directory
|
||||||
mainColorLbl = main color
|
mainColorLbl = primary color
|
||||||
languageLbl = language
|
languageLbl = Language
|
||||||
updateLbl = updates
|
updateLbl = Updates
|
||||||
branchLbl = branch
|
branchLbl = Branch
|
||||||
cemuSettingsLbl = cemu Settings
|
cemuSettingsLbl = cemu Settings
|
||||||
licensesLbl = Licenses
|
licensesLbl = Licenses
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue