Skip to content

Commit

Permalink
Feat[modpack]: verify main modpack download
Browse files Browse the repository at this point in the history
  • Loading branch information
Mathias-Boulay committed Nov 27, 2023
1 parent efc36f1 commit e8b2e93
Showing 1 changed file with 9 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public class ModpackInstaller {

public static ModLoader installModpack(ModDetail modDetail, int selectedVersion, InstallFunction installFunction) throws IOException{
String versionUrl = modDetail.versionUrls[selectedVersion];
String versionHash = modDetail.versionHashes[selectedVersion];
String modpackName = modDetail.title.toLowerCase(Locale.ROOT).trim().replace(" ", "_" );

// Build a new minecraft instance, folder first
Expand All @@ -29,9 +30,14 @@ public static ModLoader installModpack(ModDetail modDetail, int selectedVersion,
ModLoader modLoaderInfo;
try {
byte[] downloadBuffer = new byte[8192];
DownloadUtils.downloadFileMonitored(versionUrl, modpackFile, downloadBuffer,
new DownloaderProgressWrapper(R.string.modpack_download_downloading_metadata,
ProgressLayout.INSTALL_MODPACK));
int attempt = 0;
while (attempt < 3 && (!modpackFile.exists() || !Tools.compareSHA1(modpackFile, versionHash))){
attempt++;
DownloadUtils.downloadFileMonitored(versionUrl, modpackFile, downloadBuffer,
new DownloaderProgressWrapper(R.string.modpack_download_downloading_metadata,
ProgressLayout.INSTALL_MODPACK));
}

// Install the modpack
modLoaderInfo = installFunction.installModpack(modpackFile, new File(Tools.DIR_GAME_HOME, "custom_instances/"+modpackName));

Expand Down

0 comments on commit e8b2e93

Please sign in to comment.