1.3.5:更名 EDC|易得设计,空白启动首页 + 可扩展图元库识别,架构图大版本
- 品牌:更名 EDC|易得设计(exe/安卓/仓库 EasyDesignCollection;旧地址 301 兼容老客户端更新) - 首页:空白启动 + 六模块「新建文档」选择 + 最近打开;品牌菜单重做 - 架构图:手绘识别统一图形;Visio 式可扩展图元库(导入 / 存为图元 / 分类折叠 / 手绘匹配 / 多笔回溯组合);识别后图形尺寸编辑(宽高长径 + 画布标注 + 双击改值); IT 系统图元;mm 标尺(右轴数值 / 实线游标 / A0 默认画布);图层、F8 正交 / F10 极轴、 对齐均布;连线端点换绑重吸附;DXF / SVG / PNG 导出;缩小时画布溢出到侧栏的裁剪修复 - 时序图:分文件保存(*.seq.json / *.arch.json;旧 .edc.json 兼容) - 路径:运行时目录迁移 %APPDATA%/EDC;素材库 library/;安卓 Documents/EDC - 清理:参数化草图入口冻结;Windows Ink 原生桥移除;dist/ 退役 - 构建:exe + APK 双端同步(1.3.5+26);发布脚本切换 release/ 新目录结构
This commit is contained in:
@@ -6,6 +6,8 @@
|
||||
///
|
||||
/// 保存位置可配置:基础目录(Documents / Download / Pictures)+ 子文件夹名,
|
||||
/// 设置保存在应用私有目录的 `save_location.json`,跨会话生效。
|
||||
/// 默认目录为 `Documents/EDC`;旧目录 `Documents/SequenceDiagram` 在
|
||||
/// 打开对话框中一并列出(兼容读取,新文件一律写入 EDC)。
|
||||
///
|
||||
/// 桌面平台不可用([isAvailable] 为 false),此时应使用应用内文件浏览器。
|
||||
library;
|
||||
@@ -30,6 +32,12 @@ class AndroidDocs {
|
||||
/// 可选的基础目录:文档 / 下载 / 图片。
|
||||
static const List<String> baseOptions = <String>['documents', 'downloads', 'pictures'];
|
||||
|
||||
/// 默认子文件夹名(品牌 EDC)。
|
||||
static const String defaultFolder = 'EDC';
|
||||
|
||||
/// 旧版子文件夹名(兼容读取;新文件一律写入 [defaultFolder])。
|
||||
static const String legacyFolder = 'SequenceDiagram';
|
||||
|
||||
/// 基础目录的展示名。
|
||||
static String baseLabel(String base) => switch (base) {
|
||||
'downloads' => 'Download',
|
||||
@@ -52,12 +60,12 @@ class AndroidDocs {
|
||||
final Map<String, dynamic> j = jsonDecode(_settingsFile.readAsStringSync()) as Map<String, dynamic>;
|
||||
_settings = <String, String>{
|
||||
'base': j['base'] as String? ?? 'documents',
|
||||
'folder': j['folder'] as String? ?? 'SequenceDiagram',
|
||||
'folder': j['folder'] as String? ?? defaultFolder,
|
||||
};
|
||||
}
|
||||
} catch (_) {}
|
||||
if (_settings.isEmpty) {
|
||||
_settings = <String, String>{'base': 'documents', 'folder': 'SequenceDiagram'};
|
||||
_settings = <String, String>{'base': 'documents', 'folder': defaultFolder};
|
||||
}
|
||||
return _settings;
|
||||
}
|
||||
@@ -66,7 +74,7 @@ class AndroidDocs {
|
||||
static Future<void> saveSettings(String base, String folder) async {
|
||||
_settings = <String, String>{
|
||||
'base': baseOptions.contains(base) ? base : 'documents',
|
||||
'folder': folder.trim().isEmpty ? 'SequenceDiagram' : folder.trim(),
|
||||
'folder': folder.trim().isEmpty ? defaultFolder : folder.trim(),
|
||||
};
|
||||
try {
|
||||
await _settingsFile.parent.create(recursive: true);
|
||||
@@ -74,10 +82,31 @@ class AndroidDocs {
|
||||
} catch (_) {}
|
||||
}
|
||||
|
||||
/// 当前保存位置的展示描述(如 `Documents/SequenceDiagram`)。
|
||||
/// 当前保存位置的展示描述(如 `Documents/EDC`)。
|
||||
static String location() {
|
||||
final Map<String, String> s = settings();
|
||||
return '${baseLabel(s['base'] ?? 'documents')}/${s['folder'] ?? 'SequenceDiagram'}';
|
||||
return '${baseLabel(s['base'] ?? 'documents')}/${s['folder'] ?? defaultFolder}';
|
||||
}
|
||||
|
||||
/// 是否需要兼容旧目录(在默认位置下自动列出 Documents/SequenceDiagram)。
|
||||
static bool _useLegacy() {
|
||||
final Map<String, String> s = settings();
|
||||
return (s['base'] ?? 'documents') == 'documents' &&
|
||||
(s['folder'] ?? defaultFolder) == defaultFolder;
|
||||
}
|
||||
|
||||
/// 列出指定基础目录 + 文件夹下的文件。
|
||||
static Future<List<Map<String, dynamic>>> _listOne(
|
||||
String base, String folder) async {
|
||||
final Object? r =
|
||||
await _channel.invokeMethod<Object?>('listFiles', <String, Object?>{
|
||||
'base': base,
|
||||
'folder': folder,
|
||||
});
|
||||
final List<Object?> list = (r as List<Object?>?) ?? const <Object?>[];
|
||||
return list
|
||||
.map((Object? e) => Map<String, dynamic>.from(e as Map<Object?, Object?>))
|
||||
.toList();
|
||||
}
|
||||
|
||||
/// 保存文件到配置的公共目录,返回展示位置。
|
||||
@@ -94,19 +123,33 @@ class AndroidDocs {
|
||||
}
|
||||
|
||||
/// 列出配置目录下的文件(`[{name, size}]`,新在前)。
|
||||
///
|
||||
/// 默认位置额外合并旧目录(Documents/SequenceDiagram)中的文件,
|
||||
/// 同名以新目录为准(兼容旧版本保存的文档)。
|
||||
static Future<List<Map<String, dynamic>>> listFiles() async {
|
||||
final Map<String, String> s = settings();
|
||||
final Object? r = await _channel.invokeMethod<Object?>('listFiles', <String, Object?>{
|
||||
'base': s['base'],
|
||||
'folder': s['folder'],
|
||||
});
|
||||
final List<Object?> list = (r as List<Object?>?) ?? const <Object?>[];
|
||||
return list
|
||||
.map((Object? e) => Map<String, dynamic>.from(e as Map<Object?, Object?>))
|
||||
.toList();
|
||||
final List<Map<String, dynamic>> primary =
|
||||
await _listOne(s['base'] ?? 'documents', s['folder'] ?? defaultFolder);
|
||||
if (!_useLegacy()) return primary;
|
||||
final List<Map<String, dynamic>> legacy =
|
||||
await _listOne('documents', legacyFolder);
|
||||
final Set<String> names = <String>{
|
||||
for (final Map<String, dynamic> f in primary) (f['name'] as String?) ?? '',
|
||||
};
|
||||
final List<Map<String, dynamic>> out = <Map<String, dynamic>>[...primary];
|
||||
for (final Map<String, dynamic> f in legacy) {
|
||||
final String n = (f['name'] as String?) ?? '';
|
||||
if (n.isNotEmpty && !names.contains(n)) {
|
||||
out.add(f);
|
||||
names.add(n);
|
||||
}
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
/// 读取配置目录下的文件内容;不存在返回 null。
|
||||
///
|
||||
/// 默认位置下依次尝试新目录与旧目录(兼容读取)。
|
||||
static Future<Uint8List?> readFile(String name) async {
|
||||
final Map<String, String> s = settings();
|
||||
final Object? r = await _channel.invokeMethod<Object?>('readFile', <String, Object?>{
|
||||
@@ -114,8 +157,15 @@ class AndroidDocs {
|
||||
'base': s['base'],
|
||||
'folder': s['folder'],
|
||||
});
|
||||
if (r == null) return null;
|
||||
return r as Uint8List;
|
||||
if (r != null) return r as Uint8List;
|
||||
if (!_useLegacy()) return null;
|
||||
final Object? legacy =
|
||||
await _channel.invokeMethod<Object?>('readFile', <String, Object?>{
|
||||
'name': name,
|
||||
'base': 'documents',
|
||||
'folder': legacyFolder,
|
||||
});
|
||||
return legacy as Uint8List?;
|
||||
}
|
||||
|
||||
/// 用系统浏览器打开网址(官网入口;安卓经原生 Intent)。
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
/// 应用数据路径统一入口:运行时目录(由 [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 (_) {}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,146 @@
|
||||
/// 最近打开的文档记录(最多 [RecentStore.maxEntries] 条,按时间倒序)。
|
||||
///
|
||||
/// 存储位置:应用数据目录(桌面 `%APPDATA%/EDC/recent.json`,
|
||||
/// 安卓为应用内部目录;与自动快照同根)。路径书写只读展示,不保证文件仍存在,
|
||||
/// 失效条目在打开失败时自动移除。
|
||||
library;
|
||||
|
||||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
|
||||
import 'storage.dart';
|
||||
|
||||
/// 最近打开条目。
|
||||
class RecentDoc {
|
||||
/// 构造。
|
||||
const RecentDoc({
|
||||
required this.path,
|
||||
required this.moduleId,
|
||||
required this.name,
|
||||
required this.atMs,
|
||||
});
|
||||
|
||||
/// 文件路径。
|
||||
final String path;
|
||||
|
||||
/// 模块 id(sequence / architecture / …)。
|
||||
final String moduleId;
|
||||
|
||||
/// 展示名(一般取文件名)。
|
||||
final String name;
|
||||
|
||||
/// 打开时间(毫秒时间戳)。
|
||||
final int atMs;
|
||||
|
||||
/// 打开时间。
|
||||
DateTime get at => DateTime.fromMillisecondsSinceEpoch(atMs);
|
||||
|
||||
/// 序列化。
|
||||
Map<String, dynamic> toJson() => <String, dynamic>{
|
||||
'path': path,
|
||||
'moduleId': moduleId,
|
||||
'name': name,
|
||||
'at': atMs,
|
||||
};
|
||||
|
||||
/// 反序列化(无效返回 null)。
|
||||
static RecentDoc? fromJson(dynamic raw) {
|
||||
if (raw is! Map<String, dynamic>) return null;
|
||||
final String path = raw['path'] as String? ?? '';
|
||||
final String moduleId = raw['moduleId'] as String? ?? '';
|
||||
if (path.isEmpty || moduleId.isEmpty) return null;
|
||||
return RecentDoc(
|
||||
path: path,
|
||||
moduleId: moduleId,
|
||||
name: raw['name'] as String? ?? path.split(RegExp(r'[\\/]')).last,
|
||||
atMs: (raw['at'] as num?)?.toInt() ?? 0,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// 最近打开存储(静态工具类)。
|
||||
class RecentStore {
|
||||
RecentStore._();
|
||||
|
||||
/// 最多保留条数。
|
||||
static const int maxEntries = 15;
|
||||
|
||||
static File _file(String appDir) =>
|
||||
File('$appDir${Platform.pathSeparator}recent.json');
|
||||
|
||||
/// 读取列表(文件缺失 / 解析失败返回空列表,不抛异常)。
|
||||
static Future<List<RecentDoc>> load() async {
|
||||
try {
|
||||
await Storage.instance.init();
|
||||
final File f = _file(Storage.instance.appDir.path);
|
||||
if (!await f.exists()) return <RecentDoc>[];
|
||||
final dynamic raw = jsonDecode(await f.readAsString());
|
||||
if (raw is! List<dynamic>) return <RecentDoc>[];
|
||||
final List<RecentDoc> out = <RecentDoc>[];
|
||||
for (final dynamic e in raw) {
|
||||
final RecentDoc? r = RecentDoc.fromJson(e);
|
||||
if (r != null) out.add(r);
|
||||
}
|
||||
out.sort((RecentDoc a, RecentDoc b) => b.atMs.compareTo(a.atMs));
|
||||
return out;
|
||||
} catch (_) {
|
||||
return <RecentDoc>[];
|
||||
}
|
||||
}
|
||||
|
||||
/// 记录一次打开 / 保存(去重后置顶,超限裁剪)。
|
||||
static Future<void> remember({
|
||||
required String path,
|
||||
required String moduleId,
|
||||
String? name,
|
||||
}) async {
|
||||
if (path.isEmpty || moduleId.isEmpty) return;
|
||||
final List<RecentDoc> cur = await load();
|
||||
cur.removeWhere((RecentDoc r) => r.path == path);
|
||||
cur.insert(
|
||||
0,
|
||||
RecentDoc(
|
||||
path: path,
|
||||
moduleId: moduleId,
|
||||
name: (name == null || name.isEmpty)
|
||||
? path.split(RegExp(r'[\\/]')).last
|
||||
: name,
|
||||
atMs: DateTime.now().millisecondsSinceEpoch,
|
||||
),
|
||||
);
|
||||
while (cur.length > maxEntries) {
|
||||
cur.removeLast();
|
||||
}
|
||||
await _save(cur);
|
||||
}
|
||||
|
||||
/// 移除一条(打开失败时清理失效条目)。
|
||||
static Future<void> remove(String path) async {
|
||||
final List<RecentDoc> cur = await load();
|
||||
cur.removeWhere((RecentDoc r) => r.path == path);
|
||||
await _save(cur);
|
||||
}
|
||||
|
||||
/// 清空全部记录。
|
||||
static Future<void> clear() async {
|
||||
await _save(<RecentDoc>[]);
|
||||
}
|
||||
|
||||
static Future<void> _save(List<RecentDoc> list) async {
|
||||
try {
|
||||
await Storage.instance.init();
|
||||
final File f = _file(Storage.instance.appDir.path);
|
||||
if (!await f.parent.exists()) {
|
||||
await f.parent.create(recursive: true);
|
||||
}
|
||||
await f.writeAsString(
|
||||
jsonEncode(<Map<String, dynamic>>[
|
||||
for (final RecentDoc r in list) r.toJson(),
|
||||
]),
|
||||
flush: true,
|
||||
);
|
||||
} catch (_) {
|
||||
// 最近列表写入失败不影响主流程。
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,11 @@
|
||||
/// 持久化层:负责项目文件的读写、自动保存与崩溃恢复。
|
||||
///
|
||||
/// 存储布局(位于用户 AppData/LocalAppData 下的 `SequenceDiagramStudio`):
|
||||
/// 存储布局(位于用户 AppData/LocalAppData 下的 `EDC`;旧目录
|
||||
/// `SequenceDiagramStudio` 首次启动时自动复制迁移,不改写旧目录):
|
||||
/// - `autosave/current.seq.json`:最近一次项目快照;
|
||||
/// - `autosave/session.json`:会话元数据(来源路径、是否干净、更新时间);
|
||||
/// - `recent.json`:最近打开列表(见 `recent_store.dart`);
|
||||
/// - `library/`:用户素材库(符号 / 图片 / 模板,见 `app_paths.dart`);
|
||||
/// - `<项目路径>.bak`:保存前自动生成的备份。
|
||||
///
|
||||
/// 与上层关系:AppController 通过单例 [Storage.instance] 调用自动保存与保存;
|
||||
@@ -73,13 +76,29 @@ class Storage {
|
||||
/// 目录优先级:`APPDATA` > `LOCALAPPDATA` > 系统临时目录;随后创建
|
||||
/// `autosave` 子目录。副作用:设置 [appDir]/[autosaveDir]/[currentFile]/
|
||||
/// [sessionFile] 并置 [_inited]。
|
||||
///
|
||||
/// 迁移:品牌更名(EDC)后首次启动,若旧目录 `SequenceDiagramStudio`
|
||||
/// 存在且新目录尚无自动快照,则**复制**旧内容(不改写旧目录)。
|
||||
Future<void> init() async {
|
||||
if (_inited) return;
|
||||
final String base = Platform.environment['APPDATA'] ??
|
||||
Platform.environment['LOCALAPPDATA'] ??
|
||||
Directory.systemTemp.path;
|
||||
appDir = Directory('$base${Platform.pathSeparator}SequenceDiagramStudio');
|
||||
final Directory legacy =
|
||||
Directory('$base${Platform.pathSeparator}SequenceDiagramStudio');
|
||||
appDir = Directory('$base${Platform.pathSeparator}EDC');
|
||||
autosaveDir = Directory('${appDir.path}${Platform.pathSeparator}autosave');
|
||||
// 一次性迁移(失败不阻塞启动)。
|
||||
try {
|
||||
final Directory newAuto = autosaveDir;
|
||||
final Directory oldAuto =
|
||||
Directory('${legacy.path}${Platform.pathSeparator}autosave');
|
||||
if (await legacy.exists() &&
|
||||
!await newAuto.exists() &&
|
||||
await oldAuto.exists()) {
|
||||
await _copyDir(oldAuto, newAuto);
|
||||
}
|
||||
} catch (_) {}
|
||||
currentFile = File('${autosaveDir.path}${Platform.pathSeparator}current.seq.json');
|
||||
sessionFile = File('${autosaveDir.path}${Platform.pathSeparator}session.json');
|
||||
if (!await autosaveDir.exists()) {
|
||||
@@ -88,6 +107,23 @@ class Storage {
|
||||
_inited = true;
|
||||
}
|
||||
|
||||
/// 递归复制目录(迁移用;已存在的目标文件会被覆盖)。
|
||||
static Future<void> _copyDir(Directory from, Directory to) async {
|
||||
await to.create(recursive: true);
|
||||
await for (final FileSystemEntity e
|
||||
in from.list(recursive: true, followLinks: false)) {
|
||||
final String rel = e.path.substring(from.path.length);
|
||||
final String dest = '${to.path}$rel';
|
||||
if (e is File) {
|
||||
final File f = File(dest);
|
||||
await f.parent.create(recursive: true);
|
||||
await e.copy(dest);
|
||||
} else if (e is Directory) {
|
||||
await Directory(dest).create(recursive: true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// 写入自动保存快照与会话元数据。
|
||||
///
|
||||
/// 参数 [project]:项目;[projectPath]:来源文件路径;[clean]:是否已正常
|
||||
@@ -208,9 +244,13 @@ class Storage {
|
||||
|
||||
/// 将项目保存到 [path]。
|
||||
///
|
||||
/// [includeArch] 为 false 时写出**不含架构图部分**的时序图文档
|
||||
/// (`*.seq.json`);架构图单独保存为 `*.arch.json`。
|
||||
///
|
||||
/// 流程:初始化 -> 备份已有文件 -> 确保父目录存在 -> 写入项目 JSON ->
|
||||
/// 同步写自动保存(标记为干净)。返回保存路径。
|
||||
Future<String> saveProject(String path, Project project) async {
|
||||
Future<String> saveProject(String path, Project project,
|
||||
{bool includeArch = false}) async {
|
||||
await init();
|
||||
// 1) 覆盖前先备份,防止写坏原文件。
|
||||
await backupExisting(path);
|
||||
@@ -221,7 +261,7 @@ class Storage {
|
||||
await parent.create(recursive: true);
|
||||
}
|
||||
// 3) 写入项目并 flush;随后把自动保存标记为干净。
|
||||
await target.writeAsString(project.encode(), flush: true);
|
||||
await target.writeAsString(project.encode(includeArch: includeArch), flush: true);
|
||||
await writeAutosave(project, projectPath: path, clean: true);
|
||||
return path;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user