| 1 | use super::*; |
| 2 | use std::ffi::OsString; |
| 3 | |
| 4 | #[path = "fake.rs"] |
| 5 | mod fake; |
| 6 | use fake::FakeFactory; |
| 7 | |
| 8 | #[derive(Clone, Copy, Debug, Eq, PartialEq)] |
| 9 | pub struct Scenario { |
| 10 | pub name: &'static str, |
| 11 | pub description: &'static str, |
| 12 | } |
| 13 | |
| 14 | macro_rules! catalog { |
| 15 | ($($name:literal => $description:literal),+ $(,)?) => { |
| 16 | pub const SCENARIOS: &[Scenario] = &[$(Scenario { |
| 17 | name: $name, |
| 18 | description: $description, |
| 19 | }),+]; |
| 20 | }; |
| 21 | } |
| 22 | |
| 23 | catalog! { |
| 24 | "recovery-progress" => "ZIP 복구 분석과 저장 확인 전 대기", |
| 25 | "recovery-complete" => "전체 항목을 검증한 복구본 저장 완료", |
| 26 | "recovery-partial" => "유실 항목이 있는 복구본과 경고", |
| 27 | "recovery-unknown" => "전체 목록 불명의 추가 유실 경고", |
| 28 | "recovery-impossible" => "복구 가능한 항목 없음과 출력 없음", |
| 29 | "recovery-cancelled" => "복구 취소와 출력 없음", |
| 30 | "recovery-retained" => "복구 저장 실패 뒤 남은 임시 파일 경로와 정리 경고", |
| 31 | "recovery-save-error" => "복구 분석 뒤 저장 실패", |
| 32 | "recovery-resource" => "복구 작업의 자원 승인", |
| 33 | |
| 34 | "create-sevenzip" => "7z 형식 선택과 LZMA2 및 암호 미지원 안내", |
| 35 | "create-sevenzip-progress" => "7z 만들기 진행과 취소", |
| 36 | "create-sevenzip-complete" => "7z 만들기 완료", |
| 37 | "create-sevenzip-error" => "7z 만들기 저장 실패", |
| 38 | "create-sevenzip-cancelled" => "7z 만들기 취소 완료", |
| 39 | "create-sevenzip-resource" => "7z 만들기의 큰 작업 승인", |
| 40 | |
| 41 | "split-archive" => "분할 7z 목록과 미리보기 비활성화", |
| 42 | "split-first-volume" => "첫 조각의 정확한 파일명 안내", |
| 43 | "split-missing-volume" => "누락 조각 파일명과 재시도 안내", |
| 44 | "split-incomplete" => "누락 이름을 단정하지 않는 불완전 묶음 안내", |
| 45 | "split-unsupported" => "분할 ZIP과 RAR 및 분할 생성 미지원 안내", |
| 46 | "split-source-changed" => "목록 이후 분할 조각 변경 안내", |
| 47 | "preview-catalog-bytes-approval" => "16 GiB를 넘는 전체 목록의 미리보기 승인", |
| 48 | "preview-catalog-approval" => "미리보기의 전체 목록 처리 예산 승인", |
| 49 | "preview-loading" => "미리보기 로딩과 취소", |
| 50 | "preview-text" => "읽기 전용 텍스트 미리보기", |
| 51 | "preview-image" => "정적 이미지 미리보기", |
| 52 | "preview-empty" => "빈 텍스트 미리보기", |
| 53 | "preview-limit" => "미리보기 한도 초과", |
| 54 | "preview-damaged" => "손상된 미리보기 파일", |
| 55 | "preview-unsupported" => "미지원 미리보기 형식", |
| 56 | "preview-implicit-folder" => "파일 하나를 포함한 가상 폴더의 미리보기 비활성화", |
| 57 | "preview-selection" => "폴더와 여러 항목의 미리보기 비활성화", |
| 58 | "resource-approval" => "처리 전 큰 작업 승인", |
| 59 | "resource-ratio" => "고압축 작업 경고와 미확인 값", |
| 60 | "resource-retry" => "주 창 모달에서 출력 없는 한도 실패 후 확대 재시도", |
| 61 | "resource-partial" => "주 창 모달에서 일부 출력 후 한도 중단", |
| 62 | "gzip-conflict-choice" => "단일 GZ 파일의 충돌 선택", |
| 63 | "conflict-choice" => "같은 이름 파일의 세 가지 처리 선택", |
| 64 | "conflict-apply" => "남은 충돌에 같은 선택 적용", |
| 65 | "extract-skipped" => "모든 파일을 건너뛴 정상 완료", |
| 66 | "extract-renamed" => "이름을 바꿔 저장한 완료 결과", |
| 67 | "extract-rename-failed" => "새 이름을 정한 뒤 저장 전 I/O 실패", |
| 68 | "empty" => "빈 첫 화면", |
| 69 | "archive" => "폴더와 파일이 있는 압축파일", |
| 70 | "tar-bz2" => "TAR.BZ2 목록과 자동 해제 폴더", |
| 71 | "tar-xz" => "TAR.XZ 목록과 자동 해제 폴더", |
| 72 | "folder" => "사진 하위 폴더", |
| 73 | "many-items" => "500개 항목과 세로 스크롤", |
| 74 | "selection" => "여러 파일과 폴더 선택", |
| 75 | "marquee" => "반투명 사각형으로 끌어서 선택 중", |
| 76 | "search-empty" => "검색 결과 없음", |
| 77 | "password" => "압축 해제 암호 입력", |
| 78 | "password-retry" => "암호가 틀린 뒤 다시 입력", |
| 79 | "extract-progress" => "압축 해제 진행률 62%", |
| 80 | "extract-unknown" => "전체 크기를 모르는 압축 해제", |
| 81 | "extract-complete" => "압축 해제 완료", |
| 82 | "extract-cancelled" => "압축 해제 취소 완료", |
| 83 | "cancelling" => "취소 요청 후 작업 종료 대기", |
| 84 | "conflict" => "같은 이름 파일 충돌", |
| 85 | "unsupported" => "지원하지 않는 압축 형식", |
| 86 | "damaged" => "손상된 압축파일", |
| 87 | "create" => "암호 없는 ZIP 만들기 창", |
| 88 | "create-encrypted" => "암호 설정이 켜진 ZIP 만들기 창", |
| 89 | "create-progress" => "ZIP 만들기 진행률 62%", |
| 90 | "create-complete" => "ZIP 만들기 완료", |
| 91 | "folder-empty" => "항목이 없는 하위 폴더", |
| 92 | "gzip-conflict" => "단일 GZ 파일 이름 충돌", |
| 93 | "extract-disk-full" => "압축 해제 중 디스크 공간 또는 할당량 부족", |
| 94 | "extract-complete-cleanup-failed" => "압축 해제 완료와 출력 폴더의 임시 파일 정리 실패", |
| 95 | "extract-cleanup-failed" => "압축 해제 실패와 출력 폴더의 임시 파일 정리 실패", |
| 96 | "extract-partial" => "일부 파일만 풀린 결과", |
| 97 | "extract-uncertain" => "저장 여부를 확인할 수 없는 결과", |
| 98 | "extract-unsynced" => "완료 뒤 저장 확인 경고의 상세 정보", |
| 99 | "source-changed" => "목록을 연 뒤 원본이 바뀐 오류", |
| 100 | "dialog-error" => "운영체제 파일 선택 창 실행 실패", |
| 101 | "create-error" => "ZIP 만들기 중 디스크 공간 부족", |
| 102 | "password-create" => "암호 ZIP 생성의 작업자 암호 요청", |
| 103 | "close-confirm" => "진행 중 창 닫기 확인", |
| 104 | "uninstall-windows" => "Windows 제거 전 기본 앱 선택 안내", |
| 105 | "uninstall-settings-error" => "Windows 기본 앱 설정 실행 실패", |
| 106 | "uninstall-ubuntu-missing" => "Ubuntu 이전 기본 앱 복원 불가 안내", |
| 107 | "uninstall-ubuntu-unknown-user" => "Ubuntu 제거 사용자 확인 불가 안내", |
| 108 | } |
| 109 | |
| 110 | pub fn listing() -> String { |
| 111 | SCENARIOS |
| 112 | .iter() |
| 113 | .map(|s| format!("{}\t{}\n", s.name, s.description)) |
| 114 | .collect() |
| 115 | } |
| 116 | |
| 117 | pub fn parse(name: &str) -> Result<Scenario, String> { |
| 118 | SCENARIOS |
| 119 | .iter() |
| 120 | .copied() |
| 121 | .find(|s| s.name == name) |
| 122 | .ok_or_else(|| { |
| 123 | format!( |
| 124 | "알 수 없는 UI 상황: {name}\n사용 가능한 상황:\n{}", |
| 125 | listing() |
| 126 | ) |
| 127 | }) |
| 128 | } |
| 129 | |
| 130 | #[derive(Debug, PartialEq)] |
| 131 | pub enum Launch { |
| 132 | Normal(Vec<OsString>), |
| 133 | Scenario(Scenario), |
| 134 | List, |
| 135 | } |
| 136 | |
| 137 | pub fn launch(args: Vec<OsString>) -> Result<Launch, String> { |
| 138 | let requested = args |
| 139 | .iter() |
| 140 | .any(|a| a == "--ui-scenario" || a == "--list-ui-scenarios"); |
| 141 | if !requested { |
| 142 | return Ok(Launch::Normal(args)); |
| 143 | } |
| 144 | if args.len() == 1 && args[0] == "--list-ui-scenarios" { |
| 145 | return Ok(Launch::List); |
| 146 | } |
| 147 | if args.len() == 2 && args[0] == "--ui-scenario" { |
| 148 | return args[1] |
| 149 | .to_str() |
| 150 | .ok_or_else(|| format!("상황 이름은 UTF-8이어야 합니다\n{}", listing())) |
| 151 | .and_then(parse) |
| 152 | .map(Launch::Scenario); |
| 153 | } |
| 154 | Err(format!( |
| 155 | "사용법: --ui-scenario <이름> 또는 --list-ui-scenarios\n{}", |
| 156 | listing() |
| 157 | )) |
| 158 | } |
| 159 | |
| 160 | fn sample_root() -> PathBuf { |
| 161 | PathBuf::from(if cfg!(target_os = "windows") { |
| 162 | "C:\\Samples" |
| 163 | } else { |
| 164 | "/Samples" |
| 165 | }) |
| 166 | } |
| 167 | |
| 168 | fn entries(many: bool) -> Vec<Entry> { |
| 169 | let mut entries = vec![ |
| 170 | ("사진", Kind::Directory), |
| 171 | ("읽어주세요.txt", Kind::File), |
| 172 | ("여행 일정.pdf", Kind::File), |
| 173 | ("사진/바다.jpg", Kind::File), |
| 174 | ("사진/풍경.jpg", Kind::File), |
| 175 | ] |
| 176 | .into_iter() |
| 177 | .enumerate() |
| 178 | .map(|(id, (name, kind))| Entry { |
| 179 | id: id as u32, |
| 180 | name: name.into(), |
| 181 | kind, |
| 182 | bytes: Some(if kind == Kind::Directory { |
| 183 | 0 |
| 184 | } else { |
| 185 | 1_287_952 |
| 186 | }), |
| 187 | packed: Some(900_000), |
| 188 | encrypted: id == 2, |
| 189 | }) |
| 190 | .collect::<Vec<_>>(); |
| 191 | if many { |
| 192 | entries.extend((5..505).map(|id| Entry { |
| 193 | id, |
| 194 | name: format!("자료-{id:03}.txt"), |
| 195 | kind: Kind::File, |
| 196 | bytes: Some(4096), |
| 197 | packed: Some(1800), |
| 198 | encrypted: false, |
| 199 | })); |
| 200 | } |
| 201 | entries |
| 202 | } |
| 203 | |
| 204 | impl Scenario { |
| 205 | /// 제거 안내는 외부 설치 화면의 문구만 재현하며 OS 동작은 실행하지 않음. |
| 206 | pub fn show(self, app: &mut ArchiveApp, ui: &mut egui::Ui) { |
| 207 | let (title, messages, button): (&str, Vec<&str>, Option<&str>) = match self.name { |
| 208 | "uninstall-windows" => ( |
| 209 | "제거 전 기본 앱 선택", |
| 210 | vec![ |
| 211 | "Zipelo를 기본 앱으로 사용했다면 제거 전에 다른 앱을 선택하세요. [기본 앱 설정 열기]에서 .zip, .7z, .tar, .gz, .tgz를 검색해 사용할 앱을 고를 수 있습니다. 다른 앱이 없으면 먼저 설치하세요.", |
| 212 | "직접 고른 기본 앱은 자동으로 바꾸지 않습니다. 제거 후 파일이 열리지 않으면 파일을 오른쪽 클릭하고 [연결 프로그램]에서 다른 앱을 선택하세요.", |
| 213 | ], |
| 214 | Some("기본 앱 설정 열기"), |
| 215 | ), |
| 216 | "uninstall-settings-error" => ( |
| 217 | "기본 앱 설정 실행 실패", |
| 218 | vec![ |
| 219 | "Windows 설정을 열지 못했습니다. 설정 > 앱 > 기본 앱에서 확장자를 검색해 다른 앱을 선택하세요.", |
| 220 | ], |
| 221 | Some("확인"), |
| 222 | ), |
| 223 | "uninstall-ubuntu-missing" => ( |
| 224 | "Ubuntu 제거 안내", |
| 225 | vec![ |
| 226 | "Zipelo를 제거합니다. 파일이 열리지 않으면 파일을 오른쪽 클릭하고 [다른 프로그램으로 열기]에서 다른 앱을 선택하세요.", |
| 227 | "이전 앱을 복원할 수 없습니다: application/zip. 파일을 오른쪽 클릭해 [다른 프로그램으로 열기]에서 앱을 선택하세요.", |
| 228 | ], |
| 229 | None, |
| 230 | ), |
| 231 | "uninstall-ubuntu-unknown-user" => ( |
| 232 | "Ubuntu 제거 안내", |
| 233 | vec![ |
| 234 | "Zipelo를 제거합니다. 파일이 열리지 않으면 파일을 오른쪽 클릭하고 [다른 프로그램으로 열기]에서 다른 앱을 선택하세요.", |
| 235 | "제거를 요청한 사용자를 확인할 수 없어 사용자 기본 앱 설정은 변경하지 않습니다.", |
| 236 | ], |
| 237 | None, |
| 238 | ), |
| 239 | _ => { |
| 240 | app.show(ui); |
| 241 | return; |
| 242 | } |
| 243 | }; |
| 244 | egui::CentralPanel::default().show_inside(ui, |ui| { |
| 245 | ui.add_space(16.0); |
| 246 | ui.heading(title); |
| 247 | ui.add_space(16.0); |
| 248 | for message in messages { |
| 249 | ui.label(message); |
| 250 | ui.add_space(16.0); |
| 251 | } |
| 252 | if let Some(button) = button { |
| 253 | // 미리보기에서는 설정 열기와 제거를 실행하지 않음. |
| 254 | let _ = ui.button(button); |
| 255 | } |
| 256 | }); |
| 257 | } |
| 258 | |
| 259 | /// 실제 파일과 작업자를 사용하지 않고 기존 화면 상태를 준비함. |
| 260 | pub fn build(self) -> ArchiveApp { |
| 261 | let factory = FakeFactory::manual(); |
| 262 | let state = factory.state.clone(); |
| 263 | let mut app = ArchiveApp::new(Box::new(factory), None, true); |
| 264 | let base = sample_root(); |
| 265 | app.destination = base.join("풀린 자료"); |
| 266 | app.automatic_destination = false; |
| 267 | app.zip_folder = base.clone(); |
| 268 | app.zip_name = "여행 자료.zip".into(); |
| 269 | if self.name == "empty" || self.name.starts_with("uninstall-") { |
| 270 | return app; |
| 271 | } |
| 272 | let archive = base.join(match self.name { |
| 273 | "gzip-conflict" | "gzip-conflict-choice" => "여행 자료.gz", |
| 274 | "tar-bz2" => "여행 자료.TAR.BZ2", |
| 275 | "tar-xz" => "여행 자료.TaR.Xz", |
| 276 | _ => "여행 자료.zip", |
| 277 | }); |
| 278 | app.model.archive = Some(archive.clone()); |
| 279 | app.model.entries = entries(self.name == "many-items"); |
| 280 | app.model.list_id = Some(ListId { |
| 281 | catalog_version: 1, |
| 282 | format: Format::Zip, |
| 283 | source_object: SourceObject::Unix { |
| 284 | device: 1, |
| 285 | inode: 1, |
| 286 | }, |
| 287 | archive_bytes: 2_700_000, |
| 288 | archive_sha256: [7; 32], |
| 289 | }); |
| 290 | app.model.confirmed = true; |
| 291 | if self.name.starts_with("split-") { |
| 292 | let archive = base.join(if self.name == "split-unsupported" { |
| 293 | "여행.zip.001" |
| 294 | } else { |
| 295 | "여행.7z.001" |
| 296 | }); |
| 297 | app.model.archive = Some(archive.clone()); |
| 298 | app.model.list_id = Some(ListId { |
| 299 | catalog_version: 2, |
| 300 | format: Format::SevenZip, |
| 301 | source_object: SourceObject::SplitSevenZip { |
| 302 | manifest_sha256: [9; 32], |
| 303 | }, |
| 304 | archive_bytes: 2_700_000, |
| 305 | archive_sha256: [7; 32], |
| 306 | }); |
| 307 | if self.name == "split-archive" { |
| 308 | app.model.selected.insert(1); |
| 309 | return app; |
| 310 | } |
| 311 | app.start(Start::List { archive }); |
| 312 | let mut state = state.borrow_mut(); |
| 313 | state.frame(Event::Accepted { encryption: false }); |
| 314 | let reason = match self.name { |
| 315 | "split-first-volume" => Some(VolumeProblemReason::FirstVolumeRequired), |
| 316 | "split-missing-volume" => Some(VolumeProblemReason::MissingVolume), |
| 317 | "split-incomplete" => Some(VolumeProblemReason::IncompleteSet), |
| 318 | _ => None, |
| 319 | }; |
| 320 | let error = match reason { |
| 321 | Some(VolumeProblemReason::FirstVolumeRequired) => ErrorCode::InvalidRequest, |
| 322 | Some(VolumeProblemReason::MissingVolume) => ErrorCode::MissingVolume, |
| 323 | Some(VolumeProblemReason::IncompleteSet) => ErrorCode::Integrity, |
| 324 | None if self.name == "split-source-changed" => ErrorCode::SourceChanged, |
| 325 | None => ErrorCode::UnsupportedFeature, |
| 326 | }; |
| 327 | if let Some(reason) = reason { |
| 328 | state.frame(Event::VolumeProblem(VolumeProblem { |
| 329 | reason, |
| 330 | volume: NativePath::Unix(if reason == VolumeProblemReason::MissingVolume { |
| 331 | "여행.7z.003".as_bytes().to_vec() |
| 332 | } else { |
| 333 | "여행.7z.001".as_bytes().to_vec() |
| 334 | }), |
| 335 | })); |
| 336 | } |
| 337 | state.frame(Event::Terminal(Terminal { |
| 338 | outcome: Outcome::Failed, |
| 339 | error: Some(error), |
| 340 | publication: Publication::None, |
| 341 | created_count: 0, |
| 342 | retained_partial_count: 0, |
| 343 | durability: Durability::NotApplicable, |
| 344 | cleanup: Cleanup::Complete, |
| 345 | })); |
| 346 | state.queue.push_back(HostEvent::StdoutEof); |
| 347 | state.queue.push_back(HostEvent::StderrEof); |
| 348 | state.queue.push_back(HostEvent::Exited { success: true }); |
| 349 | drop(state); |
| 350 | for _ in 0..32 { |
| 351 | app.model.poll(); |
| 352 | } |
| 353 | return app; |
| 354 | } |
| 355 | if self.name.starts_with("preview-") { |
| 356 | app.model.selected = BTreeSet::from([1]); |
| 357 | if self.name == "preview-implicit-folder" { |
| 358 | app.model.entries.truncate(1); |
| 359 | app.model.entries[0].id = 1; |
| 360 | app.model.entries[0].name = "자료/안내.txt".into(); |
| 361 | app.model.entries[0].kind = Kind::File; |
| 362 | return app; |
| 363 | } |
| 364 | if self.name == "preview-selection" { |
| 365 | app.model.selected.insert(0); |
| 366 | return app; |
| 367 | } |
| 368 | if self.name == "preview-catalog-approval" { |
| 369 | let template = app.model.entries[1].clone(); |
| 370 | app.model.entries = (0..10_001) |
| 371 | .map(|id| Entry { |
| 372 | id, |
| 373 | name: if id == 1 { |
| 374 | "읽어주세요.txt".into() |
| 375 | } else { |
| 376 | format!("{id}.bin") |
| 377 | }, |
| 378 | bytes: Some(if id == 1 { 7 } else { 0 }), |
| 379 | ..template.clone() |
| 380 | }) |
| 381 | .collect(); |
| 382 | } |
| 383 | if self.name == "preview-catalog-bytes-approval" { |
| 384 | app.model.entries.truncate(2); |
| 385 | app.model.entries[0].bytes = Some(16 * 1024 * 1024 * 1024); |
| 386 | app.model.entries[1].bytes = Some(7); |
| 387 | } |
| 388 | app.begin_preview(&egui::Context::default()); |
| 389 | if matches!( |
| 390 | self.name, |
| 391 | "preview-catalog-approval" | "preview-catalog-bytes-approval" |
| 392 | ) { |
| 393 | let mut state = state.borrow_mut(); |
| 394 | state.frame(Event::Accepted { encryption: false }); |
| 395 | state.frame(Event::ResourceRequired(ResourceChallenge { |
| 396 | id: 1, |
| 397 | action: ActionKind::Preview, |
| 398 | scope: ResourceScope { |
| 399 | output: true, |
| 400 | entries: true, |
| 401 | ..ResourceScope::default() |
| 402 | }, |
| 403 | usage: ResourceUsage::default(), |
| 404 | soft_limits: Limits::default(), |
| 405 | ceiling: Limits { |
| 406 | input: u64::MAX, |
| 407 | output: 64 * 1024 * 1024 * 1024, |
| 408 | entries: 200_000, |
| 409 | }, |
| 410 | })); |
| 411 | drop(state); |
| 412 | for _ in 0..32 { |
| 413 | app.model.poll(); |
| 414 | } |
| 415 | return app; |
| 416 | } |
| 417 | { |
| 418 | let mut state = state.borrow_mut(); |
| 419 | state.frame(Event::Accepted { encryption: false }); |
| 420 | if self.name != "preview-loading" { |
| 421 | let error = match self.name { |
| 422 | "preview-limit" => Some(ErrorCode::Limit), |
| 423 | "preview-damaged" => Some(ErrorCode::Integrity), |
| 424 | "preview-unsupported" => Some(ErrorCode::UnsupportedFeature), |
| 425 | _ => None, |
| 426 | }; |
| 427 | if error.is_none() { |
| 428 | use sha2::{Digest, Sha256}; |
| 429 | let image = self.name == "preview-image"; |
| 430 | let data = if image { |
| 431 | (0..128 * 96) |
| 432 | .flat_map(|i| { |
| 433 | if (i / 128 / 16 + i % 128 / 16) % 2 == 0 { |
| 434 | [37, 99, 235, 255] |
| 435 | } else { |
| 436 | [232, 240, 254, 255] |
| 437 | } |
| 438 | }) |
| 439 | .collect::<Vec<_>>() |
| 440 | } else if self.name == "preview-empty" { |
| 441 | Vec::new() |
| 442 | } else { |
| 443 | "여행 준비 목록\n\n기차표 확인\n카메라 배터리 충전\n" |
| 444 | .as_bytes() |
| 445 | .to_vec() |
| 446 | }; |
| 447 | let info = PreviewInfo { |
| 448 | entry_id: 1, |
| 449 | format: if image { |
| 450 | PreviewFormat::Rgba8 |
| 451 | } else { |
| 452 | PreviewFormat::Utf8Text |
| 453 | }, |
| 454 | total_bytes: data.len() as u64, |
| 455 | width: if image { 128 } else { 0 }, |
| 456 | height: if image { 96 } else { 0 }, |
| 457 | }; |
| 458 | state.frame(Event::PreviewBegin(info)); |
| 459 | for (offset, chunk) in data.chunks(32768).enumerate() { |
| 460 | state.frame(Event::PreviewChunk { |
| 461 | entry_id: 1, |
| 462 | offset: (offset * 32768) as u64, |
| 463 | data: chunk.to_vec(), |
| 464 | }); |
| 465 | } |
| 466 | state.frame(Event::PreviewEnd { |
| 467 | entry_id: 1, |
| 468 | total_bytes: info.total_bytes, |
| 469 | sha256: Sha256::digest(&data).into(), |
| 470 | }); |
| 471 | } |
| 472 | state.frame(Event::Terminal(Terminal { |
| 473 | outcome: if error.is_some() { |
| 474 | Outcome::Failed |
| 475 | } else { |
| 476 | Outcome::Completed |
| 477 | }, |
| 478 | error, |
| 479 | publication: Publication::None, |
| 480 | created_count: 0, |
| 481 | retained_partial_count: 0, |
| 482 | durability: Durability::NotApplicable, |
| 483 | cleanup: Cleanup::Complete, |
| 484 | })); |
| 485 | state.queue.push_back(HostEvent::StdoutEof); |
| 486 | state.queue.push_back(HostEvent::StderrEof); |
| 487 | state.queue.push_back(HostEvent::Exited { success: true }); |
| 488 | } |
| 489 | } |
| 490 | for _ in 0..32 { |
| 491 | app.model.poll(); |
| 492 | } |
| 493 | return app; |
| 494 | } |
| 495 | match self.name { |
| 496 | "tar-bz2" | "tar-xz" => { |
| 497 | app.model.list_id.as_mut().unwrap().format = Format::Tar; |
| 498 | for entry in &mut app.model.entries { |
| 499 | entry.encrypted = false; |
| 500 | } |
| 501 | app.destination = present::default_destination(&archive); |
| 502 | app.automatic_destination = true; |
| 503 | return app; |
| 504 | } |
| 505 | "archive" | "many-items" => return app, |
| 506 | "folder-empty" => { |
| 507 | app.browse_folder("빈 폴더"); |
| 508 | return app; |
| 509 | } |
| 510 | "dialog-error" => { |
| 511 | app.ui_error = Some(DIALOG_UNAVAILABLE.into()); |
| 512 | return app; |
| 513 | } |
| 514 | "folder" => { |
| 515 | app.browse_folder("사진"); |
| 516 | return app; |
| 517 | } |
| 518 | "search-empty" => { |
| 519 | app.search = "없는 파일".into(); |
| 520 | return app; |
| 521 | } |
| 522 | "selection" | "marquee" => { |
| 523 | app.model |
| 524 | .selected |
| 525 | .extend([0, 3, 4, if self.name == "marquee" { 2 } else { 1 }]); |
| 526 | if self.name == "marquee" { |
| 527 | app.scenario_marquee = Some(egui::Rect::from_min_size( |
| 528 | egui::pos2(22.0, 8.0), |
| 529 | egui::vec2(360.0, 62.0), |
| 530 | )); |
| 531 | } |
| 532 | return app; |
| 533 | } |
| 534 | "create" | "create-encrypted" | "create-sevenzip" => { |
| 535 | app.sources = vec![base.join("읽어주세요.txt"), base.join("사진")]; |
| 536 | app.scenario_sources = Some(std::rc::Rc::new(vec![ |
| 537 | SourceRow { |
| 538 | name: "사진".into(), |
| 539 | directory: true, |
| 540 | bytes: Some(0), |
| 541 | }, |
| 542 | SourceRow { |
| 543 | name: "읽어주세요.txt".into(), |
| 544 | directory: false, |
| 545 | bytes: Some(4096), |
| 546 | }, |
| 547 | ])); |
| 548 | app.show_create(self.name == "create-encrypted"); |
| 549 | app.set_seven_zip(self.name == "create-sevenzip"); |
| 550 | return app; |
| 551 | } |
| 552 | _ => {} |
| 553 | } |
| 554 | if self.name.starts_with("recovery-") { |
| 555 | let request = Start::RecoverZip { |
| 556 | archive, |
| 557 | output_file: base.join("복구본.zip"), |
| 558 | }; |
| 559 | app.last_request = Some(request.clone()); |
| 560 | app.model.begin(request, app.factory.as_mut()); |
| 561 | let mut state = state.borrow_mut(); |
| 562 | state.frame(Event::Accepted { encryption: false }); |
| 563 | if self.name == "recovery-resource" { |
| 564 | state.frame(Event::ResourceRequired(ResourceChallenge { |
| 565 | id: 1, |
| 566 | action: ActionKind::RecoverZip, |
| 567 | scope: ResourceScope { |
| 568 | ratio: true, |
| 569 | ..Default::default() |
| 570 | }, |
| 571 | usage: ResourceUsage::default(), |
| 572 | soft_limits: Limits::default(), |
| 573 | ceiling: Limits::default(), |
| 574 | })); |
| 575 | } else if self.name == "recovery-progress" { |
| 576 | state.frame(Event::Progress { |
| 577 | stage: Stage::Scan, |
| 578 | processed: 1024, |
| 579 | total: None, |
| 580 | completed_entries: 1, |
| 581 | }); |
| 582 | } else if self.name == "recovery-cancelled" { |
| 583 | state.finish(Outcome::Cancelled, Publication::None); |
| 584 | } else { |
| 585 | let impossible = self.name == "recovery-impossible"; |
| 586 | let partial = self.name == "recovery-partial"; |
| 587 | let unknown = self.name == "recovery-unknown"; |
| 588 | let retained = self.name == "recovery-retained"; |
| 589 | let failed = self.name == "recovery-save-error" || retained; |
| 590 | state.frame(Event::RecoveryEntry(RecoveryEntry { |
| 591 | candidate_id: 0, |
| 592 | source_offset: 0, |
| 593 | name: Some("읽어주세요.txt".into()), |
| 594 | kind: Some(worker_protocol::protocol::EntryKind::File), |
| 595 | status: if impossible { |
| 596 | RecoveryStatus::Lost |
| 597 | } else { |
| 598 | RecoveryStatus::Verified |
| 599 | }, |
| 600 | reason: if impossible { |
| 601 | RecoveryReason::Truncated |
| 602 | } else { |
| 603 | RecoveryReason::HeaderRebuilt |
| 604 | }, |
| 605 | declared_size: Some(4), |
| 606 | verified_size: (!impossible).then_some(4), |
| 607 | sha256: (!impossible).then_some([1; 32]), |
| 608 | })); |
| 609 | if partial { |
| 610 | state.frame(Event::RecoveryEntry(RecoveryEntry { |
| 611 | candidate_id: 1, |
| 612 | source_offset: 128, |
| 613 | name: Some("사진.png".into()), |
| 614 | kind: Some(worker_protocol::protocol::EntryKind::File), |
| 615 | status: RecoveryStatus::Lost, |
| 616 | reason: RecoveryReason::CrcMismatch, |
| 617 | declared_size: Some(10), |
| 618 | verified_size: None, |
| 619 | sha256: None, |
| 620 | })); |
| 621 | } |
| 622 | state.frame(Event::RecoveryEnd(RecoveryEnd { |
| 623 | mode: if unknown { |
| 624 | RecoveryMode::LocalChain |
| 625 | } else { |
| 626 | RecoveryMode::CentralDirectory |
| 627 | }, |
| 628 | source_bytes: 256, |
| 629 | source_sha256: [2; 32], |
| 630 | known_entries: (!unknown).then_some(if partial { 2 } else { 1 }), |
| 631 | verified_entries: u32::from(!impossible), |
| 632 | lost_entries: u32::from(impossible || partial), |
| 633 | unverified_entries: 0, |
| 634 | unknown_loss: unknown, |
| 635 | })); |
| 636 | if !impossible && !failed { |
| 637 | state.frame(Event::Output { |
| 638 | entry_id: None, |
| 639 | relative_name: "복구본.zip".into(), |
| 640 | disposition: Disposition::Created, |
| 641 | }); |
| 642 | } |
| 643 | if retained { |
| 644 | state.frame(Event::Output { |
| 645 | entry_id: None, |
| 646 | relative_name: ".zipelo-42-1.tmp".into(), |
| 647 | disposition: Disposition::PartialRetained, |
| 648 | }); |
| 649 | } |
| 650 | state.frame(Event::Terminal(Terminal { |
| 651 | outcome: if partial || unknown || impossible || failed { |
| 652 | Outcome::Failed |
| 653 | } else { |
| 654 | Outcome::Completed |
| 655 | }, |
| 656 | error: if failed { |
| 657 | Some(ErrorCode::DiskFull) |
| 658 | } else if impossible { |
| 659 | Some(ErrorCode::RecoveryImpossible) |
| 660 | } else if partial || unknown { |
| 661 | Some(ErrorCode::RecoveryIncomplete) |
| 662 | } else { |
| 663 | None |
| 664 | }, |
| 665 | publication: if impossible || failed { |
| 666 | Publication::None |
| 667 | } else { |
| 668 | Publication::Complete |
| 669 | }, |
| 670 | created_count: u64::from(!impossible && !failed), |
| 671 | retained_partial_count: u64::from(retained), |
| 672 | durability: if impossible || failed { |
| 673 | Durability::NotApplicable |
| 674 | } else { |
| 675 | Durability::Synced |
| 676 | }, |
| 677 | cleanup: if retained { |
| 678 | Cleanup::Failed |
| 679 | } else { |
| 680 | Cleanup::Complete |
| 681 | }, |
| 682 | })); |
| 683 | state.queue.extend([ |
| 684 | HostEvent::StdoutEof, |
| 685 | HostEvent::StderrEof, |
| 686 | HostEvent::Exited { success: true }, |
| 687 | ]); |
| 688 | } |
| 689 | drop(state); |
| 690 | for _ in 0..30 { |
| 691 | app.model.poll(); |
| 692 | } |
| 693 | return app; |
| 694 | } |
| 695 | let seven_zip = self.name.starts_with("create-sevenzip"); |
| 696 | let creating = self.name.starts_with("create-") || self.name == "password-create"; |
| 697 | let listing_error = matches!(self.name, "unsupported" | "damaged"); |
| 698 | if matches!(self.name, "gzip-conflict" | "gzip-conflict-choice") { |
| 699 | app.model.list_id.as_mut().unwrap().format = Format::Gzip; |
| 700 | app.model.entries = vec![Entry { |
| 701 | id: 0, |
| 702 | name: "여행 자료".into(), |
| 703 | kind: Kind::File, |
| 704 | bytes: Some(1_287_952), |
| 705 | packed: Some(900_000), |
| 706 | encrypted: false, |
| 707 | }]; |
| 708 | app.gzip_name = "여행 자료".into(); |
| 709 | } |
| 710 | let request = if seven_zip { |
| 711 | Start::CreateSevenZip { |
| 712 | sources: vec![(base.join("사진"), "사진".into())], |
| 713 | output_file: base.join("여행 자료.7z"), |
| 714 | } |
| 715 | } else if creating { |
| 716 | Start::CreateZip { |
| 717 | sources: vec![(base.join("사진"), "사진".into())], |
| 718 | output_file: base.join("여행 자료.zip"), |
| 719 | method: Method::Deflate, |
| 720 | aes256: self.name == "password-create", |
| 721 | } |
| 722 | } else if listing_error { |
| 723 | Start::List { archive } |
| 724 | } else { |
| 725 | Start::Extract { |
| 726 | archive, |
| 727 | destination: app.destination.clone(), |
| 728 | selection: Selection::All, |
| 729 | list_id: app.model.list_id.clone().unwrap(), |
| 730 | gzip_output_name: (matches!(self.name, "gzip-conflict" | "gzip-conflict-choice")) |
| 731 | .then(|| app.gzip_name.clone()), |
| 732 | } |
| 733 | }; |
| 734 | app.targets = Some(if creating { |
| 735 | BTreeSet::from([if seven_zip { |
| 736 | "여행 자료.7z" |
| 737 | } else { |
| 738 | "여행 자료.zip" |
| 739 | } |
| 740 | .into()]) |
| 741 | } else if matches!(self.name, "gzip-conflict" | "gzip-conflict-choice") { |
| 742 | BTreeSet::from(["여행 자료".into()]) |
| 743 | } else { |
| 744 | BTreeSet::from([ |
| 745 | "읽어주세요.txt".into(), |
| 746 | "여행 일정.pdf".into(), |
| 747 | "사진/바다.jpg".into(), |
| 748 | "사진/풍경.jpg".into(), |
| 749 | ]) |
| 750 | }); |
| 751 | if matches!( |
| 752 | self.name, |
| 753 | "extract-skipped" | "extract-renamed" | "extract-rename-failed" |
| 754 | ) { |
| 755 | app.targets = Some(["읽어주세요.txt".into()].into_iter().collect()); |
| 756 | app.directories.clear(); |
| 757 | } |
| 758 | if self.name == "resource-approval" { |
| 759 | app.model.entries[1].bytes = Some(17 * 1024 * 1024 * 1024); |
| 760 | } |
| 761 | assert!(app.start(request)); |
| 762 | { |
| 763 | let mut state = state.borrow_mut(); |
| 764 | state.frame(Event::Accepted { |
| 765 | encryption: !seven_zip, |
| 766 | }); |
| 767 | match self.name { |
| 768 | "resource-approval" | "resource-ratio" | "create-sevenzip-resource" => { |
| 769 | let expanded = self.name != "resource-ratio"; |
| 770 | state.frame(Event::ResourceRequired(ResourceChallenge { |
| 771 | id: 1, |
| 772 | action: if seven_zip { |
| 773 | ActionKind::CreateSevenZip |
| 774 | } else { |
| 775 | ActionKind::Extract |
| 776 | }, |
| 777 | scope: ResourceScope { |
| 778 | output: expanded, |
| 779 | entries: expanded, |
| 780 | ratio: !expanded, |
| 781 | }, |
| 782 | usage: ResourceUsage { |
| 783 | available_bytes: Some(90 * 1024 * 1024 * 1024), |
| 784 | actual_bytes: (!expanded).then_some(300 * 1024 * 1024), |
| 785 | ratio_output_bytes: (!expanded).then_some(300 * 1024 * 1024), |
| 786 | compressed_bytes: (!expanded).then_some(4096), |
| 787 | ..ResourceUsage::default() |
| 788 | }, |
| 789 | soft_limits: Limits::default(), |
| 790 | ceiling: if expanded { |
| 791 | Limits { |
| 792 | input: u64::MAX, |
| 793 | output: 64 * 1024 * 1024 * 1024, |
| 794 | entries: 200_000, |
| 795 | } |
| 796 | } else { |
| 797 | Limits::default() |
| 798 | }, |
| 799 | })); |
| 800 | } |
| 801 | "resource-retry" | "resource-partial" => { |
| 802 | let partial = self.name == "resource-partial"; |
| 803 | if partial { |
| 804 | state.frame(Event::Output { |
| 805 | entry_id: Some(1), |
| 806 | relative_name: "읽어주세요.txt".into(), |
| 807 | disposition: Disposition::Created, |
| 808 | }); |
| 809 | } |
| 810 | state.frame(Event::Terminal(Terminal { |
| 811 | outcome: Outcome::Failed, |
| 812 | error: Some(ErrorCode::Limit), |
| 813 | publication: if partial { |
| 814 | Publication::Partial |
| 815 | } else { |
| 816 | Publication::None |
| 817 | }, |
| 818 | created_count: u64::from(partial), |
| 819 | retained_partial_count: 0, |
| 820 | durability: Durability::Synced, |
| 821 | cleanup: Cleanup::Complete, |
| 822 | })); |
| 823 | state.queue.extend([ |
| 824 | HostEvent::StdoutEof, |
| 825 | HostEvent::StderrEof, |
| 826 | HostEvent::Exited { success: true }, |
| 827 | ]); |
| 828 | } |
| 829 | "conflict-choice" | "conflict-apply" | "gzip-conflict-choice" => { |
| 830 | state.frame(Event::ConflictRequired(Conflict { |
| 831 | challenge_id: 29, |
| 832 | entry_id: if self.name == "gzip-conflict-choice" { |
| 833 | 0 |
| 834 | } else { |
| 835 | 1 |
| 836 | }, |
| 837 | relative_name: if self.name == "gzip-conflict-choice" { |
| 838 | "여행 자료" |
| 839 | } else { |
| 840 | "읽어주세요.txt" |
| 841 | } |
| 842 | .into(), |
| 843 | incoming_size: 1_287_952, |
| 844 | existing_size: 2048, |
| 845 | })); |
| 846 | } |
| 847 | "extract-skipped" | "extract-renamed" | "extract-rename-failed" => { |
| 848 | let failed = self.name == "extract-rename-failed"; |
| 849 | let skip = self.name == "extract-skipped"; |
| 850 | let name = if skip { |
| 851 | "읽어주세요.txt" |
| 852 | } else { |
| 853 | "읽어주세요 (1).txt" |
| 854 | }; |
| 855 | state.frame(Event::ConflictResolved(Resolution { |
| 856 | entry_id: 1, |
| 857 | relative_name: name.into(), |
| 858 | choice: if skip { |
| 859 | ConflictChoice::Skip |
| 860 | } else { |
| 861 | ConflictChoice::Rename |
| 862 | }, |
| 863 | })); |
| 864 | if !skip && !failed { |
| 865 | state.frame(Event::Output { |
| 866 | entry_id: Some(1), |
| 867 | relative_name: name.into(), |
| 868 | disposition: Disposition::Created, |
| 869 | }); |
| 870 | } |
| 871 | state.frame(Event::Terminal(Terminal { |
| 872 | outcome: if failed { |
| 873 | Outcome::Failed |
| 874 | } else { |
| 875 | Outcome::Completed |
| 876 | }, |
| 877 | error: failed.then_some(ErrorCode::Io), |
| 878 | publication: if skip || failed { |
| 879 | Publication::None |
| 880 | } else { |
| 881 | Publication::Complete |
| 882 | }, |
| 883 | created_count: u64::from(!skip && !failed), |
| 884 | retained_partial_count: 0, |
| 885 | durability: if skip || failed { |
| 886 | Durability::NotApplicable |
| 887 | } else { |
| 888 | Durability::Synced |
| 889 | }, |
| 890 | cleanup: Cleanup::Complete, |
| 891 | })); |
| 892 | state.queue.extend([ |
| 893 | HostEvent::StdoutEof, |
| 894 | HostEvent::StderrEof, |
| 895 | HostEvent::Exited { success: true }, |
| 896 | ]); |
| 897 | } |
| 898 | "password" | "password-retry" | "password-create" => { |
| 899 | state.frame(Event::PasswordRequired { |
| 900 | challenge_id: 17, |
| 901 | attempt: if self.name == "password-retry" { 2 } else { 1 }, |
| 902 | encrypt: self.name == "password-create", |
| 903 | }) |
| 904 | } |
| 905 | "extract-complete" |
| 906 | | "create-complete" |
| 907 | | "create-sevenzip-complete" |
| 908 | | "extract-unsynced" |
| 909 | | "extract-complete-cleanup-failed" => { |
| 910 | let names = app.targets.as_ref().unwrap(); |
| 911 | for name in names { |
| 912 | state.frame(Event::Output { |
| 913 | entry_id: None, |
| 914 | relative_name: name.clone(), |
| 915 | disposition: Disposition::Created, |
| 916 | }); |
| 917 | } |
| 918 | state.frame(Event::Terminal(Terminal { |
| 919 | outcome: Outcome::Completed, |
| 920 | error: None, |
| 921 | publication: Publication::Complete, |
| 922 | created_count: names.len() as u64, |
| 923 | retained_partial_count: 0, |
| 924 | durability: if self.name == "extract-unsynced" { |
| 925 | Durability::Unconfirmed |
| 926 | } else { |
| 927 | Durability::Synced |
| 928 | }, |
| 929 | cleanup: if self.name == "extract-complete-cleanup-failed" { |
| 930 | Cleanup::Failed |
| 931 | } else { |
| 932 | Cleanup::Complete |
| 933 | }, |
| 934 | })); |
| 935 | state.queue.extend([ |
| 936 | HostEvent::StdoutEof, |
| 937 | HostEvent::StderrEof, |
| 938 | HostEvent::Exited { success: true }, |
| 939 | ]); |
| 940 | } |
| 941 | "extract-cancelled" | "create-sevenzip-cancelled" => { |
| 942 | state.finish(Outcome::Cancelled, Publication::None) |
| 943 | } |
| 944 | "extract-partial" | "extract-uncertain" => { |
| 945 | let partial = self.name == "extract-partial"; |
| 946 | if partial { |
| 947 | state.frame(Event::Output { |
| 948 | entry_id: Some(1), |
| 949 | relative_name: "읽어주세요.txt".into(), |
| 950 | disposition: Disposition::Created, |
| 951 | }); |
| 952 | } |
| 953 | state.frame(Event::Terminal(Terminal { |
| 954 | outcome: Outcome::Failed, |
| 955 | error: Some(ErrorCode::Io), |
| 956 | publication: if partial { |
| 957 | Publication::Partial |
| 958 | } else { |
| 959 | Publication::Uncertain |
| 960 | }, |
| 961 | created_count: u64::from(partial), |
| 962 | retained_partial_count: 0, |
| 963 | durability: Durability::Synced, |
| 964 | cleanup: Cleanup::Complete, |
| 965 | })); |
| 966 | state.queue.extend([ |
| 967 | HostEvent::StdoutEof, |
| 968 | HostEvent::StderrEof, |
| 969 | HostEvent::Exited { success: true }, |
| 970 | ]); |
| 971 | } |
| 972 | "extract-disk-full" | "extract-cleanup-failed" => { |
| 973 | state.frame(Event::Terminal(Terminal { |
| 974 | outcome: Outcome::Failed, |
| 975 | error: Some(if self.name == "extract-disk-full" { |
| 976 | ErrorCode::DiskFull |
| 977 | } else { |
| 978 | ErrorCode::Io |
| 979 | }), |
| 980 | publication: Publication::None, |
| 981 | created_count: 0, |
| 982 | retained_partial_count: 0, |
| 983 | durability: Durability::NotApplicable, |
| 984 | cleanup: if self.name == "extract-cleanup-failed" { |
| 985 | Cleanup::Failed |
| 986 | } else { |
| 987 | Cleanup::Complete |
| 988 | }, |
| 989 | })); |
| 990 | state.queue.extend([ |
| 991 | HostEvent::StdoutEof, |
| 992 | HostEvent::StderrEof, |
| 993 | HostEvent::Exited { success: true }, |
| 994 | ]); |
| 995 | } |
| 996 | "conflict" |
| 997 | | "gzip-conflict" |
| 998 | | "unsupported" |
| 999 | | "damaged" |
| 1000 | | "source-changed" |
| 1001 | | "create-error" |
| 1002 | | "create-sevenzip-error" => { |
| 1003 | state.frame(Event::Terminal(Terminal { |
| 1004 | outcome: Outcome::Failed, |
| 1005 | error: Some(match self.name { |
| 1006 | "conflict" | "gzip-conflict" => ErrorCode::Conflict, |
| 1007 | "source-changed" => ErrorCode::SourceChanged, |
| 1008 | "create-error" | "create-sevenzip-error" => ErrorCode::DiskFull, |
| 1009 | "unsupported" => ErrorCode::UnsupportedFormat, |
| 1010 | _ => ErrorCode::Integrity, |
| 1011 | }), |
| 1012 | publication: Publication::None, |
| 1013 | created_count: 0, |
| 1014 | retained_partial_count: 0, |
| 1015 | durability: Durability::NotApplicable, |
| 1016 | cleanup: Cleanup::Complete, |
| 1017 | })); |
| 1018 | state.queue.extend([ |
| 1019 | HostEvent::StdoutEof, |
| 1020 | HostEvent::StderrEof, |
| 1021 | HostEvent::Exited { success: true }, |
| 1022 | ]); |
| 1023 | } |
| 1024 | _ => state.frame(Event::Progress { |
| 1025 | stage: if creating { |
| 1026 | Stage::Write |
| 1027 | } else { |
| 1028 | Stage::Decode |
| 1029 | }, |
| 1030 | processed: 38 << 20, |
| 1031 | total: (self.name != "extract-unknown").then_some(61 << 20), |
| 1032 | completed_entries: 12, |
| 1033 | }), |
| 1034 | } |
| 1035 | } |
| 1036 | for _ in 0..64 { |
| 1037 | app.model.poll(); |
| 1038 | } |
| 1039 | if self.name == "conflict-apply" { |
| 1040 | app.conflict_challenge = Some((app.model.job_id().unwrap(), 29)); |
| 1041 | app.conflict_apply = true; |
| 1042 | } |
| 1043 | if self.name == "extract-unsynced" { |
| 1044 | app.details = true; |
| 1045 | } |
| 1046 | if self.name == "cancelling" { |
| 1047 | app.model.cancel(); |
| 1048 | } |
| 1049 | if self.name == "close-confirm" { |
| 1050 | app.model.request_close(); |
| 1051 | } |
| 1052 | app |
| 1053 | } |
| 1054 | } |
| 1055 | |
| 1056 | /// 화면을 고정하고 실제 파일 조작을 막는 미리보기임. |
| 1057 | pub struct Preview(pub ArchiveApp, Option<Scenario>); |
| 1058 | impl Preview { |
| 1059 | pub fn with_scenario(mut self, scenario: Scenario) -> Self { |
| 1060 | self.1 = Some(scenario); |
| 1061 | self |
| 1062 | } |
| 1063 | |
| 1064 | pub fn show(&mut self, ui: &mut egui::Ui) { |
| 1065 | if let Some(scenario) = self.1 { |
| 1066 | scenario.show(&mut self.0, ui); |
| 1067 | } else { |
| 1068 | self.0.show(ui); |
| 1069 | } |
| 1070 | } |
| 1071 | |
| 1072 | pub fn new(app: ArchiveApp, ctx: &egui::Context) -> Self { |
| 1073 | ctx.on_begin_pass( |
| 1074 | "ui-scenario-readonly", |
| 1075 | std::sync::Arc::new(|ctx| { |
| 1076 | ctx.input_mut(|i| { |
| 1077 | i.events.clear(); |
| 1078 | i.pointer = Default::default(); |
| 1079 | i.keys_down.clear(); |
| 1080 | i.modifiers = Default::default(); |
| 1081 | i.raw.dropped_files.clear(); |
| 1082 | i.raw.hovered_files.clear(); |
| 1083 | }); |
| 1084 | }), |
| 1085 | ); |
| 1086 | Self(app, None) |
| 1087 | } |
| 1088 | } |
| 1089 | impl eframe::App for Preview { |
| 1090 | fn ui(&mut self, root: &mut egui::Ui, _: &mut eframe::Frame) { |
| 1091 | if root.ctx().input(|i| i.viewport().close_requested()) { |
| 1092 | root.ctx().send_viewport_cmd(egui::ViewportCommand::Close); |
| 1093 | return; |
| 1094 | } |
| 1095 | self.show(root); |
| 1096 | } |
| 1097 | } |