android_tools_rs/aapt2/
dump.rs1use crate::error::*;
2use std::path::{Path, PathBuf};
3use std::process::Command;
4
5pub struct Aapt2Dump {
21 subcommand: SubCommand,
22 filename_apk: PathBuf,
23 no_values: bool,
24 dumped_file: Option<PathBuf>,
25 verbose: bool,
26 help: bool,
27}
28
29impl Aapt2Dump {
30 pub fn new(subcommand: SubCommand, filename_apk: &Path) -> Self {
32 Self {
33 subcommand,
34 filename_apk: filename_apk.to_owned(),
35 no_values: false,
36 dumped_file: None,
37 verbose: false,
38 help: false,
39 }
40 }
41
42 pub fn no_values(&mut self, no_values: bool) -> &mut Self {
44 self.no_values = no_values;
45 self
46 }
47
48 pub fn dumped_file(&mut self, dumped_file: &Path) -> &mut Self {
50 self.dumped_file = Some(dumped_file.to_owned());
51 self
52 }
53
54 pub fn verbose(&mut self, verbose: bool) -> &mut Self {
56 self.verbose = verbose;
57 self
58 }
59
60 pub fn help(&mut self, help: bool) -> &mut Self {
62 self.help = help;
63 self
64 }
65
66 pub fn run(&self) -> Result<()> {
68 let mut aapt2 = Command::new("aapt2");
69 aapt2.arg("dump");
70 aapt2.arg(self.subcommand.to_string());
71 aapt2.arg(&self.filename_apk);
72 if self.no_values {
73 aapt2.arg("--no-values");
74 }
75 if let Some(dumped_file) = &self.dumped_file {
76 aapt2.arg("--file").arg(dumped_file);
77 }
78 if self.verbose {
79 aapt2.arg("-v");
80 }
81 if self.help {
82 aapt2.arg("-h");
83 }
84 aapt2.output_err(true)?;
85 Ok(())
86 }
87}
88
89#[derive(Debug, Clone, Copy, PartialEq, Eq)]
90pub enum SubCommand {
91 Apc,
93 Badging,
95 Configurations,
97 Packagename,
99 Permissions,
101 Strings,
103 Styleparents,
105 Resources,
107 Xmlstrings,
109 Xmltree,
111}
112
113impl std::fmt::Display for SubCommand {
114 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
115 match *self {
116 Self::Apc => write!(f, "apc"),
117 Self::Badging => write!(f, "badging"),
118 Self::Configurations => write!(f, "configurations"),
119 Self::Packagename => write!(f, "packagename"),
120 Self::Permissions => write!(f, "permissions"),
121 Self::Strings => write!(f, "strings"),
122 Self::Styleparents => write!(f, "styleparents"),
123 Self::Resources => write!(f, "resources"),
124 Self::Xmlstrings => write!(f, "xmlstrings"),
125 Self::Xmltree => write!(f, "xmltree"),
126 }
127 }
128}