Fix 5408 by making Paths from the default provider (not inside jars)
offer a FileInputStream rather than Files.newInputStream. Fun. Stupid ancient paulscode. Signed-off-by: cpw <cpw+github@weeksfamily.ca>
This commit is contained in:
parent
b40e2cc59e
commit
9fbfe2b98e
1 changed files with 16 additions and 4 deletions
|
@ -19,6 +19,7 @@
|
|||
|
||||
package net.minecraftforge.fml.packs;
|
||||
|
||||
import it.unimi.dsi.fastutil.io.FastByteArrayInputStream;
|
||||
import net.minecraft.resources.AbstractResourcePack;
|
||||
import net.minecraft.resources.ResourcePackInfo;
|
||||
import net.minecraft.resources.ResourcePackType;
|
||||
|
@ -26,11 +27,13 @@ import net.minecraft.util.ResourceLocation;
|
|||
import net.minecraftforge.fml.loading.moddiscovery.ModFile;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.nio.channels.ByteChannel;
|
||||
import java.nio.channels.Channels;
|
||||
import java.nio.channels.SeekableByteChannel;
|
||||
import java.nio.file.*;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Set;
|
||||
|
@ -64,7 +67,16 @@ public class ModFileResourcePack extends AbstractResourcePack
|
|||
@Override
|
||||
protected InputStream getInputStream(String name) throws IOException
|
||||
{
|
||||
return Files.newInputStream(modFile.getLocator().findPath(modFile, name));
|
||||
// because paulscode is ancient, we can't return FileChannel based InputStreams here - it will cause a deadlock or crash
|
||||
// Paulscode sends interrupt() to trigger thread processing behaviour, and FileChannels will interpret that interrupt() as
|
||||
// a sign to close the FileChannel and throw an interrupt error. Tis brilliant!
|
||||
// If the Path comes from the default filesystem provider, we will rather use the path to generate an old FileInputStream
|
||||
final Path path = modFile.getLocator().findPath(modFile, name);
|
||||
if (path.getFileSystem() == FileSystems.getDefault()) {
|
||||
return new FileInputStream(path.toFile());
|
||||
} else {
|
||||
return Files.newInputStream(path, StandardOpenOption.READ);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Reference in a new issue