Add: forgesvc for Curse Mod Detection fallback

This commit is contained in:
huanghongxun
2019-10-10 16:46:32 +08:00
parent 944d88b8af
commit 4737240c91
2 changed files with 20 additions and 8 deletions

View File

@@ -23,7 +23,8 @@ import org.jackhuang.hmcl.game.DefaultGameRepository;
import org.jackhuang.hmcl.mod.ModManager;
import org.jackhuang.hmcl.task.FileDownloadTask;
import org.jackhuang.hmcl.task.Task;
import org.jackhuang.hmcl.util.*;
import org.jackhuang.hmcl.util.Logging;
import org.jackhuang.hmcl.util.StringUtils;
import org.jackhuang.hmcl.util.gson.JsonUtils;
import org.jackhuang.hmcl.util.io.FileUtils;
import org.jackhuang.hmcl.util.io.NetworkUtils;
@@ -124,9 +125,15 @@ public final class CurseCompletionTask extends Task<Void> {
CurseMetaMod mod = JsonUtils.fromNonNullJson(result, CurseMetaMod.class);
return file.withFileName(mod.getFileNameOnDisk()).withURL(mod.getDownloadURL());
} catch (IOException | JsonParseException e2) {
Logging.LOG.log(Level.WARNING, "Could not query cursemeta for deleted mods: " + file.getUrl(), e2);
notFound.set(true);
return file;
try {
String result = NetworkUtils.doGet(NetworkUtils.toURL(String.format("https://addons-ecs.forgesvc.net/api/v2/addon/%d/file/%d", file.getProjectID(), file.getFileID())));
CurseMetaMod mod = JsonUtils.fromNonNullJson(result, CurseMetaMod.class);
return file.withFileName(mod.getFileName()).withURL(mod.getDownloadURL());
} catch (IOException | JsonParseException e3) {
Logging.LOG.log(Level.WARNING, "Could not query cursemeta for deleted mods: " + file.getUrl(), e2);
notFound.set(true);
return file;
}
}
} catch (IOException ioe) {

View File

@@ -20,18 +20,23 @@ package org.jackhuang.hmcl.mod.curse;
import com.google.gson.annotations.SerializedName;
import org.jackhuang.hmcl.util.Immutable;
/**
* CurseMetaMod is JSON structure for
* https://cursemeta.dries007.net/&lt;projectID&gt;/&lt;fileID&gt;.json
* https://addons-ecs.forgesvc.net/api/v2/addon/&lt;projectID&gt;/file/<fileID&gt;
*/
@Immutable
public final class CurseMetaMod {
@SerializedName("Id")
@SerializedName(value = "Id", alternate = "id")
private final int id;
@SerializedName("FileName")
@SerializedName(value = "FileName", alternate = "fileName")
private final String fileName;
@SerializedName("FileNameOnDisk")
@SerializedName(value = "FileNameOnDisk")
private final String fileNameOnDisk;
@SerializedName("DownloadURL")
@SerializedName(value = "DownloadURL", alternate = "downloadUrl")
private final String downloadURL;
public CurseMetaMod() {