JJ_MKVMaker/lib/core/name_clash.dart

31 lines
1.7 KiB
Dart

import '../l10n/tr.dart';
import 'file_ops.dart' show formatSize;
import 'vfs.dart' show vBasename;
/// 약속: 같은 이름 비교 글 ([clashCompareText]) · 파일 날짜 글 ([fileDateText]). 순수 함수, 오류 없음.
/// 탐색기 복사 확인 창 · 끌어 놓기 · 붙여넣기가 함께 쓴다.
/// 172: 같은 이름 - 보낼 것 (복사 · 이동, [here]) 과 대상 폴더에 이미 있는 것 ([there])
typedef NameClash = ({String src, ({bool isDir, int size, DateTime modified})? here, ({bool isDir, int size, DateTime modified}) there});
/// 172: "이름: 보낼 것 1.2 MB · 2026-10-09 14:00 / 있는 것 900 KB · 2026-10-01 09:00 (보낼 것이 더 새것)"
String clashCompareText(NameClash x) {
String one(({bool isDir, int size, DateTime modified}) s) =>
[if (!s.isDir) formatSize(s.size) else tr('폴더'), if (s.modified.year > 1) fileDateText(s.modified)].join(' · ');
final h = x.here, t = x.there;
final newer = h == null || h.modified.year <= 1 || t.modified.year <= 1
? ''
: h.modified.isAfter(t.modified.add(const Duration(seconds: 2)))
? tr(' (보낼 것이 더 새것)')
: t.modified.isAfter(h.modified.add(const Duration(seconds: 2)))
? tr(' (있는 것이 더 새것)')
: tr(' (바뀐 날 같음)');
return '${vBasename(x.src)}: ${trf('보낼 것 {0} / 있는 것 {1}', [h == null ? '?' : one(h), one(t)])}$newer';
}
/// 203: 바뀐 날을 모름 (잠긴 시스템 파일은 1970-01-01 로 온다) 은 "—"
String fileDateText(DateTime d) => d.year <= 1970
? '—'
: '${d.year}-${d.month.toString().padLeft(2, '0')}-${d.day.toString().padLeft(2, '0')} '
'${d.hour.toString().padLeft(2, '0')}:${d.minute.toString().padLeft(2, '0')}';