From 79a983bc2f40941ec3a79bf392544d5bbfd5d071 Mon Sep 17 00:00:00 2001 From: comp500 Date: Fri, 30 Aug 2019 03:39:15 +0100 Subject: [PATCH] Don't invalidate files that aren't on the current side --- build.gradle | 36 ++++++++++--------- .../infra/packwiz/installer/DownloadTask.java | 1 + .../packwiz/installer/UpdateManager.java | 4 +++ .../metadata/EfficientBooleanAdapter.java | 29 +++++++++++++++ .../installer/metadata/ManifestFile.java | 6 ++++ 5 files changed, 59 insertions(+), 17 deletions(-) create mode 100644 src/main/java/link/infra/packwiz/installer/metadata/EfficientBooleanAdapter.java diff --git a/build.gradle b/build.gradle index 35b262b..774f975 100644 --- a/build.gradle +++ b/build.gradle @@ -50,21 +50,23 @@ task copyJar(type: Copy) { 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()] -} +if (project.hasProperty("github.token")) { + 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 findProperty("github.token") ?: "" + releaseAssets = [jar.destinationDirectory.file("packwiz-installer.jar").get()] + } -tasks.githubRelease.dependsOn(build) \ No newline at end of file + tasks.githubRelease.dependsOn(build) +} \ No newline at end of file diff --git a/src/main/java/link/infra/packwiz/installer/DownloadTask.java b/src/main/java/link/infra/packwiz/installer/DownloadTask.java index 44e77d5..7149be7 100644 --- a/src/main/java/link/infra/packwiz/installer/DownloadTask.java +++ b/src/main/java/link/infra/packwiz/installer/DownloadTask.java @@ -97,6 +97,7 @@ void downloadMetadata(IndexFile parentIndexFile, SpaceSafeURI indexUri) { } } cachedFile.isOptional = isOptional(); + cachedFile.onlyOtherSide = !correctSide(); } } } diff --git a/src/main/java/link/infra/packwiz/installer/UpdateManager.java b/src/main/java/link/infra/packwiz/installer/UpdateManager.java index 6bf72b6..c1b0143 100644 --- a/src/main/java/link/infra/packwiz/installer/UpdateManager.java +++ b/src/main/java/link/infra/packwiz/installer/UpdateManager.java @@ -153,6 +153,10 @@ private void start() { List invalidatedUris = new ArrayList<>(); if (manifest.cachedFiles != null) { for (Map.Entry entry : manifest.cachedFiles.entrySet()) { + // ignore onlyOtherSide files + if (entry.getValue().onlyOtherSide) { + continue; + } boolean invalid = false; // if isn't optional, or is optional but optionValue == true if (!entry.getValue().isOptional || entry.getValue().optionValue) { diff --git a/src/main/java/link/infra/packwiz/installer/metadata/EfficientBooleanAdapter.java b/src/main/java/link/infra/packwiz/installer/metadata/EfficientBooleanAdapter.java new file mode 100644 index 0000000..28f2f3f --- /dev/null +++ b/src/main/java/link/infra/packwiz/installer/metadata/EfficientBooleanAdapter.java @@ -0,0 +1,29 @@ +package link.infra.packwiz.installer.metadata; + +import com.google.gson.TypeAdapter; +import com.google.gson.stream.JsonReader; +import com.google.gson.stream.JsonToken; +import com.google.gson.stream.JsonWriter; + +import java.io.IOException; + +public class EfficientBooleanAdapter extends TypeAdapter { + + @Override + public void write(JsonWriter out, Boolean value) throws IOException { + if (value == null || !value) { + out.nullValue(); + return; + } + out.value(true); + } + + @Override + public Boolean read(JsonReader in) throws IOException { + if (in.peek() == JsonToken.NULL) { + in.nextNull(); + return false; + } + return in.nextBoolean(); + } +} diff --git a/src/main/java/link/infra/packwiz/installer/metadata/ManifestFile.java b/src/main/java/link/infra/packwiz/installer/metadata/ManifestFile.java index 4a7dd0a..b39cfe4 100644 --- a/src/main/java/link/infra/packwiz/installer/metadata/ManifestFile.java +++ b/src/main/java/link/infra/packwiz/installer/metadata/ManifestFile.java @@ -1,5 +1,6 @@ package link.infra.packwiz.installer.metadata; +import com.google.gson.annotations.JsonAdapter; import link.infra.packwiz.installer.UpdateManager; import link.infra.packwiz.installer.metadata.hash.Hash; @@ -19,9 +20,13 @@ public static class File { public Hash linkedFileHash = null; public String cachedLocation = null; + @JsonAdapter(EfficientBooleanAdapter.class) public boolean isOptional = false; public boolean optionValue = true; + @JsonAdapter(EfficientBooleanAdapter.class) + public boolean onlyOtherSide = false; + // When an error occurs, the state needs to be reverted. To do this, I have a crude revert system. public void backup() { revert = new File(); @@ -30,6 +35,7 @@ public void backup() { revert.cachedLocation = cachedLocation; revert.isOptional = isOptional; revert.optionValue = optionValue; + revert.onlyOtherSide = onlyOtherSide; } public File getRevert() {