diff --git a/Cargo.lock b/Cargo.lock
index faa0e4c..52b8541 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -4,7 +4,7 @@ version = 4
[[package]]
name = "ads-agent"
-version = "0.2.1"
+version = "0.2.2"
dependencies = [
"ads-core",
"ads-management",
@@ -21,7 +21,7 @@ dependencies = [
[[package]]
name = "ads-client"
-version = "0.2.1"
+version = "0.2.2"
dependencies = [
"ads-core",
"anyhow",
@@ -32,7 +32,7 @@ dependencies = [
[[package]]
name = "ads-core"
-version = "0.2.1"
+version = "0.2.2"
dependencies = [
"anyhow",
"bytes",
@@ -51,7 +51,7 @@ dependencies = [
[[package]]
name = "ads-management"
-version = "0.2.1"
+version = "0.2.2"
dependencies = [
"ads-core",
"anyhow",
@@ -67,7 +67,7 @@ dependencies = [
[[package]]
name = "ads-usb"
-version = "0.2.1"
+version = "0.2.2"
dependencies = [
"anyhow",
"clap",
@@ -78,7 +78,7 @@ dependencies = [
[[package]]
name = "adsctl"
-version = "0.2.1"
+version = "0.2.2"
dependencies = [
"ads-core",
"ads-management",
diff --git a/Cargo.toml b/Cargo.toml
index 609193a..8ac89f0 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -3,7 +3,7 @@ members = ["crates/ads-core", "agent", "client", "usb", "crates/ads-management",
resolver = "2"
[workspace.package]
-version = "0.2.1"
+version = "0.2.2"
edition = "2021"
license = "MIT"
diff --git a/README.md b/README.md
index 3885df6..881ef12 100644
--- a/README.md
+++ b/README.md
@@ -244,3 +244,5 @@ Flutter 管理中心已迁移 Cupertino UI,设备按电脑归属分组,支
Windows 发布精简:Avalonia 合并托管程序集、保留原生库;Flutter 源码插件静态链接 MSVC CRT。`scripts/check-windows-crt.py` 使用 Python 标准库检查 PE 直接及延迟导入,防止缺失运行库。安装升级清理应用根目录旧 DLL,保留配置和独立工具目录。
+
+升级从 `Programs/TTSTD` 迁至 `Programs/TongTongStudio` 后,两个桌面客户端自动修复保存的工具路径,保留有效自定义路径及私有凭据。Flutter 在启动与连接前进行迁移和文件检查。
diff --git a/desktop/Ads.Desktop.Tests/ToolRelocationTests.cs b/desktop/Ads.Desktop.Tests/ToolRelocationTests.cs
new file mode 100644
index 0000000..033ce72
--- /dev/null
+++ b/desktop/Ads.Desktop.Tests/ToolRelocationTests.cs
@@ -0,0 +1,20 @@
+using Ads.Desktop;
+using Xunit;
+namespace Ads.Desktop.Tests;
+public class ToolRelocationTests {
+ [Fact] public void RelocatedManagedPathUsesCurrentBundle() {
+ var name="relocate-"+Guid.NewGuid().ToString("N");
+ var executable=name+(OperatingSystem.IsWindows()?".exe":"");
+ var bundled=Path.Combine(AppContext.BaseDirectory,executable);
+ try {
+ File.WriteAllText(bundled,"fixture");
+ var old="C:/Users/TT/AppData/Local/Programs/TTSTD/ADS-Avalonia/"+executable;
+ Assert.Equal(bundled,DesktopPaths.ResolveTool(old,name));
+ }finally{File.Delete(bundled);}
+ }
+ [Fact] public void ValidCustomToolIsPreserved() {
+ var file=Path.GetTempFileName();
+ try{Assert.Equal(Path.GetFullPath(file),DesktopPaths.ResolveTool(file,"adb"));}
+ finally{File.Delete(file);}
+ }
+}
diff --git a/desktop/Ads.Desktop/Ads.Desktop.csproj b/desktop/Ads.Desktop/Ads.Desktop.csproj
index cb079bb..187e9a5 100644
--- a/desktop/Ads.Desktop/Ads.Desktop.csproj
+++ b/desktop/Ads.Desktop/Ads.Desktop.csproj
@@ -1,4 +1,4 @@
- 0.2.1WinExenet8.0enableenable
+ 0.2.2WinExenet8.0enableenable
diff --git a/desktop/Ads.Desktop/DesktopConfiguration.cs b/desktop/Ads.Desktop/DesktopConfiguration.cs
index fbf81dc..5d29b45 100644
--- a/desktop/Ads.Desktop/DesktopConfiguration.cs
+++ b/desktop/Ads.Desktop/DesktopConfiguration.cs
@@ -104,8 +104,10 @@ public static class DesktopPaths
public static string ResolveTool(string value, string name)
{
value = Environment.ExpandEnvironmentVariables(value.Trim().Trim('"'));
- if (File.Exists(value)) return Path.GetFullPath(value);
- if (value == name || value == name + ".exe")
+ var installed = value.Replace('\\', '/');
+ var managed = System.Text.RegularExpressions.Regex.IsMatch(installed, @"/Programs/(TTSTD|TongTongStudio)/ADS-(Flutter|Avalonia)/", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
+ if (File.Exists(value) && !managed) return Path.GetFullPath(value);
+ if (managed || !File.Exists(value))
{
var found = FindTool(name);
if (File.Exists(found)) return Path.GetFullPath(found);
diff --git a/desktop/Ads.Desktop/MainViewModel.cs b/desktop/Ads.Desktop/MainViewModel.cs
index 8e940ce..604c7df 100644
--- a/desktop/Ads.Desktop/MainViewModel.cs
+++ b/desktop/Ads.Desktop/MainViewModel.cs
@@ -97,6 +97,18 @@ public partial class MainViewModel : ObservableObject, IDisposable
preferredDevice = settings.PreferredDevice;
}
catch (Exception error) { Log("读取配置失败,使用默认值:" + error.Message); }
+ if (File.Exists(settingsFile)) {
+ var changed=false;
+ string Repair(string value,string name) {
+ try {
+ var resolved=DesktopPaths.ResolveTool(value,name);
+ if(resolved!=value){changed=true;Log($"已更新 {name} 工具位置:{resolved}");}
+ return resolved;
+ } catch(InvalidOperationException) { return value; }
+ }
+ ClientPath=Repair(ClientPath,"ads-client");AdbPath=Repair(AdbPath,"adb");ScrcpyPath=Repair(ScrcpyPath,"scrcpy");
+ if(changed)PersistSelectedPaths();
+ }
var environmentToken = loadLocalCredentials ? Environment.GetEnvironmentVariable("ADS_CLIENT_TOKEN") : null;
if (!string.IsNullOrWhiteSpace(environmentToken))
{
diff --git a/desktop/README.md b/desktop/README.md
index 8403f18..1ce29a6 100644
--- a/desktop/README.md
+++ b/desktop/README.md
@@ -96,3 +96,5 @@ USB 会话后端已按操作系统选择:Windows 使用已签名 USBip 控制
桌面日志界面提供“打开日志文件夹”。Avalonia 与 Flutter 均按天保存日志,单文件达到 5 MiB 后滚动,每日最多 5 份,保留最近 14 天。设备列表显示所属电脑及 Agent。Windows 安装包默认安装到 `%LOCALAPPDATA%/Programs/TongTongStudio/ADS-{Edition}`;用户配置和日志位置保持兼容。升级保持原 AppId,安装目录不再自动沿用旧的 TTSTD 路径。
Windows 自包含发布把托管程序集打包到主程序,保留原生图形 DLL 和独立 Rust/ADB/scrcpy 工具;不启用反射裁剪,不要求安装 .NET,也不将全部应用压为单文件。发布使用全新暂存目录。`Ads.Desktop.exe --package-check` 可在隔离配置、无设备连接和不占用正式客户端互斥锁的条件下创建窗口后退出,用于验证发布包。
+
+升级安装目录后会修复保存的旧工具位置;有效自定义可执行文件保留。启动时将解析后的路径写回已有设置,避免仍使用已删除的 TTSTD 安装目录。
diff --git a/docs/verification.md b/docs/verification.md
index 3fadfae..ff59488 100644
--- a/docs/verification.md
+++ b/docs/verification.md
@@ -71,3 +71,9 @@ Port cleanup follow-up:
- Avalonia 实际发布包 `--package-check` 成功创建窗口并退出,未读取正式凭据、未建立设备连接;Flutter 6 个根目录 DLL 可由 Windows 加载。Avalonia 22 项、Flutter 27 项测试通过。未在全新 Windows 虚拟机执行本轮完整安装回归。
- 新版 Windows Setup 安装包和 Linux amd64 Avalonia/Agent deb 均为 0.2.1,带 SHA256 校验。Linux deb 元数据已验证;Flutter Linux 宿主仍未实现,本轮未生成 Flutter Linux 包。
- DLL 数量指安装目录根目录;tools/scrcpy 自带库保持完整。打包减少散落 DLL,不承诺安装程序体积同步减小。
+
+### 0.2.2:安装目录迁移后的工具启动修复
+
+- 现场 settings.json 中 client、adb、scrcpy 三项仍为 Programs/TTSTD/ADS-Flutter,且三文件已不存在;当前 TongTongStudio 安装目录中的工具存在,ads-client --version 与 adb version 可运行。已备份现场配置后修复三项路径,其他设置和凭据保持不变;已运行的旧 UI 需重启才能重新读取设置。
+- Flutter 新增 ToolPaths:启动及连接前解析、持久化当前工具位置,优先当前安装包,保留有效自定义工具。缺失工具在分配端口和建立租约之前报出修复方法,避免底层 ProcessException。投屏也解析 scrcpy/ADB 及工作目录。
+- Avalonia 同步旧路径回退、启动迁移及保存。Flutter 32 项测试、Dart 静态分析、Avalonia 24 项测试通过,实际发布包窗口启动检查 PACKAGE_CHECK_OK。并行编译压力下一次端口测试超时,完整复跑 24 项均通过。
diff --git a/flutter_manager/README.md b/flutter_manager/README.md
index f11278e..2375f33 100644
--- a/flutter_manager/README.md
+++ b/flutter_manager/README.md
@@ -137,3 +137,5 @@ USB ADB 连续 3 轮监控缺失(约 9 秒)、USB 后端退出或 scrcpy 以
桌面日志界面提供“打开日志文件夹”。Avalonia 与 Flutter 均按天保存日志,单文件达到 5 MiB 后滚动,每日最多 5 份,保留最近 14 天。设备列表显示所属电脑及 Agent。Windows 安装包默认安装到 `%LOCALAPPDATA%/Programs/TongTongStudio/ADS-{Edition}`;用户配置和日志位置保持兼容。升级保持原 AppId,安装目录不再自动沿用旧的 TTSTD 路径。
Windows 宿主、Flutter C++ 包装库和源码插件统一使用静态 MSVC CRT,保留 Flutter 引擎及插件 DLL。安装打包使用 `scripts/check-windows-crt.py`(Python 标准库 PE 导入及延迟导入检查),只附带实际需要的 MSVC 运行库及其传递依赖,缺失则拒绝发布;Rust 工具仍需的运行库不会被误删。
+
+工具位置由 `lib/data/tool_paths.dart`(Dart)统一解析:识别 TTSTD/TongTongStudio 旧安装路径,优先使用当前应用附带工具;有效自定义工具保持不变,失效路径可回退当前安装或 PATH。启动和每次连接时迁移并保存 client/adb/scrcpy 路径;缺少工具先提示重新安装或选择文件,尚未分配连接端口。用户配置与凭据位置不随安装目录变化。
diff --git a/flutter_manager/lib/data/manager_repository.dart b/flutter_manager/lib/data/manager_repository.dart
index bb71bea..2f22787 100644
--- a/flutter_manager/lib/data/manager_repository.dart
+++ b/flutter_manager/lib/data/manager_repository.dart
@@ -6,6 +6,7 @@ import 'package:path/path.dart' as p;
import 'windows_usb.dart';
import 'usb_recovery.dart';
+import 'tool_paths.dart';
class Settings {
String server = 'wss://ttstd.com/ads';
@@ -95,7 +96,8 @@ class ManagerRepository {
String token = '';
Directory? root;
late Directory storage;
- ManagerRepository(this.log);
+ final ToolPaths? paths;
+ ManagerRepository(this.log, {this.paths});
Future init() async {
storage = Directory(
@@ -138,29 +140,30 @@ class ManagerRepository {
jsonDecode(await saved.readAsString()) as Map,
);
}
+ await repairToolPaths();
token = Platform.environment['ADS_CLIENT_TOKEN'] ?? '';
if (token.isEmpty && await File(settings.credential).exists()) {
await importCredential();
}
}
- String findTool(String name) {
- final exe = Platform.isWindows ? '$name.exe' : name;
- final base = p.dirname(Platform.resolvedExecutable);
- final candidates = [
- p.join(base, exe),
- p.join(base, 'tools', 'scrcpy', exe),
- if (root != null) p.join(root!.path, 'bin', exe),
- if (root != null) p.join(root!.path, 'bin', 'tools', 'scrcpy', exe),
- for (final dir in (Platform.environment['PATH'] ?? '').split(
- Platform.isWindows ? ';' : ':',
- ))
- p.join(dir, exe),
- ];
- return candidates.firstWhere(
- (v) => File(v).existsSync(),
- orElse: () => exe,
- );
+ ToolPaths get toolPaths => paths ?? ToolPaths(projectRoot: root?.path);
+ String findTool(String name) => toolPaths.resolve(name);
+ Future repairToolPaths() async {
+ var changed = false;
+ void repair(String name, String value, void Function(String) assign) {
+ final resolved = toolPaths.resolve(name, configured: value);
+ if (resolved != value) {
+ assign(resolved);
+ changed = true;
+ log('已更新 $name 工具位置:$resolved');
+ }
+ }
+
+ repair('ads-client', settings.client, (v) => settings.client = v);
+ repair('adb', settings.adb, (v) => settings.adb = v);
+ repair('scrcpy', settings.scrcpy, (v) => settings.scrcpy = v);
+ if (changed) await save();
}
Future save() =>
@@ -292,6 +295,12 @@ class ManagerRepository {
..['NO_COLOR'] = '1';
Future run(String exe, List args) async {
+ final name = p
+ .basename(exe)
+ .replaceFirst(RegExp(r'\.exe$', caseSensitive: false), '');
+ if (['ads-client', 'ads-usb', 'adsctl', 'adb', 'scrcpy'].contains(name)) {
+ exe = toolPaths.resolve(name, configured: exe, required: true);
+ }
final proc = await Process.start(
exe,
args,
@@ -334,6 +343,17 @@ class ManagerRepository {
if (token.length < 32) {
throw const FormatException('请先导入凭据');
}
+ await repairToolPaths();
+ settings.client = toolPaths.resolve(
+ 'ads-client',
+ configured: settings.client,
+ required: true,
+ );
+ settings.adb = toolPaths.resolve(
+ 'adb',
+ configured: settings.adb,
+ required: true,
+ );
final usbMode = settings.usbMode;
final usbip = settings.usbip;
if (usbMode) {
@@ -343,7 +363,7 @@ class ManagerRepository {
if (!await File(usbip).exists()) {
throw StateError('找不到 usbip.exe,请检查配置路径');
}
- await run(findTool('ads-usb'), ['--version']);
+ await run(toolPaths.resolve('ads-usb', required: true), ['--version']);
}
final port = await allocatePort(15555, 18000);
int? usbPort;
@@ -655,8 +675,18 @@ class ManagerRepository {
String id, {
bool embedded = false,
}) {
+ final scrcpy = toolPaths.resolve(
+ 'scrcpy',
+ configured: settings.scrcpy,
+ required: true,
+ );
+ final selectedAdb = toolPaths.resolve(
+ 'adb',
+ configured: adb,
+ required: true,
+ );
return Process.start(
- settings.scrcpy,
+ scrcpy,
[
'--serial',
endpoint,
@@ -675,8 +705,8 @@ class ManagerRepository {
'60',
'--no-audio',
],
- workingDirectory: p.dirname(p.absolute(settings.scrcpy)),
- environment: environment()..['ADB'] = adb,
+ workingDirectory: p.dirname(scrcpy),
+ environment: environment()..['ADB'] = selectedAdb,
includeParentEnvironment: false,
);
}
diff --git a/flutter_manager/lib/data/tool_paths.dart b/flutter_manager/lib/data/tool_paths.dart
new file mode 100644
index 0000000..4cfcc62
--- /dev/null
+++ b/flutter_manager/lib/data/tool_paths.dart
@@ -0,0 +1,46 @@
+import 'dart:io';
+
+import 'package:path/path.dart' as p;
+
+/// Resolves relocated bundled tools while preserving valid custom executables.
+class ToolPaths {
+ ToolPaths({String? base, this.projectRoot, String? searchPath})
+ : base = base ?? p.dirname(Platform.resolvedExecutable),
+ searchPath = searchPath ?? Platform.environment['PATH'] ?? '';
+ final String base, searchPath;
+ final String? projectRoot;
+
+ static bool managed(String value) =>
+ RegExp(r'/programs/(?:ttstd|tongtongstudio)/ads-(?:flutter|avalonia)/')
+ .hasMatch(value.replaceAll(r'\', '/').toLowerCase());
+
+ String resolve(String name, {String configured = '', bool required = false}) {
+ final exe = Platform.isWindows ? '$name.exe' : name;
+ final selected = configured.trim().replaceAll(RegExp(r'^"|"$'), '');
+ if (selected.isNotEmpty &&
+ !managed(selected) &&
+ File(selected).existsSync()) {
+ return p.absolute(selected);
+ }
+ final candidates = [
+ p.join(base, exe),
+ p.join(base, 'tools', 'scrcpy', exe),
+ if (projectRoot != null) p.join(projectRoot!, 'bin', exe),
+ if (projectRoot != null)
+ p.join(projectRoot!, 'bin', 'tools', 'scrcpy', exe),
+ for (final folder in searchPath.split(Platform.isWindows ? ';' : ':'))
+ if (folder.trim().isNotEmpty)
+ p.join(folder.trim().replaceAll('"', ''), exe),
+ ];
+ for (final candidate in candidates) {
+ if (File(candidate).existsSync()) return p.absolute(candidate);
+ }
+ if (required) {
+ throw FileSystemException(
+ '找不到 $exe。请重新安装完整安装包,或在连接配置中选择有效的工具文件。当前程序目录:$base',
+ selected.isEmpty ? exe : selected,
+ );
+ }
+ return selected.isNotEmpty ? selected : exe;
+ }
+}
diff --git a/flutter_manager/pubspec.yaml b/flutter_manager/pubspec.yaml
index 4eb8cb1..aece679 100644
--- a/flutter_manager/pubspec.yaml
+++ b/flutter_manager/pubspec.yaml
@@ -16,7 +16,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
# In Windows, build-name is used as the major, minor, and patch parts
# of the product and file versions while build-number is used as the build suffix.
-version: 0.2.1+2
+version: 0.2.2+3
environment:
sdk: ^3.14.0
diff --git a/flutter_manager/test/tool_paths_test.dart b/flutter_manager/test/tool_paths_test.dart
new file mode 100644
index 0000000..9fc2b86
--- /dev/null
+++ b/flutter_manager/test/tool_paths_test.dart
@@ -0,0 +1,95 @@
+import 'dart:convert';
+import 'dart:io';
+
+import 'package:flutter_test/flutter_test.dart';
+import 'package:path/path.dart' as p;
+import 'package:ads_manager/data/tool_paths.dart';
+import 'package:ads_manager/data/manager_repository.dart';
+
+void main() {
+ group('relocated tool paths', () {
+ late Directory temp;
+ late String bundle;
+ late ToolPaths paths;
+ String exe(String name) => Platform.isWindows ? '$name.exe' : name;
+ String create(String path) {
+ final file = File(path);
+ file.parent.createSync(recursive: true);
+ file.writeAsStringSync('fixture');
+ return file.path;
+ }
+
+ setUp(() {
+ temp = Directory.systemTemp.createTempSync('ads-relocate');
+ bundle = p.join(temp.path, 'Programs', 'TongTongStudio', 'ADS-Flutter');
+ paths = ToolPaths(base: bundle, searchPath: '');
+ });
+ tearDown(() => temp.deleteSync(recursive: true));
+ for (final oldExists in [false, true]) {
+ test('migrates old install, old file exists=$oldExists', () {
+ final old = p.join(
+ temp.path,
+ 'Programs',
+ 'TTSTD',
+ 'ADS-Flutter',
+ exe('ads-client'),
+ );
+ if (oldExists) create(old);
+ final current = create(p.join(bundle, exe('ads-client')));
+ expect(
+ paths.resolve('ads-client', configured: old, required: true),
+ current,
+ );
+ });
+ }
+ test('preserves a valid custom executable', () {
+ create(p.join(bundle, exe('adb')));
+ final custom = create(p.join(temp.path, 'SDK', exe('adb')));
+ expect(paths.resolve('adb', configured: custom), custom);
+ });
+ test('migration persists tools and preserves other settings', () async {
+ final repository = ManagerRepository((_) {}, paths: paths)
+ ..storage = temp;
+ repository.settings.credential = 'private-client.env';
+ repository.settings.usbMode = true;
+ repository.settings.client = p.join(
+ temp.path,
+ 'Programs',
+ 'TTSTD',
+ 'ADS-Flutter',
+ exe('ads-client'),
+ );
+ create(p.join(bundle, exe('ads-client')));
+ create(p.join(bundle, 'tools', 'scrcpy', exe('adb')));
+ create(p.join(bundle, 'tools', 'scrcpy', exe('scrcpy')));
+ await repository.repairToolPaths();
+ final saved = jsonDecode(
+ File(p.join(temp.path, 'settings.json')).readAsStringSync(),
+ );
+ expect(saved['client'], p.join(bundle, exe('ads-client')));
+ expect(saved['adb'], p.join(bundle, 'tools', 'scrcpy', exe('adb')));
+ expect(saved['credential'], 'private-client.env');
+ expect(saved['usbMode'], true);
+ });
+ test(
+ 'missing tool fails before allocating ports or creating sessions',
+ () async {
+ final repository = ManagerRepository((_) {}, paths: paths)
+ ..storage = temp
+ ..token = 'a' * 32;
+ await expectLater(
+ repository.connect('phone'),
+ throwsA(
+ isA().having(
+ (e) => e.message,
+ 'message',
+ contains('重新安装'),
+ ),
+ ),
+ );
+ expect(repository.reservedPorts, isEmpty);
+ expect(repository.sessions, isEmpty);
+ },
+ );
+ });
+}