Feat[modpack]: Set up framework for handling ModpackApi IOExceptions

This commit is contained in:
artdeell 2023-08-21 17:48:49 +03:00 committed by ArtDev
parent e513156c6f
commit 91c834117d
5 changed files with 16 additions and 10 deletions

View File

@ -9,6 +9,7 @@ import net.kdt.pojavlaunch.modloaders.modpacks.models.ModItem;
import net.kdt.pojavlaunch.modloaders.modpacks.models.SearchFilters;
import net.kdt.pojavlaunch.modloaders.modpacks.models.SearchResult;
import java.io.IOException;
import java.util.Arrays;
import java.util.concurrent.Callable;
import java.util.concurrent.Future;
@ -92,7 +93,7 @@ public class CommonApi implements ModpackApi {
}
@Override
public ModLoader installMod(ModDetail modDetail, int selectedVersion) {
public ModLoader installMod(ModDetail modDetail, int selectedVersion) throws IOException {
return getModpackApi(modDetail.apiSource).installMod(modDetail, selectedVersion);
}

View File

@ -118,7 +118,7 @@ public class CurseforgeApi implements ModpackApi{
}
@Override
public ModLoader installMod(ModDetail modDetail, int selectedVersion) {
public ModLoader installMod(ModDetail modDetail, int selectedVersion) throws IOException{
//TODO considering only modpacks for now
return ModpackInstaller.installModpack(modDetail, selectedVersion, this::installCurseforgeZip);
}

View File

@ -7,11 +7,14 @@ import com.kdt.mcgui.ProgressLayout;
import net.kdt.pojavlaunch.PojavApplication;
import net.kdt.pojavlaunch.R;
import net.kdt.pojavlaunch.Tools;
import net.kdt.pojavlaunch.modloaders.modpacks.models.ModDetail;
import net.kdt.pojavlaunch.modloaders.modpacks.models.ModItem;
import net.kdt.pojavlaunch.modloaders.modpacks.models.SearchFilters;
import net.kdt.pojavlaunch.modloaders.modpacks.models.SearchResult;
import java.io.IOException;
/**
*
*/
@ -49,9 +52,13 @@ public interface ModpackApi {
// which may lead to two concurrent installations (very bad)
ProgressLayout.setProgress(ProgressLayout.INSTALL_MODPACK, 0, R.string.global_waiting);
PojavApplication.sExecutorService.execute(() -> {
ModLoader loaderInfo = installMod(modDetail, selectedVersion);
if (loaderInfo == null) return;
loaderInfo.getDownloadTask(new NotificationDownloadListener(context, loaderInfo)).run();
try {
ModLoader loaderInfo = installMod(modDetail, selectedVersion);
if (loaderInfo == null) return;
loaderInfo.getDownloadTask(new NotificationDownloadListener(context, loaderInfo)).run();
}catch (IOException e) {
// TODO: pass on the IOException to a relevant handler
}
});
}
@ -62,5 +69,5 @@ public interface ModpackApi {
* @param modDetail The mod detail data
* @param selectedVersion The selected version
*/
ModLoader installMod(ModDetail modDetail, int selectedVersion);
ModLoader installMod(ModDetail modDetail, int selectedVersion) throws IOException;
}

View File

@ -18,7 +18,7 @@ import java.util.Locale;
public class ModpackInstaller {
public static ModLoader installModpack(ModDetail modDetail, int selectedVersion, InstallFunction installFunction) {
public static ModLoader installModpack(ModDetail modDetail, int selectedVersion, InstallFunction installFunction) throws IOException{
String versionUrl = modDetail.versionUrls[selectedVersion];
String modpackName = modDetail.title.toLowerCase(Locale.ROOT).trim().replace(" ", "_" );
@ -35,8 +35,6 @@ public class ModpackInstaller {
// Install the modpack
modLoaderInfo = installFunction.installModpack(modpackFile, new File(Tools.DIR_GAME_HOME, "custom_instances/"+modpackName));
} catch (IOException e) {
throw new RuntimeException(e);
} finally {
modpackFile.delete();
ProgressLayout.clearProgress(ProgressLayout.INSTALL_MODPACK);

View File

@ -90,7 +90,7 @@ public class ModrinthApi implements ModpackApi{
}
@Override
public ModLoader installMod(ModDetail modDetail, int selectedVersion) {
public ModLoader installMod(ModDetail modDetail, int selectedVersion) throws IOException{
//TODO considering only modpacks for now
return ModpackInstaller.installModpack(modDetail, selectedVersion, this::installMrpack);
}