| 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 | "resource-approval" => "처리 전 큰 작업 승인", |
| 25 | "resource-ratio" => "고압축 작업 경고와 미확인 값", |
| 26 | "resource-retry" => "주 창 모달에서 출력 없는 한도 실패 후 확대 재시도", |
| 27 | "resource-partial" => "주 창 모달에서 일부 출력 후 한도 중단", |
| 28 | "gzip-conflict-choice" => "단일 GZ 파일의 충돌 선택", |
| 29 | "conflict-choice" => "같은 이름 파일의 세 가지 처리 선택", |
| 30 | "conflict-apply" => "남은 충돌에 같은 선택 적용", |
| 31 | "extract-skipped" => "모든 파일을 건너뛴 정상 완료", |
| 32 | "extract-renamed" => "이름을 바꿔 저장한 완료 결과", |
| 33 | "extract-rename-failed" => "새 이름을 정한 뒤 저장 전 I/O 실패", |
| 34 | "empty" => "빈 첫 화면", |
| 35 | "archive" => "폴더와 파일이 있는 압축파일", |
| 36 | "tar-bz2" => "TAR.BZ2 목록과 자동 해제 폴더", |
| 37 | "tar-xz" => "TAR.XZ 목록과 자동 해제 폴더", |
| 38 | "folder" => "사진 하위 폴더", |
| 39 | "many-items" => "500개 항목과 세로 스크롤", |
| 40 | "selection" => "여러 파일과 폴더 선택", |
| 41 | "marquee" => "반투명 사각형으로 끌어서 선택 중", |
| 42 | "search-empty" => "검색 결과 없음", |
| 43 | "password" => "압축 해제 암호 입력", |
| 44 | "password-retry" => "암호가 틀린 뒤 다시 입력", |
| 45 | "extract-progress" => "압축 해제 진행률 62%", |
| 46 | "extract-unknown" => "전체 크기를 모르는 압축 해제", |
| 47 | "extract-complete" => "압축 해제 완료", |
| 48 | "extract-cancelled" => "압축 해제 취소 완료", |
| 49 | "cancelling" => "취소 요청 후 작업 종료 대기", |
| 50 | "conflict" => "같은 이름 파일 충돌", |
| 51 | "unsupported" => "지원하지 않는 압축 형식", |
| 52 | "damaged" => "손상된 압축파일", |
| 53 | "create" => "암호 없는 ZIP 만들기 창", |
| 54 | "create-encrypted" => "암호 설정이 켜진 ZIP 만들기 창", |
| 55 | "create-progress" => "ZIP 만들기 진행률 62%", |
| 56 | "create-complete" => "ZIP 만들기 완료", |
| 57 | "folder-empty" => "항목이 없는 하위 폴더", |
| 58 | "gzip-conflict" => "단일 GZ 파일 이름 충돌", |
| 59 | "extract-partial" => "일부 파일만 풀린 결과", |
| 60 | "extract-uncertain" => "저장 여부를 확인할 수 없는 결과", |
| 61 | "extract-unsynced" => "완료 뒤 저장 확인 경고의 상세 정보", |
| 62 | "source-changed" => "목록을 연 뒤 원본이 바뀐 오류", |
| 63 | "dialog-error" => "운영체제 파일 선택 창 실행 실패", |
| 64 | "create-error" => "ZIP 만들기 중 디스크 공간 부족", |
| 65 | "password-create" => "암호 ZIP 생성의 작업자 암호 요청", |
| 66 | "close-confirm" => "진행 중 창 닫기 확인", |
| 67 | "uninstall-windows" => "Windows 제거 전 기본 앱 선택 안내", |
| 68 | "uninstall-settings-error" => "Windows 기본 앱 설정 실행 실패", |
| 69 | "uninstall-ubuntu-missing" => "Ubuntu 이전 기본 앱 복원 불가 안내", |
| 70 | "uninstall-ubuntu-unknown-user" => "Ubuntu 제거 사용자 확인 불가 안내", |
| 71 | } |
| 72 | |
| 73 | pub fn listing() -> String { |
| 74 | SCENARIOS |
| 75 | .iter() |
| 76 | .map(|s| format!("{}\t{}\n", s.name, s.description)) |
| 77 | .collect() |
| 78 | } |
| 79 | |
| 80 | pub fn parse(name: &str) -> Result<Scenario, String> { |
| 81 | SCENARIOS |
| 82 | .iter() |
| 83 | .copied() |
| 84 | .find(|s| s.name == name) |
| 85 | .ok_or_else(|| { |
| 86 | format!( |
| 87 | "알 수 없는 UI 상황: {name}\n사용 가능한 상황:\n{}", |
| 88 | listing() |
| 89 | ) |
| 90 | }) |
| 91 | } |
| 92 | |
| 93 | #[derive(Debug, PartialEq)] |
| 94 | pub enum Launch { |
| 95 | Normal(Vec<OsString>), |
| 96 | Scenario(Scenario), |
| 97 | List, |
| 98 | } |
| 99 | |
| 100 | pub fn launch(args: Vec<OsString>) -> Result<Launch, String> { |
| 101 | let requested = args |
| 102 | .iter() |
| 103 | .any(|a| a == "--ui-scenario" || a == "--list-ui-scenarios"); |
| 104 | if !requested { |
| 105 | return Ok(Launch::Normal(args)); |
| 106 | } |
| 107 | if args.len() == 1 && args[0] == "--list-ui-scenarios" { |
| 108 | return Ok(Launch::List); |
| 109 | } |
| 110 | if args.len() == 2 && args[0] == "--ui-scenario" { |
| 111 | return args[1] |
| 112 | .to_str() |
| 113 | .ok_or_else(|| format!("상황 이름은 UTF-8이어야 합니다\n{}", listing())) |
| 114 | .and_then(parse) |
| 115 | .map(Launch::Scenario); |
| 116 | } |
| 117 | Err(format!( |
| 118 | "사용법: --ui-scenario <이름> 또는 --list-ui-scenarios\n{}", |
| 119 | listing() |
| 120 | )) |
| 121 | } |
| 122 | |
| 123 | fn sample_root() -> PathBuf { |
| 124 | PathBuf::from(if cfg!(target_os = "windows") { |
| 125 | "C:\\Samples" |
| 126 | } else { |
| 127 | "/Samples" |
| 128 | }) |
| 129 | } |
| 130 | |
| 131 | fn entries(many: bool) -> Vec<Entry> { |
| 132 | let mut entries = vec![ |
| 133 | ("사진", Kind::Directory), |
| 134 | ("읽어주세요.txt", Kind::File), |
| 135 | ("여행 일정.pdf", Kind::File), |
| 136 | ("사진/바다.jpg", Kind::File), |
| 137 | ("사진/풍경.jpg", Kind::File), |
| 138 | ] |
| 139 | .into_iter() |
| 140 | .enumerate() |
| 141 | .map(|(id, (name, kind))| Entry { |
| 142 | id: id as u32, |
| 143 | name: name.into(), |
| 144 | kind, |
| 145 | bytes: Some(if kind == Kind::Directory { |
| 146 | 0 |
| 147 | } else { |
| 148 | 1_287_952 |
| 149 | }), |
| 150 | packed: Some(900_000), |
| 151 | encrypted: id == 2, |
| 152 | }) |
| 153 | .collect::<Vec<_>>(); |
| 154 | if many { |
| 155 | entries.extend((5..505).map(|id| Entry { |
| 156 | id, |
| 157 | name: format!("자료-{id:03}.txt"), |
| 158 | kind: Kind::File, |
| 159 | bytes: Some(4096), |
| 160 | packed: Some(1800), |
| 161 | encrypted: false, |
| 162 | })); |
| 163 | } |
| 164 | entries |
| 165 | } |
| 166 | |
| 167 | impl Scenario { |
| 168 | /// 제거 안내는 외부 설치 화면의 문구만 재현하며 OS 동작은 실행하지 않음. |
| 169 | pub fn show(self, app: &mut ArchiveApp, ui: &mut egui::Ui) { |
| 170 | let (title, messages, button): (&str, Vec<&str>, Option<&str>) = match self.name { |
| 171 | "uninstall-windows" => ( |
| 172 | "제거 전 기본 앱 선택", |
| 173 | vec![ |
| 174 | "Zipelo를 기본 앱으로 사용했다면 제거 전에 다른 앱을 선택하세요. [기본 앱 설정 열기]에서 .zip, .7z, .tar, .gz, .tgz를 검색해 사용할 앱을 고를 수 있습니다. 다른 앱이 없으면 먼저 설치하세요.", |
| 175 | "직접 고른 기본 앱은 자동으로 바꾸지 않습니다. 제거 후 파일이 열리지 않으면 파일을 오른쪽 클릭하고 [연결 프로그램]에서 다른 앱을 선택하세요.", |
| 176 | ], |
| 177 | Some("기본 앱 설정 열기"), |
| 178 | ), |
| 179 | "uninstall-settings-error" => ( |
| 180 | "기본 앱 설정 실행 실패", |
| 181 | vec![ |
| 182 | "Windows 설정을 열지 못했습니다. 설정 > 앱 > 기본 앱에서 확장자를 검색해 다른 앱을 선택하세요.", |
| 183 | ], |
| 184 | Some("확인"), |
| 185 | ), |
| 186 | "uninstall-ubuntu-missing" => ( |
| 187 | "Ubuntu 제거 안내", |
| 188 | vec![ |
| 189 | "Zipelo를 제거합니다. 파일이 열리지 않으면 파일을 오른쪽 클릭하고 [다른 프로그램으로 열기]에서 다른 앱을 선택하세요.", |
| 190 | "이전 앱을 복원할 수 없습니다: application/zip. 파일을 오른쪽 클릭해 [다른 프로그램으로 열기]에서 앱을 선택하세요.", |
| 191 | ], |
| 192 | None, |
| 193 | ), |
| 194 | "uninstall-ubuntu-unknown-user" => ( |
| 195 | "Ubuntu 제거 안내", |
| 196 | vec![ |
| 197 | "Zipelo를 제거합니다. 파일이 열리지 않으면 파일을 오른쪽 클릭하고 [다른 프로그램으로 열기]에서 다른 앱을 선택하세요.", |
| 198 | "제거를 요청한 사용자를 확인할 수 없어 사용자 기본 앱 설정은 변경하지 않습니다.", |
| 199 | ], |
| 200 | None, |
| 201 | ), |
| 202 | _ => { |
| 203 | app.show(ui); |
| 204 | return; |
| 205 | } |
| 206 | }; |
| 207 | egui::CentralPanel::default().show_inside(ui, |ui| { |
| 208 | ui.add_space(16.0); |
| 209 | ui.heading(title); |
| 210 | ui.add_space(16.0); |
| 211 | for message in messages { |
| 212 | ui.label(message); |
| 213 | ui.add_space(16.0); |
| 214 | } |
| 215 | if let Some(button) = button { |
| 216 | // 미리보기에서는 설정 열기와 제거를 실행하지 않음. |
| 217 | let _ = ui.button(button); |
| 218 | } |
| 219 | }); |
| 220 | } |
| 221 | |
| 222 | /// 실제 파일과 작업자를 사용하지 않고 기존 화면 상태를 준비함. |
| 223 | pub fn build(self) -> ArchiveApp { |
| 224 | let factory = FakeFactory::manual(); |
| 225 | let state = factory.state.clone(); |
| 226 | let mut app = ArchiveApp::new(Box::new(factory), None, true); |
| 227 | let base = sample_root(); |
| 228 | app.destination = base.join("풀린 자료"); |
| 229 | app.automatic_destination = false; |
| 230 | app.zip_folder = base.clone(); |
| 231 | app.zip_name = "여행 자료.zip".into(); |
| 232 | if self.name == "empty" || self.name.starts_with("uninstall-") { |
| 233 | return app; |
| 234 | } |
| 235 | let archive = base.join(match self.name { |
| 236 | "gzip-conflict" | "gzip-conflict-choice" => "여행 자료.gz", |
| 237 | "tar-bz2" => "여행 자료.TAR.BZ2", |
| 238 | "tar-xz" => "여행 자료.TaR.Xz", |
| 239 | _ => "여행 자료.zip", |
| 240 | }); |
| 241 | app.model.archive = Some(archive.clone()); |
| 242 | app.model.entries = entries(self.name == "many-items"); |
| 243 | app.model.list_id = Some(ListId { |
| 244 | catalog_version: 1, |
| 245 | format: Format::Zip, |
| 246 | source_object: SourceObject::Unix { |
| 247 | device: 1, |
| 248 | inode: 1, |
| 249 | }, |
| 250 | archive_bytes: 2_700_000, |
| 251 | archive_sha256: [7; 32], |
| 252 | }); |
| 253 | app.model.confirmed = true; |
| 254 | match self.name { |
| 255 | "tar-bz2" | "tar-xz" => { |
| 256 | app.model.list_id.as_mut().unwrap().format = Format::Tar; |
| 257 | for entry in &mut app.model.entries { |
| 258 | entry.encrypted = false; |
| 259 | } |
| 260 | app.destination = present::default_destination(&archive); |
| 261 | app.automatic_destination = true; |
| 262 | return app; |
| 263 | } |
| 264 | "archive" | "many-items" => return app, |
| 265 | "folder-empty" => { |
| 266 | app.browse_folder("빈 폴더"); |
| 267 | return app; |
| 268 | } |
| 269 | "dialog-error" => { |
| 270 | app.ui_error = Some(DIALOG_UNAVAILABLE.into()); |
| 271 | return app; |
| 272 | } |
| 273 | "folder" => { |
| 274 | app.browse_folder("사진"); |
| 275 | return app; |
| 276 | } |
| 277 | "search-empty" => { |
| 278 | app.search = "없는 파일".into(); |
| 279 | return app; |
| 280 | } |
| 281 | "selection" | "marquee" => { |
| 282 | app.model |
| 283 | .selected |
| 284 | .extend([0, 3, 4, if self.name == "marquee" { 2 } else { 1 }]); |
| 285 | if self.name == "marquee" { |
| 286 | app.scenario_marquee = Some(egui::Rect::from_min_size( |
| 287 | egui::pos2(22.0, 8.0), |
| 288 | egui::vec2(360.0, 62.0), |
| 289 | )); |
| 290 | } |
| 291 | return app; |
| 292 | } |
| 293 | "create" | "create-encrypted" => { |
| 294 | app.sources = vec![base.join("읽어주세요.txt"), base.join("사진")]; |
| 295 | app.scenario_sources = Some(std::rc::Rc::new(vec![ |
| 296 | SourceRow { |
| 297 | name: "사진".into(), |
| 298 | directory: true, |
| 299 | bytes: Some(0), |
| 300 | }, |
| 301 | SourceRow { |
| 302 | name: "읽어주세요.txt".into(), |
| 303 | directory: false, |
| 304 | bytes: Some(4096), |
| 305 | }, |
| 306 | ])); |
| 307 | app.show_create(self.name == "create-encrypted"); |
| 308 | return app; |
| 309 | } |
| 310 | _ => {} |
| 311 | } |
| 312 | let creating = self.name.starts_with("create-") || self.name == "password-create"; |
| 313 | let listing_error = matches!(self.name, "unsupported" | "damaged"); |
| 314 | if matches!(self.name, "gzip-conflict" | "gzip-conflict-choice") { |
| 315 | app.model.list_id.as_mut().unwrap().format = Format::Gzip; |
| 316 | app.model.entries = vec![Entry { |
| 317 | id: 0, |
| 318 | name: "여행 자료".into(), |
| 319 | kind: Kind::File, |
| 320 | bytes: Some(1_287_952), |
| 321 | packed: Some(900_000), |
| 322 | encrypted: false, |
| 323 | }]; |
| 324 | app.gzip_name = "여행 자료".into(); |
| 325 | } |
| 326 | let request = if creating { |
| 327 | Start::CreateZip { |
| 328 | sources: vec![(base.join("사진"), "사진".into())], |
| 329 | output_file: base.join("여행 자료.zip"), |
| 330 | method: Method::Deflate, |
| 331 | aes256: self.name == "password-create", |
| 332 | } |
| 333 | } else if listing_error { |
| 334 | Start::List { archive } |
| 335 | } else { |
| 336 | Start::Extract { |
| 337 | archive, |
| 338 | destination: app.destination.clone(), |
| 339 | selection: Selection::All, |
| 340 | list_id: app.model.list_id.clone().unwrap(), |
| 341 | gzip_output_name: (matches!(self.name, "gzip-conflict" | "gzip-conflict-choice")) |
| 342 | .then(|| app.gzip_name.clone()), |
| 343 | } |
| 344 | }; |
| 345 | app.targets = Some(if creating { |
| 346 | BTreeSet::from(["여행 자료.zip".into()]) |
| 347 | } else if matches!(self.name, "gzip-conflict" | "gzip-conflict-choice") { |
| 348 | BTreeSet::from(["여행 자료".into()]) |
| 349 | } else { |
| 350 | BTreeSet::from([ |
| 351 | "읽어주세요.txt".into(), |
| 352 | "여행 일정.pdf".into(), |
| 353 | "사진/바다.jpg".into(), |
| 354 | "사진/풍경.jpg".into(), |
| 355 | ]) |
| 356 | }); |
| 357 | if matches!( |
| 358 | self.name, |
| 359 | "extract-skipped" | "extract-renamed" | "extract-rename-failed" |
| 360 | ) { |
| 361 | app.targets = Some(["읽어주세요.txt".into()].into_iter().collect()); |
| 362 | app.directories.clear(); |
| 363 | } |
| 364 | if self.name == "resource-approval" { |
| 365 | app.model.entries[1].bytes = Some(17 * 1024 * 1024 * 1024); |
| 366 | } |
| 367 | assert!(app.start(request)); |
| 368 | { |
| 369 | let mut state = state.borrow_mut(); |
| 370 | state.frame(Event::Accepted { encryption: true }); |
| 371 | match self.name { |
| 372 | "resource-approval" | "resource-ratio" => { |
| 373 | let expanded = self.name == "resource-approval"; |
| 374 | state.frame(Event::ResourceRequired(ResourceChallenge { |
| 375 | id: 1, |
| 376 | action: ActionKind::Extract, |
| 377 | scope: ResourceScope { |
| 378 | output: expanded, |
| 379 | entries: expanded, |
| 380 | ratio: !expanded, |
| 381 | }, |
| 382 | usage: ResourceUsage { |
| 383 | available_bytes: Some(90 * 1024 * 1024 * 1024), |
| 384 | actual_bytes: (!expanded).then_some(300 * 1024 * 1024), |
| 385 | ratio_output_bytes: (!expanded).then_some(300 * 1024 * 1024), |
| 386 | compressed_bytes: (!expanded).then_some(4096), |
| 387 | ..ResourceUsage::default() |
| 388 | }, |
| 389 | soft_limits: Limits::default(), |
| 390 | ceiling: if expanded { |
| 391 | Limits { |
| 392 | input: u64::MAX, |
| 393 | output: 64 * 1024 * 1024 * 1024, |
| 394 | entries: 200_000, |
| 395 | } |
| 396 | } else { |
| 397 | Limits::default() |
| 398 | }, |
| 399 | })); |
| 400 | } |
| 401 | "resource-retry" | "resource-partial" => { |
| 402 | let partial = self.name == "resource-partial"; |
| 403 | if partial { |
| 404 | state.frame(Event::Output { |
| 405 | entry_id: Some(1), |
| 406 | relative_name: "읽어주세요.txt".into(), |
| 407 | disposition: Disposition::Created, |
| 408 | }); |
| 409 | } |
| 410 | state.frame(Event::Terminal(Terminal { |
| 411 | outcome: Outcome::Failed, |
| 412 | error: Some(ErrorCode::Limit), |
| 413 | publication: if partial { |
| 414 | Publication::Partial |
| 415 | } else { |
| 416 | Publication::None |
| 417 | }, |
| 418 | created_count: u64::from(partial), |
| 419 | retained_partial_count: 0, |
| 420 | durability: Durability::Synced, |
| 421 | cleanup: Cleanup::Complete, |
| 422 | })); |
| 423 | state.queue.extend([ |
| 424 | HostEvent::StdoutEof, |
| 425 | HostEvent::StderrEof, |
| 426 | HostEvent::Exited { success: true }, |
| 427 | ]); |
| 428 | } |
| 429 | "conflict-choice" | "conflict-apply" | "gzip-conflict-choice" => { |
| 430 | state.frame(Event::ConflictRequired(Conflict { |
| 431 | challenge_id: 29, |
| 432 | entry_id: if self.name == "gzip-conflict-choice" { |
| 433 | 0 |
| 434 | } else { |
| 435 | 1 |
| 436 | }, |
| 437 | relative_name: if self.name == "gzip-conflict-choice" { |
| 438 | "여행 자료" |
| 439 | } else { |
| 440 | "읽어주세요.txt" |
| 441 | } |
| 442 | .into(), |
| 443 | incoming_size: 1_287_952, |
| 444 | existing_size: 2048, |
| 445 | })); |
| 446 | } |
| 447 | "extract-skipped" | "extract-renamed" | "extract-rename-failed" => { |
| 448 | let failed = self.name == "extract-rename-failed"; |
| 449 | let skip = self.name == "extract-skipped"; |
| 450 | let name = if skip { |
| 451 | "읽어주세요.txt" |
| 452 | } else { |
| 453 | "읽어주세요 (1).txt" |
| 454 | }; |
| 455 | state.frame(Event::ConflictResolved(Resolution { |
| 456 | entry_id: 1, |
| 457 | relative_name: name.into(), |
| 458 | choice: if skip { |
| 459 | ConflictChoice::Skip |
| 460 | } else { |
| 461 | ConflictChoice::Rename |
| 462 | }, |
| 463 | })); |
| 464 | if !skip && !failed { |
| 465 | state.frame(Event::Output { |
| 466 | entry_id: Some(1), |
| 467 | relative_name: name.into(), |
| 468 | disposition: Disposition::Created, |
| 469 | }); |
| 470 | } |
| 471 | state.frame(Event::Terminal(Terminal { |
| 472 | outcome: if failed { |
| 473 | Outcome::Failed |
| 474 | } else { |
| 475 | Outcome::Completed |
| 476 | }, |
| 477 | error: failed.then_some(ErrorCode::Io), |
| 478 | publication: if skip || failed { |
| 479 | Publication::None |
| 480 | } else { |
| 481 | Publication::Complete |
| 482 | }, |
| 483 | created_count: u64::from(!skip && !failed), |
| 484 | retained_partial_count: 0, |
| 485 | durability: if skip || failed { |
| 486 | Durability::NotApplicable |
| 487 | } else { |
| 488 | Durability::Synced |
| 489 | }, |
| 490 | cleanup: Cleanup::Complete, |
| 491 | })); |
| 492 | state.queue.extend([ |
| 493 | HostEvent::StdoutEof, |
| 494 | HostEvent::StderrEof, |
| 495 | HostEvent::Exited { success: true }, |
| 496 | ]); |
| 497 | } |
| 498 | "password" | "password-retry" | "password-create" => { |
| 499 | state.frame(Event::PasswordRequired { |
| 500 | challenge_id: 17, |
| 501 | attempt: if self.name == "password-retry" { 2 } else { 1 }, |
| 502 | encrypt: self.name == "password-create", |
| 503 | }) |
| 504 | } |
| 505 | "extract-complete" | "create-complete" | "extract-unsynced" => { |
| 506 | let names = app.targets.as_ref().unwrap(); |
| 507 | for name in names { |
| 508 | state.frame(Event::Output { |
| 509 | entry_id: None, |
| 510 | relative_name: name.clone(), |
| 511 | disposition: Disposition::Created, |
| 512 | }); |
| 513 | } |
| 514 | state.frame(Event::Terminal(Terminal { |
| 515 | outcome: Outcome::Completed, |
| 516 | error: None, |
| 517 | publication: Publication::Complete, |
| 518 | created_count: names.len() as u64, |
| 519 | retained_partial_count: 0, |
| 520 | durability: if self.name == "extract-unsynced" { |
| 521 | Durability::Unconfirmed |
| 522 | } else { |
| 523 | Durability::Synced |
| 524 | }, |
| 525 | cleanup: Cleanup::Complete, |
| 526 | })); |
| 527 | state.queue.extend([ |
| 528 | HostEvent::StdoutEof, |
| 529 | HostEvent::StderrEof, |
| 530 | HostEvent::Exited { success: true }, |
| 531 | ]); |
| 532 | } |
| 533 | "extract-cancelled" => state.finish(Outcome::Cancelled, Publication::None), |
| 534 | "extract-partial" | "extract-uncertain" => { |
| 535 | let partial = self.name == "extract-partial"; |
| 536 | if partial { |
| 537 | state.frame(Event::Output { |
| 538 | entry_id: Some(1), |
| 539 | relative_name: "읽어주세요.txt".into(), |
| 540 | disposition: Disposition::Created, |
| 541 | }); |
| 542 | } |
| 543 | state.frame(Event::Terminal(Terminal { |
| 544 | outcome: Outcome::Failed, |
| 545 | error: Some(ErrorCode::Io), |
| 546 | publication: if partial { |
| 547 | Publication::Partial |
| 548 | } else { |
| 549 | Publication::Uncertain |
| 550 | }, |
| 551 | created_count: u64::from(partial), |
| 552 | retained_partial_count: 0, |
| 553 | durability: Durability::Synced, |
| 554 | cleanup: Cleanup::Complete, |
| 555 | })); |
| 556 | state.queue.extend([ |
| 557 | HostEvent::StdoutEof, |
| 558 | HostEvent::StderrEof, |
| 559 | HostEvent::Exited { success: true }, |
| 560 | ]); |
| 561 | } |
| 562 | "conflict" | "gzip-conflict" | "unsupported" | "damaged" | "source-changed" |
| 563 | | "create-error" => { |
| 564 | state.frame(Event::Terminal(Terminal { |
| 565 | outcome: Outcome::Failed, |
| 566 | error: Some(match self.name { |
| 567 | "conflict" | "gzip-conflict" => ErrorCode::Conflict, |
| 568 | "source-changed" => ErrorCode::SourceChanged, |
| 569 | "create-error" => ErrorCode::DiskFull, |
| 570 | "unsupported" => ErrorCode::UnsupportedFormat, |
| 571 | _ => ErrorCode::Integrity, |
| 572 | }), |
| 573 | publication: Publication::None, |
| 574 | created_count: 0, |
| 575 | retained_partial_count: 0, |
| 576 | durability: Durability::NotApplicable, |
| 577 | cleanup: Cleanup::Complete, |
| 578 | })); |
| 579 | state.queue.extend([ |
| 580 | HostEvent::StdoutEof, |
| 581 | HostEvent::StderrEof, |
| 582 | HostEvent::Exited { success: true }, |
| 583 | ]); |
| 584 | } |
| 585 | _ => state.frame(Event::Progress { |
| 586 | stage: if creating { |
| 587 | Stage::Write |
| 588 | } else { |
| 589 | Stage::Decode |
| 590 | }, |
| 591 | processed: 38 << 20, |
| 592 | total: (self.name != "extract-unknown").then_some(61 << 20), |
| 593 | completed_entries: 12, |
| 594 | }), |
| 595 | } |
| 596 | } |
| 597 | for _ in 0..64 { |
| 598 | app.model.poll(); |
| 599 | } |
| 600 | if self.name == "conflict-apply" { |
| 601 | app.conflict_challenge = Some((app.model.job_id().unwrap(), 29)); |
| 602 | app.conflict_apply = true; |
| 603 | } |
| 604 | if self.name == "extract-unsynced" { |
| 605 | app.details = true; |
| 606 | } |
| 607 | if self.name == "cancelling" { |
| 608 | app.model.cancel(); |
| 609 | } |
| 610 | if self.name == "close-confirm" { |
| 611 | app.model.request_close(); |
| 612 | } |
| 613 | app |
| 614 | } |
| 615 | } |
| 616 | |
| 617 | /// 화면을 고정하고 실제 파일 조작을 막는 미리보기임. |
| 618 | pub struct Preview(pub ArchiveApp, Option<Scenario>); |
| 619 | impl Preview { |
| 620 | pub fn with_scenario(mut self, scenario: Scenario) -> Self { |
| 621 | self.1 = Some(scenario); |
| 622 | self |
| 623 | } |
| 624 | |
| 625 | pub fn show(&mut self, ui: &mut egui::Ui) { |
| 626 | if let Some(scenario) = self.1 { |
| 627 | scenario.show(&mut self.0, ui); |
| 628 | } else { |
| 629 | self.0.show(ui); |
| 630 | } |
| 631 | } |
| 632 | |
| 633 | pub fn new(app: ArchiveApp, ctx: &egui::Context) -> Self { |
| 634 | ctx.on_begin_pass( |
| 635 | "ui-scenario-readonly", |
| 636 | std::sync::Arc::new(|ctx| { |
| 637 | ctx.input_mut(|i| { |
| 638 | i.events.clear(); |
| 639 | i.pointer = Default::default(); |
| 640 | i.keys_down.clear(); |
| 641 | i.modifiers = Default::default(); |
| 642 | i.raw.dropped_files.clear(); |
| 643 | i.raw.hovered_files.clear(); |
| 644 | }); |
| 645 | }), |
| 646 | ); |
| 647 | Self(app, None) |
| 648 | } |
| 649 | } |
| 650 | impl eframe::App for Preview { |
| 651 | fn ui(&mut self, root: &mut egui::Ui, _: &mut eframe::Frame) { |
| 652 | if root.ctx().input(|i| i.viewport().close_requested()) { |
| 653 | root.ctx().send_viewport_cmd(egui::ViewportCommand::Close); |
| 654 | return; |
| 655 | } |
| 656 | self.show(root); |
| 657 | } |
| 658 | } |