Compare commits

..

4 Commits

Author SHA1 Message Date
comp500
0cba5ba17b Ensure index and pack files are rechecked after errors 2019-08-12 02:17:28 +01:00
comp500
ce60cdc385 Automagic github release creation 2019-08-12 02:06:49 +01:00
comp500
b314fc8e0b Fix case-sensitivity for standard hashes, add more hash support 2019-08-12 01:37:02 +01:00
comp500
ca4a13589d Fix crash on empty index file 2019-08-11 22:37:42 +01:00
3 changed files with 47 additions and 10 deletions

View File

@@ -3,6 +3,7 @@ plugins {
id 'application'
id 'com.github.johnrengelman.shadow' version '5.0.0'
id 'com.palantir.git-version' version '0.11.0'
id 'com.github.breadmoirai.github-release' version '2.2.9'
}
sourceCompatibility = 1.8
@@ -47,4 +48,23 @@ task copyJar(type: Copy) {
into "build/libs/"
}
build.dependsOn copyJar
build.dependsOn copyJar
githubRelease {
// IntelliJ u ok?
//noinspection GroovyAssignabilityCheck
owner "comp500"
//noinspection GroovyAssignabilityCheck
repo "packwiz-installer"
//noinspection GroovyAssignabilityCheck
tagName "${project.version}"
//noinspection GroovyAssignabilityCheck
releaseName "Release ${project.version}"
//noinspection GroovyAssignabilityCheck
draft true
//noinspection GroovyAssignabilityCheck
token getProperty("github.token")
releaseAssets = [jar.destinationDirectory.file("packwiz-installer.jar").get()]
}
tasks.githubRelease.dependsOn(build)

View File

@@ -35,6 +35,7 @@ public class UpdateManager {
private boolean cancelled;
private boolean cancelledStartGame = false;
private InputStateHandler stateHandler;
private boolean errorsOccurred = false;
public static class Options {
SpaceSafeURI downloadURI = null;
@@ -199,7 +200,14 @@ public class UpdateManager {
// TODO: update MMC params, java args etc
manifest.packFileHash = packFileSource.getHash();
// If there were errors, don't write the manifest/index hashes, to ensure they are rechecked later
if (errorsOccurred) {
manifest.indexFileHash = null;
manifest.packFileHash = null;
} else {
manifest.packFileHash = packFileSource.getHash();
}
manifest.cachedSide = opts.side;
try (Writer writer = new FileWriter(Paths.get(opts.packFolder, opts.manifestFile).toString())) {
gson.toJson(manifest, writer);
@@ -296,6 +304,10 @@ public class UpdateManager {
ui.submitProgress(new InstallProgress("Comparing new files..."));
// TODO: progress bar?
if (indexFile.files == null || indexFile.files.size() == 0) {
System.out.println("Warning: Index is empty!");
indexFile.files = new ArrayList<>();
}
List<DownloadTask> tasks = DownloadTask.createTasksFromIndex(indexFile, indexFile.hashFormat, opts.side);
// If the side changes, invalidate EVERYTHING just in case
// Might not be needed, but done just to be safe
@@ -328,7 +340,8 @@ public class UpdateManager {
tasks.parallelStream().forEach(f -> f.downloadMetadata(indexFile, indexUri));
List<IExceptionDetails> failedTasks = tasks.stream().filter(t -> t.getException() != null).collect(Collectors.toList());
if (failedTasks.size() > 0) {
if (!failedTasks.isEmpty()) {
errorsOccurred = true;
IExceptionDetails.ExceptionListResult exceptionListResult;
try {
exceptionListResult = ui.showExceptions(failedTasks, tasks.size(), true).get();
@@ -426,7 +439,8 @@ public class UpdateManager {
}
List<IExceptionDetails> failedTasks2ElectricBoogaloo = nonFailedFirstTasks.stream().filter(t -> t.getException() != null).collect(Collectors.toList());
if (failedTasks2ElectricBoogaloo.size() > 0) {
if (!failedTasks2ElectricBoogaloo.isEmpty()) {
errorsOccurred = true;
IExceptionDetails.ExceptionListResult exceptionListResult;
try {
exceptionListResult = ui.showExceptions(failedTasks2ElectricBoogaloo, tasks.size(), false).get();

View File

@@ -4,9 +4,9 @@ import okio.HashingSource;
import okio.Source;
public class HashingSourceHasher implements IHasher {
String type;
private String type;
public HashingSourceHasher(String type) {
HashingSourceHasher(String type) {
this.type = type;
}
@@ -15,7 +15,7 @@ public class HashingSourceHasher implements IHasher {
HashingSource delegateHashing;
HashingSourceHash value;
public HashingSourceGeneralHashingSource(HashingSource delegate) {
HashingSourceGeneralHashingSource(HashingSource delegate) {
super(delegate);
delegateHashing = delegate;
}
@@ -46,7 +46,7 @@ public class HashingSourceHasher implements IHasher {
}
HashingSourceHash objHash = (HashingSourceHash) obj;
if (value != null) {
return value.equals(objHash.value);
return value.equalsIgnoreCase(objHash.value);
} else {
return objHash.value == null;
}
@@ -71,9 +71,12 @@ public class HashingSourceHasher implements IHasher {
@Override
public GeneralHashingSource getHashingSource(Source delegate) {
switch (type) {
case "md5":
return new HashingSourceGeneralHashingSource(HashingSource.md5(delegate));
case "sha256":
return new HashingSourceGeneralHashingSource(HashingSource.sha256(delegate));
// TODO: support other hash types
return new HashingSourceGeneralHashingSource(HashingSource.sha256(delegate));
case "sha512":
return new HashingSourceGeneralHashingSource(HashingSource.sha512(delegate));
}
throw new RuntimeException("Invalid hash type provided");
}