|
2 | 2 |
|
3 | 3 | import com.google.gson.JsonObject; |
4 | 4 | import net.neoforged.neoforgespi.IIssueReporting; |
| 5 | +import org.jetbrains.annotations.NotNull; |
5 | 6 |
|
6 | 7 | import java.nio.file.Path; |
7 | 8 |
|
8 | 9 | public record FileInfo( |
9 | 10 | String checksum, |
10 | 11 | String filename, |
11 | 12 | long size, |
12 | | - String artifact, |
13 | | - String version |
| 13 | + Artifact artifact |
14 | 14 | ) { |
15 | 15 | public FileInfo(JsonObject json) { |
16 | 16 | this( |
17 | 17 | json.get("checksum").getAsString(), |
18 | 18 | json.get("filename").getAsString(), |
19 | 19 | json.get("size").getAsLong(), |
20 | | - json.has("artifact") ? json.get("artifact").getAsString() : "", |
21 | | - json.has("version") ? json.get("version").getAsString() : "" |
| 20 | + Artifact.of(json) |
22 | 21 | ); |
23 | 22 | } |
24 | 23 |
|
25 | 24 | public FileInfo(String filename, long size) { |
26 | | - this("", filename, size, "", ""); |
| 25 | + this("", filename, size, Artifact.NONE); |
27 | 26 | } |
28 | 27 |
|
29 | 28 | public boolean isEqual(Path path, IIssueReporting issues) { |
30 | 29 | return size == PackSync.size(path) && checksum.equals(Checksum.md5(path, issues)); |
31 | 30 | } |
32 | 31 |
|
33 | | - public void toJson(JsonObject json) { |
| 32 | + public void write(JsonObject json) { |
34 | 33 | json.addProperty("checksum", checksum); |
35 | 34 | json.addProperty("filename", filename); |
36 | 35 | json.addProperty("size", size); |
| 36 | + artifact.write(json); |
| 37 | + } |
37 | 38 |
|
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 + ")"; |
45 | 43 | } |
46 | 44 | } |
0 commit comments