diff --git a/src/at/chaosfield/packupdate/FileManager.java b/src/at/chaosfield/packupdate/FileManager.java index 572bd95..4a07905 100644 --- a/src/at/chaosfield/packupdate/FileManager.java +++ b/src/at/chaosfield/packupdate/FileManager.java @@ -1,6 +1,7 @@ package at.chaosfield.packupdate; import java.io.*; +import java.net.HttpURLConnection; import java.net.URL; import java.util.HashMap; import java.util.Map; @@ -95,7 +96,53 @@ public static BufferedReader getLocalFile(String fileName) throws IOException{ //Download a binary file to a given location public static void downloadFile(String fileUrl, String destination) throws IOException{ - FileUtils.copyURLToFile(new URL(fileUrl), new File(destination)); + //FileUtils.copyURLToFile(new URL(fileUrl), new File(destination)); + + OutputStream outStream = null; + HttpURLConnection urlCon = null; + + InputStream inStream = null; + try { + byte[] buf; + int byteRead, byteWritten = 0; + outStream = new BufferedOutputStream(new FileOutputStream(destination)); + + URL url, base, next; + String location; + + while(true){ + url = new URL(fileUrl); + urlCon = (HttpURLConnection) url.openConnection(); + urlCon.setConnectTimeout(15000); + urlCon.setReadTimeout(15000); + urlCon.setInstanceFollowRedirects(false); + + switch(urlCon.getResponseCode()){ + case HttpURLConnection.HTTP_MOVED_PERM: + case HttpURLConnection.HTTP_MOVED_TEMP: + case 307: + location = urlCon.getHeaderField("Location"); + base = new URL(fileUrl); + next = new URL(base, location); + fileUrl = next.toExternalForm(); + continue; + } + + break; + } + + inStream = urlCon.getInputStream(); + buf = new byte[1024]; + while ((byteRead = inStream.read(buf)) != -1) { + outStream.write(buf, 0, byteRead); + byteWritten += byteRead; + } + }finally { + if(inStream != null) + inStream.close(); + if(outStream != null) + outStream.close(); + } } //Parse a PackInfo CSV file "name,version,download url,type" diff --git a/src/at/chaosfield/packupdate/PackUpdate.java b/src/at/chaosfield/packupdate/PackUpdate.java index 1307367..635d2d6 100644 --- a/src/at/chaosfield/packupdate/PackUpdate.java +++ b/src/at/chaosfield/packupdate/PackUpdate.java @@ -55,6 +55,7 @@ public void initRootLayout(){ Scene scene = new Scene(rootLayout); primaryStage.setScene(scene); + primaryStage.setResizable(false); primaryStage.show(); ((FxController) loader.getController()).setMain(this); diff --git a/src/version.txt b/src/version.txt index c0943d3..7208c21 100644 --- a/src/version.txt +++ b/src/version.txt @@ -1 +1 @@ -2.3 \ No newline at end of file +2.4 \ No newline at end of file