diff --git a/lib/ui/home/performance/performance_ui_model.dart b/lib/ui/home/performance/performance_ui_model.dart index 06149a4..0ce6f85 100644 --- a/lib/ui/home/performance/performance_ui_model.dart +++ b/lib/ui/home/performance/performance_ui_model.dart @@ -11,6 +11,7 @@ import 'package:starcitizen_doctor/common/utils/base_utils.dart'; import 'package:starcitizen_doctor/data/game_performance_data.dart'; import 'package:starcitizen_doctor/generated/l10n.dart'; import 'package:starcitizen_doctor/ui/home/home_ui_model.dart'; +import 'package:starcitizen_doctor/ui/tools/tools_ui_model.dart'; import 'performance_ui.json.dart'; @@ -171,15 +172,7 @@ class HomePerformanceUIModel extends _$HomePerformanceUIModel { } Future cleanShaderCache(BuildContext? context) async { - final gameShaderCachePath = await SCLoggerHelper.getShaderCachePath(); - final l = await Directory(gameShaderCachePath!).list(recursive: false).toList(); - for (var value in l) { - if (value is Directory) { - if (!value.absolute.path.contains("Crashes")) { - await value.delete(recursive: true); - } - } - } + await ToolsUIModel.cleanShaderCache(); await Future.delayed(const Duration(milliseconds: 300)); if (context != null && context.mounted) { showToast(context, S.current.performance_info_shader_clearing_warning); diff --git a/lib/ui/tools/tools_ui_model.dart b/lib/ui/tools/tools_ui_model.dart index ba6b039..8d968dc 100644 --- a/lib/ui/tools/tools_ui_model.dart +++ b/lib/ui/tools/tools_ui_model.dart @@ -27,6 +27,7 @@ import 'dialogs/hosts_booster_dialog_ui.dart'; import 'dialogs/rsi_launcher_enhance_dialog_ui.dart'; part 'tools_ui_model.g.dart'; + part 'tools_ui_model.freezed.dart'; class ToolsItemData { @@ -518,8 +519,7 @@ class ToolsUIModel extends _$ToolsUIModel { state = state.copyWith(working: false); } - Future _cleanShaderCache(BuildContext context) async { - state = state.copyWith(working: true); + static Future cleanShaderCache() async { final gameShaderCachePath = await SCLoggerHelper.getShaderCachePath(); final l = await Directory(gameShaderCachePath!).list(recursive: false).toList(); for (var value in l) { @@ -535,13 +535,18 @@ class ToolsUIModel extends _$ToolsUIModel { } } } + } + + Future _cleanShaderCache(BuildContext context) async { + state = state.copyWith(working: true); + await cleanShaderCache(); if (!context.mounted) return; loadToolsCard(context, skipPathScan: true); state = state.copyWith(working: false); } /// 清理着色器缓存目录,保留 GraphicsSettings 文件夹 - Future _cleanShaderCacheDirectory(Directory dir) async { + static Future _cleanShaderCacheDirectory(Directory dir) async { try { final contents = await dir.list(recursive: false).toList(); for (var entity in contents) {