mirror of
https://github.com/revanced/Apktool.git
synced 2025-01-07 10:35:52 +01:00
java7 try-with-resources and multi catch
This commit is contained in:
parent
9031c22365
commit
d821717253
@ -21,7 +21,6 @@ import brut.androlib.res.AndrolibResources;
|
|||||||
import brut.androlib.res.data.ResPackage;
|
import brut.androlib.res.data.ResPackage;
|
||||||
import brut.androlib.res.data.ResTable;
|
import brut.androlib.res.data.ResTable;
|
||||||
import brut.androlib.res.data.ResUnknownFiles;
|
import brut.androlib.res.data.ResUnknownFiles;
|
||||||
import brut.androlib.res.decoder.ResFileDecoder;
|
|
||||||
import brut.androlib.res.util.ExtFile;
|
import brut.androlib.res.util.ExtFile;
|
||||||
import brut.androlib.src.SmaliBuilder;
|
import brut.androlib.src.SmaliBuilder;
|
||||||
import brut.androlib.src.SmaliDecoder;
|
import brut.androlib.src.SmaliDecoder;
|
||||||
@ -30,8 +29,6 @@ import brut.directory.*;
|
|||||||
import brut.util.BrutIO;
|
import brut.util.BrutIO;
|
||||||
import brut.util.OS;
|
import brut.util.OS;
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.net.URI;
|
|
||||||
import java.net.URISyntaxException;
|
|
||||||
import java.nio.file.*;
|
import java.nio.file.*;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
@ -184,11 +181,7 @@ public class Androlib {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
apkZipFile.close();
|
apkZipFile.close();
|
||||||
}
|
} catch (DirectoryException | IOException ex) {
|
||||||
catch (DirectoryException ex) {
|
|
||||||
throw new AndrolibException(ex);
|
|
||||||
}
|
|
||||||
catch (IOException ex) {
|
|
||||||
throw new AndrolibException(ex);
|
throw new AndrolibException(ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -220,37 +213,25 @@ public class Androlib {
|
|||||||
options.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
|
options.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
|
||||||
Yaml yaml = new Yaml(options);
|
Yaml yaml = new Yaml(options);
|
||||||
|
|
||||||
Writer writer = null;
|
try (
|
||||||
try {
|
Writer writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(
|
||||||
writer = new BufferedWriter(new OutputStreamWriter(
|
new File(mOutDir, "apktool.yml")), "UTF-8"));
|
||||||
new FileOutputStream(new File(mOutDir, "apktool.yml")), "UTF-8"));
|
) {
|
||||||
yaml.dump(meta, writer);
|
yaml.dump(meta, writer);
|
||||||
} catch (IOException ex) {
|
} catch (IOException ex) {
|
||||||
throw new AndrolibException(ex);
|
throw new AndrolibException(ex);
|
||||||
} finally {
|
|
||||||
if (writer != null) {
|
|
||||||
try {
|
|
||||||
writer.close();
|
|
||||||
} catch (IOException ex) { }
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Map<String, Object> readMetaFile(ExtFile appDir)
|
public Map<String, Object> readMetaFile(ExtFile appDir)
|
||||||
throws AndrolibException {
|
throws AndrolibException {
|
||||||
InputStream in = null;
|
try(
|
||||||
try {
|
InputStream in = appDir.getDirectory().getFileInput("apktool.yml");
|
||||||
in = appDir.getDirectory().getFileInput("apktool.yml");
|
) {
|
||||||
Yaml yaml = new Yaml();
|
Yaml yaml = new Yaml();
|
||||||
return (Map<String, Object>) yaml.load(in);
|
return (Map<String, Object>) yaml.load(in);
|
||||||
} catch (DirectoryException ex) {
|
} catch (DirectoryException | IOException ex) {
|
||||||
throw new AndrolibException(ex);
|
throw new AndrolibException(ex);
|
||||||
} finally {
|
|
||||||
if (in != null) {
|
|
||||||
try {
|
|
||||||
in.close();
|
|
||||||
} catch (IOException ex) { }
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -419,8 +400,7 @@ public class Androlib {
|
|||||||
LOGGER.info("Checking whether resources has changed...");
|
LOGGER.info("Checking whether resources has changed...");
|
||||||
}
|
}
|
||||||
File apkDir = new File(appDir, APK_DIRNAME);
|
File apkDir = new File(appDir, APK_DIRNAME);
|
||||||
if (flags.get("forceBuildAll")
|
if (flags.get("forceBuildAll") || isModified(newFiles(APP_RESOURCES_FILENAMES, appDir),
|
||||||
|| isModified(newFiles(APP_RESOURCES_FILENAMES, appDir),
|
|
||||||
newFiles(APK_RESOURCES_FILENAMES, apkDir))) {
|
newFiles(APK_RESOURCES_FILENAMES, apkDir))) {
|
||||||
LOGGER.info("Building resources...");
|
LOGGER.info("Building resources...");
|
||||||
|
|
||||||
@ -478,8 +458,7 @@ public class Androlib {
|
|||||||
mAndRes.remove_application_debug(new File(apkDir,"AndroidManifest.xml").getAbsolutePath());
|
mAndRes.remove_application_debug(new File(apkDir,"AndroidManifest.xml").getAbsolutePath());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (flags.get("forceBuildAll")
|
if (flags.get("forceBuildAll") || isModified(newFiles(APK_MANIFEST_FILENAMES, appDir),
|
||||||
|| isModified(newFiles(APK_MANIFEST_FILENAMES, appDir),
|
|
||||||
newFiles(APK_MANIFEST_FILENAMES, apkDir))) {
|
newFiles(APK_MANIFEST_FILENAMES, apkDir))) {
|
||||||
LOGGER.info("Building AndroidManifest.xml...");
|
LOGGER.info("Building AndroidManifest.xml...");
|
||||||
|
|
||||||
@ -585,11 +564,11 @@ public class Androlib {
|
|||||||
|
|
||||||
private void insertFile(Path apkPath, Map<String,String> zip_properties, File insert, String method, Path location)
|
private void insertFile(Path apkPath, Map<String,String> zip_properties, File insert, String method, Path location)
|
||||||
throws AndrolibException, IOException {
|
throws AndrolibException, IOException {
|
||||||
|
|
||||||
// ZipFileSystem only writes at .close()
|
// ZipFileSystem only writes at .close()
|
||||||
// http://mail.openjdk.java.net/pipermail/nio-dev/2012-July/001764.html
|
// http://mail.openjdk.java.net/pipermail/nio-dev/2012-July/001764.html
|
||||||
try(FileSystem fs = FileSystems.newFileSystem(apkPath, null)) {
|
try(
|
||||||
|
FileSystem fs = FileSystems.newFileSystem(apkPath, null)
|
||||||
|
) {
|
||||||
Path root = fs.getPath("/");
|
Path root = fs.getPath("/");
|
||||||
|
|
||||||
// in order to get the path relative to the zip, we strip off the absolute path, minus what we
|
// in order to get the path relative to the zip, we strip off the absolute path, minus what we
|
||||||
@ -603,9 +582,9 @@ public class Androlib {
|
|||||||
|
|
||||||
private void insertFolder(Path apkPath, Map<String,String> zip_properties, File insert, String method, Path location)
|
private void insertFolder(Path apkPath, Map<String,String> zip_properties, File insert, String method, Path location)
|
||||||
throws AndrolibException, IOException {
|
throws AndrolibException, IOException {
|
||||||
|
try(
|
||||||
try(FileSystem fs = FileSystems.newFileSystem(apkPath, null)) {
|
FileSystem fs = FileSystems.newFileSystem(apkPath, null)
|
||||||
|
) {
|
||||||
Path root = fs.getPath("/");
|
Path root = fs.getPath("/");
|
||||||
Path dest = fs.getPath(root.toString(), insert.getAbsolutePath().replace(location.toString(),""));
|
Path dest = fs.getPath(root.toString(), insert.getAbsolutePath().replace(location.toString(),""));
|
||||||
Path parent = dest.normalize();
|
Path parent = dest.normalize();
|
||||||
@ -635,8 +614,7 @@ public class Androlib {
|
|||||||
if (!assetDir.exists()) {
|
if (!assetDir.exists()) {
|
||||||
assetDir = null;
|
assetDir = null;
|
||||||
}
|
}
|
||||||
mAndRes.aaptPackage(outApk, null, null, new File(appDir, APK_DIRNAME),
|
mAndRes.aaptPackage(outApk, null, null, new File(appDir, APK_DIRNAME), assetDir, null, flags, mAaptPath);
|
||||||
assetDir, null, flags, mAaptPath);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void publicizeResources(File arscFile) throws AndrolibException {
|
public void publicizeResources(File arscFile) throws AndrolibException {
|
||||||
@ -683,11 +661,7 @@ public class Androlib {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private boolean isModified(File working, File stored) {
|
private boolean isModified(File working, File stored) {
|
||||||
if (!stored.exists()) {
|
return ! stored.exists() || BrutIO.recursiveModifiedTime(working) > BrutIO .recursiveModifiedTime(stored);
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return BrutIO.recursiveModifiedTime(working) > BrutIO
|
|
||||||
.recursiveModifiedTime(stored);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isModified(File[] working, File[] stored) {
|
private boolean isModified(File[] working, File[] stored) {
|
||||||
@ -696,8 +670,7 @@ public class Androlib {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return BrutIO.recursiveModifiedTime(working) > BrutIO
|
return BrutIO.recursiveModifiedTime(working) > BrutIO.recursiveModifiedTime(stored);
|
||||||
.recursiveModifiedTime(stored);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private File[] newFiles(String[] names, File dir) {
|
private File[] newFiles(String[] names, File dir) {
|
||||||
|
Loading…
Reference in New Issue
Block a user