From 7e3e6b19698d0b30c57cdc5b24e03d9e7e49baa0 Mon Sep 17 00:00:00 2001 From: cpw Date: Sat, 15 Jun 2019 21:51:51 -0400 Subject: [PATCH] Remove paulscode hack. It is not needed in 1.14, since paulscode is no longer used. Signed-off-by: cpw --- .../fml/packs/ModFileResourcePack.java | 60 +------------------ 1 file changed, 1 insertion(+), 59 deletions(-) diff --git a/src/main/java/net/minecraftforge/fml/packs/ModFileResourcePack.java b/src/main/java/net/minecraftforge/fml/packs/ModFileResourcePack.java index bae2863fb..f2d4f71e5 100644 --- a/src/main/java/net/minecraftforge/fml/packs/ModFileResourcePack.java +++ b/src/main/java/net/minecraftforge/fml/packs/ModFileResourcePack.java @@ -54,28 +54,8 @@ import static net.minecraftforge.fml.Logging.CORE; public class ModFileResourcePack extends ResourcePack { - private static final Logger LOGGER = LogManager.getLogger(); private final ModFile modFile; private ResourcePackInfo packInfo; - private static final ExecutorService STUPIDPAULSCODEISSTUPIDWORKAROUNDTHREAD = Executors.newSingleThreadExecutor(); - private static final Path tempDir; - - static { - try { - tempDir = Files.createTempDirectory("modpacktmp"); - Runtime.getRuntime().addShutdownHook(new Thread(()-> { - try { - Files.walk(tempDir).forEach(f->{try {Files.deleteIfExists(f);}catch (IOException ioe) {}}); - Files.delete(tempDir); - } catch (IOException ioe) { - LOGGER.fatal("Failed to clean up tempdir {}", tempDir); - } - })); - } catch (IOException e) { - LOGGER.fatal(CORE, "Failed to create temporary directory", e); - throw new RuntimeException(e); - } - } public ModFileResourcePack(final ModFile modFile) { @@ -96,46 +76,8 @@ public class ModFileResourcePack extends ResourcePack @Override protected InputStream getInputStream(String name) throws IOException { - // 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()) { - LOGGER.trace(CORE, "Request for resource {} returning FileInputStream for regular file {}", name, path); - return new FileInputStream(path.toFile()); - // If the resource is in a zip file, and paulscode is the requester, we need to return a file input stream, - // but we can't just use path.tofile to do it. Instead, we copy the resource to a temporary file. As all operations - // with an nio channel are interruptible, we do this at arms length on another thread, while paulscode spams - // interrupts on the paulscode main thread, which we politely ignore. - } else if (StackTraceUtils.threadClassNameEquals("paulscode.sound.CommandThread")) { - final Path tempFile = Files.createTempFile(tempDir, "modpack", "soundresource"); - Future fis = STUPIDPAULSCODEISSTUPIDWORKAROUNDTHREAD.submit(()->{ - try (final SeekableByteChannel resourceChannel = Files.newByteChannel(path, StandardOpenOption.READ); - final FileChannel tempFileChannel = FileChannel.open(tempFile, StandardOpenOption.WRITE, StandardOpenOption.TRUNCATE_EXISTING)) { - long size = resourceChannel.size(); - for (long written = 0; written < size; ) { - written += tempFileChannel.transferFrom(resourceChannel, written, size - written); - } - } - LOGGER.trace(CORE, "Request for resource {} returning DeletingTemporaryFileInputStream for packed file {} on paulscode thread", name, path); - return new FileInputStream(tempFile.toFile()); - }); - try { - while (true) { - try { - return fis.get(); - } catch (InterruptedException ie) { - // no op - } - } - } catch (ExecutionException e) { - LOGGER.fatal(CORE, "Encountered fatal exception copying sound resource", e); - throw new RuntimeException(e); - } - } else { - return Files.newInputStream(path, StandardOpenOption.READ); - } + return Files.newInputStream(path, StandardOpenOption.READ); } @Override