mod cli; use std::error::Error; use std::process::ExitCode; use log::{error, info, trace}; use clap::Parser; use ozone::launcher::{Launcher, Settings}; use ozone::launcher::version::VersionList; use crate::cli::{Cli, ProfileCommand, RootCommand}; async fn main_inner(cli: Cli) -> Result> { let Some(home) = cli.home.or_else(Launcher::sensible_home) else { error!("Could not choose a launcher home directory. Please choose one with `--home'."); return Ok(ExitCode::FAILURE); // we print our own error message }; trace!("Sensible home could be {home:?}"); let mut settings = Settings::load(home.join("ozone.json")).await?; match &cli.subcmd { RootCommand::Profile(p) => match p.command() { ProfileCommand::List => { let mut first = true; if settings.get_profiles().is_empty() { eprintln!("There are no profiles. Create one with `profile create '."); return Ok(ExitCode::SUCCESS); } for (name, profile) in settings.get_profiles().iter() { if !first { println!(); } first = false; let sel = if settings.get_selected_profile_name().is_some_and(|n| n == name) { " (selected)" } else { "" }; let exists = if settings.get_instances().contains_key(profile.get_instance_name()) { "" } else { " (missing!)" }; println!("Profile {name}:{sel}"); println!(" Version: {}", profile.get_version()); println!(" Instance: {}{}", profile.get_instance_name(), exists); } }, ProfileCommand::Create(args) => { if settings.profiles.contains_key(&args.name) { eprintln!("A profile with that name already exists."); return Ok(ExitCode::FAILURE); } if let Some(ref src) = args.clone { if let Some(profile) = settings.get_profiles().get(src) { let profile = profile.clone(); settings.profiles.insert(args.name.clone(), profile); } else { eprintln!("Unknown profile `{src}'."); return Ok(ExitCode::FAILURE); } return Ok(ExitCode::SUCCESS); } // creating a new profile from scratch todo!() }, ProfileCommand::Select(args) => { } _ => todo!() }, RootCommand::Launch => { settings.save().await?; let launcher = Launcher::new(&home, !cli.offline).await?; let profile = settings.get_profiles().get("default").unwrap(); let launch = launcher.prepare_launch(profile, settings.get_instances().get(profile.get_instance_name()).unwrap(), settings.get_client_id()).await.map_err(|e| { error!("error launching: {e}"); e })?; dbg!(&launch); info!("ok"); ozone::launcher::run_the_game(&launch)?; } _ => todo!() } Ok(ExitCode::SUCCESS) } #[tokio::main] async fn main() -> ExitCode { simple_logger::SimpleLogger::new().env().init().unwrap(); let arg = Cli::parse(); main_inner(arg).await.unwrap_or_else(|e| { error!("Launcher initialization error:"); error!("{e}"); ExitCode::FAILURE }) /*let launcher = Launcher::new("./work", true).await?; */ }