From d21558e316e197ea2d5e20591cbeeae026f9a140 Mon Sep 17 00:00:00 2001 From: zaxar163 Date: Sun, 2 Dec 2018 17:16:23 +0300 Subject: [PATCH] Unpack hashing fixed. --- .../java/ru/gravit/utils/helper/UnpackHelper.java | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/libLauncher/src/main/java/ru/gravit/utils/helper/UnpackHelper.java b/libLauncher/src/main/java/ru/gravit/utils/helper/UnpackHelper.java index a14343ef..62f0c45c 100644 --- a/libLauncher/src/main/java/ru/gravit/utils/helper/UnpackHelper.java +++ b/libLauncher/src/main/java/ru/gravit/utils/helper/UnpackHelper.java @@ -1,24 +1,25 @@ package ru.gravit.utils.helper; import java.io.IOException; +import java.io.InputStream; import java.net.URL; import java.nio.file.Path; import java.util.Arrays; public class UnpackHelper { - @SuppressWarnings("ResultOfMethodCallIgnored") public static boolean unpack(URL resource, Path target) throws IOException { - byte[] orig = IOHelper.read(resource); if (IOHelper.exists(target)) { - if (matches(target, orig)) return false; + if (matches(target, resource)) return false; } if (!IOHelper.exists(target)) target.toFile().createNewFile(); - IOHelper.transfer(orig, target, false); + try (InputStream in = IOHelper.newInput(resource)) { + IOHelper.transfer(in, target, false); + } return true; } - private static boolean matches(Path target, byte[] in) { + private static boolean matches(Path target, URL in) { try { return Arrays.equals(SecurityHelper.digest(SecurityHelper.DigestAlgorithm.SHA256, in), SecurityHelper.digest(SecurityHelper.DigestAlgorithm.SHA256, target));