Repository navigation
Expand file tree
/
Copy pathmain.rs
More file actions
54 lines (47 loc) · 1.81 KB
/
Copy pathmain.rs
File metadata and controls
54 lines (47 loc) · 1.81 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
use framework_lib::commandline;
/// Get commandline arguments
fn get_args() -> Vec<String> {
std::env::args().collect()
}
fn main() -> Result<(), &'static str> {
let args = get_args();
// If the user double-clicks (opens from explorer/desktop),
// then we want to have the default behavior of showing a report of
// all firmware versions.
#[cfg(windows)]
let (args, double_clicked) = {
let double_clicked = unsafe {
// See https://devblogs.microsoft.com/oldnewthing/20160125-00/?p=92922
let mut plist: winapi::shared::minwindef::DWORD = 0;
let processes = winapi::um::wincon::GetConsoleProcessList(&mut plist, 1);
// If we're the only process that means we're in a fresh terminal
// without CMD or powershell. This happens in some cases, for example
// if the user double-clicks the app from Explorer.
processes == 1
};
// But it also happens if launched from the commandline and a UAC prompt is necessary,
// for example with sudo set to open "In a new windows", therefore we also have to
// check that no commandline arguments were provided.
if double_clicked && args.len() == 1 {
(
vec![args[0].clone(), "--versions".to_string()],
double_clicked,
)
} else {
(args, double_clicked)
}
};
let args = commandline::parse(&args);
if (commandline::run_with_args(&args, false)) != 0 {
return Err("Fail");
}
// Prevent command prompt from auto closing
#[cfg(windows)]
if double_clicked {
println!();
println!("Press ENTER to exit...");
let mut line = String::new();
let _ = std::io::stdin().read_line(&mut line).unwrap();
}
Ok(())
}