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);
}
}
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);
}
}
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);
}
}
}
Aggregations