reworked updater

* updater now get it's data from the github api
This commit is contained in:
Jannik
2017-06-01 17:13:26 +02:00
parent 43a31d0682
commit e53d1d1176
16 changed files with 38 additions and 17 deletions
+1
View File
@@ -1,5 +1,6 @@
eclipse.preferences.version=1 eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.8 org.eclipse.jdt.core.compiler.compliance=1.8
+2
View File
@@ -0,0 +1,2 @@
/application/
/libraries/
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
+1 -3
View File
@@ -185,8 +185,6 @@ public class MainWindowController {
private String version = "0.5.1"; private String version = "0.5.1";
private String buildNumber = "127"; private String buildNumber = "127";
private String versionName = "plasma cow"; private String versionName = "plasma cow";
private String buildURL = "https://raw.githubusercontent.com/Seil0/Project-HomeFlix/master/updates/buildNumber.txt";
private String downloadLink = "https://raw.githubusercontent.com/Seil0/Project-HomeFlix/master/updates/downloadLink.txt";
private File dirWin = new File(System.getProperty("user.home") + "/Documents/HomeFlix"); private File dirWin = new File(System.getProperty("user.home") + "/Documents/HomeFlix");
private File dirLinux = new File(System.getProperty("user.home") + "/HomeFlix"); private File dirLinux = new File(System.getProperty("user.home") + "/HomeFlix");
private File fileWin = new File(dirWin + "/config.xml"); private File fileWin = new File(dirWin + "/config.xml");
@@ -514,7 +512,7 @@ public class MainWindowController {
*/ */
void setMain(Main main) { void setMain(Main main) {
this.main = main; this.main = main;
Updater = new updater(this,buildURL, downloadLink, buildNumber); Updater = new updater(this, buildNumber);
dbController = new DBController(this, this.main); dbController = new DBController(this, this.main);
ApiQuery = new apiQuery(this, dbController, this.main); ApiQuery = new apiQuery(this, dbController, this.main);
} }
+34 -14
View File
@@ -15,20 +15,25 @@ import javax.swing.ProgressMonitorInputStream;
import org.apache.commons.io.FileUtils; import org.apache.commons.io.FileUtils;
import com.eclipsesource.json.Json;
import com.eclipsesource.json.JsonArray;
import com.eclipsesource.json.JsonObject;
import com.eclipsesource.json.JsonValue;
import javafx.application.Platform; import javafx.application.Platform;
public class updater implements Runnable{ public class updater implements Runnable{
private MainWindowController mainWindowController; private MainWindowController mainWindowController;
private String buildURL;
private String downloadLink;
private String updateBuildNumber;
private String buildNumber; private String buildNumber;
private String apiOutput;
private String updateBuildNumber; //tag_name from Github
private String browserDownloadUrl; //update download link
private String githubApi = "https://api.github.com/repos/Seil0/Project-HomeFlix/releases/latest";
public updater(MainWindowController m, String buildURL,String downloadLink,String buildNumber){
public updater(MainWindowController m, String buildNumber){
mainWindowController=m; mainWindowController=m;
this.buildURL=buildURL;
this.downloadLink=downloadLink;
this.buildNumber=buildNumber; this.buildNumber=buildNumber;
} }
@@ -37,14 +42,27 @@ public class updater implements Runnable{
Platform.runLater(() -> { Platform.runLater(() -> {
mainWindowController.updateBtn.setText(mainWindowController.bundle.getString("checkingUpdates")); mainWindowController.updateBtn.setText(mainWindowController.bundle.getString("checkingUpdates"));
}); });
try {
URL url = new URL(buildURL); //URL of the text file with the current build number try {
BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream())); URL githubApiUrl = new URL(githubApi);
updateBuildNumber = in.readLine(); //write InputStream in String BufferedReader ina = new BufferedReader(new InputStreamReader(githubApiUrl.openStream()));
in.close(); apiOutput = ina.readLine();
ina.close();
} catch (IOException e1) { } catch (IOException e1) {
mainWindowController.showErrorMsg(mainWindowController.errorUpdateV, e1); mainWindowController.showErrorMsg(mainWindowController.errorUpdateV, e1);
e1.printStackTrace();
} }
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", "");
}
System.out.println("Build: "+buildNumber+", Update: "+updateBuildNumber); System.out.println("Build: "+buildNumber+", Update: "+updateBuildNumber);
//Compares the program BuildNumber with the current BuildNumber if program BuildNumber < current BuildNumber then perform a update //Compares the program BuildNumber with the current BuildNumber if program BuildNumber < current BuildNumber then perform a update
@@ -61,9 +79,10 @@ public class updater implements Runnable{
mainWindowController.updateBtn.setText(mainWindowController.bundle.getString("updateBtnavail")); mainWindowController.updateBtn.setText(mainWindowController.bundle.getString("updateBtnavail"));
}); });
System.out.println("update available"); System.out.println("update available");
System.out.println("download link: " + browserDownloadUrl);
try { try {
//get the download-Data URL //get the download-Data URL
URL downloadURL = new URL(downloadLink); URL downloadURL = new URL(browserDownloadUrl);
BufferedReader in = new BufferedReader(new InputStreamReader(downloadURL.openStream())); BufferedReader in = new BufferedReader(new InputStreamReader(downloadURL.openStream()));
String updateDataURL = in.readLine(); String updateDataURL = in.readLine();
@@ -80,8 +99,9 @@ public class updater implements Runnable{
Runtime.getRuntime().exec("java -jar ProjectHomeFlix.jar"); //start again Runtime.getRuntime().exec("java -jar ProjectHomeFlix.jar"); //start again
System.exit(0); //finishes itself System.exit(0); //finishes itself
} catch (IOException e) { } catch (IOException e) {
//in case there is an error Platform.runLater(() -> {
mainWindowController.showErrorMsg(mainWindowController.errorUpdateD, e); mainWindowController.showErrorMsg(mainWindowController.errorUpdateD, e);
});
} }
} }
} }
Binary file not shown.