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