Skip to content

Commit 681c856

Browse files
committed
fixed asset downloading and crashing
1 parent 517fad0 commit 681c856

File tree

1 file changed

+19
-5
lines changed

1 file changed

+19
-5
lines changed

src/main/java/net/minecraftforge/gradle/tasks/DownloadAssetsTask.java

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,11 @@
2828
public class DownloadAssetsTask extends DefaultTask
2929
{
3030
DelayedFile assetsDir;
31-
31+
3232
@Input
3333
Closure<AssetIndex> index;
3434

35+
private boolean errored = false;
3536
private final ConcurrentLinkedQueue<Asset> filesLeft = new ConcurrentLinkedQueue<Asset>();
3637
private final ArrayList<AssetsThread> threads = new ArrayList<AssetsThread>();
3738
private final File minecraftDir = new File(Constants.getMinecraftDirectory(), "assets/objects");
@@ -44,7 +45,7 @@ public void doTask() throws ParserConfigurationException, SAXException, IOExcept
4445
{
4546
File out = new File(getAssetsDir(), "objects");
4647
out.mkdirs();
47-
48+
4849
AssetIndex index = getIndex();
4950

5051
for (Entry<String, AssetEntry> e : index.objects.entrySet())
@@ -65,7 +66,12 @@ public void doTask() throws ParserConfigurationException, SAXException, IOExcept
6566
int max = filesLeft.size();
6667
getLogger().info("Files Missing: " + max + "/" + index.objects.size());
6768

69+
// get number of threads
6870
int threadNum = max / 100;
71+
if (threadNum == 0 && max > 0)
72+
threadNum++; // atleats 1 thread
73+
74+
// spawn threads
6975
for (int i = 0; i < threadNum; i++)
7076
spawnThread();
7177

@@ -78,6 +84,12 @@ public void doTask() throws ParserConfigurationException, SAXException, IOExcept
7884
spawnThread();
7985
Thread.sleep(1000);
8086
}
87+
88+
if (errored)
89+
{
90+
// CRASH!
91+
throw new RuntimeException("Something went wrong with the Assets downloading!");
92+
}
8193
}
8294

8395
private void spawnThread()
@@ -163,18 +175,18 @@ public void run()
163175
file.getParentFile().mkdirs();
164176
file.createNewFile();
165177
}
166-
178+
167179
File localMc = new File(minecraftDir, asset.path);
168180
BufferedInputStream stream;
169-
181+
170182
// check for local copy
171183
if (localMc.exists() && Constants.hash(localMc, "SHA1").equals(asset.hash))
172184
// if so, copy
173185
stream = new BufferedInputStream(Files.newInputStreamSupplier(localMc).getInput());
174186
else
175187
// otherwise download
176188
stream = new BufferedInputStream(new URL(Constants.ASSETS_URL + "/" + asset.path).openStream());
177-
189+
178190
Files.write(ByteStreams.toByteArray(stream), file);
179191
stream.close();
180192

@@ -192,6 +204,8 @@ public void run()
192204
{
193205
getLogger().error("Error downloading asset: " + asset.path);
194206
e.printStackTrace();
207+
if (!errored)
208+
errored = true;
195209
}
196210
}
197211
}

0 commit comments

Comments
 (0)