Skip to content

Commit

Permalink
Don't invalidate files that aren't on the current side
Browse files Browse the repository at this point in the history
  • Loading branch information
comp500 committed Aug 30, 2019
1 parent 0cba5ba commit 79a983b
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 17 deletions.
36 changes: 19 additions & 17 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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)
tasks.githubRelease.dependsOn(build)
}
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ void downloadMetadata(IndexFile parentIndexFile, SpaceSafeURI indexUri) {
}
}
cachedFile.isOptional = isOptional();
cachedFile.onlyOtherSide = !correctSide();
}
}
}
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/link/infra/packwiz/installer/UpdateManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,10 @@ private void start() {
List<SpaceSafeURI> invalidatedUris = new ArrayList<>();
if (manifest.cachedFiles != null) {
for (Map.Entry<SpaceSafeURI, ManifestFile.File> 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) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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();
}
}
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -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();
Expand All @@ -30,6 +35,7 @@ public void backup() {
revert.cachedLocation = cachedLocation;
revert.isOptional = isOptional;
revert.optionValue = optionValue;
revert.onlyOtherSide = onlyOtherSide;
}

public File getRevert() {
Expand Down

0 comments on commit 79a983b

Please sign in to comment.