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{
|
public class CurseforgeApi implements ModpackApi{
|
||||||
private static final Pattern sMcVersionPattern = Pattern.compile("([0-9]+)\\.([0-9]+)\\.?([0-9]+)?");
|
private static final Pattern sMcVersionPattern = Pattern.compile("([0-9]+)\\.([0-9]+)\\.?([0-9]+)?");
|
||||||
|
private static final int ALGO_SHA_1 = 1;
|
||||||
// Stolen from
|
// Stolen from
|
||||||
// https://github.com/AnzhiZhang/CurseForgeModpackDownloader/blob/6cb3f428459f0cc8f444d16e54aea4cd1186fd7b/utils/requester.py#L93
|
// https://github.com/AnzhiZhang/CurseForgeModpackDownloader/blob/6cb3f428459f0cc8f444d16e54aea4cd1186fd7b/utils/requester.py#L93
|
||||||
private static final int CURSEFORGE_MINECRAFT_GAME_ID = 432;
|
private static final int CURSEFORGE_MINECRAFT_GAME_ID = 432;
|
||||||
@ -103,11 +104,14 @@ public class CurseforgeApi implements ModpackApi{
|
|||||||
String[] versionNames = new String[length];
|
String[] versionNames = new String[length];
|
||||||
String[] mcVersionNames = new String[length];
|
String[] mcVersionNames = new String[length];
|
||||||
String[] versionUrls = new String[length];
|
String[] versionUrls = new String[length];
|
||||||
|
String[] hashes = new String[length];
|
||||||
for(int i = 0; i < allModDetails.size(); i++) {
|
for(int i = 0; i < allModDetails.size(); i++) {
|
||||||
JsonObject modDetail = allModDetails.get(i);
|
JsonObject modDetail = allModDetails.get(i);
|
||||||
versionNames[i] = modDetail.get("displayName").getAsString();
|
versionNames[i] = modDetail.get("displayName").getAsString();
|
||||||
|
|
||||||
JsonElement downloadUrl = modDetail.get("downloadUrl");
|
JsonElement downloadUrl = modDetail.get("downloadUrl");
|
||||||
versionUrls[i] = downloadUrl.getAsString();
|
versionUrls[i] = downloadUrl.getAsString();
|
||||||
|
|
||||||
JsonArray gameVersions = modDetail.getAsJsonArray("gameVersions");
|
JsonArray gameVersions = modDetail.getAsJsonArray("gameVersions");
|
||||||
for(JsonElement jsonElement : gameVersions) {
|
for(JsonElement jsonElement : gameVersions) {
|
||||||
String gameVersion = jsonElement.getAsString();
|
String gameVersion = jsonElement.getAsString();
|
||||||
@ -117,8 +121,18 @@ public class CurseforgeApi implements ModpackApi{
|
|||||||
mcVersionNames[i] = gameVersion;
|
mcVersionNames[i] = gameVersion;
|
||||||
break;
|
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
|
@Override
|
||||||
@ -137,6 +151,7 @@ public class CurseforgeApi implements ModpackApi{
|
|||||||
if(response == null) return CURSEFORGE_PAGINATION_ERROR;
|
if(response == null) return CURSEFORGE_PAGINATION_ERROR;
|
||||||
JsonArray data = response.getAsJsonArray("data");
|
JsonArray data = response.getAsJsonArray("data");
|
||||||
if(data == null) return CURSEFORGE_PAGINATION_ERROR;
|
if(data == null) return CURSEFORGE_PAGINATION_ERROR;
|
||||||
|
|
||||||
for(int i = 0; i < data.size(); i++) {
|
for(int i = 0; i < data.size(); i++) {
|
||||||
JsonObject fileInfo = data.get(i).getAsJsonObject();
|
JsonObject fileInfo = data.get(i).getAsJsonObject();
|
||||||
if(fileInfo.get("isServerPack").getAsBoolean()) continue;
|
if(fileInfo.get("isServerPack").getAsBoolean()) continue;
|
||||||
|
@ -79,15 +79,18 @@ public class ModrinthApi implements ModpackApi{
|
|||||||
String[] names = new String[response.size()];
|
String[] names = new String[response.size()];
|
||||||
String[] mcNames = new String[response.size()];
|
String[] mcNames = new String[response.size()];
|
||||||
String[] urls = new String[response.size()];
|
String[] urls = new String[response.size()];
|
||||||
|
String[] hashes = new String[response.size()];
|
||||||
|
|
||||||
for (int i=0; i<response.size(); ++i) {
|
for (int i=0; i<response.size(); ++i) {
|
||||||
JsonObject version = response.get(i).getAsJsonObject();
|
JsonObject version = response.get(i).getAsJsonObject();
|
||||||
names[i] = version.get("name").getAsString();
|
names[i] = version.get("name").getAsString();
|
||||||
mcNames[i] = version.get("game_versions").getAsJsonArray().get(0).getAsString();
|
mcNames[i] = version.get("game_versions").getAsJsonArray().get(0).getAsString();
|
||||||
urls[i] = version.get("files").getAsJsonArray().get(0).getAsJsonObject().get("url").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
|
@Override
|
||||||
|
@ -10,11 +10,14 @@ public class ModDetail extends ModItem {
|
|||||||
public String[] versionNames;
|
public String[] versionNames;
|
||||||
public String [] mcVersionNames;
|
public String [] mcVersionNames;
|
||||||
public String[] versionUrls;
|
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);
|
super(item.apiSource, item.isModpack, item.id, item.title, item.description, item.imageUrl);
|
||||||
this.versionNames = versionNames;
|
this.versionNames = versionNames;
|
||||||
this.mcVersionNames = mcVersionNames;
|
this.mcVersionNames = mcVersionNames;
|
||||||
this.versionUrls = versionUrls;
|
this.versionUrls = versionUrls;
|
||||||
|
this.versionHashes = hashes;
|
||||||
|
|
||||||
// Add the mc version to the version model
|
// Add the mc version to the version model
|
||||||
for (int i=0; i<versionNames.length; i++){
|
for (int i=0; i<versionNames.length; i++){
|
||||||
|
Loading…
x
Reference in New Issue
Block a user