Search in sources :

Example 1 with BundleReader

use of info.ata4.junity.bundle.BundleReader in project disunity by ata4.

the class BundleUnpack method runFile.

@Override
protected void runFile(Path file) {
    try (BundleReader bundleReader = new BundleReader(file)) {
        Bundle bundle = bundleReader.read();
        AtomicInteger done = new AtomicInteger();
        long total = bundle.entryInfos().size();
        // define output directory, if not yet defined
        if (outputDir == null) {
            // with sub-directories
            if (bundle.entryInfos().size() == 1) {
                outputDir = file.getParent();
                if (outputDir == null) {
                    // Passed a filename only. Use the current directory.
                    outputDir = Paths.get(".");
                }
            } else {
                String fileName = PathUtils.getBaseName(file);
                outputDir = file.resolveSibling(fileName);
            }
        }
        try {
            bundle.entries().stream().filter(entry -> filename == null || entry.name().equals(filename)).forEach(uncheck(entry -> {
                progress.update(Optional.of(entry.name()), done.getAndIncrement() / (double) total);
                Path entryFile = outputDir.resolve(entry.name());
                Files.createDirectories(entryFile.getParent());
                Files.copy(entry.inputStream(), entryFile, REPLACE_EXISTING);
                if (done.get() == total) {
                    progress.update(Optional.empty(), 1);
                }
            }));
        } catch (UncheckedIOException ex) {
            throw ex.getCause();
        }
        if (writeProp && filename == null) {
            String bundleName = outputDir.getFileName().toString();
            Path propsFile = outputDir.getParent().resolve(bundleName + ".json");
            BundleProps.write(propsFile, bundle);
        }
    } catch (IOException ex) {
        L.log(Level.WARNING, "Can't unpack asset bundle " + file, ex);
    }
}
Also used : LogUtils(info.ata4.log.LogUtils) Parameters(com.beust.jcommander.Parameters) IOConsumer.uncheck(info.ata4.util.function.IOConsumer.uncheck) Parameter(com.beust.jcommander.Parameter) Files(java.nio.file.Files) IOException(java.io.IOException) Logger(java.util.logging.Logger) Level(java.util.logging.Level) UncheckedIOException(java.io.UncheckedIOException) FileCommand(info.ata4.disunity.cli.command.FileCommand) PathConverter(info.ata4.disunity.cli.converters.PathConverter) Bundle(info.ata4.junity.bundle.Bundle) Paths(java.nio.file.Paths) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) PathUtils(info.ata4.io.util.PathUtils) Optional(java.util.Optional) BundleReader(info.ata4.junity.bundle.BundleReader) Path(java.nio.file.Path) REPLACE_EXISTING(java.nio.file.StandardCopyOption.REPLACE_EXISTING) Path(java.nio.file.Path) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Bundle(info.ata4.junity.bundle.Bundle) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException) BundleReader(info.ata4.junity.bundle.BundleReader)

Example 2 with BundleReader

use of info.ata4.junity.bundle.BundleReader in project disunity by ata4.

the class BundleCommand method runFileRecursive.

@Override
protected void runFileRecursive(Path file) {
    try (BundleReader reader = new BundleReader(file)) {
        Bundle bundle = reader.read();
        runBundle(file, bundle);
    } catch (IOException ex) {
        L.log(Level.WARNING, "Can't open asset bundle " + file, ex);
    }
}
Also used : Bundle(info.ata4.junity.bundle.Bundle) IOException(java.io.IOException) BundleReader(info.ata4.junity.bundle.BundleReader)

Example 3 with BundleReader

use of info.ata4.junity.bundle.BundleReader in project disunity by ata4.

the class AssetCommand method runFileRecursive.

@Override
protected void runFileRecursive(Path file) {
    if (BundleUtils.isBundle(file)) {
        // file is a bundle, load serialized files from it
        try (BundleReader bundleReader = new BundleReader(file)) {
            Bundle bundle = bundleReader.read();
            bundle.entries().stream().filter(not(BundleEntry::isLibrary)).filter(not(BundleEntry::isResource)).forEach(uncheck(entry -> {
                try (SerializedFileReader reader = new SerializedFileReader(BundleUtils.dataReaderForEntry(entry))) {
                    SerializedFile serialized = reader.read();
                    runSerializedFile(file.resolve(entry.name()), serialized);
                }
            }));
        } catch (UncheckedIOException | IOException ex) {
            L.log(Level.WARNING, "Can't open asset bundle " + file, ex);
        }
    } else {
        // load file directly
        try (SerializedFileReader reader = new SerializedFileReader(file)) {
            SerializedFile serialized = reader.read();
            runSerializedFile(file, serialized);
        } catch (IOException ex) {
            L.log(Level.WARNING, "Can't open asset file " + file, ex);
        }
    }
}
Also used : RecursiveFileCommand(info.ata4.disunity.cli.command.RecursiveFileCommand) LogUtils(info.ata4.log.LogUtils) IOConsumer.uncheck(info.ata4.util.function.IOConsumer.uncheck) IOException(java.io.IOException) Logger(java.util.logging.Logger) BundleUtils(info.ata4.junity.bundle.BundleUtils) SerializedFile(info.ata4.junity.serialize.SerializedFile) Predicates.not(info.ata4.util.function.Predicates.not) Level(java.util.logging.Level) BundleEntry(info.ata4.junity.bundle.BundleEntry) UncheckedIOException(java.io.UncheckedIOException) Bundle(info.ata4.junity.bundle.Bundle) SerializedFileReader(info.ata4.junity.serialize.SerializedFileReader) BundleReader(info.ata4.junity.bundle.BundleReader) Path(java.nio.file.Path) SerializedFileReader(info.ata4.junity.serialize.SerializedFileReader) SerializedFile(info.ata4.junity.serialize.SerializedFile) Bundle(info.ata4.junity.bundle.Bundle) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException) BundleEntry(info.ata4.junity.bundle.BundleEntry) BundleReader(info.ata4.junity.bundle.BundleReader)

Aggregations

Bundle (info.ata4.junity.bundle.Bundle)3 BundleReader (info.ata4.junity.bundle.BundleReader)3 IOException (java.io.IOException)3 LogUtils (info.ata4.log.LogUtils)2 IOConsumer.uncheck (info.ata4.util.function.IOConsumer.uncheck)2 UncheckedIOException (java.io.UncheckedIOException)2 Path (java.nio.file.Path)2 Level (java.util.logging.Level)2 Logger (java.util.logging.Logger)2 Parameter (com.beust.jcommander.Parameter)1 Parameters (com.beust.jcommander.Parameters)1 FileCommand (info.ata4.disunity.cli.command.FileCommand)1 RecursiveFileCommand (info.ata4.disunity.cli.command.RecursiveFileCommand)1 PathConverter (info.ata4.disunity.cli.converters.PathConverter)1 PathUtils (info.ata4.io.util.PathUtils)1 BundleEntry (info.ata4.junity.bundle.BundleEntry)1 BundleUtils (info.ata4.junity.bundle.BundleUtils)1 SerializedFile (info.ata4.junity.serialize.SerializedFile)1 SerializedFileReader (info.ata4.junity.serialize.SerializedFileReader)1 Predicates.not (info.ata4.util.function.Predicates.not)1