Fix[forge]: consult the version list for the full loader version

This commit is contained in:
artdeell 2023-08-19 22:18:30 +03:00 committed by ArtDev
parent 78d6d09107
commit d8b1fbf968
3 changed files with 60 additions and 18 deletions

View File

@ -10,30 +10,29 @@ import net.kdt.pojavlaunch.utils.DownloadUtils;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.List;
public class ForgeDownloadTask implements Runnable, Tools.DownloaderFeedback {
private final String mForgeUrl;
private final String mForgeVersion;
private String mDownloadUrl;
private String mFullVersion;
private String mLoaderVersion;
private String mGameVersion;
private final ModloaderDownloadListener mListener;
public ForgeDownloadTask(ModloaderDownloadListener listener, String forgeVersion) {
this.mListener = listener;
this.mForgeUrl = ForgeUtils.getInstallerUrl(forgeVersion);
this.mForgeVersion = forgeVersion;
this.mDownloadUrl = ForgeUtils.getInstallerUrl(forgeVersion);
this.mFullVersion = forgeVersion;
}
public ForgeDownloadTask(ModloaderDownloadListener listener, String gameVersion, String loaderVersion) {
this.mListener = listener;
this.mLoaderVersion = loaderVersion;
this.mGameVersion = gameVersion;
}
@Override
public void run() {
ProgressKeeper.submitProgress(ProgressLayout.INSTALL_MODPACK, 0, R.string.forge_dl_progress, mForgeVersion);
try {
File destinationFile = new File(Tools.DIR_CACHE, "forge-installer.jar");
byte[] buffer = new byte[8192];
DownloadUtils.downloadFileMonitored(mForgeUrl, destinationFile, buffer, this);
mListener.onDownloadFinished(destinationFile);
}catch (IOException e) {
if(e instanceof FileNotFoundException) {
mListener.onDataNotAvailable();
}else{
mListener.onDownloadError(e);
}
if(determineDownloadUrl()) {
downloadForge();
}
ProgressKeeper.submitProgress(ProgressLayout.INSTALL_MODPACK, -1, -1);
}
@ -41,7 +40,49 @@ public class ForgeDownloadTask implements Runnable, Tools.DownloaderFeedback {
@Override
public void updateProgress(int curr, int max) {
int progress100 = (int)(((float)curr / (float)max)*100f);
ProgressKeeper.submitProgress(ProgressLayout.INSTALL_MODPACK, progress100, R.string.forge_dl_progress, mForgeVersion);
ProgressKeeper.submitProgress(ProgressLayout.INSTALL_MODPACK, progress100, R.string.forge_dl_progress, mFullVersion);
}
private void downloadForge() {
ProgressKeeper.submitProgress(ProgressLayout.INSTALL_MODPACK, 0, R.string.forge_dl_progress, mFullVersion);
try {
File destinationFile = new File(Tools.DIR_CACHE, "forge-installer.jar");
byte[] buffer = new byte[8192];
DownloadUtils.downloadFileMonitored(mDownloadUrl, destinationFile, buffer, this);
mListener.onDownloadFinished(destinationFile);
}catch (FileNotFoundException e) {
mListener.onDataNotAvailable();
} catch (IOException e) {
mListener.onDownloadError(e);
}
}
public boolean determineDownloadUrl() {
if(mDownloadUrl != null && mFullVersion != null) return true;
ProgressKeeper.submitProgress(ProgressLayout.INSTALL_MODPACK, 0, R.string.forge_dl_searching);
try {
if(!findVersion()) {
mListener.onDataNotAvailable();
return false;
}
}catch (IOException e) {
mListener.onDownloadError(e);
return false;
}
return true;
}
public boolean findVersion() throws IOException {
List<String> forgeVersions = ForgeUtils.downloadForgeVersions();
if(forgeVersions == null) return false;
String versionStart = mGameVersion+"-"+mLoaderVersion;
for(String versionName : forgeVersions) {
if(!versionName.startsWith(versionStart)) continue;
mFullVersion = versionName;
mDownloadUrl = ForgeUtils.getInstallerUrl(mFullVersion);
return true;
}
return false;
}
}

View File

@ -51,7 +51,7 @@ public class ModLoader {
public Runnable getDownloadTask(ModloaderDownloadListener listener) {
switch (modLoaderType) {
case MOD_LOADER_FORGE:
return new ForgeDownloadTask(listener, minecraftVersion+"-"+modLoaderVersion);
return new ForgeDownloadTask(listener, minecraftVersion, modLoaderVersion);
case MOD_LOADER_FABRIC:
return new FabricDownloadTask(listener);
case MOD_LOADER_QUILT:

View File

@ -384,6 +384,7 @@
<string name="preference_force_big_core_desc">Forces the Minecraft render thread to run on the core with the highest max frequency</string>
<string name="version_select_hint">Select a version</string>
<string name="forge_dl_progress">Downloading installer for %s</string>
<string name="forge_dl_searching">Searching for Forge version number</string>
<string name="modloader_dl_failed_to_load_list">Failed to load the version list!</string>
<string name="forge_dl_no_installer">Sorry, but this version of Forge does not have an installer, which is not yet supported.</string>
<string name="forge_dl_select_version">Select Forge version</string>