//! Desktop shell for Paperdoll Renderer project files. //! //! The window edits a `.ppd` project and shows a live skinned glTF/GLB or FBX preview. use std::process::ExitCode; use paperdoll_renderer::editor::EditorApp; use paperdoll_renderer::foundation::{help_text, parse_cli, report, CliError, CliRequest}; fn main() -> ExitCode { let args: Vec = std::env::args().skip(1).collect(); let borrowed: Vec<&str> = args.iter().map(String::as_str).collect(); match parse_cli(borrowed) { Ok(CliRequest::InstallDesktop) => { #[cfg(target_os = "linux")] { let exe = std::env::var_os("APPIMAGE") .map(std::path::PathBuf::from) .or_else(|| std::env::current_exe().ok()); match exe .ok_or_else(|| "geen uitvoerbaar pad".to_string()) .and_then(|exe| paperdoll_renderer::file_assoc::install_linux_integration(&exe)) { Ok(()) => { println!("Openen met is geregistreerd."); ExitCode::SUCCESS } Err(error) => { eprintln!("{error}"); ExitCode::FAILURE } } } #[cfg(not(target_os = "linux"))] { eprintln!("--install-desktop is voor Linux"); ExitCode::from(2) } } Ok(CliRequest::PrintHelp) => { println!("{}", help_text()); ExitCode::SUCCESS } Ok(CliRequest::PrintStatus) => { println!("{}", report()); ExitCode::SUCCESS } Ok(CliRequest::PreviewFixtures) => open_window(true, None), Ok(CliRequest::OpenWindow) => open_window(false, None), Ok(CliRequest::OpenProject(path)) => { open_window(false, Some(std::path::PathBuf::from(path))) } Err(CliError::Usage(message)) => { eprintln!("paperdoll-renderer: {message}"); ExitCode::from(2) } Err(CliError::UnknownArgument(arg)) => { eprintln!("paperdoll-renderer: onbekend argument '{arg}'."); eprintln!("Gebruik --help."); ExitCode::from(2) } } } fn open_window(fixtures: bool, path: Option) -> ExitCode { #[cfg(windows)] if let Ok(exe) = std::env::current_exe() { if let Err(error) = paperdoll_renderer::file_assoc::ensure_user_file_association(&exe) { eprintln!("Openen met registreren: {error}"); } } if let Some(message) = window_preflight() { eprintln!("paperdoll-renderer: {message}"); return ExitCode::from(1); } match run_window(fixtures, path) { Ok(()) => ExitCode::SUCCESS, Err(err) => { eprintln!("paperdoll-renderer: het venster openen is mislukt: {err}"); ExitCode::from(1) } } } fn window_preflight() -> Option { #[cfg(target_os = "linux")] { let missing = paperdoll_renderer::foundation::missing_window_libraries(); if missing.is_empty() { None } else { Some(paperdoll_renderer::foundation::missing_library_message( &missing, )) } } #[cfg(not(target_os = "linux"))] { None } } fn run_window(fixtures: bool, path: Option) -> eframe::Result<()> { let (width, height, rgba) = paperdoll_renderer::icon::window_icon_rgba(); let options = eframe::NativeOptions { viewport: eframe::egui::ViewportBuilder::default() .with_title("Paperdoll Renderer") .with_app_id(paperdoll_renderer::icon::APP_ID) .with_inner_size(paperdoll_renderer::session::START_WINDOW) .with_min_inner_size([420.0, 220.0]) .with_icon(eframe::egui::IconData { rgba, width, height, }), ..paperdoll_renderer::preview_gl::native_options() }; eframe::run_native( "Paperdoll Renderer", options, Box::new(move |_creation| { let mut app = EditorApp::default(); if fixtures { app.open_fixture_project(); } if let Some(path) = path { app.open_path(path); } Ok(Box::new(app)) }), ) }