JJ_MKVMaker/lib/app/file_opener.dart

36 lines
1.8 KiB
Dart

import '../core/archive_ops.dart' show ArchiveKind, archiveKindOf;
import '../core/hwp_source.dart' show hwpExtensions;
import '../core/playlist.dart' show isVideoFile;
import '../core/reader_sources.dart' show extOf, zipExtensions;
import 'components.dart' show AppComponent;
/// 약속 (E5c): 파일을 "열" 때 어느 길로 여는지 고른다 ([openRouteFor]). 순수 함수 - 여는 일은 부르는 화면이 한다.
/// 입력 = 경로 · 켠 컴포넌트 · 그림 확장자 · 기기 · HWP 엔진이 있는지, 출력 = [OpenRoute]. 오류 없음.
/// 차례: 동영상 → 내장 플레이어 · 7z/RAR → 압축 풀기 · (보기 컴포넌트) 그림 · PDF · ZIP/CBZ →
/// (Android · 보기 · 엔진) HWP → 앱 안 보기 (못 열면 바깥 앱) · (Windows · 문서 컴포넌트) 문서 미리 보기 → 바깥 앱.
/// - 다시 쓰는 곳: 탐색기 · 다운로드 화면 · 보관함 · 찾기 결과.
enum OpenRoute { player, extractArchive, images, pdf, zip, hwp, docPreview, external }
OpenRoute openRouteFor(
String path, {
required List<String> components,
required List<String> imageExts,
required bool android,
required bool windows,
required bool hwpEngine,
}) {
if (isVideoFile(path)) return OpenRoute.player;
final kind = archiveKindOf(path);
if (kind == ArchiveKind.sevenZip || kind == ArchiveKind.rar) return OpenRoute.extractArchive;
final ext = extOf(path);
final viewer = components.contains('viewer');
if (viewer) {
if (imageExts.contains(ext)) return OpenRoute.images;
if (ext == 'pdf') return OpenRoute.pdf;
if (zipExtensions.contains(ext)) return OpenRoute.zip;
}
if (android && viewer && hwpExtensions.contains(ext) && hwpEngine) return OpenRoute.hwp;
if (components.contains('docs') && windows && AppComponent.docExtensions.contains(ext)) return OpenRoute.docPreview;
return OpenRoute.external;
}