reworked update download

*added progress indicator for downloads
This commit is contained in:
Seil0
2017-04-25 23:35:20 +02:00
parent 853daafe34
commit 8786b8edef
18 changed files with 37 additions and 12 deletions
+1
View File
@@ -6,5 +6,6 @@
<classpathentry kind="lib" path="src/libraries/minimal-json-0.9.4.jar"/> <classpathentry kind="lib" path="src/libraries/minimal-json-0.9.4.jar"/>
<classpathentry kind="lib" path="src/libraries/sqlite-jdbc-3.16.1.jar"/> <classpathentry kind="lib" path="src/libraries/sqlite-jdbc-3.16.1.jar"/>
<classpathentry kind="lib" path="src/libraries/jfoenix-1.3.0.jar"/> <classpathentry kind="lib" path="src/libraries/jfoenix-1.3.0.jar"/>
<classpathentry kind="lib" path="src/libraries/commons-io-2.5.jar"/>
<classpathentry kind="output" path="bin"/> <classpathentry kind="output" path="bin"/>
</classpath> </classpath>
+1
View File
@@ -0,0 +1 @@
/application/
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.
Binary file not shown.
+4 -1
View File
@@ -43,6 +43,7 @@ public class Main extends Application {
Stage primaryStage; Stage primaryStage;
private String path; private String path;
String currentWorkingDirectory;
// 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";
@@ -60,7 +61,8 @@ public class Main extends Application {
private String dirLinux = System.getProperty("user.home") + "/HomeFlix"; //Linux: /home/"User"/HomeFlix private String dirLinux = System.getProperty("user.home") + "/HomeFlix"; //Linux: /home/"User"/HomeFlix
@Override @Override
public void start(Stage primaryStage) { public void start(Stage primaryStage) throws IOException {
currentWorkingDirectory = new java.io.File( "." ).getCanonicalPath();
this.primaryStage = primaryStage; this.primaryStage = primaryStage;
mainWindow(); mainWindow();
} }
@@ -78,6 +80,7 @@ public class Main extends Application {
mainWindowController = loader.getController(); //Link of FXMLController and controller class mainWindowController = loader.getController(); //Link of FXMLController and controller class
mainWindowController.setAutoUpdate(AUTO_UPDATE); //set auto-update mainWindowController.setAutoUpdate(AUTO_UPDATE); //set auto-update
mainWindowController.setCurrentWorkingDirectory(currentWorkingDirectory);
mainWindowController.setMain(this); //call setMain mainWindowController.setMain(this); //call setMain
/**Linux else Windows, check if directory & config exist /**Linux else Windows, check if directory & config exist
+10 -1
View File
@@ -183,7 +183,7 @@ public class MainWindowController {
private boolean autoUpdate = 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.1";
private String buildNumber = "121"; private String buildNumber = "121";
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 buildURL = "https://raw.githubusercontent.com/Seil0/Project-HomeFlix/master/updates/buildNumber.txt";
@@ -204,6 +204,7 @@ public class MainWindowController {
private String infoText; private String infoText;
private String linuxBugText; private String linuxBugText;
private String vlcNotInstalled; private String vlcNotInstalled;
private String currentWorkingDirectory;
private String path; private String path;
private String streamingPath; private String streamingPath;
private String color; private String color;
@@ -1137,4 +1138,12 @@ public class MainWindowController {
public String getMode(){ public String getMode(){
return mode; return mode;
} }
public String getCurrentWorkingDirectory() {
return currentWorkingDirectory;
}
public void setCurrentWorkingDirectory(String currentWorkingDirectory) {
this.currentWorkingDirectory = currentWorkingDirectory;
}
} }
+21 -10
View File
@@ -5,16 +5,18 @@
package application; package application;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.FileOutputStream; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL; import java.net.URL;
import java.nio.channels.Channels; import javax.swing.ProgressMonitor;
import java.nio.channels.ReadableByteChannel; import javax.swing.ProgressMonitorInputStream;
import org.apache.commons.io.FileUtils;
import javafx.application.Platform; import javafx.application.Platform;
//TODO rework the process after the update is downloaded, need to replace the old config.xml
public class updater extends Thread{ public class updater extends Thread{
private MainWindowController mainWindowController; private MainWindowController mainWindowController;
@@ -60,15 +62,24 @@ public class updater extends Thread{
}); });
System.out.println("update available"); System.out.println("update available");
try { try {
URL website; //get the download-Data URL
URL downloadURL = new URL(downloadLink); URL downloadURL = new URL(downloadLink);
BufferedReader in = new BufferedReader(new InputStreamReader(downloadURL.openStream())); BufferedReader in = new BufferedReader(new InputStreamReader(downloadURL.openStream()));
String updateDataURL = in.readLine(); String updateDataURL = in.readLine();
website = new URL(updateDataURL); //Update URL
ReadableByteChannel rbc = Channels.newChannel(website.openStream()); //open new Stream/Channel //open new Http connection, ProgressMonitorInputStream for downloading the data
FileOutputStream fos = new FileOutputStream("ProjectHomeFlix.jar"); //new FileOutputStream for ProjectHomeFLix.jar HttpURLConnection conn = (HttpURLConnection) new URL(updateDataURL).openConnection();
fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE); //gets file from 0 to max size ProgressMonitorInputStream pmis = new ProgressMonitorInputStream(null, "Downloading...", conn.getInputStream());
fos.close(); //close fos (extrem wichtig!) 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("ProjectHomeFlix.jar"));
//need to check if the old config file is compatible TODO
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) {
Binary file not shown.