Skip to content

Commit 29d36cd

Browse files
committed
Added recursive auth token lookup, repository file validation
1 parent 750e4e8 commit 29d36cd

File tree

2 files changed

+33
-4
lines changed

2 files changed

+33
-4
lines changed

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ mod_name=Pack Sync
88
maven_group=dev.latvian.mods
99
mod_author=latvian.dev
1010

11-
mod_version=2104.1.1
11+
mod_version=2105.1.2
1212

1313
neoforge_version=21.5.95
1414
neoForge.parchment.minecraftVersion=1.21.5

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

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,6 @@ public static void findMods(Executor executor, HttpClient httpClient, IDiscovery
255255
LOGGER.info("Found %,d local files in %,d ms".formatted(repositoryFiles.size(), now - startTime));
256256
startTime = now;
257257

258-
var packVersion = info.get("version").getAsString();
259258
var api = config.get("api").getAsString();
260259

261260
while (api.endsWith("/")) {
@@ -265,7 +264,7 @@ public static void findMods(Executor executor, HttpClient httpClient, IDiscovery
265264
var packCode = config.get("pack_code").getAsString();
266265
var auth = info.get("auth").getAsString();
267266

268-
if (auth.startsWith("%") && auth.endsWith("%")) {
267+
while (auth.length() >= 3 && auth.startsWith("%") && auth.endsWith("%")) {
269268
auth = Optional.ofNullable(System.getenv(auth.substring(1, auth.length() - 1))).orElse("");
270269
}
271270

@@ -297,7 +296,14 @@ public static void findMods(Executor executor, HttpClient httpClient, IDiscovery
297296
ignoredMods.add(e.getAsString());
298297
}
299298

300-
if (info.get("pause_updates").getAsBoolean()) {
299+
var packVersion = info.get("version").getAsString();
300+
301+
if (!packVersion.isEmpty() && !checkModsExist(repositoryFiles, info, ignoredMods)) {
302+
LOGGER.info("Found missing or broken repository files, forcing an update...");
303+
packVersion = "";
304+
}
305+
306+
if (!packVersion.isEmpty() && info.get("pause_updates").getAsBoolean()) {
301307
LOGGER.info("Pack updates are paused ('" + packVersion + "')!");
302308
loadMods(repositoryFiles, info, ignoredMods, pipeline);
303309

@@ -596,6 +602,29 @@ public static void findMods(Executor executor, HttpClient httpClient, IDiscovery
596602
loadMods(repositoryFiles, info, ignoredMods, pipeline);
597603
}
598604

605+
private static boolean checkModsExist(Map<String, RepositoryFile> repositoryFiles, JsonObject info, Set<String> ignoredMods) {
606+
for (var entry : info.get("mods").getAsJsonArray()) {
607+
try {
608+
var fileInfo = new FileInfo(entry.getAsJsonObject());
609+
var artifact = fileInfo.artifact();
610+
611+
if (!artifact.isEmpty() && ignoredMods.contains(artifact)) {
612+
continue;
613+
}
614+
615+
var repositoryFile = repositoryFiles.get(fileInfo.checksum());
616+
617+
if (repositoryFile == null) {
618+
return false;
619+
}
620+
} catch (Exception ex) {
621+
return false;
622+
}
623+
}
624+
625+
return true;
626+
}
627+
599628
private static void loadMods(Map<String, RepositoryFile> repositoryFiles, JsonObject info, Set<String> ignoredMods, IDiscoveryPipeline pipeline) {
600629
var filesToLoad = new ArrayList<RepositoryFile>();
601630

0 commit comments

Comments
 (0)