11package org .mcphackers .mcp .tools .versions ;
22
33import java .io .IOException ;
4- import java .net .URL ;
54import java .nio .file .Files ;
65import java .nio .file .Path ;
76import java .util .ArrayList ;
87import java .util .List ;
9- import java .util .Map .Entry ;
108
11- import org .json .JSONObject ;
129import org .mcphackers .mcp .DownloadListener ;
1310import org .mcphackers .mcp .MCP ;
1411import org .mcphackers .mcp .MCPPaths ;
1714import org .mcphackers .mcp .tools .Util ;
1815import org .mcphackers .mcp .tools .versions .json .Artifact ;
1916import org .mcphackers .mcp .tools .versions .json .AssetIndex ;
20- import org .mcphackers .mcp .tools .versions .json .AssetIndex .Asset ;
2117import org .mcphackers .mcp .tools .versions .json .DependDownload ;
2218import org .mcphackers .mcp .tools .versions .json .Download ;
2319import org .mcphackers .mcp .tools .versions .json .Rule ;
@@ -39,7 +35,6 @@ public DownloadEntry(Download dl, Path filePath, boolean verify) {
3935
4036 protected List <DownloadEntry > downloadQueue = new ArrayList <>();
4137 protected AssetIndex assets ;
42- private Path gameDir ;
4338 public int totalSize ;
4439 public List <DownloadEntry > natives = new ArrayList <>();
4540
@@ -48,7 +43,6 @@ public DownloadData(MCP mcp, Version version) {
4843 }
4944
5045 public DownloadData (Path libraries , Path gameDir , Path client , Path server , Version version ) {
51- this .gameDir = gameDir ;
5246 if (version .downloads .client != null && client != null ) {
5347 queueDownload (version .downloads .client , client , true ); // TODO may want to make verify flag togglable
5448 }
@@ -73,29 +67,6 @@ public DownloadData(Path libraries, Path gameDir, Path client, Path server, Vers
7367 }
7468 }
7569 }
76- try {
77- Path assetIndex = gameDir .resolve ("assets/indexes/" + version .assets + ".json" );
78- String assetIndexString ;
79- if (!Files .exists (assetIndex ) || !version .assetIndex .sha1 .equals (Util .getSHA1 (assetIndex ))) {
80- assetIndexString = new String (Util .readAllBytes (new URL (version .assetIndex .url ).openStream ()));
81- Files .write (assetIndex , assetIndexString .getBytes ());
82- }
83- else {
84- assetIndexString = new String (Files .readAllBytes (assetIndex ));
85- }
86- setAssets (AssetIndex .from (new JSONObject (assetIndexString )));
87- }
88- catch (IOException ignored ) {}
89- }
90-
91- public void setAssets (AssetIndex assets ) {
92- if (this .assets != null ) {
93- return ;
94- }
95- this .assets = assets ;
96- for (Entry <String , Asset > entry : assets .objects .entrySet ()) {
97- totalSize += entry .getValue ().size ();
98- }
9970 }
10071
10172 public DownloadEntry queueDownload (Download dl , Path path , boolean verify ) {
@@ -119,20 +90,6 @@ public void performDownload(DownloadListener listener) throws IOException {
11990 FileUtil .downloadFile (dlObj .url , file );
12091 }
12192 }
122- if (assets != null ) {
123- for (Entry <String , Asset > entry : assets .objects .entrySet ()) {
124- Asset asset = entry .getValue ();
125- String hash = asset .hash .substring (0 , 2 ) + "/" + asset .hash ;
126- String filename = assets .map_to_resources ? "resources/" + entry .getKey () : "assets/objects/" + hash ;
127- Path file = gameDir .resolve (filename );
128- listener .notify (asset , totalSize );
129- if (!Files .exists (file )) {
130- Path parent = file .getParent ();
131- if (parent != null ) Files .createDirectories (parent );
132- FileUtil .downloadFile ("http://resources.download.minecraft.net/" + hash , file );
133- }
134- }
135- }
13693 }
13794
13895 public static List <String > getLibraries (Version version ) {
0 commit comments