team-ljyzipelo

공개
441줄16 KB
1use eframe::egui::{self, FontId, TextStyle};
2use std::{collections::VecDeque, path::PathBuf};
3use zipelo_ui_memory_app::{archive_screen::ArchiveApp, archive_ui::*};
4#[path = "../../experiments/rust-ui-memory-app/src/renderer.rs"]
5mod renderer;
6#[path = "../../experiments/rust-ui-memory-app/src/system_font.rs"]
7mod system_font;
8
9#[derive(Clone)]
10struct CaptureFactory {
11 mode: String,
12}
13struct CaptureConnection {
14 job: u64,
15 sequence: u64,
16 mode: String,
17 queue: VecDeque<HostEvent>,
18 create_name: Option<String>,
19}
20impl CaptureConnection {
21 fn event(&mut self, event: Event) {
22 self.queue.push_back(HostEvent::Frame {
23 job_id: self.job,
24 sequence: self.sequence,
25 event,
26 });
27 self.sequence += 1;
28 }
29 fn terminal(&mut self, terminal: Terminal) {
30 self.event(Event::Terminal(terminal));
31 self.queue.extend([
32 HostEvent::StdoutEof,
33 HostEvent::StderrEof,
34 HostEvent::Exited { success: true },
35 ]);
36 }
37 fn finish(&mut self, listing: bool) {
38 let error = !listing && self.mode == "error";
39 let cancelled = !listing && self.mode == "cancelled";
40 let mut count = 0;
41 if !listing && !error && !cancelled {
42 let names = self
43 .create_name
44 .clone()
45 .map(|name| vec![name])
46 .unwrap_or_else(|| {
47 vec![
48 "읽어주세요.txt".into(),
49 "여행 일정.pdf".into(),
50 "사진".into(),
51 ]
52 });
53 for name in names {
54 self.event(Event::Output {
55 entry_id: None,
56 relative_name: name,
57 disposition: Disposition::Created,
58 });
59 count += 1;
60 }
61 }
62 self.terminal(Terminal {
63 outcome: if error {
64 Outcome::Failed
65 } else if cancelled {
66 Outcome::Cancelled
67 } else {
68 Outcome::Completed
69 },
70 error: error.then_some(ErrorCode::DiskFull),
71 publication: if listing || error || cancelled {
72 Publication::None
73 } else {
74 Publication::Complete
75 },
76 created_count: count,
77 retained_partial_count: 0,
78 durability: if listing {
79 Durability::NotApplicable
80 } else {
81 Durability::Synced
82 },
83 cleanup: Cleanup::Complete,
84 });
85 }
86}
87fn entries() -> Vec<Entry> {
88 vec![
89 Entry {
90 id: 0,
91 name: "읽어주세요.txt".into(),
92 kind: Kind::File,
93 bytes: Some(4096),
94 packed: Some(1800),
95 encrypted: false,
96 },
97 Entry {
98 id: 1,
99 name: "여행 일정.pdf".into(),
100 kind: Kind::File,
101 bytes: Some(1_287_952),
102 packed: Some(900_000),
103 encrypted: true,
104 },
105 Entry {
106 id: 2,
107 name: "사진".into(),
108 kind: Kind::Directory,
109 bytes: Some(0),
110 packed: None,
111 encrypted: false,
112 },
113 ]
114}
115fn toolbar_entries() -> Vec<Entry> {
116 let mut entries = vec![
117 Entry {
118 id: 0,
119 name: "Install".into(),
120 kind: Kind::Directory,
121 bytes: Some(0),
122 packed: None,
123 encrypted: false,
124 },
125 Entry {
126 id: 1,
127 name: "Install.exe".into(),
128 kind: Kind::File,
129 bytes: Some(234_906),
130 packed: None,
131 encrypted: false,
132 },
133 ];
134 for (index, name) in [
135 "cab1.cab",
136 "cab10.cab",
137 "cab11.cab",
138 "cab12.cab",
139 "cab2.cab",
140 "cab3.cab",
141 "cab4.cab",
142 "cab5.cab",
143 ]
144 .iter()
145 .enumerate()
146 {
147 entries.push(Entry {
148 id: index as u32 + 2,
149 name: format!("Install/{name}"),
150 kind: Kind::File,
151 bytes: Some(
152 [
153 99_510_272,
154 77_909_197,
155 102_236_160,
156 67_842_867,
157 103_389_594,
158 59_454_669,
159 78_014_054,
160 81_159_782,
161 ][index],
162 ),
163 packed: None,
164 encrypted: false,
165 });
166 }
167 entries
168}
169
170impl Factory for CaptureFactory {
171 fn connect(&mut self, job: u64) -> Result<Box<dyn Connection>, String> {
172 Ok(Box::new(CaptureConnection {
173 job,
174 sequence: 0,
175 mode: self.mode.clone(),
176 queue: VecDeque::new(),
177 create_name: None,
178 }))
179 }
180}
181impl Connection for CaptureConnection {
182 fn send(&mut self, request: Request) -> Result<(), String> {
183 match request.command {
184 Command::Start(start) | Command::StartExpanded(start) => {
185 self.event(Event::Accepted { encryption: true });
186 match start {
187 Start::List { .. } => {
188 let entries = if self.mode.starts_with("toolbar-") {
189 toolbar_entries()
190 } else {
191 entries()
192 };
193 let count = entries.len() as u32;
194 for entry in entries {
195 self.event(Event::Entry(entry));
196 }
197 self.event(Event::ListEnd {
198 entry_count: count,
199 list_id: ListId {
200 catalog_version: 1,
201 format: Format::Zip,
202 source_object: SourceObject::Unix {
203 device: 1,
204 inode: 1,
205 },
206 archive_bytes: 902000,
207 archive_sha256: [7; 32],
208 },
209 });
210 self.finish(true);
211 }
212 Start::Extract { .. } => {
213 if self.mode.starts_with("password") {
214 self.event(Event::PasswordRequired {
215 challenge_id: 17,
216 attempt: if self.mode == "password-retry" { 2 } else { 1 },
217 encrypt: false,
218 });
219 } else if self.mode.starts_with("progress") || self.mode == "cancelling" {
220 self.event(Event::Progress {
221 stage: Stage::Decode,
222 processed: 38 << 20,
223 total: (self.mode != "progress-unknown").then_some(61 << 20),
224 completed_entries: 12,
225 });
226 } else {
227 self.finish(false);
228 }
229 }
230 Start::CreateZip {
231 output_file,
232 aes256,
233 ..
234 } => {
235 self.create_name =
236 Some(output_file.file_name().unwrap().to_string_lossy().into());
237 if aes256 {
238 self.event(Event::PasswordRequired {
239 challenge_id: 17,
240 attempt: 1,
241 encrypt: true,
242 });
243 } else {
244 self.finish(false);
245 }
246 }
247 }
248 }
249 Command::ConflictReply { .. } => return Err("충돌 선택은 상황 명령으로 확인함".into()),
250 Command::Password { .. } => self.finish(false),
251 Command::ResourceReply { .. } => {}
252 Command::Cancel => {
253 self.event(Event::CancelAck {
254 request_sequence: request.sequence,
255 status: CancelStatus::Requested,
256 });
257 if self.mode != "cancelling" {
258 self.terminal(Terminal {
259 outcome: Outcome::Cancelled,
260 error: None,
261 publication: Publication::None,
262 created_count: 0,
263 retained_partial_count: 0,
264 durability: Durability::NotApplicable,
265 cleanup: Cleanup::Complete,
266 });
267 }
268 }
269 }
270 Ok(())
271 }
272 fn poll(&mut self) -> Option<HostEvent> {
273 self.queue.pop_front()
274 }
275}
276struct Capture {
277 app: ArchiveApp,
278 mode: String,
279 factory: CaptureFactory,
280 triggered: bool,
281}
282impl eframe::App for Capture {
283 fn ui(&mut self, root: &mut egui::Ui, _: &mut eframe::Frame) {
284 if self.mode == "hover" {
285 root.ctx().input_mut(|i| {
286 i.raw.hovered_files = vec![egui::HoveredFile {
287 path: Some(PathBuf::from("여행.zip")),
288 ..Default::default()
289 }]
290 });
291 }
292 if !self.triggered && self.app.model.list_id.is_some() {
293 self.triggered = true;
294 if self.mode.starts_with("long-") {
295 let name = format!("{}.txt", "W".repeat(220));
296 let folder = "deep-folder/".repeat(30);
297 let base = std::env::current_dir()
298 .unwrap()
299 .join("tests/ui-redesign/runs/fixtures");
300 self.app.model.archive = Some(base.join(&folder).join(format!("{name}.zip")));
301 if self.mode == "long-list" || self.mode == "long-folder" {
302 self.app.model.entries = (0..5000)
303 .map(|id| Entry {
304 id,
305 name: format!(
306 "{}{id:04}-{name}",
307 if self.mode == "long-folder" {
308 folder.as_str()
309 } else {
310 ""
311 }
312 ),
313 kind: Kind::File,
314 bytes: Some(31),
315 packed: None,
316 encrypted: true,
317 })
318 .collect();
319 if self.mode == "long-folder" {
320 self.app.browse_folder(folder.trim_end_matches('/'));
321 }
322 }
323 if self.mode == "long-create" {
324 let source = base.join(&name);
325 std::fs::write(&source, b"capture source").unwrap();
326 self.app.add_sources(vec![source]);
327 self.app.show_create(false);
328 }
329 if self.mode == "long-result" {
330 let destination = base.join(&folder);
331 std::fs::create_dir_all(&destination).unwrap();
332 self.app.choose_destination(destination);
333 self.app.begin_extract();
334 }
335 }
336 if self.mode == "toolbar-folder" {
337 self.app.browse_folder("Install");
338 }
339 if self.mode == "toolbar-create" {
340 self.app.show_create(false);
341 }
342 if [
343 "password",
344 "password-retry",
345 "password-create",
346 "progress",
347 "progress-unknown",
348 "cancelling",
349 "success",
350 "error",
351 "cancelled",
352 ]
353 .contains(&self.mode.as_str())
354 {
355 let archive = self.app.model.archive.clone().unwrap();
356 let start = if self.mode == "password-create" {
357 Start::CreateZip {
358 sources: vec![(archive.clone(), "자료".into())],
359 output_file: archive.with_file_name("보호한 자료.zip"),
360 method: Method::Deflate,
361 aes256: true,
362 }
363 } else {
364 Start::Extract {
365 archive,
366 destination: std::env::current_dir().unwrap(),
367 selection: Selection::All,
368 list_id: self.app.model.list_id.clone().unwrap(),
369 gzip_output_name: None,
370 }
371 };
372 // 이전 화면과 같은 공개 상태 API로 암호 및 진행 상태를 재현함.
373 if self.mode == "password-create" {
374 self.app.model.begin(start, &mut self.factory);
375 } else {
376 self.app.begin_extract();
377 }
378 }
379 }
380 self.app.show(root);
381 root.ctx()
382 .request_repaint_after(std::time::Duration::from_millis(30));
383 }
384}
385fn main() -> eframe::Result {
386 let mode = std::env::args().nth(1).unwrap_or_else(|| "empty".into());
387 let base = std::env::current_dir()
388 .unwrap()
389 .join("tests/ui-redesign/runs/fixtures");
390 std::fs::create_dir_all(&base).unwrap();
391 std::fs::write(base.join("읽어주세요.txt"), "화면 검증 입력").unwrap();
392 std::fs::create_dir_all(base.join("사진")).unwrap();
393 let fallback = system_font::load()
394 .ok()
395 .map(|font| (font.bytes, font.face_index));
396 let title = format!("Zipelo UI capture {mode}");
397 renderer::run_native(
398 &title,
399 eframe::NativeOptions {
400 viewport: egui::ViewportBuilder::default()
401 .with_inner_size([1060.0, 720.0])
402 .with_min_inner_size([760.0, 540.0]),
403 ..Default::default()
404 },
405 || {
406 let mode = mode.clone();
407 let base = base.clone();
408 let fallback = fallback.clone();
409 Box::new(move |cc| {
410 cc.egui_ctx
411 .set_fonts(zipelo_ui_memory_app::archive_theme::fonts(fallback.clone()));
412 cc.egui_ctx.set_visuals(egui::Visuals::light());
413 cc.egui_ctx.style_mut_of(egui::Theme::Light, |style| {
414 style
415 .text_styles
416 .insert(TextStyle::Body, FontId::proportional(18.0));
417 style
418 .text_styles
419 .insert(TextStyle::Button, FontId::proportional(18.0));
420 style
421 .text_styles
422 .insert(TextStyle::Heading, FontId::proportional(26.0));
423 });
424 let factory = CaptureFactory { mode: mode.clone() };
425 let startup = (!["empty", "hover", "create", "create-filled"]
426 .contains(&mode.as_str()))
427 .then(|| base.join("여행.zip"));
428 let mut app = ArchiveApp::new(Box::new(factory.clone()), startup, true);
429 if mode == "create-filled" {
430 app.add_sources(vec![base.join("읽어주세요.txt"), base.join("사진")]);
431 }
432 Ok(Box::new(Capture {
433 app,
434 mode,
435 factory,
436 triggered: false,
437 }))
438 })
439 },
440 )
441}