-
Notifications
You must be signed in to change notification settings - Fork 64
Expand file tree
/
Copy pathmain.rs
More file actions
175 lines (151 loc) · 4.19 KB
/
Copy pathmain.rs
File metadata and controls
175 lines (151 loc) · 4.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
//----------------------------------------
mod commands;
mod package;
//----------------------------------------
use clap::{Parser, Subcommand};
use std::path::PathBuf;
//----------------------------------------
// https://rust-lang-nursery.github.io/rust-cookbook/file/dir.html
// https://rust-lang-nursery.github.io/rust-cookbook/compression/tar.html
// https://serde.rs
//----------------------------------------
#[derive(Parser)]
#[command(
author,
version,
about,
long_about = None,
arg_required_else_help = true,
subcommand_required = true
)]
struct Cli {
/// Unity Package (Tar, TarGz, or Folder)
package: PathBuf,
#[command(subcommand)]
command: Option<Commands>,
}
//----------------------------------------
#[derive(Subcommand)]
enum Commands {
// Test,
/// Find source of dump crashes
Debug,
/// Show package info
Info,
/// Display path from guid/pathname file
Name {
guid: String,
},
/// Dump package contents
Dump {
/// Pretty Print JSON
#[arg(short, long)]
pretty: bool,
},
/// List package contents
List {
/// Hide GUIDs
#[arg(short, long)]
no_guid: bool,
/// Pretty Print JSON
#[arg(short, long)]
pretty: bool,
/// Directory Filter
#[arg(short, long)]
dir: Option<String>,
},
/// Extract package file
Extract {
#[arg(required = true)]
guid: Option<String>,
/// Extract to file
#[arg(short, long)]
output_file: Option<PathBuf>,
/// Extract /asset.meta file instead of /asset
#[arg(short, long)]
meta: bool,
/// Process yaml to json
#[arg(short, long)]
json: bool,
/// Pretty Print JSON
#[arg(short, long)]
pretty: bool,
/// Convert FBX to GLTF
#[arg(short, long)]
fbx2gltf: bool,
/// Base64 encode output
#[arg(short, long)]
base64: bool,
},
/// Calculate xxhash 64 of string
XxHash {
#[arg(required = true)]
text: String,
}
}
//----------------------------------------
fn main() {
let cli = Cli::parse();
let package_path = cli.package.to_str().unwrap();
match &cli.command {
&Some(Commands::Info) => {
println!(
"Package: {}",
package::Package::new(package_path).unwrap()
);
}
&Some(Commands::Dump { pretty }) => {
commands::package_contents_dump(package_path, pretty, false);
}
&Some(Commands::Name { ref guid }) => {
commands::package_contents_name(package_path, guid);
}
Some(Commands::List {
no_guid,
pretty,
dir,
}) => {
commands::package_contents_list(package_path, dir, !*no_guid, *pretty);
}
&Some(Commands::Extract {
ref guid,
ref output_file,
meta,
json,
pretty,
fbx2gltf,
base64,
}) => {
commands::package_file_extract(
package_path,
guid.as_ref().unwrap(),
output_file,
meta,
json,
pretty,
fbx2gltf,
base64,
);
}
// &Some(Commands::Test) => {
// let package = package::Package::new(package_path);
// // println!("{:?}", package);
// if let Ok(package) = package {
// let result = package.open();
// for file in result.unwrap().entries() {
// let size = file.as_ref().unwrap().size().unwrap();
// let path = file.as_ref().unwrap().path().unwrap();
// println!("{} {}", size, path.display());
// }
// }
// }
&Some(Commands::Debug) => {
commands::package_contents_dump(package_path, false, true);
}
&Some(Commands::XxHash { ref text }) => {
commands::xx_hash(text);
}
&None => (),
}
}
//----------------------------------------