use of net.technicpack.launchercore.install.verifiers.IFileVerifier 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));
}
});
}
use of net.technicpack.launchercore.install.verifiers.IFileVerifier in project LauncherV3 by TechnicPack.
the class QueryUpdateStream method runTask.
@Override
public void runTask(InstallTasksQueue queue) throws IOException, InterruptedException {
try {
StreamVersion version = updateStream.getStreamVersion(relauncher.getStreamName());
if (version == null || version.getBuild() == 0)
return;
for (LauncherResource resource : version.getResources()) {
IFileVerifier verifier = new MD5FileVerifier(resource.getMd5());
File downloadFile = new File(new File(directories.getAssetsDirectory(), "launcher"), resource.getFilename());
if (!downloadFile.exists() || !verifier.isFileValid(downloadFile))
downloadTasks.addTask(new DownloadFileTask(resource.getUrl(), downloadFile, verifier, resource.getFilename()));
}
if (version.getBuild() == relauncher.getCurrentBuild() || (relauncher.getStreamName().startsWith("beta") && version.getBuild() <= relauncher.getCurrentBuild()))
return;
String updateUrl = null;
String runningPath = relauncher.getRunningPath();
if (runningPath == null) {
throw new DownloadException("Could not load a running path for currently-executing launcher.");
}
if (runningPath.endsWith(".exe"))
updateUrl = version.getExeUrl();
else
updateUrl = version.getJarUrl();
downloadTasks.addTask(new DownloadUpdate(updateUrl, relauncher, postDownloadTasks));
} catch (RestfulAPIException ex) {
return;
}
}
Aggregations