Fix download assets for 1.13+

This commit is contained in:
khanhduytran0 2020-09-11 20:13:18 +07:00
parent 71fcfa4ed1
commit 5980b5822f
2 changed files with 10 additions and 5 deletions

View File

@ -15,6 +15,7 @@ public class JMinecraftVersionList {
public static class Version { public static class Version {
// Since 1.13, so it's one of ways to check // Since 1.13, so it's one of ways to check
public Arguments arguments; public Arguments arguments;
public AssetIndex assetIndex;
public String assets; public String assets;
public Map<String, MinecraftClientInfo> downloads; public Map<String, MinecraftClientInfo> downloads;
@ -46,5 +47,9 @@ public class JMinecraftVersionList {
} }
} }
} }
public static class AssetIndex {
public String id, sha1, url;
public long size, totalSize;
}
} }

View File

@ -469,8 +469,7 @@ public class MCLauncherActivity extends AppCompatActivity
statusIsLaunching(true); statusIsLaunching(true);
} }
private int maxSubProgress = 1; private JMinecraftVersionList.Version verInfo;
private int valSubProgress = 1;
@Override @Override
protected Throwable doInBackground(final String[] p1) { protected Throwable doInBackground(final String[] p1) {
Throwable throwable = null; Throwable throwable = null;
@ -479,8 +478,6 @@ public class MCLauncherActivity extends AppCompatActivity
//Downloading libraries //Downloading libraries
String inputPath = Tools.versnDir + downVName + ".jar"; String inputPath = Tools.versnDir + downVName + ".jar";
JMinecraftVersionList.Version verInfo;
try { try {
//com.pojavdx.dx.mod.Main.debug = true; //com.pojavdx.dx.mod.Main.debug = true;
@ -593,6 +590,8 @@ public class MCLauncherActivity extends AppCompatActivity
try { try {
downloadAssets(verInfo.assets, new File(Tools.ASSETS_PATH)); downloadAssets(verInfo.assets, new File(Tools.ASSETS_PATH));
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace();
// Ignore it // Ignore it
launchWithError = false; launchWithError = false;
} finally { } finally {
@ -691,12 +690,13 @@ public class MCLauncherActivity extends AppCompatActivity
public static final String MINECRAFT_RES = "http://resources.download.minecraft.net/"; public static final String MINECRAFT_RES = "http://resources.download.minecraft.net/";
public JAssets downloadIndex(String versionName, File output) throws Exception { public JAssets downloadIndex(String versionName, File output) throws Exception {
String versionJson = DownloadUtils.downloadString("http://s3.amazonaws.com/Minecraft.Download/indexes/" + versionName + ".json"); String versionJson = DownloadUtils.downloadString(verInfo.assetIndex != null ? verInfo.assetIndex.url : "http://s3.amazonaws.com/Minecraft.Download/indexes/" + versionName + ".json");
JAssets version = gsonss.fromJson(versionJson, JAssets.class); JAssets version = gsonss.fromJson(versionJson, JAssets.class);
output.getParentFile().mkdirs(); output.getParentFile().mkdirs();
Tools.write(output.getAbsolutePath(), versionJson.getBytes(Charset.forName("UTF-8"))); Tools.write(output.getAbsolutePath(), versionJson.getBytes(Charset.forName("UTF-8")));
return version; return version;
} }
public void downloadAsset(JAssetInfo asset, File objectsDir) throws IOException, Throwable { public void downloadAsset(JAssetInfo asset, File objectsDir) throws IOException, Throwable {
String assetPath = asset.hash.substring(0, 2) + "/" + asset.hash; String assetPath = asset.hash.substring(0, 2) + "/" + asset.hash;
File outFile = new File(objectsDir, assetPath); File outFile = new File(objectsDir, assetPath);