use of net.technicpack.launchercore.install.verifiers.SHA1FileVerifier in project LauncherV3 by TechnicPack.
the class EnsureJavaRuntimeManifestTask method runTask.
@Override
public void runTask(InstallTasksQueue queue) throws IOException {
MojangVersion version = ((InstallTasksQueue<MojangVersion>) queue).getMetadata();
JavaVersion wantedRuntime = version.getJavaVersion();
if (wantedRuntime == null) {
// Nothing to do here, this version doesn't have a Mojang JRE
return;
}
final String runtimeName = wantedRuntime.getComponent();
JavaRuntimes availableRuntimes = MojangUtils.getJavaRuntimes();
if (availableRuntimes == null) {
throw new DownloadException("Failed to get Mojang JRE information");
}
JavaRuntime runtime = availableRuntimes.getRuntimeForCurrentOS(runtimeName);
Download manifest = runtime.getManifest();
File output = new File(runtimesDirectory + File.separator + "manifests", runtimeName + ".json");
(new File(output.getParent())).mkdirs();
IFileVerifier fileVerifier = new SHA1FileVerifier(manifest.getSha1());
if (!output.exists() || !fileVerifier.isFileValid(output)) {
examineJavaQueue.addTask(new DownloadFileTask(manifest.getUrl(), output, fileVerifier));
}
examineJavaQueue.addTask(new InstallJavaRuntimeTask(modpack, runtimesDirectory, output, runtimeName, examineJavaQueue, downloadJavaQueue));
}
use of net.technicpack.launchercore.install.verifiers.SHA1FileVerifier in project LauncherV3 by TechnicPack.
the class InstallMinecraftIfNecessaryTask method runTask.
@Override
public void runTask(InstallTasksQueue queue) throws IOException, InterruptedException {
super.runTask(queue);
MojangVersion version = ((InstallTasksQueue<MojangVersion>) queue).getMetadata();
String url;
GameDownloads dls = version.getDownloads();
IFileVerifier verifier = null;
if (dls != null) {
url = dls.forClient().getUrl();
verifier = new SHA1FileVerifier(dls.forClient().getSha1());
} else {
url = MojangUtils.getOldVersionDownload(this.minecraftVersion);
Utils.getLogger().log(Level.SEVERE, "Using legacy Minecraft download! Version id = " + version.getId() + "; parent = " + version.getParentVersion());
String md5 = Utils.getETag(url);
if (md5 != null && !md5.isEmpty()) {
verifier = new MD5FileVerifier(md5);
} else {
verifier = new ValidZipFileVerifier();
}
}
File cache = new File(cacheDirectory, "minecraft_" + this.minecraftVersion + ".jar");
if (!cache.exists() || !verifier.isFileValid(cache)) {
String output = this.pack.getCacheDir() + File.separator + "minecraft.jar";
Utils.downloadFile(url, cache.getName(), output, cache, verifier, this);
}
MojangUtils.copyMinecraftJar(cache, new File(this.pack.getBinDir(), "minecraft.jar"));
}
use of net.technicpack.launchercore.install.verifiers.SHA1FileVerifier in project LauncherV3 by TechnicPack.
the class EnsureAssetsIndexTask method runTask.
@Override
public void runTask(InstallTasksQueue queue) throws IOException {
MojangVersion version = ((InstallTasksQueue<MojangVersion>) queue).getMetadata();
String assetKey = version.getAssetsKey();
if (assetKey == null || assetKey.isEmpty()) {
assetKey = "legacy";
}
String assetsUrl;
AssetIndex assetIndex = version.getAssetIndex();
if (assetIndex != null) {
assetsUrl = assetIndex.getUrl();
} else {
assetsUrl = MojangUtils.getAssetsIndex(assetKey);
}
File output = new File(assetsDirectory + File.separator + "indexes", assetKey + ".json");
(new File(output.getParent())).mkdirs();
IFileVerifier fileVerifier;
if (assetIndex != null && assetIndex.getSha1() != null)
fileVerifier = new SHA1FileVerifier(assetIndex.getSha1());
else
fileVerifier = new ValidJsonFileVerifier(MojangUtils.getGson());
if (!output.exists() || !fileVerifier.isFileValid(output)) {
downloadIndexQueue.addTask(new DownloadFileTask(assetsUrl, output, fileVerifier));
}
examineIndexQueue.addTask(new InstallMinecraftAssetsTask(modpack, assetsDirectory.getAbsolutePath(), output, checkAssetsQueue, downloadAssetsQueue, installAssetsQueue));
}
use of net.technicpack.launchercore.install.verifiers.SHA1FileVerifier in project LauncherV3 by TechnicPack.
the class InstallVersionLibTask method runTask.
@Override
public void runTask(InstallTasksQueue queue) throws IOException, InterruptedException {
super.runTask(queue);
queue.refreshProgress();
// Native classifier as in the library's downloads -> classifiers -> $nativeClassifier
// (the mapping of which is taken from the library's natives map)
String nativeClassifier = null;
File extractDirectory = null;
if (library.getNatives() != null) {
nativeClassifier = library.getNatives().get(OperatingSystem.getOperatingSystem());
if (nativeClassifier != null) {
extractDirectory = new File(this.pack.getBinDir(), "natives");
}
}
String path = library.getArtifactPath(nativeClassifier).replace("${arch}", JavaUtils.getJavaBitness());
File cache = new File(directories.getCacheDirectory(), path);
if (cache.getParentFile() != null) {
cache.getParentFile().mkdirs();
}
IFileVerifier verifier;
String sha1 = library.getArtifactSha1(nativeClassifier);
if (sha1 != null && !sha1.isEmpty())
verifier = new SHA1FileVerifier(sha1);
else
verifier = new ValidZipFileVerifier();
// TODO: Add check based on size (so it fails early if the size is different)
if (cache.exists() && verifier.isFileValid(cache) && extractDirectory == null)
return;
String url = null;
// TODO: this causes verification to happen twice, for natives
if (!cache.exists() || !verifier.isFileValid(cache)) {
url = library.getDownloadUrl(path).replace("${arch}", JavaUtils.getJavaBitness());
if (sha1 == null || sha1.isEmpty()) {
String md5 = Utils.getETag(url);
if (md5 != null && !md5.isEmpty()) {
verifier = new MD5FileVerifier(md5);
}
}
}
IZipFileFilter filter = null;
if (library.getExtract() != null)
filter = new ExtractRulesFileFilter(library.getExtract());
grabQueue.addTask(new EnsureFileTask(cache, verifier, extractDirectory, url, downloadLibraryQueue, copyLibraryQueue, filter));
}
use of net.technicpack.launchercore.install.verifiers.SHA1FileVerifier in project LauncherV3 by TechnicPack.
the class InstallJavaRuntimeTask method runTask.
@Override
public void runTask(InstallTasksQueue queue) throws IOException {
String json = FileUtils.readFileToString(runtimeManifestFile, StandardCharsets.UTF_8);
JavaRuntimeManifest manifest = MojangUtils.getGson().fromJson(json, JavaRuntimeManifest.class);
if (manifest == null) {
throw new DownloadException("The Java runtime manifest is invalid.");
}
// TODO: Check runtime isn't downloaded/installed outside of its directory
// Create the runtime directory if it doesn't exist
File runtimeRoot = new File(runtimesDirectory, runtimeName);
runtimeRoot.mkdirs();
// First, create the dirs
manifest.getFiles().forEach((path, runtimeFile) -> {
// We're only interested in the dirs for now
if (runtimeFile.getType() == JavaRuntimeFileType.DIRECTORY) {
File dir = new File(runtimeRoot, path);
dir.mkdirs();
}
});
// Then, download the files
manifest.getFiles().forEach((path, runtimeFile) -> {
// We're only interested in the files right now
if (runtimeFile.getType() == JavaRuntimeFileType.FILE) {
File target = new File(runtimeRoot, path);
// Apparently the Mac Java 8 JRE spec doesn't have any directory entries, so we have to create them regardless
target.getParentFile().mkdirs();
Download download = runtimeFile.getDownloads().getRaw();
IFileVerifier verifier = new SHA1FileVerifier(download.getSha1());
EnsureFileTask ensureFileTask = new EnsureFileTask(target, verifier, null, download.getUrl(), downloadJavaQueue, null);
ensureFileTask.setExecutable(runtimeFile.isExecutable());
examineJavaQueue.addTask(ensureFileTask);
}
});
// Then, create the links
manifest.getFiles().forEach((path, runtimeFile) -> {
// We're only interested in links right now
if (runtimeFile.getType() == JavaRuntimeFileType.LINK) {
File link = new File(runtimeRoot, path);
File target = new File(link, runtimeFile.getTarget());
// We add it to the download queue so it runs after all the files exist
downloadJavaQueue.addTask(new EnsureLinkedFileTask(link, target));
}
});
}
Aggregations