diff --git a/bin/application/Main$1$1.class b/bin/application/Main$1$1.class
index 072117f..ca76911 100644
Binary files a/bin/application/Main$1$1.class and b/bin/application/Main$1$1.class differ
diff --git a/bin/application/Main$1.class b/bin/application/Main$1.class
index 915e77e..5b8ab66 100644
Binary files a/bin/application/Main$1.class and b/bin/application/Main$1.class differ
diff --git a/bin/application/Main$2$1.class b/bin/application/Main$2$1.class
index f1a0f2e..213dd2b 100644
Binary files a/bin/application/Main$2$1.class and b/bin/application/Main$2$1.class differ
diff --git a/bin/application/Main$2.class b/bin/application/Main$2.class
index 20139a2..3cb0f53 100644
Binary files a/bin/application/Main$2.class and b/bin/application/Main$2.class differ
diff --git a/bin/application/Main$3.class b/bin/application/Main$3.class
index 42ac9bc..bc96d27 100644
Binary files a/bin/application/Main$3.class and b/bin/application/Main$3.class differ
diff --git a/bin/application/Main.class b/bin/application/Main.class
index a425db7..035ba89 100644
Binary files a/bin/application/Main.class and b/bin/application/Main.class differ
diff --git a/bin/application/MainWindow.fxml b/bin/application/MainWindow.fxml
index dd8360d..5ce3d8a 100644
--- a/bin/application/MainWindow.fxml
+++ b/bin/application/MainWindow.fxml
@@ -86,7 +86,7 @@
-
+
diff --git a/bin/application/MainWindowController$1.class b/bin/application/MainWindowController$1.class
index a54e453..831b770 100644
Binary files a/bin/application/MainWindowController$1.class and b/bin/application/MainWindowController$1.class differ
diff --git a/bin/application/MainWindowController$10.class b/bin/application/MainWindowController$10.class
index bec5184..c31f0b5 100644
Binary files a/bin/application/MainWindowController$10.class and b/bin/application/MainWindowController$10.class differ
diff --git a/bin/application/MainWindowController$11.class b/bin/application/MainWindowController$11.class
index 38c45ae..1c7389a 100644
Binary files a/bin/application/MainWindowController$11.class and b/bin/application/MainWindowController$11.class differ
diff --git a/bin/application/MainWindowController$12.class b/bin/application/MainWindowController$12.class
index 8b48f41..b69604a 100644
Binary files a/bin/application/MainWindowController$12.class and b/bin/application/MainWindowController$12.class differ
diff --git a/bin/application/MainWindowController$2.class b/bin/application/MainWindowController$2.class
index 39ba3c0..1f4287f 100644
Binary files a/bin/application/MainWindowController$2.class and b/bin/application/MainWindowController$2.class differ
diff --git a/bin/application/MainWindowController$3.class b/bin/application/MainWindowController$3.class
index fe84c5d..05b2a8a 100644
Binary files a/bin/application/MainWindowController$3.class and b/bin/application/MainWindowController$3.class differ
diff --git a/bin/application/MainWindowController$4.class b/bin/application/MainWindowController$4.class
index 91c78f2..739c3f6 100644
Binary files a/bin/application/MainWindowController$4.class and b/bin/application/MainWindowController$4.class differ
diff --git a/bin/application/MainWindowController$5.class b/bin/application/MainWindowController$5.class
index 980952b..dc8e58c 100644
Binary files a/bin/application/MainWindowController$5.class and b/bin/application/MainWindowController$5.class differ
diff --git a/bin/application/MainWindowController$6.class b/bin/application/MainWindowController$6.class
index a5f5cd5..b112c42 100644
Binary files a/bin/application/MainWindowController$6.class and b/bin/application/MainWindowController$6.class differ
diff --git a/bin/application/MainWindowController$7.class b/bin/application/MainWindowController$7.class
index a3c4853..bdbb52f 100644
Binary files a/bin/application/MainWindowController$7.class and b/bin/application/MainWindowController$7.class differ
diff --git a/bin/application/MainWindowController$8.class b/bin/application/MainWindowController$8.class
index f3d2a00..2d5a480 100644
Binary files a/bin/application/MainWindowController$8.class and b/bin/application/MainWindowController$8.class differ
diff --git a/bin/application/MainWindowController$9.class b/bin/application/MainWindowController$9.class
index f631160..d3336d7 100644
Binary files a/bin/application/MainWindowController$9.class and b/bin/application/MainWindowController$9.class differ
diff --git a/bin/application/MainWindowController.class b/bin/application/MainWindowController.class
index ef23991..dbe7700 100644
Binary files a/bin/application/MainWindowController.class and b/bin/application/MainWindowController.class differ
diff --git a/cemu_UI.jar b/cemu_UI.jar
new file mode 100644
index 0000000..c29206a
Binary files /dev/null and b/cemu_UI.jar differ
diff --git a/src/application/Main.java b/src/application/Main.java
index 85099eb..5f0d2d1 100644
--- a/src/application/Main.java
+++ b/src/application/Main.java
@@ -122,6 +122,7 @@ public class Main extends Application {
LOGGER.info("firststart, setting default values");
firstStart();
mainWindowController.setColor("00a8cc");
+ mainWindowController.setAutoUpdate(false);
mainWindowController.setxPosHelper(0);
mainWindowController.saveSettings();
Runtime.getRuntime().exec("java -jar cemu_UI.jar"); //start again (preventing Bugs)
@@ -148,6 +149,7 @@ public class Main extends Application {
//loading settings and initialize UI, dbController.main() loads all databases
mainWindowController.loadSettings();
+ mainWindowController.checkAutoUpdate();
mainWindowController.initActions();
mainWindowController.initUI();
mainWindowController.dbController.main();
diff --git a/src/application/MainWindow.fxml b/src/application/MainWindow.fxml
index dd8360d..5ce3d8a 100644
--- a/src/application/MainWindow.fxml
+++ b/src/application/MainWindow.fxml
@@ -86,7 +86,7 @@
-
+
diff --git a/src/application/MainWindowController.java b/src/application/MainWindowController.java
index a15d72e..6e82aaf 100644
--- a/src/application/MainWindowController.java
+++ b/src/application/MainWindowController.java
@@ -245,10 +245,12 @@ public class MainWindowController {
dbController dbController;
SmmdbApiQuery smmdbApiQuery;
playGame playGame;
+ private UpdateController updateController;
private boolean menuTrue = false;
private boolean settingsTrue = false;
private boolean playTrue = false;
private boolean smmdbTrue = false;
+ private boolean autoUpdate = false;
private boolean fullscreen;
private boolean cloudSync;
private String cloudService = ""; //set cloud provider (at the moment only GoogleDrive, Dropbox is planed)
@@ -325,8 +327,9 @@ public class MainWindowController {
colorPicker.setValue(Color.valueOf(getColor()));
fullscreenToggleBtn.setSelected(isFullscreen());
cloudSyncToggleBtn.setSelected(isCloudSync());
- updateBtn.setDisable(true); // TODO
- autoUpdateToggleBtn.setDisable(true); // TODO
+ autoUpdateToggleBtn.setSelected(isAutoUpdate());
+ updateBtn.setDisable(false); // TODO
+ autoUpdateToggleBtn.setDisable(false); // TODO
applyColor();
//initialize courseTable
@@ -831,13 +834,20 @@ public class MainWindowController {
@FXML
void updateBtnAction(ActionEvent event) {
- // TODO implement and call update method
+ updateController = new UpdateController(this, buildNumber);
+ Thread updateThread = new Thread(updateController);
+ updateThread.setName("Updater");
+ updateThread.start();
}
@FXML
void autoUpdateToggleBtnAction(ActionEvent event) {
- // TODO implement auto update function
- }
+ if(isAutoUpdate()){
+ setAutoUpdate(false);
+ }else{
+ setAutoUpdate(true);
+ }
+ saveSettings(); }
@FXML
void smmdbDownloadBtnAction(ActionEvent event){
@@ -1295,6 +1305,22 @@ public class MainWindowController {
lastTimePlayedBtn.setLayoutX((width/2)+50+20.5);
}
+ void checkAutoUpdate() {
+
+ if(isAutoUpdate()){
+ try {
+ LOGGER.info("AutoUpdate: looking for updates on startup ...");
+ updateController = new UpdateController(this, buildNumber);
+ Thread updateThread = new Thread(updateController);
+ updateThread.setName("Updater");
+ updateThread.start();
+ updateThread.join();
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+
private void addCourseDescription(SmmdbApiDataType course) {
String courseTheme;
String gameStyle;
@@ -1519,7 +1545,8 @@ public class MainWindowController {
props.setProperty("romPath", getRomPath());
props.setProperty("color", getColor());
props.setProperty("fullscreen", String.valueOf(isFullscreen()));
- props.setProperty("cloudSync", String.valueOf(cloudSync));
+ props.setProperty("cloudSync", String.valueOf(isCloudSync()));
+ props.setProperty("autoUpdate", String.valueOf(isAutoUpdate()));
if (getCloudService() == null) {
props.setProperty("cloudService", "");
} else {
@@ -1591,6 +1618,14 @@ public class MainWindowController {
setCloudSync(false);
}
+ try {
+ setAutoUpdate(Boolean.parseBoolean(props.getProperty("autoUpdate")));
+ } catch (Exception e) {
+ LOGGER.error("cloud not load autoUpdate", e);
+ setAutoUpdate(false);
+ }
+
+
try {
setCloudService(props.getProperty("cloudService"));
} catch (Exception e) {
@@ -1801,6 +1836,14 @@ public class MainWindowController {
this.cloudSync = cloudSync;
}
+ public boolean isAutoUpdate() {
+ return autoUpdate;
+ }
+
+ public void setAutoUpdate(boolean autoUpdate) {
+ this.autoUpdate = autoUpdate;
+ }
+
public String getGameExecutePath() {
return gameExecutePath;
}
@@ -1861,4 +1904,8 @@ public class MainWindowController {
return mainAnchorPane;
}
+ public JFXButton getUpdateBtn() {
+ return updateBtn;
+ }
+
}
diff --git a/src/application/UpdateController.java b/src/application/UpdateController.java
new file mode 100644
index 0000000..29bd8ca
--- /dev/null
+++ b/src/application/UpdateController.java
@@ -0,0 +1,129 @@
+/**
+ * cemu_UI
+ *
+ * Copyright 2017 <@Seil0>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ */
+
+package application;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.net.HttpURLConnection;
+import java.net.URL;
+import javax.swing.ProgressMonitor;
+import javax.swing.ProgressMonitorInputStream;
+
+import org.apache.commons.io.FileUtils;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+
+import com.eclipsesource.json.Json;
+import com.eclipsesource.json.JsonArray;
+import com.eclipsesource.json.JsonObject;
+import com.eclipsesource.json.JsonValue;
+
+import javafx.application.Platform;
+
+public class UpdateController implements Runnable{
+
+ private MainWindowController mainWindowController;
+ 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/cemu_UI/releases/latest";
+ private static final Logger LOGGER = LogManager.getLogger(UpdateController.class.getName());
+
+ /**
+ * updater for cemu_UI based on Project HomeFlix
+ * checks for Updates and download it in case there is one
+ */
+ public UpdateController(MainWindowController mwc, String buildNumber){
+ mainWindowController=mwc;
+ this.buildNumber=buildNumber;
+ }
+
+ public void run(){
+ System.out.println("checking for updates ...");
+ Platform.runLater(() -> {
+ mainWindowController.getUpdateBtn().setText("checking for updates ...");
+ });
+
+ try {
+ URL githubApiUrl = new URL(githubApi);
+ BufferedReader ina = new BufferedReader(new InputStreamReader(githubApiUrl.openStream()));
+ apiOutput = ina.readLine();
+ ina.close();
+ } catch (IOException e) {
+ Platform.runLater(() -> {
+ LOGGER.error("could not check update version", e);
+ });
+ }
+
+ 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", "");
+
+ }
+ LOGGER.info("Build: "+buildNumber+", Update: "+updateBuildNumber);
+
+ //Compares the program BuildNumber with the current BuildNumber if program BuildNumber < current BuildNumber then perform a update
+ int iversion = Integer.parseInt(buildNumber);
+ int iaktVersion = Integer.parseInt(updateBuildNumber.replace(".", ""));
+
+ if(iversion >= iaktVersion){
+ Platform.runLater(() -> {
+ mainWindowController.getUpdateBtn().setText("no update available");
+ });
+ LOGGER.info("no update available");
+ }else{
+ Platform.runLater(() -> {
+ mainWindowController.getUpdateBtn().setText("update available");
+ });
+ LOGGER.info("update available");
+ LOGGER.info("download link: " + browserDownloadUrl);
+ try {
+ //open new Http connection, ProgressMonitorInputStream for downloading the data
+ HttpURLConnection conn = (HttpURLConnection) new URL(browserDownloadUrl).openConnection();
+ ProgressMonitorInputStream pmis = new ProgressMonitorInputStream(null, "Downloading...", conn.getInputStream());
+ ProgressMonitor pm = pmis.getProgressMonitor();
+ pm.setMillisToDecideToPopup(0);
+ pm.setMillisToPopup(0);
+ pm.setMinimum(0);// tell the progress bar that we start at the beginning of the stream
+ pm.setMaximum(conn.getContentLength());// tell the progress bar the total number of bytes we are going to read.
+ FileUtils.copyInputStreamToFile(pmis, new File("cemu_UI_update.jar")); //download update
+ org.apache.commons.io.FileUtils.copyFile(new File("cemu_UI_update.jar"), new File("cemu_UI.jar")); //TODO rename update to old name
+ org.apache.commons.io.FileUtils.deleteQuietly(new File("cemu_UI_update.jar")); //delete update
+ Runtime.getRuntime().exec("java -jar cemu_UI.jar"); //start again
+ System.exit(0); //finishes itself
+ } catch (IOException e) {
+ Platform.runLater(() -> {
+ LOGGER.info("could not download update files", e);
+ });
+ }
+ }
+ }
+}
+