Don't invalidate files that aren't on the current side

This commit is contained in:
comp500 2019-08-30 03:39:15 +01:00
parent 0cba5ba17b
commit 79a983bc2f
5 changed files with 59 additions and 17 deletions

View File

@ -50,6 +50,7 @@ task copyJar(type: Copy) {
build.dependsOn copyJar build.dependsOn copyJar
if (project.hasProperty("github.token")) {
githubRelease { githubRelease {
// IntelliJ u ok? // IntelliJ u ok?
//noinspection GroovyAssignabilityCheck //noinspection GroovyAssignabilityCheck
@ -63,8 +64,9 @@ githubRelease {
//noinspection GroovyAssignabilityCheck //noinspection GroovyAssignabilityCheck
draft true draft true
//noinspection GroovyAssignabilityCheck //noinspection GroovyAssignabilityCheck
token getProperty("github.token") token findProperty("github.token") ?: ""
releaseAssets = [jar.destinationDirectory.file("packwiz-installer.jar").get()] releaseAssets = [jar.destinationDirectory.file("packwiz-installer.jar").get()]
} }
tasks.githubRelease.dependsOn(build) tasks.githubRelease.dependsOn(build)
}

View File

@ -97,6 +97,7 @@ class DownloadTask implements IOptionDetails, IExceptionDetails {
} }
} }
cachedFile.isOptional = isOptional(); cachedFile.isOptional = isOptional();
cachedFile.onlyOtherSide = !correctSide();
} }
} }
} }

View File

@ -153,6 +153,10 @@ public class UpdateManager {
List<SpaceSafeURI> invalidatedUris = new ArrayList<>(); List<SpaceSafeURI> invalidatedUris = new ArrayList<>();
if (manifest.cachedFiles != null) { if (manifest.cachedFiles != null) {
for (Map.Entry<SpaceSafeURI, ManifestFile.File> entry : manifest.cachedFiles.entrySet()) { for (Map.Entry<SpaceSafeURI, ManifestFile.File> entry : manifest.cachedFiles.entrySet()) {
// ignore onlyOtherSide files
if (entry.getValue().onlyOtherSide) {
continue;
}
boolean invalid = false; boolean invalid = false;
// if isn't optional, or is optional but optionValue == true // if isn't optional, or is optional but optionValue == true
if (!entry.getValue().isOptional || entry.getValue().optionValue) { if (!entry.getValue().isOptional || entry.getValue().optionValue) {

View File

@ -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<Boolean> {
@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();
}
}

View File

@ -1,5 +1,6 @@
package link.infra.packwiz.installer.metadata; package link.infra.packwiz.installer.metadata;
import com.google.gson.annotations.JsonAdapter;
import link.infra.packwiz.installer.UpdateManager; import link.infra.packwiz.installer.UpdateManager;
import link.infra.packwiz.installer.metadata.hash.Hash; import link.infra.packwiz.installer.metadata.hash.Hash;
@ -19,9 +20,13 @@ public class ManifestFile {
public Hash linkedFileHash = null; public Hash linkedFileHash = null;
public String cachedLocation = null; public String cachedLocation = null;
@JsonAdapter(EfficientBooleanAdapter.class)
public boolean isOptional = false; public boolean isOptional = false;
public boolean optionValue = true; 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. // When an error occurs, the state needs to be reverted. To do this, I have a crude revert system.
public void backup() { public void backup() {
revert = new File(); revert = new File();
@ -30,6 +35,7 @@ public class ManifestFile {
revert.cachedLocation = cachedLocation; revert.cachedLocation = cachedLocation;
revert.isOptional = isOptional; revert.isOptional = isOptional;
revert.optionValue = optionValue; revert.optionValue = optionValue;
revert.onlyOtherSide = onlyOtherSide;
} }
public File getRevert() { public File getRevert() {