[FIX] Ошибка на обновление.

This commit is contained in:
Zaxar163 2019-09-15 19:38:54 +02:00
parent 22282df126
commit d210666df2
No known key found for this signature in database
GPG key ID: 1FE4F2E1F053831B

View file

@ -1,6 +1,8 @@
package pro.gravit.launcher.request.update;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;
@ -25,6 +27,9 @@ public final class LauncherRequest extends Request<LauncherRequestEvent> impleme
public int launcher_type = EXE_BINARY ? 2 : 1;
@LauncherAPI
public static final Path BINARY_PATH = IOHelper.getCodeSource(Launcher.class);
@LauncherAPI
public static final Path C_BINARY_PATH = BINARY_PATH.getParent().resolve(IOHelper.getFileName(BINARY_PATH) + ".tmp");
@LauncherAPI
public static final boolean EXE_BINARY = IOHelper.hasExtension(BINARY_PATH, "exe");
@ -52,7 +57,11 @@ public static void update(LauncherRequestEvent result) throws IOException {
}*/
try {
ListDownloader downloader = new ListDownloader();
downloader.downloadOne(result.url, BINARY_PATH);
downloader.downloadOne(result.url, C_BINARY_PATH);
try (InputStream in = IOHelper.newInput(C_BINARY_PATH)) {
IOHelper.transfer(in, BINARY_PATH);
}
Files.deleteIfExists(C_BINARY_PATH);
} catch (Throwable e) {
LogHelper.error(e);
}