team-ljyzipelo

공개

압축파일 안 파일 열기와 선택 항목 풀기 메뉴 추가

- umask 002로 만든 775 출력 폴더를 개인 그룹이면 허용함
- 부모 창 안 작업 창 닫기 버튼에 마우스 올림 표시를 넣음
- 파일을 더블클릭하면 압축파일 옆 임시 폴더에 풀어 기본 프로그램으로 엶
- 마우스 뒤로 버튼으로 상위 폴더로 이동함
- 오른쪽 클릭 메뉴로 선택 항목을 새 폴더나 고른 폴더에 풂
- 부모 안 작업 창을 끌 때 목록 선택 사각형이 생기지 않게 함

Co-Authored-By: Claude Opus 5.5 <[email protected]>
작성자
LeeJunyoung
작성 시각
커밋
26121d4cc8943aa4e2335550bd94f35b8a81a777
부모
f5399dd
이 시점의 파일 보기

변경된 파일 10개

+909-29
수정experiments/rust-archive-worker/src/filesystem.rs+51-1
@@ -194,6 +194,50 @@ mod platform {
194194 fn renameat(fd: i32, path: *const i8, newfd: i32, newpath: *const i8) -> i32;
195195 fn unlinkat(fd: i32, path: *const i8, flags: i32) -> i32;
196196 fn geteuid() -> u32;
197추가: fn getegid() -> u32;
198추가: fn getgrgid_r(
199추가: gid: u32,
200추가: group: *mut Group,
201추가: buffer: *mut i8,
202추가: length: usize,
203추가: result: *mut *mut Group,
204추가: ) -> i32;
205추가: }
206추가: #[repr(C)]
207추가: struct Group {
208추가: name: *mut i8,
209추가: password: *mut i8,
210추가: gid: u32,
211추가: members: *mut *mut i8,
212추가: }
213추가: /// 현재 계정의 기본 그룹이 따로 등록된 구성원이 없는 개인 그룹인지 확인함.
214추가: /// Ubuntu는 계정마다 같은 이름의 개인 그룹을 만들고 umask 002를 써서,
215추가: /// 파일 관리자나 폴더 선택 창에서 새로 만든 폴더가 그룹 쓰기 권한(775)을 가짐.
216추가: fn private_group(gid: u32) -> bool {
217추가: if gid != unsafe { getegid() } {
218추가: return false;
219추가: }
220추가: let mut group = Group {
221추가: name: std::ptr::null_mut(),
222추가: password: std::ptr::null_mut(),
223추가: gid: 0,
224추가: members: std::ptr::null_mut(),
225추가: };
226추가: let mut result = std::ptr::null_mut();
227추가: let mut buffer = vec![0i8; 16 * 1024];
228추가: let status = unsafe {
229추가: getgrgid_r(
230추가: gid,
231추가: &mut group,
232추가: buffer.as_mut_ptr(),
233추가: buffer.len(),
234추가: &mut result,
235추가: )
236추가: };
237추가: // 그룹 정보를 읽지 못하면 안전하다고 볼 근거가 없으므로 거부함.
238추가: status == 0
239추가: && !result.is_null()
240추가: && (group.members.is_null() || unsafe { *group.members }.is_null())
197241 }
198242 pub struct Dir {
199243 file: File,
@@ -242,7 +286,13 @@ mod platform {
242286 fn trusted(&self) -> Result<()> {
243287 let m = self.file.metadata().map_err(|_| ErrorCode::Io)?;
244288 // 다른 계정이 바꿀 수 있는 출력 폴더를 거부함.
245삭제: if !m.is_dir() || m.uid() != unsafe { geteuid() } || m.mode() & 0o022 != 0 {
289추가: // 그룹 쓰기는 그 그룹이 현재 계정만의 개인 그룹일 때만 허용함.
290추가: let group_writable = m.mode() & 0o020 != 0;
291추가: if !m.is_dir()
292추가: || m.uid() != unsafe { geteuid() }
293추가: || m.mode() & 0o002 != 0
294추가: || (group_writable && !private_group(m.gid()))
295추가: {
246296 return Err(ErrorCode::UnsafePath);
247297 }
248298 Ok(())
수정experiments/rust-ui-memory-app/src/archive_present.rs+122-0
@@ -479,3 +479,125 @@ pub fn excluded_split(path: &Path) -> bool {
479479 .to_ascii_lowercase();
480480 name.ends_with(".zip.001") || name.ends_with(".z01") || name.ends_with(".rar")
481481}
482추가:
483추가: /// 같은 이름이 이미 있으면 `이름 (1)`, `이름 (2)`처럼 비어 있는 이름을 찾음.
484추가: pub fn unique_folder(base: &Path) -> PathBuf {
485추가: let taken = |path: &Path| fs::symlink_metadata(path).is_ok();
486추가: if !taken(base) {
487추가: return base.to_path_buf();
488추가: }
489추가: let name = base.file_name().unwrap_or_default().to_string_lossy();
490추가: (1..)
491추가: .map(|n| base.with_file_name(format!("{name} ({n})")))
492추가: .find(|path| !taken(path))
493추가: .unwrap()
494추가: }
495추가:
496추가: fn private_dir(path: &Path) -> io::Result<()> {
497추가: let mut builder = fs::DirBuilder::new();
498추가: #[cfg(unix)]
499추가: {
500추가: use std::os::unix::fs::DirBuilderExt;
501추가: builder.mode(0o700);
502추가: }
503추가: builder.create(path)
504추가: }
505추가:
506추가: /// 압축파일 안 파일을 기본 프로그램으로 열 때 쓸 임시 폴더를 만듦.
507추가: /// 압축파일과 같은 폴더에 만들고, 그곳에 만들 수 없으면 시스템 임시 폴더를 씀.
508추가: /// 숨김 폴더로 만들지 않음. snap으로 설치한 Firefox 등은 홈 바로 아래 숨김 폴더와
509추가: /// 시스템 임시 폴더의 파일을 읽지 못해 열기 요청을 조용히 무시함.
510추가: pub fn create_open_root(archive: &Path) -> io::Result<PathBuf> {
511추가: let name = archive.file_name().unwrap_or_default().to_string_lossy();
512추가: let mut error = None;
513추가: if let Some(parent) = archive.parent().filter(|p| !p.as_os_str().is_empty()) {
514추가: let base = parent.join(open_root_name(&name));
515추가: for _ in 0..8 {
516추가: let path = unique_folder(&base);
517추가: match private_dir(&path) {
518추가: Ok(()) => return Ok(path),
519추가: Err(e) if e.kind() == io::ErrorKind::AlreadyExists => continue,
520추가: Err(e) => {
521추가: error = Some(e);
522추가: break;
523추가: }
524추가: }
525추가: }
526추가: }
527추가: let base = std::env::temp_dir().join(format!("zipelo-{}-{name}", std::process::id()));
528추가: let path = unique_folder(&base);
529추가: private_dir(&path).map_err(|e| error.unwrap_or(e))?;
530추가: Ok(path)
531추가: }
532추가:
533추가: /// 열기용 임시 폴더 이름. 예: `자료.zip (Zipelo 임시)`.
534추가: pub fn open_root_name(archive_name: &str) -> String {
535추가: format!("{archive_name} (Zipelo 임시)")
536추가: }
537추가:
538추가: /// 이 앱이 만든 열기용 폴더를 지움. 다른 프로그램이 파일을 쓰고 있으면 남을 수 있음.
539추가: pub fn remove_open_root(path: &Path) {
540추가: let _ = fs::remove_dir_all(path);
541추가: }
542추가:
543추가: /// 기본 프로그램으로 열면 실행될 수 있는 파일은 바로 열지 않음.
544추가: /// Windows는 스크립트도 연결 프로그램이 바로 실행하므로 범위가 넓고,
545추가: /// Linux는 스크립트를 편집기로 열므로 실행·설치 파일만 막음.
546추가: pub fn blocked_open(name: &str) -> bool {
547추가: #[cfg(windows)]
548추가: const EXECUTABLE: &[&str] = &[
549추가: "exe", "com", "bat", "cmd", "scr", "pif", "msi", "msp", "msc", "ps1", "psm1", "vbs",
550추가: "vbe", "js", "jse", "wsf", "wsh", "hta", "cpl", "lnk", "url", "reg", "jar", "inf", "scf",
551추가: "chm", "dll", "sys", "appref-ms", "application", "gadget", "settingcontent-ms",
552추가: ];
553추가: #[cfg(not(windows))]
554추가: const EXECUTABLE: &[&str] = &[
555추가: "desktop", "appimage", "run", "bin", "jar", "deb", "rpm", "snap", "flatpakref",
556추가: "flatpak", "exe", "msi",
557추가: ];
558추가: open_extension(name).is_some_and(|ext| EXECUTABLE.contains(&ext.to_ascii_lowercase().as_str()))
559추가: }
560추가:
561추가: fn open_extension(name: &str) -> Option<&str> {
562추가: let leaf = name.rsplit(['/', '\\']).next().unwrap_or(name);
563추가: leaf.rsplit_once('.')
564추가: .map(|(_, ext)| ext)
565추가: .filter(|ext| !ext.is_empty())
566추가: }
567추가:
568추가: /// 실행 파일이라 열지 않았다는 짧은 안내. 압축은 풀지 않음.
569추가: pub fn open_blocked_text(name: &str) -> String {
570추가: match open_extension(name) {
571추가: Some(ext) => format!("실행 파일(.{ext})은 안전을 위해 바로 열 수 없습니다"),
572추가: None => "실행 파일은 안전을 위해 바로 열 수 없습니다".into(),
573추가: }
574추가: }
575추가:
576추가: pub const OPEN_FAILED: &str = "파일을 열 프로그램을 실행하지 못했습니다";
577추가: pub const OPEN_MISSING: &str = "풀린 파일을 찾지 못해 열지 못했습니다";
578추가:
579추가: /// 운영체제에 설정된 기본 프로그램으로 파일을 엶.
580추가: pub fn open_with_default(path: &Path) -> Result<(), String> {
581추가: #[cfg(windows)]
582추가: let mut command = {
583추가: let mut command = std::process::Command::new("explorer.exe");
584추가: command.arg(path);
585추가: command
586추가: };
587추가: #[cfg(not(windows))]
588추가: let mut command = {
589추가: let mut command = std::process::Command::new("xdg-open");
590추가: command.arg(path);
591추가: command
592추가: };
593추가: command
594추가: .stdin(std::process::Stdio::null())
595추가: .stdout(std::process::Stdio::null())
596추가: .stderr(std::process::Stdio::null());
597추가: let mut child = command.spawn().map_err(|_| OPEN_FAILED.to_owned())?;
598추가: // 끝난 자식 프로세스를 거둬 좀비로 남지 않게 함.
599추가: std::thread::spawn(move || {
600추가: let _ = child.wait();
601추가: });
602추가: Ok(())
603추가: }
수정experiments/rust-ui-memory-app/src/archive_screen.rs+242-17
@@ -198,6 +198,24 @@ struct Marquee {
198198/// 파일 목록 한 행의 높이. 행 안의 크기 칸(theme::ROW)이 위아래 2px 여백으로 들어감.
199199const LIST_ROW: f32 = 36.0;
200200
201추가: /// 기본 프로그램으로 열려고 임시 폴더에 푸는 작업. 끝나면 원래 풀 위치로 되돌림.
202추가: struct OpenRequest {
203추가: folder: PathBuf,
204추가: /// 풀린 뒤 열 파일의 압축파일 안 경로. 작업자는 새로 만든 상위 폴더도 출력으로 알리므로
205추가: /// 출력 목록에서 이 경로와 같은 항목을 찾아 엶.
206추가: name: String,
207추가: destination: PathBuf,
208추가: automatic: bool,
209추가: }
210추가:
211추가: /// 파일 목록의 오른쪽 클릭 메뉴에서 고른 동작.
212추가: enum MenuAction {
213추가: NewFolder,
214추가: ChooseFolder,
215추가: }
216추가:
217추가: type Opener = Box<dyn FnMut(&Path) -> Result<(), String>>;
218추가:
201219pub struct ArchiveApp {
202220 pub model: Model,
203221 factory: Box<dyn Factory>,
@@ -262,6 +280,13 @@ pub struct ArchiveApp {
262280 checked_destination: bool,
263281 ui_error: Option<String>,
264282 initialized: bool,
283추가: opening: Option<OpenRequest>,
284추가: /// 마지막 풀기가 기본 프로그램으로 열기였으면 그 항목. 다시 시도할 때 다시 엶.
285추가: last_open: Option<u32>,
286추가: /// 압축파일별 열기용 임시 폴더. 앱을 닫을 때 지움.
287추가: open_roots: Vec<(PathBuf, PathBuf)>,
288추가: open_count: u64,
289추가: opener: Opener,
265290 #[cfg(all(feature = "ui-fixture", debug_assertions))]
266291 scenario_marquee: Option<egui::Rect>,
267292 #[cfg(all(feature = "ui-fixture", debug_assertions))]
@@ -329,6 +354,11 @@ impl ArchiveApp {
329354 checked_destination: false,
330355 ui_error: None,
331356 initialized: false,
357추가: opening: None,
358추가: last_open: None,
359추가: open_roots: Vec::new(),
360추가: open_count: 0,
361추가: opener: Box::new(present::open_with_default),
332362 #[cfg(all(feature = "ui-fixture", debug_assertions))]
333363 scenario_marquee: None,
334364 #[cfg(all(feature = "ui-fixture", debug_assertions))]
@@ -344,6 +374,116 @@ impl ArchiveApp {
344374 self.dialogs = dialogs;
345375 }
346376
377추가: /// 파일을 기본 프로그램으로 여는 방법을 바꿈. 시험에서 실제 프로그램 실행을 막을 때 씀.
378추가: pub fn set_opener(&mut self, opener: Opener) {
379추가: self.opener = opener;
380추가: }
381추가:
382추가: /// 압축파일 안 파일 하나를 임시 폴더에 풀고 기본 프로그램으로 엶.
383추가: pub fn open_entry(&mut self, entry_id: u32) -> bool {
384추가: if !self.model.can_extract() || self.opening.is_some() {
385추가: return false;
386추가: }
387추가: let Some(entry) = self.model.entries.iter().find(|e| e.id == entry_id) else {
388추가: return false;
389추가: };
390추가: if entry.kind != Kind::File {
391추가: return false;
392추가: }
393추가: let name = if self
394추가: .model
395추가: .list_id
396추가: .as_ref()
397추가: .is_some_and(|id| id.format == Format::Gzip)
398추가: {
399추가: self.gzip_name.clone()
400추가: } else {
401추가: entry.name.clone()
402추가: };
403추가: if present::blocked_open(&name) {
404추가: // 압축을 풀지 않고 바로 안내만 함.
405추가: self.dismissed = false;
406추가: self.ui_error = Some(present::open_blocked_text(&name));
407추가: return false;
408추가: }
409추가: let Some(archive) = self.model.archive.clone() else {
410추가: return false;
411추가: };
412추가: let root = match self.open_roots.iter().find(|(a, _)| *a == archive) {
413추가: Some((_, root)) if root.is_dir() => root.clone(),
414추가: _ => match present::create_open_root(&archive) {
415추가: Ok(root) => {
416추가: self.open_roots.retain(|(a, _)| *a != archive);
417추가: self.open_roots.push((archive, root.clone()));
418추가: root
419추가: }
420추가: Err(_) => {
421추가: self.dismissed = false;
422추가: self.ui_error = Some(present::FOLDER_ERROR.into());
423추가: return false;
424추가: }
425추가: },
426추가: };
427추가: // 같은 파일을 여러 번 열어도 충돌하지 않도록 열 때마다 새 하위 폴더에 풂.
428추가: self.open_count += 1;
429추가: let folder = present::unique_folder(&root.join(self.open_count.to_string()));
430추가: let request = OpenRequest {
431추가: folder: folder.clone(),
432추가: name: name.replace('\\', "/"),
433추가: destination: std::mem::replace(&mut self.destination, folder),
434추가: automatic: std::mem::replace(&mut self.automatic_destination, true),
435추가: };
436추가: self.opening = Some(request);
437추가: if self.extract_selection(Selection::EntryIds(vec![entry_id])) {
438추가: self.last_open = Some(entry_id);
439추가: true
440추가: } else {
441추가: self.finish_open(false);
442추가: false
443추가: }
444추가: }
445추가:
446추가: /// 열기용 풀기가 끝나면 원래 풀 위치를 되돌리고, 성공했으면 기본 프로그램을 실행함.
447추가: fn finish_open(&mut self, completed: bool) {
448추가: let Some(request) = self.opening.take() else {
449추가: return;
450추가: };
451추가: self.destination = request.destination;
452추가: self.automatic_destination = request.automatic;
453추가: if !completed {
454추가: return;
455추가: }
456추가: let Some(name) = self
457추가: .model
458추가: .outputs
459추가: .iter()
460추가: .filter(|(_, d)| *d == Disposition::Created)
461추가: .map(|(name, _)| name.replace('\\', "/"))
462추가: .find(|name| name.trim_end_matches('/') == request.name)
463추가: else {
464추가: self.ui_error = Some(present::OPEN_MISSING.into());
465추가: return;
466추가: };
467추가: let path = name
468추가: .split('/')
469추가: .fold(request.folder, |path, part| path.join(part));
470추가: match (self.opener)(&path) {
471추가: // 결과 창 없이 바로 열린 파일을 보여 줌.
472추가: Ok(()) => self.dismissed = true,
473추가: Err(error) => self.ui_error = Some(error),
474추가: }
475추가: }
476추가:
477추가: /// 압축파일 이름으로 새 폴더를 만들고(같은 이름이 있으면 번호를 붙임) 선택 항목을 풂.
478추가: fn extract_to_new_folder(&mut self) -> bool {
479추가: let Some(archive) = self.model.archive.clone() else {
480추가: return false;
481추가: };
482추가: self.destination = present::unique_folder(&present::default_destination(&archive));
483추가: self.automatic_destination = true;
484추가: self.begin_extract()
485추가: }
486추가:
347487 /// 창 순서를 지정할 수 없는 환경에서는 부모 안에 작업 화면을 그림.
348488 pub fn set_work_window_in_parent(&mut self, enabled: bool) {
349489 self.work_in_parent = enabled;
@@ -590,6 +730,9 @@ impl ArchiveApp {
590730 return false;
591731 }
592732 self.selected_only = matches!(&selection, Selection::EntryIds(_));
733추가: if self.opening.is_none() {
734추가: self.last_open = None;
735추가: }
593736 match present::prepare_destination(&self.destination, self.automatic_destination) {
594737 Ok(true) => self.owned_destination = Some(self.destination.clone()),
595738 Ok(false) => self.owned_destination = None,
@@ -806,6 +949,8 @@ impl ArchiveApp {
806949 }
807950 }
808951 Purpose::Destination | Purpose::Retry => {
952추가: // 다른 폴더를 골랐으면 기본 프로그램 열기가 아닌 일반 풀기로 다시 함.
953추가: self.last_open = None;
809954 self.choose_destination(path);
810955 self.selected_only = !self.model.selected.is_empty();
811956 if purpose == Purpose::Retry {
@@ -862,6 +1007,9 @@ impl ArchiveApp {
8621007 match request {
8631008 Start::List { archive } => self.open_path(archive),
8641009 Start::Preview { .. } | Start::RecoverZip { .. } => {}
1010추가: Start::Extract { .. } if let Some(entry_id) = self.last_open => {
1011추가: self.open_entry(entry_id);
1012추가: }
8651013 Start::Extract {
8661014 selection,
8671015 gzip_output_name,
@@ -918,6 +1066,17 @@ impl ArchiveApp {
9181066 self.model.close = Close::Confirm;
9191067 }
9201068 if busy && !self.model.busy() {
1069추가: let completed = self.model.confirmed
1070추가: && self
1071추가: .model
1072추가: .terminal
1073추가: .as_ref()
1074추가: .is_some_and(|t| t.outcome == Outcome::Completed);
1075추가: if self.opening.is_some() {
1076추가: // 열기용 폴더는 앱을 닫을 때 지우므로 풀 위치 소유 기록만 정리함.
1077추가: self.owned_destination = None;
1078추가: self.finish_open(completed);
1079추가: }
9211080 if let Some(path) = self.owned_destination.take() {
9221081 if !self.model.confirmed
9231082 || self
@@ -1365,6 +1524,8 @@ impl ArchiveApp {
13651524 }
13661525 let mut focused = None;
13671526 let mut open = None;
1527추가: let mut open_file = None;
1528추가: let mut menu_action = None;
13681529 let mut next_offset = None;
13691530 let output = egui::ScrollArea::vertical()
13701531 .id_salt("archive-rows")
@@ -1386,7 +1547,12 @@ impl ArchiveApp {
13861547 && relative.x <= width
13871548 && relative.y >= 0.0
13881549 && relative.y < rows.len() as f32 * LIST_ROW;
1389삭제: if clip.contains(press) && !in_row && ui.input(|i| i.pointer.primary_pressed())
1550추가: // 목록 위에 떠 있는 창(부모 안 작업 창 등)을 누른 경우는 목록 조작이 아님.
1551추가: let on_list = ui.ctx().layer_id_at(press) == Some(ui.layer_id());
1552추가: if clip.contains(press)
1553추가: && on_list
1554추가: && !in_row
1555추가: && ui.input(|i| i.pointer.primary_pressed())
13901556 {
13911557 background.request_focus();
13921558 let ctrl = ui.input(|i| i.modifiers.ctrl || i.modifiers.command);
@@ -1499,8 +1665,26 @@ impl ArchiveApp {
14991665 modifiers.shift,
15001666 );
15011667 }
1502삭제: if row.directory && response.double_clicked() {
1503삭제: open = Some(row.path.clone());
1668추가: if response.double_clicked() {
1669추가: if row.directory {
1670추가: open = Some(row.path.clone());
1671추가: } else if let [id] = row.ids.iter().copied().collect::<Vec<_>>()[..] {
1672추가: open_file = Some(id);
1673추가: }
1674추가: }
1675추가: if active && response.secondary_clicked() && !selected {
1676추가: // 선택하지 않은 행을 오른쪽 클릭하면 그 행만 선택한 뒤 메뉴를 엶.
1677추가: self.select_row(&rows, index, false, false);
1678추가: }
1679추가: if active {
1680추가: response.context_menu(|ui| {
1681추가: if ui.button("압축 파일명으로 새 폴더를 만들어 압축 풀기").clicked() {
1682추가: menu_action = Some(MenuAction::NewFolder);
1683추가: }
1684추가: if ui.button("특정 폴더에 압축 풀기").clicked() {
1685추가: menu_action = Some(MenuAction::ChooseFolder);
1686추가: }
1687추가: });
15041688 }
15051689 // 암호가 걸린 항목은 이름 앞에 *를 붙이고, 툴팁은 실제 이름을 보여 줌.
15061690 let name = if row.encrypted {
@@ -1638,6 +1822,8 @@ impl ArchiveApp {
16381822 .min(rows.len() - 1);
16391823 if rows[index].directory {
16401824 open = Some(rows[index].path.clone());
1825추가: } else if let [id] = rows[index].ids.iter().copied().collect::<Vec<_>>()[..] {
1826추가: open_file = Some(id);
16411827 }
16421828 }
16431829 }
@@ -1650,10 +1836,37 @@ impl ArchiveApp {
16501836 );
16511837 }
16521838 }
1839추가: // 마우스 옆 버튼(뒤로)을 목록 위에서 누르면 상위 폴더로 이동함.
1840추가: if active
1841추가: && !self.folder.is_empty()
1842추가: && ui.input(|i| {
1843추가: i.pointer.button_pressed(egui::PointerButton::Extra1)
1844추가: && i.pointer
1845추가: .interact_pos()
1846추가: .is_some_and(|pos| path_row.union(background.rect).contains(pos))
1847추가: })
1848추가: {
1849추가: open = Some(
1850추가: self.folder
1851추가: .rsplit_once('/')
1852추가: .map_or("", |(parent, _)| parent)
1853추가: .to_owned(),
1854추가: );
1855추가: }
16531856 if let Some(folder) = open {
16541857 self.browse_folder(&folder);
16551858 background.request_focus();
16561859 }
1860추가: if let Some(id) = open_file {
1861추가: self.open_entry(id);
1862추가: }
1863추가: match menu_action {
1864추가: Some(MenuAction::NewFolder) => {
1865추가: self.extract_to_new_folder();
1866추가: }
1867추가: Some(MenuAction::ChooseFolder) => self.open_picker(Purpose::Destination),
1868추가: None => {}
1869추가: }
16571870 }
16581871
16591872 fn clear_list_selection(&mut self) {
@@ -1966,9 +2179,13 @@ impl ArchiveApp {
19662179 };
19672180 if self.work_in_parent {
19682181 // Wayland는 창 올리기를 지원하지 않으므로 부모 안에서 같은 내용을 그림.
1969삭제: let mut open = true;
1970삭제: let mut window = egui::Window::new(RichText::new(title).size(theme::FONT_SMALL))
2182추가: // egui 기본 제목 줄의 닫기 버튼은 마우스를 올려도 모양이 바뀌지 않으므로
2183추가: // 제목 줄을 직접 그리고 별도 창과 같은 닫기 버튼을 씀.
2184추가: let mut close = false;
2185추가: let busy = self.model.busy();
2186추가: egui::Window::new(RichText::new(&title).size(theme::FONT_SMALL))
19712187 .id(egui::Id::new("archive-work-in-parent"))
2188추가: .title_bar(false)
19722189 .default_pos(
19732190 ctx.content_rect().center() - egui::vec2(WORK_WIDTH, self.work.height) / 2.0,
19742191 )
@@ -1980,21 +2197,26 @@ impl ArchiveApp {
19802197 .resizable(false)
19812198 .fade_in(false)
19822199 .fade_out(false)
1983삭제: .title_frame(
1984삭제: theme::panel(theme::STRIPE)
1985삭제: .inner_margin(egui::Margin::symmetric(16, 8))
1986삭제: .corner_radius(0),
1987삭제: )
19882200 .frame(
1989삭제: theme::panel(theme::PANEL)
2201추가: egui::Frame::new()
2202추가: .fill(theme::PANEL)
19902203 .stroke(egui::Stroke::new(1.0, theme::BORDER))
2204추가: .inner_margin(egui::Margin::ZERO)
19912205 .corner_radius(0),
1992삭제: );
1993삭제: if !self.model.busy() {
1994삭제: window = window.open(&mut open);
1995삭제: }
1996삭제: window.show(ctx, |ui| self.work_area(ui));
1997삭제: if !open {
2206추가: )
2207추가: .show(ctx, |ui| {
2208추가: let spacing = ui.spacing().item_spacing.y;
2209추가: ui.spacing_mut().item_spacing.y = 0.0;
2210추가: close = window_frame::in_parent_title(ui, "work-in-parent", &title, !busy);
2211추가: egui::Frame::new()
2212추가: .inner_margin(egui::Margin::same(theme::PAD))
2213추가: .show(ui, |ui| {
2214추가: ui.spacing_mut().item_spacing.y = spacing;
2215추가: ui.set_width(WORK_WIDTH - 2.0 * theme::PAD as f32);
2216추가: self.work_area(ui)
2217추가: });
2218추가: });
2219추가: if close {
19982220 self.dismissed = true;
19992221 self.ui_error = None;
20002222 self.model.input_error = None;
@@ -3435,5 +3657,8 @@ impl eframe::App for ArchiveApp {
34353657impl Drop for ArchiveApp {
34363658 fn drop(&mut self) {
34373659 self.clear_password();
3660추가: for (_, root) in self.open_roots.drain(..) {
3661추가: present::remove_open_root(&root);
3662추가: }
34383663 }
34393664}
수정experiments/rust-ui-memory-app/src/window_frame.rs+30-0
@@ -11,6 +11,7 @@ pub const TITLE_HEIGHT: f32 = 38.0;
1111const BUTTON_SIZE: Vec2 = egui::vec2(34.0, 26.0);
1212const RESIZE_EDGE: f32 = 6.0;
1313const DRAG_THRESHOLD: f32 = 4.0;
14추가: const IN_PARENT_TITLE: f32 = 36.0;
1415const TITLE_BG: Color32 = Color32::from_rgb(235, 238, 242);
1516
1617/// 창 테두리를 직접 그려야 하는지 판단함.
@@ -113,6 +114,35 @@ pub fn title_bar(root: &mut egui::Ui, id: &str, title: &str, buttons: Buttons) -
113114 moved
114115}
115116
117추가: /// 부모 창 안에 그리는 자식 창의 제목 줄. 닫기 버튼을 누르면 true를 돌려줌.
118추가: /// 별도 창의 제목 표시줄과 같은 닫기 버튼(마우스를 올리면 빨간 배경)을 씀.
119추가: pub fn in_parent_title(ui: &mut egui::Ui, id: &str, title: &str, closable: bool) -> bool {
120추가: let width = ui.available_width();
121추가: let (rect, _) = ui.allocate_exact_size(egui::vec2(width, IN_PARENT_TITLE), Sense::hover());
122추가: let painter = ui.painter();
123추가: painter.rect_filled(rect, 0.0, theme::STRIPE);
124추가: painter.hline(
125추가: rect.x_range(),
126추가: rect.bottom() - 0.5,
127추가: Stroke::new(1.0, theme::BORDER),
128추가: );
129추가: let button = Rect::from_center_size(
130추가: egui::pos2(rect.right() - 6.0 - BUTTON_SIZE.x / 2.0, rect.center().y),
131추가: BUTTON_SIZE,
132추가: );
133추가: let reserved = if closable { BUTTON_SIZE.x + 12.0 } else { 0.0 };
134추가: let font = FontId::proportional(theme::FONT_SMALL);
135추가: let text = fit(ui, title, &font, (rect.width() - 32.0 - reserved).max(0.0));
136추가: ui.painter().text(
137추가: egui::pos2(rect.left() + 16.0, rect.center().y),
138추가: Align2::LEFT_CENTER,
139추가: text,
140추가: font,
141추가: theme::TEXT,
142추가: );
143추가: closable && window_button(ui, id, button, Glyph::Close).clicked()
144추가: }
145추가:
116146/// 제목 표시줄을 누른 채 움직였는지를 원시 입력으로 판단함.
117147/// 창 이동 중에는 운영체제가 마우스를 가져가서 버튼 놓기가 앱에 오지 않으므로,
118148/// egui의 끌기 상태에 기대면 다음 끌기가 시작되지 않음.
수정tests/rust-app-real-worker/selection_flows.rs+53-0
@@ -287,3 +287,56 @@ fn explorer_folder_click_and_escape_control_actual_extraction_scope() {
287287 ));
288288 assert_reaped(&observed);
289289}
290추가:
291추가: // 작업자는 새로 만든 상위 폴더도 출력으로 알림. 하위 폴더 안 파일도 그 파일 자체를 열어야 함.
292추가: #[test]
293추가: fn double_click_open_extracts_nested_file_and_opens_that_file() {
294추가: let scratch = Scratch::new();
295추가: let folder = make_directory(&scratch.path("site"));
296추가: fs::write(folder.join("index.html"), b"<p>zipelo</p>").unwrap();
297추가: fs::write(folder.join("style.css"), b"p{}").unwrap();
298추가: let archive = scratch.path("site.zip");
299추가: let (factory, observed) = observed_factory();
300추가: let mut screen = Screen::new(factory);
301추가: let opened = std::rc::Rc::new(std::cell::RefCell::new(Vec::new()));
302추가: let record = opened.clone();
303추가: screen.app.set_opener(Box::new(move |path| {
304추가: record.borrow_mut().push(path.to_path_buf());
305추가: Ok(())
306추가: }));
307추가: screen.app.add_sources(vec![folder]);
308추가: screen.render(vec![]);
309추가: screen.set_text("zip-name", "site.zip");
310추가: screen.click("압축하기");
311추가: screen.settle();
312추가: screen.open(&archive);
313추가: for name in ["site/index.html", "site/style.css"] {
314추가: let id = screen
315추가: .app
316추가: .model
317추가: .entries
318추가: .iter()
319추가: .find(|entry| entry.name == name)
320추가: .unwrap()
321추가: .id;
322추가: assert!(screen.app.open_entry(id));
323추가: screen.settle();
324추가: screen.render(vec![]);
325추가: }
326추가: let root = scratch.path("site.zip (Zipelo 임시)");
327추가: assert_eq!(
328추가: *opened.borrow(),
329추가: vec![
330추가: root.join("1/site/index.html"),
331추가: root.join("2/site/style.css")
332추가: ]
333추가: );
334추가: assert_eq!(
335추가: fs::read(root.join("1/site/index.html")).unwrap(),
336추가: b"<p>zipelo</p>"
337추가: );
338추가: assert!(!root.join("1/site/style.css").exists());
339추가: assert_reaped(&observed);
340추가: drop(screen);
341추가: assert!(!root.exists());
342추가: }
수정tests/rust-app-ui/explorer_selection.rs+251-6
@@ -3,6 +3,7 @@ struct Explorer {
33 ctx: egui::Context,
44 factory: FakeFactory,
55 time: f64,
6추가: opened: std::rc::Rc<std::cell::RefCell<Vec<PathBuf>>>,
67}
78impl Explorer {
89 fn new(scratch: &Folder) -> Self {
@@ -25,11 +26,18 @@ impl Explorer {
2526 encrypted: false,
2627 })
2728 .into();
29추가: let opened = std::rc::Rc::new(std::cell::RefCell::new(Vec::new()));
30추가: let record = opened.clone();
31추가: app.set_opener(Box::new(move |path| {
32추가: record.borrow_mut().push(path.to_path_buf());
33추가: Ok(())
34추가: }));
2835 let mut screen = Self {
2936 app,
3037 ctx: egui::Context::default(),
3138 factory,
3239 time: 0.0,
40추가: opened,
3341 };
3442 screen.frame(egui::Modifiers::NONE, vec![]);
3543 screen.frame(egui::Modifiers::NONE, vec![]);
@@ -115,6 +123,44 @@ impl Explorer {
115123 }],
116124 );
117125 }
126추가: fn button(&mut self, point: egui::Pos2, button: egui::PointerButton) {
127추가: self.time += 1.0;
128추가: for pressed in [true, false] {
129추가: self.frame(
130추가: egui::Modifiers::NONE,
131추가: vec![
132추가: egui::Event::PointerMoved(point),
133추가: egui::Event::PointerButton {
134추가: pos: point,
135추가: button,
136추가: pressed,
137추가: modifiers: egui::Modifiers::NONE,
138추가: },
139추가: ],
140추가: );
141추가: }
142추가: self.frame(egui::Modifiers::NONE, vec![]);
143추가: }
144추가: fn double_click(&mut self, path: &str) {
145추가: self.time += 1.0;
146추가: let point = self.row(path).center();
147추가: for _ in 0..2 {
148추가: self.pointer(point, true, egui::Modifiers::NONE);
149추가: self.pointer(point, false, egui::Modifiers::NONE);
150추가: }
151추가: for _ in 0..30 {
152추가: self.frame(egui::Modifiers::NONE, vec![]);
153추가: }
154추가: }
155추가: fn click_text(&mut self, label: &str) {
156추가: let output = self.frame(egui::Modifiers::NONE, vec![]);
157추가: let rect = layout_text(&output)
158추가: .into_iter()
159추가: .find(|(text, _, _)| text == label)
160추가: .unwrap_or_else(|| panic!("{label} 없음"))
161추가: .1;
162추가: self.button(rect.center(), egui::PointerButton::Primary);
163추가: }
118164 #[track_caller]
119165 fn selected(&self, ids: &[u32]) {
120166 assert_eq!(self.app.model.selected, ids.iter().copied().collect());
@@ -222,16 +268,215 @@ fn explorer_keyboard_ranges_enter_backspace_and_escape_are_scoped_to_the_list()
222268}
223269
224270#[test]
225삭제: fn explorer_double_click_opens_only_folders_and_resets_selection() {
271추가: fn explorer_double_click_opens_files_with_default_app_and_folders_in_place() {
226272 let scratch = Folder::new();
227273 let mut s = Explorer::new(&scratch);
228삭제: let point = s.row("alpha.txt").center();
229삭제: for _ in 0..2 {
230삭제: s.pointer(point, true, egui::Modifiers::NONE);
231삭제: s.pointer(point, false, egui::Modifiers::NONE);
274추가: let destination = s.app.model.archive.clone().unwrap().with_file_name("sample");
275추가: // 실제 작업자처럼 새로 만든 상위 폴더도 출력으로 알림.
276추가: s.factory.state.borrow_mut().outputs = Some(vec!["docs".into(), "docs/child.txt".into()]);
277추가: s.app.browse_folder("docs");
278추가: s.double_click("docs/child.txt");
279추가: s.selected(&[0]);
280추가: // 파일은 압축파일 옆 숨김 임시 폴더에 그 파일만 풀고 기본 프로그램으로 엶.
281추가: let root = scratch.0.join("sample.zip (Zipelo 임시)");
282추가: {
283추가: let state = s.factory.state.borrow();
284추가: assert_eq!(state.starts.len(), 2);
285추가: let Start::Extract {
286추가: destination: folder,
287추가: selection,
288추가: ..
289추가: } = state.starts.last().unwrap()
290추가: else {
291추가: panic!("{:?}", state.starts.last());
292추가: };
293추가: assert_eq!(selection, &Selection::EntryIds(vec![0]));
294추가: assert_eq!(folder, &root.join("1"));
232295 }
233삭제: s.selected(&[1]);
296추가: assert_eq!(
297추가: *s.opened.borrow(),
298추가: vec![root.join("1").join("docs").join("child.txt")]
299추가: );
300추가: let output = s.frame(egui::Modifiers::NONE, vec![]);
301추가: assert!(
302추가: !layout_text(&output)
303추가: .iter()
304추가: .any(|(text, _, _)| text == "작업 결과")
305추가: );
306추가: // 같은 파일을 다시 열면 새 하위 폴더를 씀.
307추가: s.double_click("docs/child.txt");
308추가: assert!(matches!(
309추가: s.factory.state.borrow().starts.last(),
310추가: Some(Start::Extract { destination, .. }) if destination == &root.join("2")
311추가: ));
312추가: assert_eq!(s.opened.borrow().len(), 2);
313추가: // 열 파일이 출력에 없으면 조용히 넘어가지 않고 알림.
314추가: s.factory.state.borrow_mut().outputs = Some(vec!["docs".into()]);
315추가: s.double_click("docs/child.txt");
316추가: assert_eq!(s.opened.borrow().len(), 2);
317추가: assert!(
318추가: layout_text(&s.frame(egui::Modifiers::NONE, vec![]))
319추가: .iter()
320추가: .any(|(text, _, _)| text == "풀린 파일을 찾지 못해 열지 못했습니다")
321추가: );
322추가: // 열기용 폴더는 압축파일 이름 폴더와 섞이지 않음.
323추가: assert!(!destination.exists());
324추가: // 앱을 닫으면 열기용 폴더를 지움.
325추가: assert!(root.is_dir());
326추가: drop(s);
327추가: assert!(!root.exists());
328추가: }
329추가:
330추가: #[test]
331추가: fn explorer_double_click_does_not_open_executables() {
332추가: let scratch = Folder::new();
333추가: let mut s = Explorer::new(&scratch);
334추가: s.app.model.entries[2].name = "setup.EXE".into();
335추가: s.double_click("setup.EXE");
234336 assert_eq!(s.factory.state.borrow().starts.len(), 1);
337추가: assert!(s.opened.borrow().is_empty());
338추가: let output = s.frame(egui::Modifiers::NONE, vec![]);
339추가: assert!(
340추가: layout_text(&output)
341추가: .iter()
342추가: .any(|(text, _, _)| text == "실행 파일(.EXE)은 안전을 위해 바로 열 수 없습니다")
343추가: );
344추가: // 실행 파일은 압축을 풀지 않으므로 임시 폴더도 만들지 않음.
345추가: assert!(!scratch.0.join("sample.zip (Zipelo 임시)").exists());
346추가: }
347추가:
348추가: #[test]
349추가: fn explorer_dragging_in_parent_work_window_does_not_select_rows() {
350추가: let scratch = Folder::new();
351추가: let mut s = Explorer::new(&scratch);
352추가: s.app.set_work_window_in_parent(true);
353추가: s.app.model.entries[2].name = "setup.EXE".into();
354추가: s.double_click("setup.EXE");
355추가: s.selected(&[2]);
356추가: let close = s
357추가: .ctx
358추가: .read_response(egui::Id::unique(("window-button", "work-in-parent", "닫기")))
359추가: .expect("부모 안 작업 창")
360추가: .rect;
361추가: // 행이 하나뿐인 폴더로 옮겨 작업 창 제목 줄 아래가 목록의 빈 곳이 되게 함.
362추가: s.app.browse_folder("docs");
363추가: let row = s.row("docs/child.txt");
364추가: s.selected(&[]);
365추가: // 작업 창 제목 줄을 누르고 목록 행 위로 끌어도 목록 선택 사각형이 생기지 않아야 함.
366추가: let start = egui::pos2(close.left() - 120.0, close.center().y);
367추가: assert!(start.y > row.bottom(), "{start:?} {row:?}");
368추가: s.pointer(start, true, egui::Modifiers::NONE);
369추가: let end = egui::pos2(row.center().x, row.center().y);
370추가: for step in 1..=6 {
371추가: let t = step as f32 / 6.0;
372추가: s.frame(
373추가: egui::Modifiers::NONE,
374추가: vec![egui::Event::PointerMoved(start + (end - start) * t)],
375추가: );
376추가: }
377추가: let output = s.frame(egui::Modifiers::NONE, vec![]);
378추가: s.selected(&[]);
379추가: assert!(!output.shapes.iter().any(|shape| matches!(
380추가: &shape.shape,
381추가: egui::epaint::Shape::Rect(rect) if rect.fill == theme_blue_fill()
382추가: )));
383추가: s.pointer(end, false, egui::Modifiers::NONE);
384추가: s.selected(&[]);
385추가: }
386추가:
387추가: fn theme_blue_fill() -> egui::Color32 {
388추가: zipelo_ui_memory_app::archive_theme::BLUE.gamma_multiply(0.16)
389추가: }
390추가:
391추가: #[test]
392추가: fn explorer_context_menu_extracts_selection_into_numbered_archive_folder() {
393추가: let scratch = Folder::new();
394추가: let mut s = Explorer::new(&scratch);
395추가: fs::create_dir(scratch.0.join("sample")).unwrap();
396추가: s.click("alpha.txt", egui::Modifiers::NONE);
397추가: // 선택하지 않은 행을 오른쪽 클릭하면 그 행만 선택하고 메뉴를 엶.
398추가: let point = s.row("docs").center();
399추가: s.button(point, egui::PointerButton::Secondary);
400추가: s.selected(&[0, 5]);
401추가: s.click_text("압축 파일명으로 새 폴더를 만들어 압축 풀기");
402추가: for _ in 0..30 {
403추가: s.frame(egui::Modifiers::NONE, vec![]);
404추가: }
405추가: let state = s.factory.state.borrow();
406추가: let Some(Start::Extract {
407추가: destination,
408추가: selection,
409추가: ..
410추가: }) = state.starts.last()
411추가: else {
412추가: panic!("{:?}", state.starts.last());
413추가: };
414추가: assert_eq!(destination, &scratch.0.join("sample (1)"));
415추가: assert_eq!(selection, &Selection::EntryIds(vec![0, 5]));
416추가: assert!(scratch.0.join("sample (1)").is_dir());
417추가: assert!(s.opened.borrow().is_empty());
418추가: }
419추가:
420추가: #[test]
421추가: fn explorer_context_menu_asks_for_folder_and_extracts_only_selection() {
422추가: let scratch = Folder::new();
423추가: let mut s = Explorer::new(&scratch);
424추가: let dialogs = crate::dialogs::TestDialogs::default();
425추가: let target = scratch.0.join("target");
426추가: fs::create_dir(&target).unwrap();
427추가: dialogs
428추가: .0
429추가: .borrow_mut()
430추가: .answers
431추가: .push_back(Some(vec![target.clone()]));
432추가: s.app.set_dialogs(Box::new(dialogs.clone()));
433추가: s.click("alpha.txt", egui::Modifiers::NONE);
434추가: s.click("beta.txt", explorer_ctrl());
435추가: let point = s.row("beta.txt").center();
436추가: s.button(point, egui::PointerButton::Secondary);
437추가: s.selected(&[1, 2]);
438추가: s.click_text("특정 폴더에 압축 풀기");
439추가: for _ in 0..30 {
440추가: s.frame(egui::Modifiers::NONE, vec![]);
441추가: }
442추가: assert_eq!(
443추가: dialogs.0.borrow().requests.last().unwrap().purpose,
444추가: zipelo_ui_memory_app::archive_dialog::Purpose::Destination
445추가: );
446추가: assert!(matches!(
447추가: s.factory.state.borrow().starts.last(),
448추가: Some(Start::Extract { destination, selection: Selection::EntryIds(ids), .. })
449추가: if destination == &target && ids == &vec![1, 2]
450추가: ));
451추가: }
452추가:
453추가: #[test]
454추가: fn explorer_mouse_back_button_goes_to_parent_folder() {
455추가: let scratch = Folder::new();
456추가: let mut s = Explorer::new(&scratch);
457추가: s.app.browse_folder("docs");
458추가: let point = s.row("docs/child.txt").center();
459추가: s.button(point, egui::PointerButton::Extra2);
460추가: assert!(s.ctx.read_response(egui::Id::unique(("archive-row", "docs/child.txt"))).is_some());
461추가: s.button(point, egui::PointerButton::Extra1);
462추가: assert!(
463추가: layout_text(&s.frame(egui::Modifiers::NONE, vec![]))
464추가: .iter()
465추가: .any(|(text, _, _)| text == "alpha.txt")
466추가: );
467추가: // 최상위에서는 아무 일도 하지 않음.
468추가: s.button(point, egui::PointerButton::Extra1);
469추가: assert!(
470추가: layout_text(&s.frame(egui::Modifiers::NONE, vec![]))
471추가: .iter()
472추가: .any(|(text, _, _)| text == "alpha.txt")
473추가: );
474추가: }
475추가:
476추가: #[test]
477추가: fn explorer_double_click_opens_only_folders_and_resets_selection() {
478추가: let scratch = Folder::new();
479추가: let mut s = Explorer::new(&scratch);
235480 s.time += 1.0;
236481 let point = s.row("docs").center();
237482 for _ in 0..2 {
수정tests/rust-app-ui/fake.rs+13-5
@@ -18,6 +18,8 @@ pub struct State {
1818 pub list_format: Option<Format>,
1919 pub fail_start: bool,
2020 pub dropped_connections: usize,
21추가: /// 풀기 출력으로 알릴 이름. 없으면 "읽어주세요.txt" 하나를 알림.
22추가: pub outputs: Option<Vec<String>>,
2123 pause: bool,
2224}
2325#[derive(Default, Clone)]
@@ -132,11 +134,17 @@ impl State {
132134 total: Some(31),
133135 completed_entries: 1,
134136 });
135삭제: self.frame(Event::Output {
136삭제: entry_id: Some(0),
137삭제: relative_name: "읽어주세요.txt".into(),
138삭제: disposition: Disposition::Created,
139삭제: });
137추가: let names = self
138추가: .outputs
139추가: .clone()
140추가: .unwrap_or_else(|| vec!["읽어주세요.txt".into()]);
141추가: for name in names {
142추가: self.frame(Event::Output {
143추가: entry_id: None,
144추가: relative_name: name,
145추가: disposition: Disposition::Created,
146추가: });
147추가: }
140148 self.finish(Outcome::Completed, Publication::Complete);
141149 }
142150 }
수정tests/rust-app-ui/presentation.rs+24-0
@@ -333,6 +333,19 @@ fn default_names_and_middle_truncation_preserve_unicode() {
333333 assert_eq!(default_destination(&path(name)), path("압축 해제"));
334334 }
335335 assert_eq!(default_destination(&path("자료.zip")), path("자료"));
336추가: assert!(blocked_open("폴더/setup.EXE"));
337추가: assert!(blocked_open("run.desktop"));
338추가: assert!(!blocked_open("사진.jpg"));
339추가: assert!(!blocked_open("exe"));
340추가: // Linux는 스크립트를 편집기로 열므로 막지 않음.
341추가: #[cfg(not(windows))]
342추가: assert!(!blocked_open("app.js"));
343추가: #[cfg(windows)]
344추가: assert!(blocked_open("app.js"));
345추가: assert_eq!(
346추가: open_blocked_text("폴더/setup.EXE"),
347추가: "실행 파일(.EXE)은 안전을 위해 바로 열 수 없습니다"
348추가: );
336349 assert_eq!(middle_text("가나다라마바사아자차", 7), "가나다…아자차");
337350 assert_eq!(bytes_text(21), "21 B");
338351}
@@ -358,6 +371,17 @@ impl Drop for Folder {
358371 }
359372}
360373
374추가: #[test]
375추가: fn unique_folder_numbers_existing_names() {
376추가: let scratch = Folder::new();
377추가: let base = scratch.0.join("자료");
378추가: assert_eq!(unique_folder(&base), base);
379추가: fs::create_dir(&base).unwrap();
380추가: assert_eq!(unique_folder(&base), scratch.0.join("자료 (1)"));
381추가: fs::write(scratch.0.join("자료 (1)"), b"").unwrap();
382추가: assert_eq!(unique_folder(&base), scratch.0.join("자료 (2)"));
383추가: }
384추가:
361385#[test]
362386fn automatic_destination_creation_and_failure_are_distinct() {
363387 let scratch = Folder::new();
수정tests/rust-app-ui/work_window.rs+83-0
@@ -938,3 +938,86 @@ fn scenario_window_hosting_survives_platform_frame_configuration() {
938938 }
939939 }
940940}
941추가:
942추가: #[test]
943추가: fn hosted_work_window_close_button_shows_hover_and_dismisses_result() {
944추가: let factory = FakeFactory::manual();
945추가: let mut app = ArchiveApp::new(Box::new(factory.clone()), Some("/sample.zip".into()), false);
946추가: app.set_work_window_in_parent(true);
947추가: let ctx = egui::Context::default();
948추가: ctx.set_embed_viewports(false);
949추가: install_work_child_renderer();
950추가: {
951추가: let mut worker = factory.state.borrow_mut();
952추가: worker.finish(Outcome::Failed, Publication::None);
953추가: for event in &mut worker.queue {
954추가: if let HostEvent::Frame {
955추가: event: Event::Terminal(terminal),
956추가: ..
957추가: } = event
958추가: {
959추가: terminal.error = Some(ErrorCode::Io);
960추가: }
961추가: }
962추가: }
963추가: let render = |app: &mut ArchiveApp, events: Vec<egui::Event>| {
964추가: let mut output = ctx.run_ui(
965추가: egui::RawInput {
966추가: screen_rect: Some(egui::Rect::from_min_size(
967추가: egui::Pos2::ZERO,
968추가: egui::vec2(1060.0, 720.0),
969추가: )),
970추가: events,
971추가: ..Default::default()
972추가: },
973추가: |ui| app.show(ui),
974추가: );
975추가: output.textures_delta.clear();
976추가: output
977추가: };
978추가: for _ in 0..4 {
979추가: render(&mut app, vec![]);
980추가: }
981추가: let close_id = egui::Id::unique(("window-button", "work-in-parent", "닫기"));
982추가: let close = ctx.read_response(close_id).expect("닫기 버튼").rect;
983추가: let red = egui::Color32::from_rgb(232, 17, 35);
984추가: fn has_fill(shapes: &[egui::epaint::ClippedShape], color: egui::Color32) -> bool {
985추가: fn walk(shape: &Shape, color: egui::Color32) -> bool {
986추가: match shape {
987추가: Shape::Rect(rect) => rect.fill == color,
988추가: Shape::Vec(shapes) => shapes.iter().any(|s| walk(s, color)),
989추가: _ => false,
990추가: }
991추가: }
992추가: shapes.iter().any(|s| walk(&s.shape, color))
993추가: }
994추가: let idle = render(&mut app, vec![egui::Event::PointerMoved(egui::pos2(5.0, 5.0))]);
995추가: assert!(!has_fill(&idle.shapes, red));
996추가: assert!(
997추가: labels(&idle.shapes)
998추가: .iter()
999추가: .any(|(text, _)| text == "압축파일을 열지 못했습니다")
1000추가: );
1001추가: render(&mut app, vec![egui::Event::PointerMoved(close.center())]);
1002추가: let hovered = render(&mut app, vec![]);
1003추가: assert!(has_fill(&hovered.shapes, red));
1004추가: for pressed in [true, false] {
1005추가: render(
1006추가: &mut app,
1007추가: vec![egui::Event::PointerButton {
1008추가: pos: close.center(),
1009추가: button: egui::PointerButton::Primary,
1010추가: pressed,
1011추가: modifiers: egui::Modifiers::NONE,
1012추가: }],
1013추가: );
1014추가: }
1015추가: render(&mut app, vec![]);
1016추가: let shown = labels(&render(&mut app, vec![]).shapes);
1017추가: assert!(
1018추가: !shown
1019추가: .iter()
1020추가: .any(|(text, _)| text == "압축파일을 열지 못했습니다"),
1021추가: "{shown:?}"
1022추가: );
1023추가: }
수정tests/rust-archive-worker/main.rs+40-0
@@ -519,6 +519,46 @@ fn symlink_parent_escape_is_rejected() {
519519 assert_eq!(fs::read_dir(s.0.join("outside")).unwrap().count(), 0);
520520}
521521
522추가: // umask 002에서 폴더 선택 창으로 새로 만든 폴더(775)에도 풀 수 있어야 함.
523추가: // 다른 계정이 쓸 수 있는 폴더(777)는 계속 거부함.
524추가: #[cfg(target_os = "linux")]
525추가: #[test]
526추가: fn private_group_writable_output_is_accepted() {
527추가: use std::os::unix::fs::{MetadataExt, PermissionsExt};
528추가: for (mode, other) in [(0o775, false), (0o777, true)] {
529추가: let s = Scratch::new();
530추가: fs::create_dir(s.0.join("output")).unwrap();
531추가: fs::set_permissions(s.0.join("output"), fs::Permissions::from_mode(mode)).unwrap();
532추가: let gid = fs::metadata(s.0.join("output")).unwrap().gid();
533추가: let entry = Command::new("getent")
534추가: .args(["group", &gid.to_string()])
535추가: .output()
536추가: .unwrap();
537추가: let entry = String::from_utf8_lossy(&entry.stdout);
538추가: let egid = Command::new("id").arg("-g").output().unwrap();
539추가: let private = String::from_utf8_lossy(&egid.stdout).trim() == gid.to_string()
540추가: && entry.trim_end().ends_with(':');
541추가: let e = extract(
542추가: &s,
543추가: include_bytes!("fixtures/store.zip"),
544추가: None,
545추가: Selection::All,
546추가: None,
547추가: Limits::default(),
548추가: );
549추가: if other || !private {
550추가: assert_eq!(terminal(&e).error, ErrorCode::UnsafePath, "{mode:o}");
551추가: assert!(!s.0.join("output/folder").exists());
552추가: } else {
553추가: assert_eq!(terminal(&e).outcome, Outcome::Completed, "{e:?}");
554추가: assert_eq!(
555추가: fs::read(s.0.join("output/folder/hello.txt")).unwrap(),
556추가: PAYLOAD
557추가: );
558추가: }
559추가: }
560추가: }
561추가:
522562#[test]
523563fn changed_source_is_reopen_error_before_decode() {
524564 let s = Scratch::new();