android_tools/aapt2/
dump.rs1use super::aapt2_tool;
2use crate::error::*;
3use std::path::{Path, PathBuf};
4
5#[derive(Default)]
21pub struct Aapt2Dump {
22 subcommand: SubCommand,
23 filename_apk: PathBuf,
24 no_values: bool,
25 dumped_file: Option<PathBuf>,
26 verbose: bool,
27 help: bool,
28}
29
30impl Aapt2Dump {
31 pub fn new(subcommand: SubCommand, filename_apk: &Path) -> Self {
33 Self {
34 subcommand,
35 filename_apk: filename_apk.to_owned(),
36 ..Default::default()
37 }
38 }
39
40 pub fn no_values(&mut self, no_values: bool) -> &mut Self {
42 self.no_values = no_values;
43 self
44 }
45
46 pub fn dumped_file(&mut self, dumped_file: &Path) -> &mut Self {
48 self.dumped_file = Some(dumped_file.to_owned());
49 self
50 }
51
52 pub fn verbose(&mut self, verbose: bool) -> &mut Self {
54 self.verbose = verbose;
55 self
56 }
57
58 pub fn help(&mut self, help: bool) -> &mut Self {
60 self.help = help;
61 self
62 }
63
64 pub fn run(&self) -> Result<()> {
66 let mut aapt2 = aapt2_tool()?;
67 aapt2.arg("dump");
68 aapt2.arg(self.subcommand.to_string());
69 aapt2.arg(&self.filename_apk);
70 if self.no_values {
71 aapt2.arg("--no-values");
72 }
73 if let Some(dumped_file) = &self.dumped_file {
74 aapt2.arg("--file").arg(dumped_file);
75 }
76 if self.verbose {
77 aapt2.arg("-v");
78 }
79 if self.help {
80 aapt2.arg("-h");
81 }
82 aapt2.output_err(true)?;
83 Ok(())
84 }
85}
86
87pub enum SubCommand {
88 Apc,
90 Badging,
92 Configurations,
94 Packagename,
96 Permissions,
98 Strings,
100 Styleparents,
102 Resources,
104 Xmlstrings,
106 Xmltree,
108}
109
110impl std::fmt::Display for SubCommand {
111 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
112 match *self {
113 Self::Apc => write!(f, "apc"),
114 Self::Badging => write!(f, "badging"),
115 Self::Configurations => write!(f, "configurations"),
116 Self::Packagename => write!(f, "packagename"),
117 Self::Permissions => write!(f, "permissions"),
118 Self::Strings => write!(f, "strings"),
119 Self::Styleparents => write!(f, "styleparents"),
120 Self::Resources => write!(f, "resources"),
121 Self::Xmlstrings => write!(f, "xmlstrings"),
122 Self::Xmltree => write!(f, "xmltree"),
123 }
124 }
125}
126
127impl Default for SubCommand {
128 fn default() -> Self {
129 Self::Apc
130 }
131}