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