From 7c8e509c95c2af0c0d076b13fbbc5aa63a06cb69 Mon Sep 17 00:00:00 2001
From: 905086 <k2049@qq.com>
Date: Sat, 07 Nov 2026 19:35:38 +0800
Subject: [PATCH] chore: 删除无用的测试工具及相关文件

---
 fluttergamebox/lib/store/app_state.dart |   50 +++++++++++++++++++++++++++++++++++++++++++++++---
 1 files changed, 47 insertions(+), 3 deletions(-)

diff --git a/fluttergamebox/lib/store/app_state.dart b/fluttergamebox/lib/store/app_state.dart
index c9b9af0..345dd96 100644
--- a/fluttergamebox/lib/store/app_state.dart
+++ b/fluttergamebox/lib/store/app_state.dart
@@ -91,6 +91,7 @@
   final String title;
   final List<DownloadTaskFile> files;
   final String launchExe; // 启动程序相对路径(相对游戏安装目录)
+  final bool isTool; // 是否为工具下载任务(工具与游戏id独立,避免误判)
   double speed = 0; // bytes/s
   bool autoShutdown = false;
   bool paused = false;
@@ -106,7 +107,8 @@
       {required this.gameId,
       required this.title,
       required List<DownloadTaskFile> files,
-      this.launchExe = ''})
+      this.launchExe = '',
+      this.isTool = false})
       : files = files;
 
   double get totalBytes =>
@@ -146,10 +148,19 @@
     notifyListeners();
   }
 
-  /// 清除指定游戏已完成的任务记录(卸载后不再视为已安装)
+  /// 清除指定游戏已完成的任务记录(卸载后不再视为已安装;不影响工具任务)
   void clearFinishedTask(int gameId) {
     final t = activeTask;
-    if (t != null && t.gameId == gameId && t.finished) {
+    if (t != null && !t.isTool && t.gameId == gameId && t.finished) {
+      activeTask = null;
+      notifyListeners();
+    }
+  }
+
+  /// 清除指定工具已完成的任务记录(工具卸载后不再视为已安装)
+  void clearFinishedToolTask(int toolId) {
+    final t = activeTask;
+    if (t != null && t.isTool && t.gameId == toolId && t.finished) {
       activeTask = null;
       notifyListeners();
     }
@@ -188,6 +199,39 @@
     _runLoop();
   }
 
+  /// 工具安装:下载压缩包并解压(与游戏流程一致,无需会员校验)
+  Future<void> startToolDownload(Tool tool) async {
+    final res = await ApiService.toolDownloadInfo(tool.id);
+    if (res['code'] != 0) {
+      throw res['msg'] ?? '获取下载信息失败';
+    }
+    final List<dynamic> fileList = _parseFiles(res['data']['files']);
+    final dlPath = await AppPrefs.getDownloadPath();
+    if (dlPath.isEmpty) {
+      throw '请先在右上角菜单中设置下载安装路径';
+    }
+    if (fileList.isEmpty) {
+      throw '该工具暂无下载文件,请联系管理员上传压缩包';
+    }
+    final tasks = <DownloadTaskFile>[];
+    for (final f in fileList) {
+      tasks.add(DownloadTaskFile(
+          name: f['name'] ?? 'file',
+          url: f['url'] ?? '',
+          totalBytes: _parseSizeToBytes(f['size'] ?? '0 B')));
+    }
+    final task = DownloadTask(
+        gameId: tool.id,
+        title: tool.name,
+        files: tasks,
+        launchExe: (res['data']['launch_exe'] ?? '') as String,
+        isTool: true);
+    this.tasks.insert(0, task);
+    activeTask = task;
+    notifyListeners();
+    _runLoop();
+  }
+
   /// 服务端files字段为JSON字符串或数组,统一解析为List
   List<dynamic> _parseFiles(dynamic raw) {
     if (raw is List) return raw;

--
Gitblit v1.10.0