Skip to content

Commit 77f61ce

Browse files
committed
Moved and split pack-sync-info.json
1 parent 23c065e commit 77f61ce

3 files changed

Lines changed: 152 additions & 103 deletions

File tree

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package dev.latvian.mods.packsync;
2+
3+
import com.google.gson.JsonObject;
4+
import org.jetbrains.annotations.NotNull;
5+
6+
public record Artifact(String artifact, String version) {
7+
public static Artifact NONE = new Artifact("", "");
8+
9+
public static Artifact of(JsonObject json) {
10+
var a = json.has("artifact") ? json.get("artifact").getAsString() : "";
11+
var v = json.has("version") ? json.get("version").getAsString() : "";
12+
return a.isEmpty() && v.isEmpty() ? NONE : new Artifact(a, v);
13+
}
14+
15+
public void write(JsonObject json) {
16+
if (!artifact.isEmpty()) {
17+
json.addProperty("artifact", artifact);
18+
}
19+
20+
if (!version.isEmpty()) {
21+
json.addProperty("version", version);
22+
}
23+
}
24+
25+
@Override
26+
public @NotNull String toString() {
27+
if (artifact.isEmpty() && version.isEmpty()) {
28+
return "no-artifact";
29+
}
30+
31+
return artifact + ":" + version;
32+
}
33+
}

src/main/java/dev/latvian/mods/packsync/FileInfo.java

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,45 +2,43 @@
22

33
import com.google.gson.JsonObject;
44
import net.neoforged.neoforgespi.IIssueReporting;
5+
import org.jetbrains.annotations.NotNull;
56

67
import java.nio.file.Path;
78

89
public record FileInfo(
910
String checksum,
1011
String filename,
1112
long size,
12-
String artifact,
13-
String version
13+
Artifact artifact
1414
) {
1515
public FileInfo(JsonObject json) {
1616
this(
1717
json.get("checksum").getAsString(),
1818
json.get("filename").getAsString(),
1919
json.get("size").getAsLong(),
20-
json.has("artifact") ? json.get("artifact").getAsString() : "",
21-
json.has("version") ? json.get("version").getAsString() : ""
20+
Artifact.of(json)
2221
);
2322
}
2423

2524
public FileInfo(String filename, long size) {
26-
this("", filename, size, "", "");
25+
this("", filename, size, Artifact.NONE);
2726
}
2827

2928
public boolean isEqual(Path path, IIssueReporting issues) {
3029
return size == PackSync.size(path) && checksum.equals(Checksum.md5(path, issues));
3130
}
3231

33-
public void toJson(JsonObject json) {
32+
public void write(JsonObject json) {
3433
json.addProperty("checksum", checksum);
3534
json.addProperty("filename", filename);
3635
json.addProperty("size", size);
36+
artifact.write(json);
37+
}
3738

38-
if (!artifact.isEmpty()) {
39-
json.addProperty("artifact", artifact);
40-
}
41-
42-
if (!version.isEmpty()) {
43-
json.addProperty("version", version);
44-
}
39+
@Override
40+
@NotNull
41+
public String toString() {
42+
return filename + " (" + (artifact.equals(Artifact.NONE) ? "" : (artifact + "/")) + checksum + ")";
4543
}
4644
}

0 commit comments

Comments
 (0)