mirror of
https://github.com/AngelAuraMC/Amethyst-Android.git
synced 2025-09-17 00:29:50 -04:00
Feat[modpacks]: collect sha1 hashes
This commit is contained in:
parent
f88fb3c61a
commit
30541c2e3c
@ -28,6 +28,7 @@ import java.util.zip.ZipFile;
|
||||
|
||||
public class CurseforgeApi implements ModpackApi{
|
||||
private static final Pattern sMcVersionPattern = Pattern.compile("([0-9]+)\\.([0-9]+)\\.?([0-9]+)?");
|
||||
private static final int ALGO_SHA_1 = 1;
|
||||
// Stolen from
|
||||
// https://github.com/AnzhiZhang/CurseForgeModpackDownloader/blob/6cb3f428459f0cc8f444d16e54aea4cd1186fd7b/utils/requester.py#L93
|
||||
private static final int CURSEFORGE_MINECRAFT_GAME_ID = 432;
|
||||
@ -103,11 +104,14 @@ public class CurseforgeApi implements ModpackApi{
|
||||
String[] versionNames = new String[length];
|
||||
String[] mcVersionNames = new String[length];
|
||||
String[] versionUrls = new String[length];
|
||||
String[] hashes = new String[length];
|
||||
for(int i = 0; i < allModDetails.size(); i++) {
|
||||
JsonObject modDetail = allModDetails.get(i);
|
||||
versionNames[i] = modDetail.get("displayName").getAsString();
|
||||
|
||||
JsonElement downloadUrl = modDetail.get("downloadUrl");
|
||||
versionUrls[i] = downloadUrl.getAsString();
|
||||
|
||||
JsonArray gameVersions = modDetail.getAsJsonArray("gameVersions");
|
||||
for(JsonElement jsonElement : gameVersions) {
|
||||
String gameVersion = jsonElement.getAsString();
|
||||
@ -117,8 +121,18 @@ public class CurseforgeApi implements ModpackApi{
|
||||
mcVersionNames[i] = gameVersion;
|
||||
break;
|
||||
}
|
||||
|
||||
JsonArray downloadHashes = modDetail.getAsJsonArray("hashes");
|
||||
hashes[i] = null;
|
||||
for (JsonElement jsonElement : downloadHashes) {
|
||||
// The sha1 = 1; md5 = 2;
|
||||
if(jsonElement.getAsJsonObject().get("algo").getAsInt() == ALGO_SHA_1){
|
||||
hashes[i] = jsonElement.getAsJsonObject().get("value").getAsString();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return new ModDetail(item, versionNames, mcVersionNames, versionUrls);
|
||||
return new ModDetail(item, versionNames, mcVersionNames, versionUrls, hashes);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -137,6 +151,7 @@ public class CurseforgeApi implements ModpackApi{
|
||||
if(response == null) return CURSEFORGE_PAGINATION_ERROR;
|
||||
JsonArray data = response.getAsJsonArray("data");
|
||||
if(data == null) return CURSEFORGE_PAGINATION_ERROR;
|
||||
|
||||
for(int i = 0; i < data.size(); i++) {
|
||||
JsonObject fileInfo = data.get(i).getAsJsonObject();
|
||||
if(fileInfo.get("isServerPack").getAsBoolean()) continue;
|
||||
|
@ -79,15 +79,18 @@ public class ModrinthApi implements ModpackApi{
|
||||
String[] names = new String[response.size()];
|
||||
String[] mcNames = new String[response.size()];
|
||||
String[] urls = new String[response.size()];
|
||||
String[] hashes = new String[response.size()];
|
||||
|
||||
for (int i=0; i<response.size(); ++i) {
|
||||
JsonObject version = response.get(i).getAsJsonObject();
|
||||
names[i] = version.get("name").getAsString();
|
||||
mcNames[i] = version.get("game_versions").getAsJsonArray().get(0).getAsString();
|
||||
urls[i] = version.get("files").getAsJsonArray().get(0).getAsJsonObject().get("url").getAsString();
|
||||
hashes[i] = version.getAsJsonArray("files").get(0).getAsJsonObject()
|
||||
.get("hashes").getAsJsonObject().get("sha1").getAsString();
|
||||
}
|
||||
|
||||
return new ModDetail(item, names, mcNames, urls);
|
||||
return new ModDetail(item, names, mcNames, urls, hashes);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -10,11 +10,14 @@ public class ModDetail extends ModItem {
|
||||
public String[] versionNames;
|
||||
public String [] mcVersionNames;
|
||||
public String[] versionUrls;
|
||||
public ModDetail(ModItem item, String[] versionNames, String[] mcVersionNames, String[] versionUrls) {
|
||||
/* SHA 1 hashes, null if a hash is unavailable */
|
||||
public String[] versionHashes;
|
||||
public ModDetail(ModItem item, String[] versionNames, String[] mcVersionNames, String[] versionUrls, String[] hashes) {
|
||||
super(item.apiSource, item.isModpack, item.id, item.title, item.description, item.imageUrl);
|
||||
this.versionNames = versionNames;
|
||||
this.mcVersionNames = mcVersionNames;
|
||||
this.versionUrls = versionUrls;
|
||||
this.versionHashes = hashes;
|
||||
|
||||
// Add the mc version to the version model
|
||||
for (int i=0; i<versionNames.length; i++){
|
||||
|
Loading…
x
Reference in New Issue
Block a user