Skip to content

Commit

Permalink
reworked update download
Browse files Browse the repository at this point in the history
*added progress indicator for downloads
  • Loading branch information
Seil0 committed Apr 25, 2017
1 parent 853daaf commit 8786b8e
Show file tree
Hide file tree
Showing 18 changed files with 37 additions and 12 deletions.
1 change: 1 addition & 0 deletions .classpath
Original file line number Diff line number Diff line change
Expand Up @@ -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 change: 1 addition & 0 deletions bin/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/application/
Binary file modified bin/application/DBController.class
Binary file not shown.
Binary file modified bin/application/Main.class
Binary file not shown.
Binary file modified bin/application/MainWindowController$1.class
Binary file not shown.
Binary file modified bin/application/MainWindowController$2.class
Binary file not shown.
Binary file modified bin/application/MainWindowController$3.class
Binary file not shown.
Binary file modified bin/application/MainWindowController$4.class
Binary file not shown.
Binary file modified bin/application/MainWindowController$5.class
Binary file not shown.
Binary file modified bin/application/MainWindowController$6.class
Binary file not shown.
Binary file modified bin/application/MainWindowController$7.class
Binary file not shown.
Binary file modified bin/application/MainWindowController.class
Binary file not shown.
Binary file modified bin/application/updater.class
Binary file not shown.
Binary file added bin/libraries/commons-io-2.5.jar
Binary file not shown.
5 changes: 4 additions & 1 deletion src/application/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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();
}
Expand All @@ -78,6 +80,7 @@ private void mainWindow(){

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
Expand Down
11 changes: 10 additions & 1 deletion src/application/MainWindowController.java
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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;
Expand Down Expand Up @@ -1137,4 +1138,12 @@ public void setMode(String input){
public String getMode(){
return mode;
}

public String getCurrentWorkingDirectory() {
return currentWorkingDirectory;
}

public void setCurrentWorkingDirectory(String currentWorkingDirectory) {
this.currentWorkingDirectory = currentWorkingDirectory;
}
}
31 changes: 21 additions & 10 deletions src/application/updater.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -60,15 +62,24 @@ public void run(){
});
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) {
Expand Down
Binary file added src/libraries/commons-io-2.5.jar
Binary file not shown.

0 comments on commit 8786b8e

Please sign in to comment.