mirror of
https://github.com/AngelAuraMC/Amethyst-Android.git
synced 2025-09-13 23:00:45 -04:00
Refactor[modpacks]: handle non valued algo
This commit is contained in:
parent
26cad1a47b
commit
fc5187bd65
@ -2,6 +2,7 @@ package net.kdt.pojavlaunch.modloaders.modpacks.api;
|
|||||||
|
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
|
|
||||||
import com.google.gson.JsonArray;
|
import com.google.gson.JsonArray;
|
||||||
@ -124,15 +125,7 @@ public class CurseforgeApi implements ModpackApi{
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
JsonArray downloadHashes = modDetail.getAsJsonArray("hashes");
|
hashes[i] = getSha1FromResponse(modDetail);
|
||||||
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, hashes);
|
return new ModDetail(item, versionNames, mcVersionNames, versionUrls, hashes);
|
||||||
}
|
}
|
||||||
@ -247,15 +240,18 @@ public class CurseforgeApi implements ModpackApi{
|
|||||||
JsonObject response = mApiHandler.get("mods/"+projectID+"/files/"+fileID, JsonObject.class);
|
JsonObject response = mApiHandler.get("mods/"+projectID+"/files/"+fileID, JsonObject.class);
|
||||||
if (response == null || response.get("data").isJsonNull()) return null;
|
if (response == null || response.get("data").isJsonNull()) return null;
|
||||||
|
|
||||||
JsonArray hashes = response.get("data").getAsJsonObject().getAsJsonArray("hashes");
|
return getSha1FromResponse(response);
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getSha1FromResponse(@NonNull JsonElement element) {
|
||||||
|
JsonArray hashes = element.getAsJsonObject().get("data").getAsJsonObject().getAsJsonArray("hashes");
|
||||||
for (JsonElement jsonElement : hashes) {
|
for (JsonElement jsonElement : hashes) {
|
||||||
// The sha1 = 1; md5 = 2;
|
// The sha1 = 1; md5 = 2;
|
||||||
if(jsonElement.getAsJsonObject().get("algo").getAsInt() == ALGO_SHA_1){
|
JsonElement algo = jsonElement.getAsJsonObject().get("algo");
|
||||||
|
if(algo != null && algo.getAsInt() == ALGO_SHA_1){
|
||||||
return jsonElement.getAsJsonObject().get("value").getAsString();
|
return jsonElement.getAsJsonObject().get("value").getAsString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// No hashes available
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user