reworked updater

updater is now in its own thread
This commit is contained in:
Seil0 2017-03-25 16:20:48 +01:00
parent 131c8a491b
commit 0f5d0b859f
19 changed files with 47 additions and 32 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -8,6 +8,7 @@ openFolder = Ordner \u00F6ffnen
chooseFolder = Ordner ausw\u00E4hlen chooseFolder = Ordner ausw\u00E4hlen
fontSize = Schriftgr\u00F6\u00DFe: fontSize = Schriftgr\u00F6\u00DFe:
checkUpdates = Auf Update pr\u00FCfen checkUpdates = Auf Update pr\u00FCfen
checkingUpdates = Es wird nach Updates gesucht...
updateBtnavail = Update verf\u00FCgbar updateBtnavail = Update verf\u00FCgbar
updateBtnNotavail = Kein Update verf\u00FCgbar updateBtnNotavail = Kein Update verf\u00FCgbar
autoUpdate = beim Start nach Updates suchen: autoUpdate = beim Start nach Updates suchen:

View File

@ -8,6 +8,7 @@ openFolder = open Folder
chooseFolder = choose Directory chooseFolder = choose Directory
fontSize = font size: fontSize = font size:
checkUpdates = check for updates checkUpdates = check for updates
checkingUpdates = checking for updates...
updateBtnavail = update available updateBtnavail = update available
updateBtnNotavail = no update available updateBtnNotavail = no update available
autoUpdate = check at startup for updates: autoUpdate = check at startup for updates:

View File

@ -232,7 +232,7 @@ public class DBController {
try { try {
//load local Data //load local Data
Statement stmt = connection.createStatement(); Statement stmt = connection.createStatement();
ResultSet rs = stmt.executeQuery("SELECT * FROM film_local"); ResultSet rs = stmt.executeQuery("SELECT * FROM film_local ORDER BY titel");
while (rs.next()) { while (rs.next()) {
if(rs.getString(4).equals("favorite_black")){ if(rs.getString(4).equals("favorite_black")){
mainWindowController.localFilms.add( new tableData(1, 1, 1, rs.getDouble(1), "1", rs.getString(2), rs.getString(3), new ImageView(favorite_black),rs.getBoolean(5))); mainWindowController.localFilms.add( new tableData(1, 1, 1, rs.getDouble(1), "1", rs.getString(2), rs.getString(3), new ImageView(favorite_black),rs.getBoolean(5)));
@ -244,7 +244,7 @@ public class DBController {
rs.close(); rs.close();
//load streaming Data TODO check if there are streaming data before loading -> maybe there is an issue now //load streaming Data TODO check if there are streaming data before loading -> maybe there is an issue now
rs = stmt.executeQuery("SELECT * FROM film_streaming;"); rs = stmt.executeQuery("SELECT * FROM film_streaming ORDER BY titel;");
while (rs.next()) { while (rs.next()) {
if(rs.getString(8).equals("favorite_black")){ if(rs.getString(8).equals("favorite_black")){
mainWindowController.streamingFilms.add(new tableData(rs.getInt(1), rs.getInt(2), rs.getInt(3), rs.getDouble(4), rs.getString(5), rs.getString(6), rs.getString(7), new ImageView(favorite_black),rs.getBoolean(9))); mainWindowController.streamingFilms.add(new tableData(rs.getInt(1), rs.getInt(2), rs.getInt(3), rs.getDouble(4), rs.getString(5), rs.getString(6), rs.getString(7), new ImageView(favorite_black),rs.getBoolean(9)));
@ -330,7 +330,7 @@ public class DBController {
* @throws FileNotFoundException * @throws FileNotFoundException
* @throws IOException * @throws IOException
*/ */
private void checkAddEntry() throws SQLException, FileNotFoundException, IOException{ //TODO sort alphabetical private void checkAddEntry() throws SQLException, FileNotFoundException, IOException{
System.out.println("checking for entrys to add to DB ..."); System.out.println("checking for entrys to add to DB ...");
String[] entries = new File(mainWindowController.getPath()).list(); String[] entries = new File(mainWindowController.getPath()).list();
Statement stmt = connection.createStatement(); Statement stmt = connection.createStatement();

View File

@ -45,9 +45,9 @@ public class Main extends Application {
private String streamingPathWin = System.getProperty("user.home") + "\\Documents\\HomeFlix"; private String streamingPathWin = System.getProperty("user.home") + "\\Documents\\HomeFlix";
private String streamingPathLinux = System.getProperty("user.home") + "/HomeFlix"; private String streamingPathLinux = System.getProperty("user.home") + "/HomeFlix";
private String color = "ee3523"; private String color = "ee3523";
private String autoUpdate = "0";
private String mode = "local"; //local or streaming private String mode = "local"; //local or streaming
private String local = System.getProperty("user.language")+"_"+System.getProperty("user.country"); private String local = System.getProperty("user.language")+"_"+System.getProperty("user.country");
private boolean autoUpdate = false;
private double size = 17; private double size = 17;
private ResourceBundle bundle; private ResourceBundle bundle;
private MainWindowController mainWindowController; private MainWindowController mainWindowController;
@ -77,7 +77,7 @@ public class Main extends Application {
mainWindowController.setAutoUpdate(autoUpdate); //set auto-update mainWindowController.setAutoUpdate(autoUpdate); //set auto-update
mainWindowController.setMain(this); //call setMain mainWindowController.setMain(this); //call setMain
//Linux if directory exists -> check config.xml //Linux if directory exists -> check config.xml
if(System.getProperty("os.name").equals("Linux")){ if(System.getProperty("os.name").equals("Linux")){
if(dirLinux.exists() != true){ if(dirLinux.exists() != true){
dirLinux.mkdir(); dirLinux.mkdir();

View File

@ -182,6 +182,7 @@ public class MainWindowController {
private boolean menutrue = false; //saves the position of menubtn (opened or closed) private boolean menutrue = false; //saves the position of menubtn (opened or closed)
private boolean settingstrue = false; private boolean settingstrue = false;
private boolean streamingSettingsTrue = false; private boolean streamingSettingsTrue = false;
private boolean autoUpdate = false;
static boolean firststart = false; static boolean firststart = false;
private int hashA = -2055934614; private int hashA = -2055934614;
private String version = "0.5.0"; private String version = "0.5.0";
@ -196,22 +197,20 @@ public class MainWindowController {
String errorUpdateD; String errorUpdateD;
String errorUpdateV; String errorUpdateV;
String noFilmFound;
private String errorPlay; private String errorPlay;
private String errorOpenStream; private String errorOpenStream;
private String errorMode; private String errorMode;
private String errorLoad; private String errorLoad;
private String errorSave; private String errorSave;
String noFilmFound;
private String infoText; private String infoText;
private String linuxBugText; private String linuxBugText;
private String vlcNotInstalled; private String vlcNotInstalled;
private String aktBuildNumber;
private String path; private String path;
private String streamingPath; private String streamingPath;
private String color; private String color;
private String name; private String name;
private String datPath; private String datPath;
private String autoUpdate;
private String mode; private String mode;
@SuppressWarnings("unused") @SuppressWarnings("unused")
private String ratingSortType; private String ratingSortType;
@ -472,21 +471,21 @@ public class MainWindowController {
@FXML @FXML
private void updateBtnAction(){ private void updateBtnAction(){
// Updater.update(buildURL, downloadLink, aktBuildNumber, buildNumber);
System.out.println(Updater.getState()); System.out.println(Updater.getState());
if(Updater.getState() == State.NEW){ if(Updater.getState() == State.NEW){
Updater.start(); Updater.start();
}else{ }else{
Updater.run(); Updater.run();
} }
} }
@FXML @FXML
private void autoupdateBtnAction(){ private void autoupdateBtnAction(){
if(autoUpdate.equals("0")){ if(autoUpdate){
setAutoUpdate("1"); setAutoUpdate(false);
}else{ }else{
setAutoUpdate("0"); setAutoUpdate(true);
} }
saveSettings(); saveSettings();
} }
@ -519,7 +518,7 @@ public class MainWindowController {
//"Main" Method called in Main.java main() when starting //"Main" Method called in Main.java main() when starting
void setMain(Main main) { void setMain(Main main) {
this.main = main; this.main = main;
Updater = new updater(this,buildURL, downloadLink, aktBuildNumber, buildNumber); Updater = new updater(this,buildURL, downloadLink, buildNumber);
dbController = new DBController(this); dbController = new DBController(this);
ApiQuery = new apiQuery(this, dbController); ApiQuery = new apiQuery(this, dbController);
} }
@ -760,10 +759,14 @@ public class MainWindowController {
updateBtn.setFont(Font.font("System", 12)); updateBtn.setFont(Font.font("System", 12));
cbLocal.setItems(locals); cbLocal.setItems(locals);
//TODO rework! if(autoUpdate){
if(autoUpdate.equals("1")){
autoupdateBtn.setSelected(true); autoupdateBtn.setSelected(true);
Updater.start(); try {
Updater.start();
Updater.join();
} catch (InterruptedException e) {
e.printStackTrace();
}
}else{ }else{
autoupdateBtn.setSelected(false); autoupdateBtn.setSelected(false);
} }
@ -1022,7 +1025,7 @@ public class MainWindowController {
try { try {
props.setProperty("path", getPath()); //writes path into property props.setProperty("path", getPath()); //writes path into property
props.setProperty("color", getColor()); props.setProperty("color", getColor());
props.setProperty("autoUpdate", getAutoUpdate()); props.setProperty("autoUpdate", String.valueOf(isAutoUpdate()));
props.setProperty("size", getSize().toString()); props.setProperty("size", getSize().toString());
props.setProperty("local", getLocal()); props.setProperty("local", getLocal());
props.setProperty("streamingPath", getStreamingPath()); props.setProperty("streamingPath", getStreamingPath());
@ -1058,7 +1061,7 @@ public class MainWindowController {
streamingPath = props.getProperty("streamingPath"); streamingPath = props.getProperty("streamingPath");
color = props.getProperty("color"); color = props.getProperty("color");
size = Double.parseDouble(props.getProperty("size")); size = Double.parseDouble(props.getProperty("size"));
autoUpdate = props.getProperty("autoUpdate"); autoUpdate = Boolean.parseBoolean(props.getProperty("autoUpdate"));
local = props.getProperty("local"); local = props.getProperty("local");
mode = props.getProperty("mode"); mode = props.getProperty("mode");
ratingSortType = props.getProperty("ratingSortType"); ratingSortType = props.getProperty("ratingSortType");
@ -1068,7 +1071,7 @@ public class MainWindowController {
showErrorMsg(errorSave, e); showErrorMsg(errorSave, e);
e.printStackTrace(); e.printStackTrace();
} }
// showErrorMsg(errorLoad, e); //TODO das soll beim ersten start nicht erscheinen // showErrorMsg(errorLoad, e); //TODO This should not be visible at first startup
} }
} }
@ -1113,11 +1116,11 @@ public class MainWindowController {
return size; return size;
} }
public void setAutoUpdate(String input){ public void setAutoUpdate(boolean input){
this.autoUpdate = input; this.autoUpdate = input;
} }
public String getAutoUpdate(){ public boolean isAutoUpdate(){
return autoUpdate; return autoUpdate;
} }

View File

@ -12,43 +12,51 @@ import java.net.URL;
import java.nio.channels.Channels; import java.nio.channels.Channels;
import java.nio.channels.ReadableByteChannel; import java.nio.channels.ReadableByteChannel;
import javafx.application.Platform;
public class updater extends Thread{ public class updater extends Thread{
private MainWindowController mainWindowController; private MainWindowController mainWindowController;
private String buildURL; private String buildURL;
private String downloadLink; private String downloadLink;
private String aktBuildNumber; private String updateBuildNumber;
private String buildNumber; private String buildNumber;
public updater(MainWindowController m, String buildURL,String downloadLink,String aktBuildNumber,String buildNumber){ public updater(MainWindowController m, String buildURL,String downloadLink,String buildNumber){
mainWindowController=m; mainWindowController=m;
this.buildURL=buildURL; this.buildURL=buildURL;
this.downloadLink=downloadLink; this.downloadLink=downloadLink;
this.aktBuildNumber=aktBuildNumber;
this.buildNumber=buildNumber; this.buildNumber=buildNumber;
} }
public void run(){ public void run(){
System.out.println("check for updates ..."); System.out.println("check for updates ...");
Platform.runLater(() -> {
mainWindowController.updateBtn.setText(mainWindowController.bundle.getString("checkingUpdates"));
});
try { try {
URL url = new URL(buildURL); //URL der Datei mit aktueller Versionsnummer URL url = new URL(buildURL); //URL of the text file with the current build number
BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream())); BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
aktBuildNumber = in.readLine(); //schreibt inputstream in String updateBuildNumber = in.readLine(); //write InputStream in String
in.close(); in.close();
} catch (IOException e1) { } catch (IOException e1) {
mainWindowController.showErrorMsg(mainWindowController.errorUpdateV, e1); mainWindowController.showErrorMsg(mainWindowController.errorUpdateV, e1);
} }
System.out.println("Build: "+buildNumber+", Update: "+aktBuildNumber); System.out.println("Build: "+buildNumber+", Update: "+updateBuildNumber);
//vergleicht die Versionsnummern, bei aktversion > version wird ein Update durchgrf<EFBFBD>hrt //Compares the program BuildNumber with the current BuildNumber if program BuildNumber < current BuildNumber then perform a update
int iversion = Integer.parseInt(buildNumber); int iversion = Integer.parseInt(buildNumber);
int iaktVersion = Integer.parseInt(aktBuildNumber.replace(".", "")); int iaktVersion = Integer.parseInt(updateBuildNumber.replace(".", ""));
if(iversion >= iaktVersion){ if(iversion >= iaktVersion){
// mainWindowController.updateBtn.setText(mainWindowController.bundle.getString("updateBtnNotavail")); Platform.runLater(() -> {
mainWindowController.updateBtn.setText(mainWindowController.bundle.getString("updateBtnNotavail"));
});
System.out.println("no update available"); System.out.println("no update available");
}else{ }else{
// mainWindowController.updateBtn.setText(mainWindowController.bundle.getString("updateBtnavail")); Platform.runLater(() -> {
mainWindowController.updateBtn.setText(mainWindowController.bundle.getString("updateBtnavail"));
});
System.out.println("update available"); System.out.println("update available");
try { try {
URL website; URL website;
@ -57,7 +65,7 @@ public class updater extends Thread{
String updateDataURL = in.readLine(); String updateDataURL = in.readLine();
website = new URL(updateDataURL); //Update URL website = new URL(updateDataURL); //Update URL
ReadableByteChannel rbc = Channels.newChannel(website.openStream()); //open new Stream/Channel ReadableByteChannel rbc = Channels.newChannel(website.openStream()); //open new Stream/Channel
FileOutputStream fos = new FileOutputStream("ProjectHomeFlix.jar"); //nea fileoutputstram for ProjectHomeFLix.jar FileOutputStream fos = new FileOutputStream("ProjectHomeFlix.jar"); //new FileOutputStream for ProjectHomeFLix.jar
fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE); //gets file from 0 to max size fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE); //gets file from 0 to max size
fos.close(); //close fos (extrem wichtig!) fos.close(); //close fos (extrem wichtig!)
Runtime.getRuntime().exec("java -jar ProjectHomeFlix.jar"); //start again Runtime.getRuntime().exec("java -jar ProjectHomeFlix.jar"); //start again

View File

@ -8,6 +8,7 @@ openFolder = Ordner \u00F6ffnen
chooseFolder = Ordner ausw\u00E4hlen chooseFolder = Ordner ausw\u00E4hlen
fontSize = Schriftgr\u00F6\u00DFe: fontSize = Schriftgr\u00F6\u00DFe:
checkUpdates = Auf Update pr\u00FCfen checkUpdates = Auf Update pr\u00FCfen
checkingUpdates = Es wird nach Updates gesucht...
updateBtnavail = Update verf\u00FCgbar updateBtnavail = Update verf\u00FCgbar
updateBtnNotavail = Kein Update verf\u00FCgbar updateBtnNotavail = Kein Update verf\u00FCgbar
autoUpdate = beim Start nach Updates suchen: autoUpdate = beim Start nach Updates suchen:

View File

@ -8,6 +8,7 @@ openFolder = open Folder
chooseFolder = choose Directory chooseFolder = choose Directory
fontSize = font size: fontSize = font size:
checkUpdates = check for updates checkUpdates = check for updates
checkingUpdates = checking for updates...
updateBtnavail = update available updateBtnavail = update available
updateBtnNotavail = no update available updateBtnNotavail = no update available
autoUpdate = check at startup for updates: autoUpdate = check at startup for updates: