team-ljyzipelo

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