60 lines
2.0 KiB
Dart
60 lines
2.0 KiB
Dart
|
|
/// 应用数据路径统一入口:运行时目录(由 [Storage] 管理)与素材库目录。
|
||
|
|
///
|
||
|
|
/// 素材库布局(桌面 `%APPDATA%/EDC/library/`;安卓为应用内部目录下的
|
||
|
|
/// `library/`,公共目录导出见 [AndroidDocs]):
|
||
|
|
/// - `symbols/` 自定义图元(`*.symbol.json`,电气符号 / 架构图形等);
|
||
|
|
/// - `images/` 导入的图片素材;
|
||
|
|
/// - `templates/` 文档模板;
|
||
|
|
///
|
||
|
|
/// 内置素材(随安装包发布、只读)走 Flutter assets,不占用这些目录;
|
||
|
|
/// 用户新增 / 导入的素材一律进这里。
|
||
|
|
library;
|
||
|
|
|
||
|
|
import 'dart:io';
|
||
|
|
|
||
|
|
import 'storage.dart';
|
||
|
|
|
||
|
|
/// 应用路径工具。
|
||
|
|
class AppPaths {
|
||
|
|
AppPaths._();
|
||
|
|
|
||
|
|
/// 应用数据根目录(桌面 `%APPDATA%/EDC`;需先 [Storage.init])。
|
||
|
|
static Future<Directory> dataRoot() async {
|
||
|
|
await Storage.instance.init();
|
||
|
|
return Storage.instance.appDir;
|
||
|
|
}
|
||
|
|
|
||
|
|
/// 素材库根目录。
|
||
|
|
static Future<Directory> libraryDir() async {
|
||
|
|
final Directory root = await dataRoot();
|
||
|
|
return Directory('${root.path}${Platform.pathSeparator}library');
|
||
|
|
}
|
||
|
|
|
||
|
|
/// 自定义图元目录(`library/symbols`)。
|
||
|
|
static Future<Directory> symbolsDir() async {
|
||
|
|
final Directory lib = await libraryDir();
|
||
|
|
return Directory('${lib.path}${Platform.pathSeparator}symbols');
|
||
|
|
}
|
||
|
|
|
||
|
|
/// 图片素材目录(`library/images`)。
|
||
|
|
static Future<Directory> imagesDir() async {
|
||
|
|
final Directory lib = await libraryDir();
|
||
|
|
return Directory('${lib.path}${Platform.pathSeparator}images');
|
||
|
|
}
|
||
|
|
|
||
|
|
/// 文档模板目录(`library/templates`)。
|
||
|
|
static Future<Directory> templatesDir() async {
|
||
|
|
final Directory lib = await libraryDir();
|
||
|
|
return Directory('${lib.path}${Platform.pathSeparator}templates');
|
||
|
|
}
|
||
|
|
|
||
|
|
/// 确保素材库目录存在(幂等;失败静默,不阻塞启动)。
|
||
|
|
static Future<void> ensureLibrary() async {
|
||
|
|
try {
|
||
|
|
await (await symbolsDir()).create(recursive: true);
|
||
|
|
await (await imagesDir()).create(recursive: true);
|
||
|
|
await (await templatesDir()).create(recursive: true);
|
||
|
|
} catch (_) {}
|
||
|
|
}
|
||
|
|
}
|