From 1801723bdb925878cff13dd5510784780a653ca3 Mon Sep 17 00:00:00 2001 From: Jannik Date: Sun, 5 Feb 2017 17:14:34 +0100 Subject: [PATCH] fixed bug #6 fixed a bug that prevented homeflix from starting under linux --- src/application/DBController.java | 11 ++- src/application/Main.java | 115 +++++++++++++++------- src/application/MainWindowController.java | 22 ++++- 3 files changed, 106 insertions(+), 42 deletions(-) diff --git a/src/application/DBController.java b/src/application/DBController.java index 9844614..04dd231 100644 --- a/src/application/DBController.java +++ b/src/application/DBController.java @@ -49,6 +49,11 @@ public class DBController { Connection connection = null; public void main() { + if (System.getProperty("os.name").equals("Linux")) { + DB_PATH = System.getProperty("user.home") + "/HomeFlix/Homeflix.db"; + }else{ + DB_PATH = System.getProperty("user.home") + "\\Documents\\HomeFlix" + "\\" + "Homeflix.db"; + } try { // create a database connection connection = DriverManager.getConnection("jdbc:sqlite:" + DB_PATH); @@ -181,7 +186,7 @@ public class DBController { ps.close(); psS.close(); }catch (SQLException ea) { - System.err.println("Konnte nicht ausgeführt werden"); + System.err.println("Konnte nicht ausgef�hrt werden"); ea.printStackTrace(); } }else { @@ -322,7 +327,7 @@ public class DBController { String titel = items.get(i).asObject().getString("titel",""); if(streamURL.equals(filmsStreamURL.get(b))){ - System.out.println("hinzufügen \""+titel+"\""); + System.out.println("hinzuf�gen \""+titel+"\""); ps.setInt(1, items.get(i).asObject().getInt("year", 0)); ps.setInt(2, items.get(i).asObject().getInt("season", 0)); @@ -345,7 +350,7 @@ public class DBController { } void ausgeben(){ - System.out.println("Einträge ausgeben ... \n"); + System.out.println("Eintr�ge ausgeben ... \n"); try { Statement stmt = connection.createStatement(); ResultSet rs = stmt.executeQuery("SELECT * FROM film_local"); diff --git a/src/application/Main.java b/src/application/Main.java index 2590e86..a1e2c2b 100644 --- a/src/application/Main.java +++ b/src/application/Main.java @@ -46,14 +46,18 @@ public class Main extends Application { public Stage primaryStage; private String path; - private String streamingPath = System.getProperty("user.home") + "\\Documents\\HomeFlix"; + private InputStream inputStream; + private String streamingPathWin = System.getProperty("user.home") + "\\Documents\\HomeFlix"; + private String streamingPathLinux = System.getProperty("user.home") + "/HomeFlix"; private String color = "ee3523"; private String autoUpdate = "0"; private String mode = "local"; //local or streaming private double size = 12; private int local = 0; - private File dir = new File(System.getProperty("user.home") + "/Documents/HomeFlix"); //Windows: C:/Users/"User"/Documents/HomeFlix OSX: not tested yet Linux: not tested yet(shalt not work!) - private File file = new File(dir + "/config.xml"); //Windows: C:/Users/"User"/Documents/HomeFlix/config.xml OSX: not tested yet Linux: not tested yet(shalt not work!) + private File dirWin = new File(System.getProperty("user.home") + "/Documents/HomeFlix"); //Windows: C:/Users/"User"/Documents/HomeFlix OSX: not tested yet Linux: not tested yet(shalt not work!) + private File dirLinux = new File(System.getProperty("user.home") + "/HomeFlix"); + private File fileWin = new File(dirWin + "/config.xml"); //Windows: C:/Users/"User"/Documents/HomeFlix/config.xml OSX: not tested yet Linux: not tested yet(shalt not work!) + private File fileLinux = new File(dirLinux + "/config.xml"); Properties props = new Properties(); private MainWindowController mainWindowController; @@ -79,33 +83,68 @@ public class Main extends Application { mainWindowController.setMain(this); //call setMain //dir exists -> check config.xml - if(dir.exists() == true){ - if (file.exists() != true) { - mainWindowController.setPath(firstStart()); - mainWindowController.setStreamingPath(streamingPath); - mainWindowController.setColor(color); - mainWindowController.setSize(size); - mainWindowController.setAutoUpdate(autoUpdate); - mainWindowController.setLoaclUI(local); - mainWindowController.setMode(mode); - mainWindowController.saveSettings(); - Runtime.getRuntime().exec("java -jar ProjectHomeFlix.jar"); //start again (preventing Bugs) - System.exit(0); //finishes itself + if(System.getProperty("os.name").equals("Linux")){ + if(dirLinux.exists() == true){ + if (fileLinux.exists() != true) { + mainWindowController.setPath(firstStart()); + if(System.getProperty("os.name").equals("Linux")){ + mainWindowController.setStreamingPath(streamingPathLinux); + }else{ + mainWindowController.setStreamingPath(streamingPathWin); + } + mainWindowController.setColor(color); + mainWindowController.setSize(size); + mainWindowController.setAutoUpdate(autoUpdate); + mainWindowController.setLoaclUI(local); + mainWindowController.setMode(mode); + mainWindowController.saveSettings(); + Runtime.getRuntime().exec("java -jar ProjectHomeFlix.jar"); //start again (preventing Bugs) + System.exit(0); //finishes itself + }else{ + loadSettings(); + } }else{ - loadSettings(); - } + dirLinux.mkdir(); + mainWindowController.setPath(firstStart()); + mainWindowController.setStreamingPath(streamingPathLinux); + mainWindowController.setColor(color); + mainWindowController.setSize(size); + mainWindowController.setAutoUpdate(autoUpdate); + mainWindowController.setLoaclUI(local); + mainWindowController.setMode(mode); + mainWindowController.saveSettings(); + Runtime.getRuntime().exec("java -jar ProjectHomeFlix.jar"); //start again (preventing Bugs) + System.exit(0); //finishes itself + } }else{ - dir.mkdir(); - mainWindowController.setPath(firstStart()); - mainWindowController.setStreamingPath(streamingPath); - mainWindowController.setColor(color); - mainWindowController.setSize(size); - mainWindowController.setAutoUpdate(autoUpdate); - mainWindowController.setLoaclUI(local); - mainWindowController.setMode(mode); - mainWindowController.saveSettings(); - Runtime.getRuntime().exec("java -jar ProjectHomeFlix.jar"); //start again (preventing Bugs) - System.exit(0); //finishes itself + if(dirWin.exists() == true){ + if (fileWin.exists() != true) { + mainWindowController.setPath(firstStart()); + mainWindowController.setStreamingPath(streamingPathWin); + mainWindowController.setColor(color); + mainWindowController.setSize(size); + mainWindowController.setAutoUpdate(autoUpdate); + mainWindowController.setLoaclUI(local); + mainWindowController.setMode(mode); + mainWindowController.saveSettings(); + Runtime.getRuntime().exec("java -jar ProjectHomeFlix.jar"); //start again (preventing Bugs) + System.exit(0); //finishes itself + }else{ + loadSettings(); + } + }else{ + dirWin.mkdir(); + mainWindowController.setPath(firstStart()); + mainWindowController.setStreamingPath(streamingPathWin); + mainWindowController.setColor(color); + mainWindowController.setSize(size); + mainWindowController.setAutoUpdate(autoUpdate); + mainWindowController.setLoaclUI(local); + mainWindowController.setMode(mode); + mainWindowController.saveSettings(); + Runtime.getRuntime().exec("java -jar ProjectHomeFlix.jar"); //start again (preventing Bugs) + System.exit(0); //finishes itself + } } mainWindowController.loadStreamingSettings(); @@ -117,7 +156,7 @@ public class Main extends Application { mainWindowController.dbController.createDatabase(); //creating the database mainWindowController.dbController.loadData(); //loading data from database to mainWindowController -// mainWindowController.loadData(); //läd die Daten im Controller +// mainWindowController.loadData(); //l�d die Daten im Controller mainWindowController.addDataUI(); Scene scene = new Scene(pane); //create new scene, append pane to scene @@ -129,11 +168,11 @@ public class Main extends Application { } } - //methode für den erstmaligen Start + //methode f�r den erstmaligen Start private String firstStart(){ Alert alert = new Alert(AlertType.CONFIRMATION); //new alert with filechooser alert.setTitle("Project HomeFlix"); - alert.setHeaderText("Es ist kein Stammverzeichniss für Filme angegeben!"); //TODO translate + alert.setHeaderText("Es ist kein Stammverzeichniss f�r Filme angegeben!"); //TODO translate alert.setContentText("Stammverzeichniss angeben?"); Optional result = alert.showAndWait(); @@ -149,13 +188,21 @@ public class Main extends Application { return path; } - //lädt die einstellungen aus der XML + //lädt die einstellungen aus der XML public void loadSettings(){ try { - InputStream inputStream = new FileInputStream(file); + if(System.getProperty("os.name").equals("Linux")){ + inputStream = new FileInputStream(fileLinux); + }else{ + inputStream = new FileInputStream(fileWin); + } props.loadFromXML(inputStream); path = props.getProperty("path"); //setzt Propselement in Pfad - streamingPath = props.getProperty("streamingPath"); + if(System.getProperty("os.name").equals("Linux")){ + streamingPathLinux = props.getProperty("streamingPath"); + }else{ + streamingPathWin = props.getProperty("streamingPath"); + } color = props.getProperty("color"); size = Double.parseDouble(props.getProperty("size")); autoUpdate = props.getProperty("autoUpdate"); diff --git a/src/application/MainWindowController.java b/src/application/MainWindowController.java index e15517b..2fed23f 100644 --- a/src/application/MainWindowController.java +++ b/src/application/MainWindowController.java @@ -184,12 +184,14 @@ public class MainWindowController { private boolean streamingSettingsTrue = false; private int hashA = -2055934614; private String version = "0.4.99"; - private String buildNumber = "110"; + private String buildNumber = "112"; private String versionName = "plasma cow (pre Release)"; 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 dir = new File(System.getProperty("user.home") + "/Documents/HomeFlix"); - private File file = new File(dir + "/config.xml"); + private File dirWin = new File(System.getProperty("user.home") + "/Documents/HomeFlix"); + private File dirLinux = new File(System.getProperty("user.home") + "/HomeFlix"); + private File fileWin = new File(dirWin + "/config.xml"); + private File fileLinux = new File(dirLinux + "/config.xml"); String errorUpdateD; String errorUpdateV; @@ -936,6 +938,7 @@ public class MainWindowController { //saves the Settings public void saveSettings(){ + OutputStream outputStream; //new outputstream try { props.setProperty("path", getPath()); //writes path into property props.setProperty("color", getColor()); @@ -945,7 +948,11 @@ public class MainWindowController { props.setProperty("streamingPath", getStreamingPath()); props.setProperty("mode", getMode()); props.setProperty("ratingSortType", columnRating.getSortType().toString()); - OutputStream outputStream = new FileOutputStream(file); //new outputstream + if(System.getProperty("os.name").equals("Linux")){ + outputStream = new FileOutputStream(fileLinux); + }else{ + outputStream = new FileOutputStream(fileWin); + } props.storeToXML(outputStream, "Project HomeFlix settings"); //writes new .xml outputStream.close(); } catch (IOException e) { @@ -956,8 +963,13 @@ public class MainWindowController { //loads the Settings public void loadSettings(){ + InputStream inputStream; try { - InputStream inputStream = new FileInputStream(file); + if(System.getProperty("os.name").equals("Linux")){ + inputStream = new FileInputStream(fileLinux); + }else{ + inputStream = new FileInputStream(fileWin); + } props.loadFromXML(inputStream); //new inputstream from .xml path = props.getProperty("path"); //reads path from property streamingPath = props.getProperty("streamingPath");