|
| 1 | +use framework_lib::commandline; |
| 2 | + |
| 3 | +/// Get commandline arguments |
| 4 | +fn get_args() -> Vec<String> { |
| 5 | + std::env::args().collect() |
| 6 | +} |
| 7 | + |
| 8 | +fn main() -> Result<(), &'static str> { |
| 9 | + let args = get_args(); |
| 10 | + |
| 11 | + // If the user double-clicks (opens from explorer/desktop), |
| 12 | + // then we want to have the default behavior of showing a report of |
| 13 | + // all firmware versions. |
| 14 | + #[cfg(windows)] |
| 15 | + let (args, double_clicked) = { |
| 16 | + let double_clicked = unsafe { |
| 17 | + // See https://devblogs.microsoft.com/oldnewthing/20160125-00/?p=92922 |
| 18 | + let mut plist: winapi::shared::minwindef::DWORD = 0; |
| 19 | + let processes = winapi::um::wincon::GetConsoleProcessList(&mut plist, 1); |
| 20 | + |
| 21 | + // If we're the only process that means we're in a fresh terminal |
| 22 | + // without CMD or powershell. This happens in some cases, for example |
| 23 | + // if the user double-clicks the app from Explorer. |
| 24 | + processes == 1 |
| 25 | + }; |
| 26 | + // But it also happens if launched from the commandline and a UAC prompt is necessary, |
| 27 | + // for example with sudo set to open "In a new windows", therefore we also have to |
| 28 | + // check that no commandline arguments were provided. |
| 29 | + if double_clicked && args.len() == 1 { |
| 30 | + ( |
| 31 | + vec![args[0].clone(), "--versions".to_string()], |
| 32 | + double_clicked, |
| 33 | + ) |
| 34 | + } else { |
| 35 | + (args, double_clicked) |
| 36 | + } |
| 37 | + }; |
| 38 | + |
| 39 | + let args = commandline::parse(&args); |
| 40 | + if (commandline::run_with_args(&args, false)) != 0 { |
| 41 | + return Err("Fail"); |
| 42 | + } |
| 43 | + |
| 44 | + // Prevent command prompt from auto closing |
| 45 | + #[cfg(windows)] |
| 46 | + if double_clicked { |
| 47 | + println!(); |
| 48 | + println!("Press ENTER to exit..."); |
| 49 | + let mut line = String::new(); |
| 50 | + let _ = std::io::stdin().read_line(&mut line).unwrap(); |
| 51 | + } |
| 52 | + |
| 53 | + Ok(()) |
| 54 | +} |
0 commit comments