diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/MainBuildTask.java b/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/MainBuildTask.java index dc27b3fb..f420cd7b 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/MainBuildTask.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/MainBuildTask.java @@ -8,7 +8,6 @@ import java.nio.file.Path; import java.nio.file.SimpleFileVisitor; import java.nio.file.attribute.BasicFileAttributes; -import java.util.Arrays; import java.util.Base64; import java.util.HashMap; import java.util.Map; diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/command/hash/DownloadAssetCommand.java b/LaunchServer/src/main/java/pro/gravit/launchserver/command/hash/DownloadAssetCommand.java index 78317457..77e60c26 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/command/hash/DownloadAssetCommand.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/command/hash/DownloadAssetCommand.java @@ -4,10 +4,8 @@ import java.nio.file.Path; import java.util.Collections; -import pro.gravit.launcher.profiles.ClientProfile.Version; import pro.gravit.launchserver.LaunchServer; import pro.gravit.launchserver.command.Command; -import pro.gravit.utils.HttpDownloader; import pro.gravit.utils.helper.IOHelper; import pro.gravit.utils.helper.LogHelper; diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/command/hash/DownloadClientCommand.java b/LaunchServer/src/main/java/pro/gravit/launchserver/command/hash/DownloadClientCommand.java index bc89c1c6..99c9da7f 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/command/hash/DownloadClientCommand.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/command/hash/DownloadClientCommand.java @@ -10,10 +10,8 @@ import com.google.gson.JsonElement; import pro.gravit.launcher.Launcher; import pro.gravit.launcher.profiles.ClientProfile; -import pro.gravit.launcher.profiles.ClientProfile.Version; import pro.gravit.launchserver.LaunchServer; import pro.gravit.launchserver.command.Command; -import pro.gravit.utils.HttpDownloader; import pro.gravit.utils.command.CommandException; import pro.gravit.utils.helper.IOHelper; import pro.gravit.utils.helper.LogHelper; diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/update/LauncherResponse.java b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/update/LauncherResponse.java index d5974076..e8bb79e6 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/update/LauncherResponse.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/update/LauncherResponse.java @@ -8,7 +8,6 @@ import pro.gravit.launchserver.socket.Client; import pro.gravit.launchserver.socket.response.SimpleResponse; import pro.gravit.utils.Version; -import pro.gravit.utils.helper.LogHelper; import pro.gravit.utils.helper.SecurityHelper; public class LauncherResponse extends SimpleResponse { diff --git a/Launcher/src/main/java/pro/gravit/launcher/LauncherAgent.java b/Launcher/src/main/java/pro/gravit/launcher/LauncherAgent.java index d6664146..317bd48a 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/LauncherAgent.java +++ b/Launcher/src/main/java/pro/gravit/launcher/LauncherAgent.java @@ -6,9 +6,6 @@ import java.nio.file.Path; import java.util.jar.JarFile; -import cpw.mods.fml.SafeExitJVMLegacy; -import net.minecraftforge.fml.SafeExitJVM; -import pro.gravit.launcher.utils.NativeJVMHalt; import pro.gravit.utils.helper.LogHelper; @LauncherAPI diff --git a/LauncherCore/src/main/java/pro/gravit/utils/HTTPRequest.java b/LauncherCore/src/main/java/pro/gravit/utils/HTTPRequest.java index 59077f26..97a33fe8 100644 --- a/LauncherCore/src/main/java/pro/gravit/utils/HTTPRequest.java +++ b/LauncherCore/src/main/java/pro/gravit/utils/HTTPRequest.java @@ -6,7 +6,6 @@ import java.io.OutputStreamWriter; import java.net.HttpURLConnection; import java.net.URL; -import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; import com.google.gson.JsonElement; diff --git a/LauncherCore/src/main/java/pro/gravit/utils/HttpDownloader.java b/LauncherCore/src/main/java/pro/gravit/utils/HttpDownloader.java index 6fffb2e6..58b7d7fd 100644 --- a/LauncherCore/src/main/java/pro/gravit/utils/HttpDownloader.java +++ b/LauncherCore/src/main/java/pro/gravit/utils/HttpDownloader.java @@ -1,59 +1,59 @@ package pro.gravit.utils; import java.io.BufferedInputStream; -import java.io.FileOutputStream; import java.io.IOException; +import java.io.OutputStream; import java.net.URL; import java.nio.file.Path; -import java.util.Observable; import java.util.concurrent.atomic.AtomicInteger; +import java.util.function.Consumer; import java.util.zip.ZipEntry; import java.util.zip.ZipInputStream; import pro.gravit.utils.helper.IOHelper; import pro.gravit.utils.helper.LogHelper; -public final class HttpDownloader extends Observable { - public static final int BUFER_SIZE = 8192; - public static final int INTERVAL = 300; - public AtomicInteger writed = new AtomicInteger(0); - private String filename; - public Thread thread; +public final class HttpDownloader { + public static final int INTERVAL = 500; + public final AtomicInteger writed; + private volatile String filename; + public final Thread thread; - public HttpDownloader(URL url, String file) { - Runnable run = () -> { + public HttpDownloader(URL url, Path file) { + writed = new AtomicInteger(0); + filename = null; + thread = new Thread(() -> { try { - filename = file; - downloadFile(url, file); + filename = IOHelper.getFileName(file); + downloadFile(url, file, writed::set); } catch (IOException e) { e.printStackTrace(); } - }; - Thread downloader = new Thread(run); - thread = downloader; - downloader.start(); + }); + thread.setDaemon(true); + thread.start(); } - public synchronized String getFilename() { + public String getFilename() { return filename; } - public void downloadFile(URL url, String file) throws IOException { - try (BufferedInputStream in = new BufferedInputStream(url.openStream()); FileOutputStream fout = new FileOutputStream(file)) { + public static void downloadFile(URL url, Path file, Consumer chanheTrack) throws IOException { + try (BufferedInputStream in = new BufferedInputStream(url.openStream()); OutputStream fout = IOHelper.newOutput(file, false)) { - final byte[] data = new byte[BUFER_SIZE]; + final byte[] data = new byte[IOHelper.BUFFER_SIZE]; int count; long timestamp = System.currentTimeMillis(); int writed_local = 0; - while ((count = in.read(data, 0, BUFER_SIZE)) != -1) { + while ((count = in.read(data, 0, IOHelper.BUFFER_SIZE)) != -1) { fout.write(data, 0, count); writed_local += count; if (System.currentTimeMillis() - timestamp > INTERVAL) { - writed.set(writed_local); + chanheTrack.accept(writed_local); LogHelper.debug("Downloaded %d", writed_local); } } - writed.set(writed_local); + chanheTrack.accept(writed_local); } }