From 579dc144ec238e19411df8bb9967d34ffa29cb99 Mon Sep 17 00:00:00 2001 From: xkeyC <3334969096@qq.com> Date: Fri, 13 Oct 2023 22:18:02 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=B7=A5=E5=85=B7=E5=8A=A0?= =?UTF-8?q?=E8=BD=BD=E9=80=9F=E5=BA=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/ui/tools/tools_ui.dart | 14 +++- lib/ui/tools/tools_ui_model.dart | 113 +++++++++++++++++++------------ 2 files changed, 83 insertions(+), 44 deletions(-) diff --git a/lib/ui/tools/tools_ui.dart b/lib/ui/tools/tools_ui.dart index b246220..75cd92a 100644 --- a/lib/ui/tools/tools_ui.dart +++ b/lib/ui/tools/tools_ui.dart @@ -58,9 +58,21 @@ class ToolsUI extends BaseUI { crossAxisCount: 3, mainAxisSpacing: 12, crossAxisSpacing: 12, - itemCount: model.items.length, + itemCount: (model.isItemLoading) + ? model.items.length + 1 + : model.items.length, shrinkWrap: true, itemBuilder: (context, index) { + if (index == model.items.length) { + return Container( + width: 300, + height: 200, + decoration: BoxDecoration( + borderRadius: BorderRadius.circular(12), + color: FluentTheme.of(context).cardColor, + ), + child: makeLoading(context)); + } final item = model.items[index]; return Container( width: 300, diff --git a/lib/ui/tools/tools_ui_model.dart b/lib/ui/tools/tools_ui_model.dart index c11c10c..77c3aac 100644 --- a/lib/ui/tools/tools_ui_model.dart +++ b/lib/ui/tools/tools_ui_model.dart @@ -29,27 +29,16 @@ class ToolsUIModel extends BaseUIModel { var items = <_ToolsItemData>[]; + bool isItemLoading = false; + @override Future loadData({bool skipPathScan = false}) async { items.clear(); notifyListeners(); - if (!skipPathScan) { await reScanPath(); } try { - final nvmePatchStatus = await SystemHelper.checkNvmePatchStatus(); - - final gameShaderCachePath = await SCLoggerHelper.getShaderCachePath(); - - double logPathLen = 0; - try { - logPathLen = - (await File(await SCLoggerHelper.getLogFilePath() ?? "").length()) / - 1024 / - 1024; - } catch (_) {} - items = [ _ToolsItemData( "systeminfo", @@ -78,30 +67,53 @@ class ToolsUIModel extends BaseUIModel { "在某些情况下 RSI启动器 无法正确获得管理员权限,您可尝试使用该功能以管理员模式运行启动器。", const Icon(FluentIcons.admin, size: 28), onTap: _adminRSILauncher, - ), - _ToolsItemData( - "clean_shaders", - "清理着色器缓存", - "若游戏画面出现异常或版本更新后可使用本工具清理过期的着色器(当大于500M时,建议清理) \n\n缓存大小:${((await SystemHelper.getDirLen(gameShaderCachePath ?? "", skipPath: [ - "$gameShaderCachePath\\Crashes" - ])) / 1024 / 1024).toStringAsFixed(4)} MB", - const Icon(FontAwesomeIcons.shapes, size: 28), - onTap: _cleanShaderCache, - ), - _ToolsItemData( - "rsilauncher_log_fix", - "RSI Launcher Log 修复", - "在某些情况下 RSI启动器 的 log 文件会损坏,导致无法完成问题扫描,使用此工具清理损坏的 log 文件。\n\n当前日志文件大小:${(logPathLen.toStringAsFixed(4))} MB", - const Icon(FontAwesomeIcons.bookBible, size: 28), - onTap: _rsiLogFix, - ), - _ToolsItemData( - "rsilauncher_log_select", - "RSI Launcher Log 查看", - "打开 RSI启动器 Log文件 所在文件夹", - const Icon(FontAwesomeIcons.bookBible, size: 28), - onTap: _selectLog, - ), + ) + ]; + isItemLoading = true; + notifyListeners(); + items.addAll(await _addLogCard()); + notifyListeners(); + items.addAll(await _addNvmePatchCard()); + notifyListeners(); + items.add(await _addShaderCard()); + isItemLoading = false; + notifyListeners(); + } catch (e) { + showToast(context!, "初始化失败,请截图报告给开发者。$e"); + } + notifyListeners(); + } + + Future> _addLogCard() async { + double logPathLen = 0; + try { + logPathLen = + (await File(await SCLoggerHelper.getLogFilePath() ?? "").length()) / + 1024 / + 1024; + } catch (_) {} + return [ + _ToolsItemData( + "rsilauncher_log_select", + "RSI Launcher Log 查看", + "打开 RSI启动器 Log文件 所在文件夹", + const Icon(FontAwesomeIcons.bookBible, size: 28), + onTap: _selectLog, + ), + _ToolsItemData( + "rsilauncher_log_fix", + "RSI Launcher Log 修复", + "在某些情况下 RSI启动器 的 log 文件会损坏,导致无法完成问题扫描,使用此工具清理损坏的 log 文件。\n\n当前日志文件大小:${(logPathLen.toStringAsFixed(4))} MB", + const Icon(FontAwesomeIcons.bookBible, size: 28), + onTap: _rsiLogFix, + ), + ]; + } + + Future> _addNvmePatchCard() async { + final nvmePatchStatus = await SystemHelper.checkNvmePatchStatus(); + return [ + if (nvmePatchStatus) _ToolsItemData( "remove_nvme_settings", "移除 nvme 注册表补丁", @@ -117,6 +129,7 @@ class ToolsUIModel extends BaseUIModel { } : null, ), + if (!nvmePatchStatus) _ToolsItemData( "add_nvme_settings", "写入 nvme 注册表补丁", @@ -135,14 +148,28 @@ class ToolsUIModel extends BaseUIModel { working = false; loadData(skipPathScan: true); }, - ), - ]; - } catch (e) { - showToast(context!, "初始化失败,请截图报告给开发者。$e"); - } - notifyListeners(); + ) + ]; } + Future<_ToolsItemData> _addShaderCard() async { + final gameShaderCachePath = await SCLoggerHelper.getShaderCachePath(); + return _ToolsItemData( + "clean_shaders", + "清理着色器缓存", + "若游戏画面出现异常或版本更新后可使用本工具清理过期的着色器(当大于500M时,建议清理) \n\n缓存大小:${((await SystemHelper.getDirLen(gameShaderCachePath ?? "", skipPath: [ + "$gameShaderCachePath\\Crashes" + ])) / 1024 / 1024).toStringAsFixed(4)} MB", + const Icon(FontAwesomeIcons.shapes, size: 28), + onTap: _cleanShaderCache, + ); + } + + /// ---------------------------- func ------------------------------------------------------- + /// ----------------------------------------------------------------------------------------- + /// ----------------------------------------------------------------------------------------- + /// ----------------------------------------------------------------------------------------- + Future reScanPath() async { scInstallPaths.clear(); rsiLauncherInstallPaths.clear();