You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
CleanFlashInstaller/rust/crates/clean_flash_installer/src/silent_installer.rs

82 lines
2.8 KiB
Rust

use crate::cli_args::InstallerArgs;
use crate::install_flags::{self, InstallFlags};
use crate::installer;
use clean_flash_common::{uninstaller, redirection, update_checker, ProgressCallback, InstallError};
struct SilentProgressCallback {
silent: bool,
}
impl ProgressCallback for SilentProgressCallback {
fn update_progress_label(&self, text: &str, _tick: bool) {
if !self.silent {
eprintln!("[*] {}", text);
}
}
fn tick_progress(&self) {}
}
pub fn run_silent_install(args: &InstallerArgs) -> Result<(), Box<dyn std::error::Error>> {
let version = update_checker::FLASH_VERSION;
let mut flags = InstallFlags::new();
flags.set_conditionally(args.native_host, install_flags::NATIVE_HOST);
flags.set_conditionally(args.pepper, install_flags::PEPPER);
flags.set_conditionally(args.netscape, install_flags::NETSCAPE);
flags.set_conditionally(args.activex, install_flags::ACTIVEX);
flags.set_conditionally(args.player, install_flags::PLAYER);
flags.set_conditionally(args.player_desktop, install_flags::PLAYER_DESKTOP);
flags.set_conditionally(args.player_start_menu, install_flags::PLAYER_START_MENU);
flags.set_conditionally(args.debug, install_flags::DEBUG);
if flags.is_none_set() {
if !args.silent {
eprintln!("No components selected. Use flags to select what to install:");
eprintln!(" --native-host Modern Browsers (MV3)");
eprintln!(" --pepper Pepper API (PPAPI)");
eprintln!(" --netscape Netscape API (NPAPI)");
eprintln!(" --activex ActiveX (OCX)");
eprintln!(" --player Standalone Flash Player");
eprintln!(" --player-desktop Desktop shortcuts (requires --player)");
eprintln!(" --player-start-menu Start Menu shortcuts (requires --player)");
eprintln!(" --debug Debug version");
eprintln!("\nExample: clean_flash_installer --install --native-host --pepper");
}
std::process::exit(1);
}
if !args.silent {
eprintln!("Clean Flash Player {} - Installation", version);
}
let callback = SilentProgressCallback {
silent: args.silent,
};
let redir = redirection::disable_redirection();
let result = (|| -> Result<(), InstallError> {
uninstaller::uninstall(&callback)?;
installer::install(&callback, &mut flags)?;
Ok(())
})();
redirection::enable_redirection(redir);
match result {
Ok(()) => {
if !args.silent {
eprintln!("[+] Installation completed successfully.");
}
Ok(())
}
Err(e) => {
if !args.silent {
eprintln!("[!] Installation failed: {}", e);
}
std::process::exit(1);
}
}
}