-
Notifications
You must be signed in to change notification settings - Fork 0
/
FalconUpdater.java
37 lines (31 loc) · 1.27 KB
/
FalconUpdater.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package fr.voidnetwork.falcon.centralisation.updater;
import fr.voidnetwork.falcon.centralisation.updater.security.KeyManager;
import java.io.BufferedInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.net.URL;
public class FalconUpdater {
private final String webSite = "";
private final String pluginName = "Falcon";
public FalconUpdater () {}
public void update(){
try {
new KeyManager().onDownload();
download(this.webSite, "plugins/" + this.pluginName + ".jar");
System.out.println("[Updater] Update downloaded successfully.");
} catch (IOException e) {
System.out.println("Failed to download update: " + e.getMessage());
}
}
private void download(String url, String output) throws IOException {
try (BufferedInputStream in = new BufferedInputStream(new URL(url).openStream());
FileOutputStream fileOutputStream = new FileOutputStream(output)) {
byte[] dataBuffer = new byte[1024];
int bytesRead;
while ((bytesRead = in.read(dataBuffer, 0, 1024)) != -1) {
fileOutputStream.write(dataBuffer, 0, bytesRead);
}
new KeyManager().onFinishedDownload();
}
}
}