| 1 | #![cfg_attr( |
| 2 | all( |
| 3 | target_os = "windows", |
| 4 | not(all(feature = "ui-fixture", debug_assertions)) |
| 5 | ), |
| 6 | windows_subsystem = "windows" |
| 7 | )] |
| 8 | |
| 9 | #[cfg(feature = "ui-fixture")] |
| 10 | #[path = "../../../tests/rust-app-ui/fake.rs"] |
| 11 | mod fake; |
| 12 | #[path = "renderer.rs"] |
| 13 | mod renderer; |
| 14 | #[path = "system_font.rs"] |
| 15 | mod system_font; |
| 16 | use eframe::egui; |
| 17 | fn main() -> eframe::Result { |
| 18 | zipelo_ui_memory_app::log_info!( |
| 19 | "Zipelo {} 시작 (로그 단계 {:?}, ZIPELO_LOG로 변경 가능)", |
| 20 | env!("CARGO_PKG_VERSION"), |
| 21 | zipelo_ui_memory_app::applog::level() |
| 22 | ); |
| 23 | let result = run(); |
| 24 | match &result { |
| 25 | Ok(()) => zipelo_ui_memory_app::log_info!("Zipelo 정상 종료"), |
| 26 | Err(error) => zipelo_ui_memory_app::log_error!("Zipelo 시작 또는 실행 실패: {error}"), |
| 27 | } |
| 28 | #[cfg(all( |
| 29 | target_os = "windows", |
| 30 | not(all(feature = "ui-fixture", debug_assertions)) |
| 31 | ))] |
| 32 | if let Err(error) = &result { |
| 33 | let message = if matches!(error, eframe::Error::AppCreation(_)) { |
| 34 | "앱을 시작하지 못했습니다. 설치 파일을 다시 설치한 뒤 시도해 주세요." |
| 35 | } else { |
| 36 | "이 PC에서 화면을 표시할 수 없습니다. 그래픽 드라이버를 업데이트해 주세요." |
| 37 | }; |
| 38 | show_startup_error(message); |
| 39 | } |
| 40 | result |
| 41 | } |
| 42 | |
| 43 | #[cfg(all( |
| 44 | target_os = "windows", |
| 45 | not(all(feature = "ui-fixture", debug_assertions)) |
| 46 | ))] |
| 47 | fn show_startup_error(message: &str) { |
| 48 | #[link(name = "user32")] |
| 49 | unsafe extern "system" { |
| 50 | fn MessageBoxW( |
| 51 | window: *mut std::ffi::c_void, |
| 52 | text: *const u16, |
| 53 | caption: *const u16, |
| 54 | kind: u32, |
| 55 | ) -> i32; |
| 56 | } |
| 57 | let text: Vec<u16> = message.encode_utf16().chain(Some(0)).collect(); |
| 58 | let caption: Vec<u16> = "Zipelo".encode_utf16().chain(Some(0)).collect(); |
| 59 | // 종료까지 유효한 NUL 종료 문자열로 기본 오류 창을 표시함. |
| 60 | unsafe { |
| 61 | MessageBoxW(std::ptr::null_mut(), text.as_ptr(), caption.as_ptr(), 0x10); |
| 62 | } |
| 63 | } |
| 64 | |
| 65 | fn run() -> eframe::Result { |
| 66 | let args: Vec<_> = std::env::args_os().skip(1).collect(); |
| 67 | #[cfg(all(feature = "ui-fixture", debug_assertions))] |
| 68 | let (args, scenario) = { |
| 69 | use zipelo_ui_memory_app::archive_screen::scenarios::{self, Launch}; |
| 70 | match scenarios::launch(args) |
| 71 | .map_err(|e| eframe::Error::AppCreation(Box::new(std::io::Error::other(e))))? |
| 72 | { |
| 73 | Launch::List => { |
| 74 | print!("{}", scenarios::listing()); |
| 75 | return Ok(()); |
| 76 | } |
| 77 | Launch::Scenario(scenario) => (Vec::new(), Some(scenario)), |
| 78 | Launch::Normal(args) => (args, None), |
| 79 | } |
| 80 | }; |
| 81 | #[cfg(not(all(feature = "ui-fixture", debug_assertions)))] |
| 82 | if args |
| 83 | .iter() |
| 84 | .any(|arg| arg == "--ui-scenario" || arg == "--list-ui-scenarios") |
| 85 | { |
| 86 | return Err(eframe::Error::AppCreation(Box::new(std::io::Error::other( |
| 87 | "지원하지 않는 명령줄 옵션입니다", |
| 88 | )))); |
| 89 | } |
| 90 | let (fixture, startup) = zipelo_ui_memory_app::archive_ui::launch_args( |
| 91 | args, |
| 92 | std::env::current_dir().map_err(|e| eframe::Error::AppCreation(Box::new(e)))?, |
| 93 | ) |
| 94 | .map_err(|e| eframe::Error::AppCreation(Box::new(std::io::Error::other(e))))?; |
| 95 | let custom_frame = zipelo_ui_memory_app::window_frame::custom_frame_needed(); |
| 96 | zipelo_ui_memory_app::log_debug!( |
| 97 | "실행 인자 해석: 시험 모드={fixture}, 시작 파일={:?}, 직접 그린 창 테두리={custom_frame}", |
| 98 | startup |
| 99 | ); |
| 100 | // 운영체제 한글 글꼴은 Pretendard에 없는 글자를 위한 대체 글꼴로만 씀. |
| 101 | let fallback = system_font::load() |
| 102 | .ok() |
| 103 | .map(|font| (font.bytes, font.face_index)); |
| 104 | renderer::run_native( |
| 105 | "Zipelo", |
| 106 | eframe::NativeOptions { |
| 107 | viewport: egui::ViewportBuilder::default() |
| 108 | .with_inner_size([1060.0, 720.0]) |
| 109 | .with_min_inner_size([760.0, 540.0]) |
| 110 | .with_decorations(!custom_frame), |
| 111 | ..Default::default() |
| 112 | }, |
| 113 | || { |
| 114 | let fallback = fallback.clone(); |
| 115 | let startup = startup.clone(); |
| 116 | Box::new(move |cc| { |
| 117 | cc.egui_ctx |
| 118 | .set_fonts(zipelo_ui_memory_app::archive_theme::fonts(fallback)); |
| 119 | zipelo_ui_memory_app::archive_theme::apply(&cc.egui_ctx); |
| 120 | #[cfg(all(feature = "ui-fixture", debug_assertions))] |
| 121 | if let Some(scenario) = scenario { |
| 122 | let app = scenario.build_with_frame(custom_frame); |
| 123 | return Ok(Box::new( |
| 124 | zipelo_ui_memory_app::archive_screen::scenarios::Preview::new( |
| 125 | app, |
| 126 | &cc.egui_ctx, |
| 127 | ) |
| 128 | .with_scenario(scenario), |
| 129 | ) as Box<dyn eframe::App>); |
| 130 | } |
| 131 | let factory: Box<dyn zipelo_ui_memory_app::archive_ui::Factory> = if fixture { |
| 132 | #[cfg(feature = "ui-fixture")] |
| 133 | { |
| 134 | Box::new(fake::FakeFactory::default()) |
| 135 | } |
| 136 | #[cfg(not(feature = "ui-fixture"))] |
| 137 | { |
| 138 | return Err(Box::new(std::io::Error::other( |
| 139 | "ui-fixture feature가 필요합니다", |
| 140 | ))); |
| 141 | } |
| 142 | } else { |
| 143 | Box::new( |
| 144 | zipelo_ui_memory_app::archive_process::ProcessFactory::sibling() |
| 145 | .map_err(std::io::Error::other)?, |
| 146 | ) |
| 147 | }; |
| 148 | let mut app = zipelo_ui_memory_app::archive_screen::ArchiveApp::new( |
| 149 | factory, |
| 150 | startup.clone(), |
| 151 | fixture, |
| 152 | ); |
| 153 | app.set_custom_frame(custom_frame); |
| 154 | app.set_work_window_in_parent(custom_frame); |
| 155 | Ok(Box::new(app)) |
| 156 | }) |
| 157 | }, |
| 158 | ) |
| 159 | } |