mirror of
https://github.com/SKCraft/Launcher.git
synced 2024-11-27 12:46:22 +01:00
Check hash of existing file in case a download is not required.
This commit is contained in:
parent
f6fb3139a2
commit
70057607ad
@ -7,6 +7,9 @@
|
|||||||
package com.skcraft.launcher.model.modpack;
|
package com.skcraft.launcher.model.modpack;
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||||
|
import com.google.common.hash.HashFunction;
|
||||||
|
import com.google.common.hash.Hashing;
|
||||||
|
import com.google.common.io.Files;
|
||||||
import com.skcraft.launcher.install.InstallLog;
|
import com.skcraft.launcher.install.InstallLog;
|
||||||
import com.skcraft.launcher.install.InstallLogFileMover;
|
import com.skcraft.launcher.install.InstallLogFileMover;
|
||||||
import com.skcraft.launcher.install.Installer;
|
import com.skcraft.launcher.install.Installer;
|
||||||
@ -17,7 +20,7 @@ import lombok.NonNull;
|
|||||||
import org.apache.commons.io.FilenameUtils;
|
import org.apache.commons.io.FilenameUtils;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.net.MalformedURLException;
|
import java.io.IOException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
|
|
||||||
import static com.google.common.base.Preconditions.checkNotNull;
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
@ -27,6 +30,7 @@ import static com.skcraft.launcher.LauncherUtils.concat;
|
|||||||
@EqualsAndHashCode(callSuper = false)
|
@EqualsAndHashCode(callSuper = false)
|
||||||
public class FileInstall extends ManifestEntry {
|
public class FileInstall extends ManifestEntry {
|
||||||
|
|
||||||
|
private static HashFunction hf = Hashing.sha1();
|
||||||
private String version;
|
private String version;
|
||||||
private String hash;
|
private String hash;
|
||||||
private String location;
|
private String location;
|
||||||
@ -46,7 +50,7 @@ public class FileInstall extends ManifestEntry {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void install(@NonNull Installer installer, @NonNull InstallLog log,
|
public void install(@NonNull Installer installer, @NonNull InstallLog log,
|
||||||
@NonNull UpdateCache cache, @NonNull File contentDir) throws MalformedURLException {
|
@NonNull UpdateCache cache, @NonNull File contentDir) throws IOException {
|
||||||
if (getWhen() != null && !getWhen().matches()) {
|
if (getWhen() != null && !getWhen().matches()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -56,8 +60,7 @@ public class FileInstall extends ManifestEntry {
|
|||||||
String fileVersion = getImpliedVersion();
|
String fileVersion = getImpliedVersion();
|
||||||
URL url = concat(getManifest().getObjectsUrl(), getLocation());
|
URL url = concat(getManifest().getObjectsUrl(), getLocation());
|
||||||
|
|
||||||
if (!(isUserFile() && targetFile.exists()) &&
|
if (shouldUpdate(cache, targetFile)) {
|
||||||
(!targetFile.exists() || cache.mark(FilenameUtils.normalize(targetPath), fileVersion))) {
|
|
||||||
long size = this.size;
|
long size = this.size;
|
||||||
if (size <= 0) {
|
if (size <= 0) {
|
||||||
size = 10 * 1024;
|
size = 10 * 1024;
|
||||||
@ -70,4 +73,23 @@ public class FileInstall extends ManifestEntry {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean shouldUpdate(UpdateCache cache, File targetFile) throws IOException {
|
||||||
|
if (targetFile.exists() && isUserFile()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!targetFile.exists()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (hash != null) {
|
||||||
|
String existingHash = Files.hash(targetFile, hf).toString();
|
||||||
|
if (existingHash.equalsIgnoreCase(hash)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return cache.mark(FilenameUtils.normalize(getTargetPath()), getImpliedVersion());
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user