mirror of
https://github.com/SKCraft/Launcher.git
synced 2024-11-27 12:46:22 +01:00
Verify libraries & game jars during updates
This commit is contained in:
parent
3981fe4ab2
commit
15a87f0df3
@ -0,0 +1,42 @@
|
||||
package com.skcraft.launcher.install;
|
||||
|
||||
import com.skcraft.launcher.Launcher;
|
||||
import com.skcraft.launcher.LauncherException;
|
||||
import com.skcraft.launcher.util.FileUtils;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.java.Log;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
@RequiredArgsConstructor
|
||||
@Log
|
||||
public class FileVerify implements InstallTask {
|
||||
private final File target;
|
||||
private final String name;
|
||||
private final String hash;
|
||||
|
||||
@Override
|
||||
public void execute(Launcher launcher) throws Exception {
|
||||
log.info("Verifying file " + name);
|
||||
|
||||
String actualHash = FileUtils.getShaHash(target);
|
||||
if (!actualHash.equals(hash)) {
|
||||
String message = String.format(
|
||||
"File %s (%s) is corrupt (invalid hash)\n" +
|
||||
"Expected '%s'\nGot '%s'",
|
||||
name, target.getAbsolutePath(), hash, actualHash);
|
||||
|
||||
throw new LauncherException(message, message);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getProgress() {
|
||||
return -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getStatus() {
|
||||
return "Verifying " + name;
|
||||
}
|
||||
}
|
@ -145,6 +145,7 @@ public class Library {
|
||||
private String path;
|
||||
private String url;
|
||||
private String sha1;
|
||||
private int size;
|
||||
}
|
||||
|
||||
@Data
|
||||
|
@ -147,14 +147,19 @@ public abstract class BaseUpdater {
|
||||
}
|
||||
|
||||
protected void installJar(@NonNull Installer installer,
|
||||
@NonNull VersionManifest.Artifact artifact,
|
||||
@NonNull File jarFile,
|
||||
@NonNull URL url) throws InterruptedException {
|
||||
// If the JAR does not exist, install it
|
||||
if (!jarFile.exists()) {
|
||||
List<File> targets = new ArrayList<File>();
|
||||
long size = artifact.getSize();
|
||||
if (size <= 0) size = JAR_SIZE_ESTIMATE;
|
||||
|
||||
File tempFile = installer.getDownloader().download(url, "", JAR_SIZE_ESTIMATE, jarFile.getName());
|
||||
File tempFile = installer.getDownloader().download(url, "", size, jarFile.getName());
|
||||
installer.queue(new FileMover(tempFile, jarFile));
|
||||
if (artifact.getHash() != null) {
|
||||
installer.queue(new FileVerify(jarFile, jarFile.getName(), artifact.getHash()));
|
||||
}
|
||||
log.info("Installing " + jarFile.getName() + " from " + url);
|
||||
}
|
||||
}
|
||||
@ -217,7 +222,12 @@ public abstract class BaseUpdater {
|
||||
if (library.matches(environment)) {
|
||||
checkInterrupted();
|
||||
|
||||
String path = library.getPath(environment);
|
||||
Library.Artifact artifact = library.getArtifact(environment);
|
||||
String path = artifact.getPath();
|
||||
|
||||
long size = artifact.getSize();
|
||||
if (size <= 0) size = LIBRARY_SIZE_ESTIMATE;
|
||||
|
||||
File targetFile = new File(librariesDir, path);
|
||||
|
||||
if (!targetFile.exists()) {
|
||||
@ -230,10 +240,13 @@ public abstract class BaseUpdater {
|
||||
}
|
||||
}
|
||||
|
||||
File tempFile = installer.getDownloader().download(urls, "", LIBRARY_SIZE_ESTIMATE,
|
||||
File tempFile = installer.getDownloader().download(urls, "", size,
|
||||
library.getName() + ".jar");
|
||||
log.info("Fetching " + path + " from " + urls);
|
||||
installer.queue(new FileMover( tempFile, targetFile));
|
||||
installer.queue(new FileMover(tempFile, targetFile));
|
||||
if (artifact.getSha1() != null) {
|
||||
installer.queue(new FileVerify(targetFile, library.getName(), artifact.getSha1()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -176,9 +176,10 @@ public class Updater extends BaseUpdater implements Callable<Instance>, Progress
|
||||
|
||||
// Install the .jar
|
||||
File jarPath = launcher.getJarPath(version);
|
||||
URL jarSource = url(version.getDownloads().get("client").getUrl());
|
||||
VersionManifest.Artifact clientJar = version.getDownloads().get("client");
|
||||
URL jarSource = url(clientJar.getUrl());
|
||||
log.info("JAR at " + jarPath.getAbsolutePath() + ", fetched from " + jarSource);
|
||||
installJar(installer, jarPath, jarSource);
|
||||
installJar(installer, clientJar, jarPath, jarSource);
|
||||
|
||||
// Download libraries
|
||||
log.info("Enumerating libraries to download...");
|
||||
|
Loading…
Reference in New Issue
Block a user