added update support
* added a manuall update function * added a auto update function
This commit is contained in:
@ -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();
|
||||
|
@ -86,7 +86,7 @@
|
||||
</Label>
|
||||
<JFXToggleButton fx:id="cloudSyncToggleBtn" layoutX="10.0" layoutY="247.0" onAction="#cloudSyncToggleBtnAction" text="cloud savegames (Google Drive)" AnchorPane.leftAnchor="10.0" AnchorPane.topAnchor="247.0" />
|
||||
<Label fx:id="updateLbl" layoutX="10.0" layoutY="315.0" text="Updates" AnchorPane.leftAnchor="10.0" AnchorPane.topAnchor="315.0" />
|
||||
<JFXButton fx:id="updateBtn" layoutX="14.0" layoutY="335.0" onAction="#updateBtnAction" prefHeight="32.0" prefWidth="111.0" text="check now!" AnchorPane.leftAnchor="14.0" AnchorPane.topAnchor="335.0" />
|
||||
<JFXButton fx:id="updateBtn" layoutX="14.0" layoutY="335.0" onAction="#updateBtnAction" prefHeight="32.0" text="check now!" AnchorPane.leftAnchor="14.0" AnchorPane.topAnchor="335.0" />
|
||||
<JFXToggleButton fx:id="autoUpdateToggleBtn" layoutX="10.0" layoutY="372.0" onAction="#autoUpdateToggleBtnAction" text="check for updates on startup" AnchorPane.leftAnchor="10.0" AnchorPane.topAnchor="372.0" />
|
||||
</children>
|
||||
</AnchorPane>
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
129
src/application/UpdateController.java
Normal file
129
src/application/UpdateController.java
Normal file
@ -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);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user