905086
2026-11-08 b1e9aef9d2698cf27eccde2f131eae3c4e6a65d0
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;