mirror of
https://github.com/revanced/Apktool.git
synced 2024-12-13 06:17:46 +01:00
buildUnknownFiles optimization
newFileSystem will file replication overhead
This commit is contained in:
parent
35f9786fac
commit
f3582b60db
@ -544,7 +544,6 @@ public class Androlib {
|
|||||||
|
|
||||||
public void buildUnknownFiles(File appDir, File outFile, Map<String, Object> meta)
|
public void buildUnknownFiles(File appDir, File outFile, Map<String, Object> meta)
|
||||||
throws AndrolibException {
|
throws AndrolibException {
|
||||||
File file;
|
|
||||||
Path globalPath = Paths.get(appDir.getPath() + File.separatorChar + UNK_DIRNAME);
|
Path globalPath = Paths.get(appDir.getPath() + File.separatorChar + UNK_DIRNAME);
|
||||||
|
|
||||||
if (meta.containsKey("unknownFiles")) {
|
if (meta.containsKey("unknownFiles")) {
|
||||||
@ -561,16 +560,20 @@ public class Androlib {
|
|||||||
// create filesystem
|
// create filesystem
|
||||||
Path path = Paths.get(outFile.getAbsolutePath());
|
Path path = Paths.get(outFile.getAbsolutePath());
|
||||||
|
|
||||||
|
try(
|
||||||
|
FileSystem fs = FileSystems.newFileSystem(path, null)
|
||||||
|
) {
|
||||||
// loop through files inside
|
// loop through files inside
|
||||||
for (Map.Entry<String,String> entry : files.entrySet()) {
|
for (Map.Entry<String,String> entry : files.entrySet()) {
|
||||||
|
|
||||||
file = new File(globalPath.toFile(), entry.getKey());
|
File file = new File(globalPath.toFile(), entry.getKey());
|
||||||
if (file.isFile() && file.exists()) {
|
Path dest = fs.getPath(entry.getKey());
|
||||||
insertFolder(path, zip_properties, file.getParentFile(), entry.getValue(),
|
Path destParent = dest.getParent();
|
||||||
globalPath.toAbsolutePath());
|
if (destParent != null && !Files.exists(destParent)) {
|
||||||
|
Files.createDirectories(destParent);
|
||||||
insertFile(path, zip_properties, file, entry.getValue(),
|
}
|
||||||
globalPath.toAbsolutePath());
|
Path newFile = Paths.get(file.getAbsolutePath());
|
||||||
|
Files.copy(newFile, dest, StandardCopyOption.REPLACE_EXISTING);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (IOException ex) {
|
} catch (IOException ex) {
|
||||||
@ -579,43 +582,6 @@ public class Androlib {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void insertFile(Path apkPath, Map<String,String> zip_properties, File insert, String method, Path location)
|
|
||||||
throws AndrolibException, IOException {
|
|
||||||
// ZipFileSystem only writes at .close()
|
|
||||||
// http://mail.openjdk.java.net/pipermail/nio-dev/2012-July/001764.html
|
|
||||||
try(
|
|
||||||
FileSystem fs = FileSystems.newFileSystem(apkPath, null)
|
|
||||||
) {
|
|
||||||
Path root = fs.getPath("/");
|
|
||||||
|
|
||||||
// in order to get the path relative to the zip, we strip off the absolute path, minus what we
|
|
||||||
// already have in the zip. thus /var/files/apktool/apk/unknown/folder/file => /folder/file
|
|
||||||
Path dest = fs.getPath(root.toString(), insert.getAbsolutePath().replace(location.toString(),""));
|
|
||||||
Path newFile = Paths.get(insert.getAbsolutePath());
|
|
||||||
Files.copy(newFile,dest, StandardCopyOption.REPLACE_EXISTING);
|
|
||||||
fs.close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void insertFolder(Path apkPath, Map<String,String> zip_properties, File insert, String method, Path location)
|
|
||||||
throws AndrolibException, IOException {
|
|
||||||
try(
|
|
||||||
FileSystem fs = FileSystems.newFileSystem(apkPath, null)
|
|
||||||
) {
|
|
||||||
Path root = fs.getPath("/");
|
|
||||||
Path dest = fs.getPath(root.toString(), insert.getAbsolutePath().replace(location.toString(),""));
|
|
||||||
Path parent = dest.normalize();
|
|
||||||
|
|
||||||
// check for folder existing in apkFileSystem
|
|
||||||
if (parent != null && Files.notExists(parent)) {
|
|
||||||
if (!Files.isDirectory(parent, LinkOption.NOFOLLOW_LINKS)) {
|
|
||||||
Files.createDirectories(parent);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
fs.close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void buildApk(File appDir, File outApk) throws AndrolibException {
|
public void buildApk(File appDir, File outApk) throws AndrolibException {
|
||||||
LOGGER.info("Building apk file...");
|
LOGGER.info("Building apk file...");
|
||||||
if (outApk.exists()) {
|
if (outApk.exists()) {
|
||||||
|
Loading…
Reference in New Issue
Block a user