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

View File

@ -6,5 +6,6 @@
<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/jfoenix-1.3.0.jar"/>
<classpathentry kind="lib" path="src/libraries/commons-io-2.5.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>

1
bin/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
/application/

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -43,6 +43,7 @@ public class Main extends Application {
Stage primaryStage;
private String path;
String currentWorkingDirectory;
// private String streamingPathWin = System.getProperty("user.home") + "\\Documents\\HomeFlix";
// private String streamingPathLinux = System.getProperty("user.home") + "/HomeFlix";
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
@Override
public void start(Stage primaryStage) {
public void start(Stage primaryStage) throws IOException {
currentWorkingDirectory = new java.io.File( "." ).getCanonicalPath();
this.primaryStage = primaryStage;
mainWindow();
}
@ -78,6 +80,7 @@ public class Main extends Application {
mainWindowController = loader.getController(); //Link of FXMLController and controller class
mainWindowController.setAutoUpdate(AUTO_UPDATE); //set auto-update
mainWindowController.setCurrentWorkingDirectory(currentWorkingDirectory);
mainWindowController.setMain(this); //call setMain
/**Linux else Windows, check if directory & config exist

View File

@ -183,7 +183,7 @@ public class MainWindowController {
private boolean autoUpdate = false;
static boolean firststart = false;
private int hashA = -2055934614;
private String version = "0.5.0";
private String version = "0.5.1";
private String buildNumber = "121";
private String versionName = "plasma cow";
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 linuxBugText;
private String vlcNotInstalled;
private String currentWorkingDirectory;
private String path;
private String streamingPath;
private String color;
@ -1137,4 +1138,12 @@ public class MainWindowController {
public String getMode(){
return mode;
}
public String getCurrentWorkingDirectory() {
return currentWorkingDirectory;
}
public void setCurrentWorkingDirectory(String currentWorkingDirectory) {
this.currentWorkingDirectory = currentWorkingDirectory;
}
}

View File

@ -5,16 +5,18 @@
package application;
import java.io.BufferedReader;
import java.io.FileOutputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.nio.channels.Channels;
import java.nio.channels.ReadableByteChannel;
import javax.swing.ProgressMonitor;
import javax.swing.ProgressMonitorInputStream;
import org.apache.commons.io.FileUtils;
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{
private MainWindowController mainWindowController;
@ -60,15 +62,24 @@ public class updater extends Thread{
});
System.out.println("update available");
try {
URL website;
//get the download-Data URL
URL downloadURL = new URL(downloadLink);
BufferedReader in = new BufferedReader(new InputStreamReader(downloadURL.openStream()));
String updateDataURL = in.readLine();
website = new URL(updateDataURL); //Update URL
ReadableByteChannel rbc = Channels.newChannel(website.openStream()); //open new Stream/Channel
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.close(); //close fos (extrem wichtig!)
//open new Http connection, ProgressMonitorInputStream for downloading the data
HttpURLConnection conn = (HttpURLConnection) new URL(updateDataURL).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("ProjectHomeFlix.jar"));
//need to check if the old config file is compatible TODO
Runtime.getRuntime().exec("java -jar ProjectHomeFlix.jar"); //start again
System.exit(0); //finishes itself
} catch (IOException e) {

Binary file not shown.