Skip to content

Commit 290acdf

Browse files
committed
fix: move tools download to github
1 parent c13a611 commit 290acdf

File tree

3 files changed

+24
-47
lines changed

3 files changed

+24
-47
lines changed

baseDownload

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
http://astuteinternet.dl.sourceforge.net/project/kmttg
1+
https://github.com/lart2150/kmttg/releases/download/v2.9-l/

src/com/tivo/kmttg/install/baseDownload.java

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,29 +18,30 @@
1818
*/
1919
package com.tivo.kmttg.install;
2020

21-
import java.io.BufferedReader;
22-
import java.io.InputStreamReader;
23-
import java.net.URI;
24-
import java.net.URL;
25-
import java.net.URLConnection;
21+
import org.apache.hc.client5.http.classic.HttpClient;
22+
import org.apache.hc.client5.http.classic.methods.HttpGet;
23+
import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse;
24+
import org.apache.hc.client5.http.impl.classic.HttpClientBuilder;
25+
import org.apache.hc.core5.http.io.entity.EntityUtils;
2626

2727
import com.tivo.kmttg.util.debug;
28+
import com.tivo.kmttg.util.log;
2829

2930
public class baseDownload {
3031
public static String getBase() {
3132
debug.print("");
3233
String base = null;
33-
String base_url = "http://svn.code.sf.net/p/kmttg/code/trunk/baseDownload";
34+
String base_url = "https://raw.githubusercontent.com/lart2150/kmttg/refs/heads/master/baseDownload";
3435
try {
35-
URL url = new URI(base_url).toURL();
36-
URLConnection con = url.openConnection();
37-
BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
38-
String inputLine;
39-
while ((inputLine = in.readLine()) != null)
40-
base = inputLine;
41-
in.close();
36+
HttpClientBuilder httpClientBuilder = HttpClientBuilder.create();
37+
HttpClient httpClient = httpClientBuilder.build();
38+
HttpGet httpget = new HttpGet(base_url);
39+
try (CloseableHttpResponse response = (CloseableHttpResponse) httpClient.execute(httpget)) {
40+
base = EntityUtils.toString(response.getEntity()).trim();
41+
}
4242
} catch (Exception ex) {
4343
base = null;
44+
log.error("Error getting tool download path");
4445
}
4546
return base;
4647
}

src/com/tivo/kmttg/install/toolDownload.java

Lines changed: 9 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@
2525
import java.net.ConnectException;
2626
import java.net.MalformedURLException;
2727
import java.net.NoRouteToHostException;
28-
import java.net.URI;
29-
import java.net.URL;
30-
import java.net.URLConnection;
3128

32-
import javafx.application.Platform;
29+
import org.apache.hc.client5.http.classic.HttpClient;
30+
import org.apache.hc.client5.http.classic.methods.HttpGet;
31+
import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse;
32+
import org.apache.hc.client5.http.impl.classic.HttpClientBuilder;
3333

3434
import com.tivo.kmttg.main.config;
3535
import com.tivo.kmttg.util.debug;
@@ -46,7 +46,6 @@ public String download(String dir, String os) {
4646
log.error("toolDownload - error retrieving base download URL");
4747
return null;
4848
}
49-
base += "/tools/";
5049
debug.print("dir=" + dir + " os=" + os);
5150
String urlString = null;
5251
String localFileName = null;
@@ -80,39 +79,16 @@ public String download(String dir, String os) {
8079
private Boolean downloadUrl(String urlString, String localFileName) {
8180
BufferedInputStream in = null;
8281
RandomAccessFile out = null;
83-
Integer size = 0;
84-
int BLOCK_SIZE = 4096;
8582
try {
86-
URL url = new URI(urlString).toURL();
8783
log.warn("Downloading file: " + urlString + " ...");
88-
URLConnection con = url.openConnection();
89-
size = con.getContentLength();
84+
HttpClientBuilder httpClientBuilder = HttpClientBuilder.create();
85+
HttpClient httpClient = httpClientBuilder.build();
86+
HttpGet httpget = new HttpGet(urlString);
9087

91-
in = new BufferedInputStream(con.getInputStream());
88+
CloseableHttpResponse response = (CloseableHttpResponse) httpClient.execute(httpget);
89+
in = new BufferedInputStream(response.getEntity().getContent());
9290
out = new RandomAccessFile(localFileName, "rw");
9391

94-
Integer howManyBytes;
95-
Integer readSoFar = 0;
96-
byte[] bytesIn = new byte[BLOCK_SIZE];
97-
int last_pct = 0;
98-
99-
while ((howManyBytes = in.read(bytesIn)) >= 0) {
100-
out.write(bytesIn, 0, howManyBytes);
101-
readSoFar += howManyBytes;
102-
Float f = 100*readSoFar.floatValue()/size.floatValue();
103-
final Integer pct = f.intValue();
104-
final String title = String.format("download: %d%% %s", pct, config.kmttg);
105-
if (pct % 5 == 0 && pct > last_pct) {
106-
last_pct += 5;
107-
Platform.runLater(new Runnable() {
108-
@Override public void run() {
109-
config.gui.progressBar_setValue(pct);
110-
config.gui.setTitle(title);
111-
}
112-
});
113-
}
114-
}
115-
11692
// Done
11793
in.close();
11894
out.close();

0 commit comments

Comments
 (0)