From 38af66b2ddacac581a1ba695c3c1a65c140fefe7 Mon Sep 17 00:00:00 2001 From: Mateusz Faderewski Date: Mon, 6 Mar 2023 21:34:32 +0100 Subject: [PATCH] firmware update prompt --- sw/deployer/src/main.rs | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/sw/deployer/src/main.rs b/sw/deployer/src/main.rs index 457c500..7ae33af 100644 --- a/sw/deployer/src/main.rs +++ b/sw/deployer/src/main.rs @@ -9,7 +9,7 @@ use colored::Colorize; use panic_message::panic_message; use std::{ fs::File, - io::{stdout, BufReader, Read, Write}, + io::{stdin, stdout, BufReader, Read, Write}, path::PathBuf, sync::{ atomic::{AtomicBool, Ordering}, @@ -532,7 +532,7 @@ fn handle_firmware_command( let metadata = sc64::firmware::verify(&firmware)?; println!("{}", "Firmware metadata:".bold()); - println!("{}", metadata); + println!("{}", format!("{}", metadata).blue().to_string()); Ok(()) } @@ -551,7 +551,7 @@ fn handle_firmware_command( let metadata = sc64::firmware::verify(&firmware)?; println!("{}", "Firmware metadata:".bold()); - println!("{}", metadata); + println!("{}", format!("{}", metadata).blue().to_string()); backup_file.write_all(&firmware)?; @@ -568,7 +568,12 @@ fn handle_firmware_command( let metadata = sc64::firmware::verify(&firmware)?; println!("{}", "Firmware metadata:".bold()); - println!("{}", metadata); + println!("{}", format!("{}", metadata).blue().to_string()); + println!("{}", "Firmware file verification was successful".green()); + let answer = prompt(format!("{}", "Continue with update process? [y/N] ".bold())); + if answer.to_ascii_lowercase() != "y" { + panic!("Firmware update process aborted"); + } sc64.reset_state()?; @@ -622,6 +627,14 @@ fn log_wait Result, T, E>(message: String, operation: F) -> result } +fn prompt(message: String) -> String { + print!("{message}"); + stdout().flush().unwrap(); + let mut answer = String::new(); + stdin().read_line(&mut answer).unwrap(); + answer.trim_end().to_string() +} + fn open_file(path: &PathBuf) -> Result<(File, String, usize), sc64::Error> { let name: String = path.file_name().unwrap().to_string_lossy().to_string(); let file = File::open(path)?;