creator_tools/tools/aapt2/
dump.rs1use std::path::{Path, PathBuf};
2use std::process::Command;
3
4pub struct Aapt2Dump {
20 subcommand: SubCommand,
21 filename_apk: PathBuf,
22 no_values: bool,
24 file: Option<PathBuf>,
26 v: bool,
28}
29
30impl Aapt2Dump {
31 pub fn new(subcommand: SubCommand, filename_apk: &Path) -> Aapt2Dump {
32 Aapt2Dump {
33 subcommand,
34 filename_apk: filename_apk.to_owned(),
35 no_values: false,
36 file: None,
37 v: false,
38 }
39 }
40
41 pub fn no_values(&mut self, no_values: bool) -> &mut Self {
42 self.no_values = no_values;
43 self
44 }
45
46 pub fn file(&mut self, file: &Path) -> &mut Self {
47 self.file = Some(file.to_owned());
48 self
49 }
50
51 pub fn v(&mut self, v: bool) -> &mut Self {
52 self.v = v;
53 self
54 }
55
56 pub fn run(&self) {
57 let mut aapt2 = Command::new("aapt2");
58 aapt2.arg("dump");
59 aapt2.arg(self.subcommand.to_string());
60 aapt2.arg(&self.filename_apk);
61 if self.no_values {
62 aapt2.arg("--no-values");
63 }
64 if let Some(file) = &self.file {
65 aapt2.arg("--file").arg(file);
66 }
67 if self.v {
68 aapt2.arg("-v");
69 }
70 }
71}
72
73#[derive(Debug, Clone, Copy, PartialEq, Eq)]
74pub enum SubCommand {
75 Apc,
77 Badging,
79 Configurations,
81 Packagename,
83 Permissions,
85 Strings,
87 Styleparents,
89 Resources,
91 Xmlstrings,
93 Xmltree,
95}
96
97impl std::fmt::Display for SubCommand {
98 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
99 match *self {
100 Self::Apc => write!(f, "apc"),
101 Self::Badging => write!(f, "badging"),
102 Self::Configurations => write!(f, "configurations"),
103 Self::Packagename => write!(f, "packagename"),
104 Self::Permissions => write!(f, "permissions"),
105 Self::Strings => write!(f, "strings"),
106 Self::Styleparents => write!(f, "styleparents"),
107 Self::Resources => write!(f, "resources"),
108 Self::Xmlstrings => write!(f, "xmlstrings"),
109 Self::Xmltree => write!(f, "xmltree"),
110 }
111 }
112}