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