Auto-download inherited version if it does not exist

This commit is contained in:
artdeell 2021-01-31 00:10:33 +03:00
parent 91815f486e
commit d7acd362e2
3 changed files with 17 additions and 6 deletions

View File

@ -127,7 +127,7 @@ public class BaseMainActivity extends LoggableActivity {
logStream = new PrintStream(logFile.getAbsolutePath());
mProfile = PojavProfile.getCurrentProfileContent(this);
mVersionInfo = Tools.getVersionInfo(mProfile.selectedVersion);
mVersionInfo = Tools.getVersionInfo(null,mProfile.selectedVersion);
setTitle("Minecraft " + mProfile.selectedVersion);

View File

@ -534,7 +534,7 @@ public final class Tools
return libDir.toArray(new String[0]);
}
public static JMinecraftVersionList.Version getVersionInfo(String versionName) {
public static JMinecraftVersionList.Version getVersionInfo(BaseLauncherActivity bla, String versionName) {
try {
JMinecraftVersionList.Version customVer = Tools.GLOBAL_GSON.fromJson(read(DIR_HOME_VERSION + "/" + versionName + "/" + versionName + ".json"), JMinecraftVersionList.Version.class);
for (DependentLibrary lib : customVer.libraries) {
@ -545,9 +545,20 @@ public final class Tools
if (customVer.inheritsFrom == null || customVer.inheritsFrom.equals(customVer.id)) {
return customVer;
} else {
JMinecraftVersionList.Version inheritsVer = Tools.GLOBAL_GSON.fromJson(read(DIR_HOME_VERSION + "/" + customVer.inheritsFrom + "/" + customVer.inheritsFrom + ".json"), JMinecraftVersionList.Version.class);
JMinecraftVersionList.Version inheritsVer = null;
if(bla != null) if (bla.mVersionList != null) {
for (JMinecraftVersionList.Version valueVer : bla.mVersionList.versions) {
if (valueVer.id.equals(customVer.inheritsFrom) && (!new File(DIR_HOME_VERSION + "/" + customVer.inheritsFrom + "/" + customVer.inheritsFrom + ".json").exists()) && (valueVer.url != null)) {
Tools.downloadFile(valueVer.url,DIR_HOME_VERSION + "/" + customVer.inheritsFrom + "/" + customVer.inheritsFrom + ".json");
}
}
}//If it won't download, just search for it
try{
inheritsVer = Tools.GLOBAL_GSON.fromJson(read(DIR_HOME_VERSION + "/" + customVer.inheritsFrom + "/" + customVer.inheritsFrom + ".json"), JMinecraftVersionList.Version.class);
}catch(IOException e) {
throw new RuntimeException("Can't find the source version for "+ versionName +" (req version="+customVer.inheritsFrom+")");
}
inheritsVer.inheritsFrom = inheritsVer.id;
insertSafety(inheritsVer, customVer,
"assetIndex", "assets", "id",
"mainClass", "minecraftArguments",

View File

@ -58,7 +58,7 @@ public class MinecraftDownloaderTask extends AsyncTask<String, String, Throwable
);
}
verInfo = Tools.getVersionInfo(p1[0]);
verInfo = Tools.getVersionInfo(mActivity,p1[0]);
try {
assets = downloadIndex(verInfo.assets, new File(Tools.ASSETS_PATH, "indexes/" + verInfo.assets + ".json"));
} catch (IOException e) {
@ -341,6 +341,6 @@ public class MinecraftDownloaderTask extends AsyncTask<String, String, Throwable
}
// Custom version, inherits from base.
return Tools.getVersionInfo(version);
return Tools.getVersionInfo(mActivity,version);
}
}