@Override public void processAsset(AssetFile asset) throws IOException { Path assetFile = asset.getSourceFile(); Path assetDir = assetFile.getParent(); String assetFileName = assetFile.getFileName().toString(); String assetPath; if (assetDir == null) { assetPath = ""; } else { assetPath = assetDir.toAbsolutePath().toString(); assetPath = FilenameUtils.separatorsToUnix(assetPath) + "/"; } // fix path for all assets with (shared)assets extension boolean changed = false; for (AssetRef ref : asset.getReferences()) { Path refFile = Paths.get(ref.getFilePath()); String refExt = FilenameUtils.getExtension(refFile.getFileName().toString()); if (refExt.endsWith("assets") && Files.notExists(refFile)) { String filePathOld = ref.getFilePath(); String filePathNew = assetPath + FilenameUtils.getName(ref.getFilePath()); Path refFileNew = Paths.get(filePathNew); if (Files.exists(refFileNew)) { L.log(Level.FINE, "Fixed reference: {0} -> {1}", new Object[] {filePathOld, filePathNew}); ref.setFilePath(filePathNew); changed = true; } else { L.log(Level.FINE, "Fixed reference not found: {0}", refFileNew); } } } if (!changed) { L.fine("No references changed, skipping saving"); return; } // create backup by renaming the original file Path assetFileBackup = assetFile.resolveSibling(assetFileName + ".bak"); Files.move(assetFile, assetFileBackup, StandardCopyOption.REPLACE_EXISTING); // save asset asset.save(assetFile); }
public void printInfo(PrintStream ps) { AssetObjectPathTable objTable = asset.getObjectPaths(); AssetRefTable refTable = asset.getReferences(); AssetHeader header = asset.getHeader(); AssetTypeTree fieldTree = asset.getTypeTree(); ps.println("Header"); ps.println(" File size: " + humanReadableByteCount(header.fileSize, true)); ps.println(" Tree size: " + humanReadableByteCount(header.treeSize, true)); ps.println(" Format: " + header.format); ps.println(" Data offset: " + header.dataOffset); ps.println(" Unknown: " + header.unknown); ps.println(); ps.println("Serialized data"); ps.println(" Revision: " + fieldTree.revision); ps.println(" Version: " + fieldTree.version); ps.println(" Standalone: " + (fieldTree.isStandalone() ? "yes" : "no")); ps.println(" Objects: " + objTable.size()); ps.println(); if (!refTable.isEmpty()) { ps.println("External references"); for (AssetRef ref : refTable) { if (!ref.assetPath.isEmpty()) { ps.printf(" Asset path: \"%s\"\n", ref.assetPath); } if (!ref.filePath.isEmpty()) { ps.printf(" File path: \"%s\"\n", ref.filePath); } ps.printf(" GUID: %s\n", DatatypeConverter.printHexBinary(ref.guid)); ps.printf(" Type: %d\n", ref.type); ps.println(); } } }