oxyromon 0.23.0

Rusty ROM OrgaNizer
use super::bchunk;
use super::chdman;
use super::ctrtool;
use super::database::*;
use super::dolphin;
use super::flips;
use super::maxcso;
use super::nsz;
use super::progress::*;
use super::sevenzip;
use super::wit;
use super::xdelta3;
use anyhow::Result;
use clap::Command;
use indicatif::ProgressBar;
use sqlx::sqlite::SqliteConnection;

pub fn subcommand() -> Command {
    Command::new("info").about("Print system information")
}

pub async fn main(connection: &mut SqliteConnection, progress_bar: &ProgressBar) -> Result<()> {
    start_action(progress_bar, None);

    // Dependencies
    print_header(progress_bar, "Dependencies");

    let mut deps: Vec<(&str, Result<String, _>)> = vec![
        ("7-zip", sevenzip::get_version().await),
        ("bchunk", bchunk::get_version().await),
        ("chdman", chdman::get_version().await),
        ("ctrtool", ctrtool::get_version().await),
        ("flips", flips::get_version().await),
        ("maxcso", maxcso::get_version().await),
        ("nsz", nsz::get_version().await),
        ("xdelta3", xdelta3::get_version().await),
    ];
    // RVZ and WBFS share a backend when it is the native one, so list it once
    deps.push((dolphin::BACKEND_NAME, dolphin::get_version().await));
    if wit::BACKEND_NAME != dolphin::BACKEND_NAME {
        deps.push((wit::BACKEND_NAME, wit::get_version().await));
    }
    deps.sort_by_key(|(name, _)| *name);

    for (name, result) in &deps {
        match result {
            Ok(version) => print_success(progress_bar, &format!("{}: {}", name, version)),
            Err(_) => print_skip(progress_bar, &format!("{}: not found", name)),
        }
    }

    print_separator(progress_bar);

    // Statistics
    print_header(progress_bar, "Statistics");

    let system_count = count_systems(connection).await;
    let game_count = count_games(connection).await;
    let rom_count = count_roms(connection).await;

    print_info(progress_bar, &format!("Systems: {}", system_count));
    print_info(progress_bar, &format!("Games:   {}", game_count));
    print_info(progress_bar, &format!("ROMs:    {}", rom_count));

    print_separator(progress_bar);

    progress_bar.println("  If you find oxyromon useful, please consider buying me a coffee:");
    progress_bar.println("  https://ko-fi.com/alucryd");

    progress_bar.finish_and_clear();

    Ok(())
}