mirror of
https://github.com/AngelAuraMC/Amethyst-Android.git
synced 2025-09-15 15:48:26 -04:00
Feat[modpack]: Set up framework for handling ModpackApi IOExceptions
This commit is contained in:
parent
e513156c6f
commit
91c834117d
@ -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.SearchFilters;
|
||||||
import net.kdt.pojavlaunch.modloaders.modpacks.models.SearchResult;
|
import net.kdt.pojavlaunch.modloaders.modpacks.models.SearchResult;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.concurrent.Callable;
|
import java.util.concurrent.Callable;
|
||||||
import java.util.concurrent.Future;
|
import java.util.concurrent.Future;
|
||||||
@ -92,7 +93,7 @@ public class CommonApi implements ModpackApi {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ModLoader installMod(ModDetail modDetail, int selectedVersion) {
|
public ModLoader installMod(ModDetail modDetail, int selectedVersion) throws IOException {
|
||||||
return getModpackApi(modDetail.apiSource).installMod(modDetail, selectedVersion);
|
return getModpackApi(modDetail.apiSource).installMod(modDetail, selectedVersion);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -118,7 +118,7 @@ public class CurseforgeApi implements ModpackApi{
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ModLoader installMod(ModDetail modDetail, int selectedVersion) {
|
public ModLoader installMod(ModDetail modDetail, int selectedVersion) throws IOException{
|
||||||
//TODO considering only modpacks for now
|
//TODO considering only modpacks for now
|
||||||
return ModpackInstaller.installModpack(modDetail, selectedVersion, this::installCurseforgeZip);
|
return ModpackInstaller.installModpack(modDetail, selectedVersion, this::installCurseforgeZip);
|
||||||
}
|
}
|
||||||
|
@ -7,11 +7,14 @@ import com.kdt.mcgui.ProgressLayout;
|
|||||||
|
|
||||||
import net.kdt.pojavlaunch.PojavApplication;
|
import net.kdt.pojavlaunch.PojavApplication;
|
||||||
import net.kdt.pojavlaunch.R;
|
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.ModDetail;
|
||||||
import net.kdt.pojavlaunch.modloaders.modpacks.models.ModItem;
|
import net.kdt.pojavlaunch.modloaders.modpacks.models.ModItem;
|
||||||
import net.kdt.pojavlaunch.modloaders.modpacks.models.SearchFilters;
|
import net.kdt.pojavlaunch.modloaders.modpacks.models.SearchFilters;
|
||||||
import net.kdt.pojavlaunch.modloaders.modpacks.models.SearchResult;
|
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)
|
// which may lead to two concurrent installations (very bad)
|
||||||
ProgressLayout.setProgress(ProgressLayout.INSTALL_MODPACK, 0, R.string.global_waiting);
|
ProgressLayout.setProgress(ProgressLayout.INSTALL_MODPACK, 0, R.string.global_waiting);
|
||||||
PojavApplication.sExecutorService.execute(() -> {
|
PojavApplication.sExecutorService.execute(() -> {
|
||||||
|
try {
|
||||||
ModLoader loaderInfo = installMod(modDetail, selectedVersion);
|
ModLoader loaderInfo = installMod(modDetail, selectedVersion);
|
||||||
if (loaderInfo == null) return;
|
if (loaderInfo == null) return;
|
||||||
loaderInfo.getDownloadTask(new NotificationDownloadListener(context, loaderInfo)).run();
|
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 modDetail The mod detail data
|
||||||
* @param selectedVersion The selected version
|
* @param selectedVersion The selected version
|
||||||
*/
|
*/
|
||||||
ModLoader installMod(ModDetail modDetail, int selectedVersion);
|
ModLoader installMod(ModDetail modDetail, int selectedVersion) throws IOException;
|
||||||
}
|
}
|
||||||
|
@ -18,7 +18,7 @@ import java.util.Locale;
|
|||||||
|
|
||||||
public class ModpackInstaller {
|
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 versionUrl = modDetail.versionUrls[selectedVersion];
|
||||||
String modpackName = modDetail.title.toLowerCase(Locale.ROOT).trim().replace(" ", "_" );
|
String modpackName = modDetail.title.toLowerCase(Locale.ROOT).trim().replace(" ", "_" );
|
||||||
|
|
||||||
@ -35,8 +35,6 @@ public class ModpackInstaller {
|
|||||||
// Install the modpack
|
// Install the modpack
|
||||||
modLoaderInfo = installFunction.installModpack(modpackFile, new File(Tools.DIR_GAME_HOME, "custom_instances/"+modpackName));
|
modLoaderInfo = installFunction.installModpack(modpackFile, new File(Tools.DIR_GAME_HOME, "custom_instances/"+modpackName));
|
||||||
|
|
||||||
} catch (IOException e) {
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
} finally {
|
} finally {
|
||||||
modpackFile.delete();
|
modpackFile.delete();
|
||||||
ProgressLayout.clearProgress(ProgressLayout.INSTALL_MODPACK);
|
ProgressLayout.clearProgress(ProgressLayout.INSTALL_MODPACK);
|
||||||
|
@ -90,7 +90,7 @@ public class ModrinthApi implements ModpackApi{
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ModLoader installMod(ModDetail modDetail, int selectedVersion) {
|
public ModLoader installMod(ModDetail modDetail, int selectedVersion) throws IOException{
|
||||||
//TODO considering only modpacks for now
|
//TODO considering only modpacks for now
|
||||||
return ModpackInstaller.installModpack(modDetail, selectedVersion, this::installMrpack);
|
return ModpackInstaller.installModpack(modDetail, selectedVersion, this::installMrpack);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user