/
auto_mount.rs
73 lines (63 loc) · 2.03 KB
/
auto_mount.rs
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
use std::process::ExitCode;
#[cfg(unix)]
mod inner {
pub use clap::Parser;
pub use std::env;
use std::path::PathBuf;
#[derive(Parser)]
#[command(name = "arx", author, version, about, long_about=None)]
pub struct Cli {
#[arg(short, long, action=clap::ArgAction::Count)]
pub verbose: u8,
#[arg(value_parser)]
pub mountdir: PathBuf,
}
pub fn mount<INP, OUTP>(infile: INP, outdir: OUTP) -> jbk::Result<()>
where
INP: AsRef<std::path::Path>,
OUTP: AsRef<std::path::Path>,
{
let arx = arx::Arx::new(&infile)?;
let arxfs = arx::ArxFs::new(arx)?;
let mut abs_path = env::current_dir().unwrap();
abs_path = abs_path.join(infile.as_ref());
arxfs.mount(abs_path.to_str().unwrap().to_string(), &outdir)
}
}
#[cfg(unix)]
fn main() -> ExitCode {
use inner::*;
use log::{error, info};
human_panic::setup_panic!();
let args = Cli::parse();
match env::current_exe() {
Ok(exe_path) => {
if args.verbose > 0 {
info!("Auto Mount archive {:?} in {:?}", exe_path, args.mountdir);
}
match mount(exe_path, args.mountdir) {
Ok(()) => ExitCode::SUCCESS,
Err(e) => match e.error {
jbk::ErrorKind::NotAJbk => {
error!("Impossible to locate a Jubako archive in the executable.");
error!("This binary is not intented to be directly used, you must put a Jubako archive at its end.");
ExitCode::FAILURE
}
_ => {
error!("Error: {e}");
ExitCode::FAILURE
}
},
}
}
Err(e) => {
eprintln!("failed to get current exe path: {e}");
ExitCode::FAILURE
}
}
}
#[cfg(windows)]
fn main() -> ExitCode {
eprintln!("Mount feature is not available on Windows.");
ExitCode::FAILURE
}