From ffd32ec7fff858967c45366077d3e679291592b7 Mon Sep 17 00:00:00 2001 From: xkeyC <3334969096@qq.com> Date: Wed, 11 Sep 2024 20:41:14 +0800 Subject: [PATCH] fix: game path scan --- lib/common/helper/log_helper.dart | 54 +++++++++++-------------------- lib/ui/tools/tools_ui_model.dart | 45 -------------------------- 2 files changed, 19 insertions(+), 80 deletions(-) diff --git a/lib/common/helper/log_helper.dart b/lib/common/helper/log_helper.dart index 0a2c7c1..977498d 100644 --- a/lib/common/helper/log_helper.dart +++ b/lib/common/helper/log_helper.dart @@ -36,16 +36,7 @@ class SCLoggerHelper { final jsonLogPath = await getLogFilePath(); if (jsonLogPath == null) throw "no file path"; var jsonString = utf8.decode(await File(jsonLogPath).readAsBytes()); - if (jsonString.endsWith("\n")) { - jsonString = jsonString.substring(0, jsonString.length - 3); - } - if (jsonString.endsWith(" ")) { - jsonString = jsonString.substring(0, jsonString.length - 3); - } - if (jsonString.endsWith(",")) { - jsonString = jsonString.substring(0, jsonString.length - 3); - } - return json.decode("[$jsonString]"); + return jsonString.split("\n"); } catch (e) { dPrint(e); return []; @@ -58,6 +49,8 @@ class SCLoggerHelper { List scInstallPaths = []; checkAndAddPath(String path, bool checkExists) async { + // 将所有连续的 \\ 替换为 \ + path = path.replaceAll(RegExp(r'\\+'), "\\"); if (path.isNotEmpty && !scInstallPaths.contains(path)) { if (!checkExists) { dPrint("find installPath == $path"); @@ -80,36 +73,27 @@ class SCLoggerHelper { try { for (var v in withVersion) { + String pattern = + r'([a-zA-Z]:\\\\[^\\\\]*\\\\[^\\\\]*\\\\StarCitizen\\\\' + v + r')'; + RegExp regExp = RegExp(pattern, caseSensitive: false); for (var i = listData.length - 1; i > 0; i--) { - final m = listData[i]; - final info = m["[browser][info] "]; - if (info is String) { - String installPath = ""; - if (info.contains("Installing Star Citizen $v")) { - installPath = "${info.split(" at ")[1]}\\$v"; - } - if (info.contains("Verifying Star Citizen $v")) { - installPath = "${info.split(" at ")[1]}\\$v"; - } - if (info.contains("Launching Star Citizen $v from")) { - installPath = info - .replaceAll("Launching Star Citizen $v from (", "") - .replaceAll(")", ""); - } - await checkAndAddPath(installPath, checkExists); + final line = listData[i]; + final matches = regExp.allMatches(line); + for (var match in matches) { + await checkAndAddPath(match.group(0)!, checkExists); } } + } - if (scInstallPaths.isNotEmpty) { - // 动态检测更多位置 + if (scInstallPaths.isNotEmpty) { + // 动态检测更多位置 + for (var fileName in List.from(scInstallPaths)) { for (var v in withVersion) { - for (var fileName in List.from(scInstallPaths)) { - if (fileName.toString().endsWith(v)) { - for (var nv in withVersion) { - final nextName = - "${fileName.toString().replaceAll("\\$v", "")}\\$nv"; - await checkAndAddPath(nextName, true); - } + if (fileName.toString().endsWith(v)) { + for (var nv in withVersion) { + final nextName = + "${fileName.toString().replaceAll("\\$v", "")}\\$nv"; + await checkAndAddPath(nextName, true); } } } diff --git a/lib/ui/tools/tools_ui_model.dart b/lib/ui/tools/tools_ui_model.dart index 8b40709..fa684b4 100644 --- a/lib/ui/tools/tools_ui_model.dart +++ b/lib/ui/tools/tools_ui_model.dart @@ -129,9 +129,6 @@ class ToolsUIModel extends _$ToolsUIModel { items.add(await _addPhotographyCard(context)); state = state.copyWith(items: items); if (!context.mounted) return; - items.addAll(await _addLogCard(context)); - state = state.copyWith(items: items); - if (!context.mounted) return; items.addAll(await _addNvmePatchCard(context)); state = state.copyWith(items: items, isItemLoading: false); } catch (e) { @@ -140,26 +137,6 @@ class ToolsUIModel extends _$ToolsUIModel { } } - Future> _addLogCard(BuildContext context) async { - double logPathLen = 0; - try { - logPathLen = - (await File(await SCLoggerHelper.getLogFilePath() ?? "").length()) / - 1024 / - 1024; - } catch (_) {} - return [ - ToolsItemData( - "rsilauncher_log_fix", - S.current.tools_action_rsi_launcher_log_fix, - S.current.tools_action_info_rsi_launcher_log_issue( - logPathLen.toStringAsFixed(4)), - const Icon(FontAwesomeIcons.bookBible, size: 24), - onTap: () => _rsiLogFix(context), - ), - ]; - } - Future> _addNvmePatchCard(BuildContext context) async { final nvmePatchStatus = await SystemHelper.checkNvmePatchStatus(); return [ @@ -353,28 +330,6 @@ class ToolsUIModel extends _$ToolsUIModel { SystemHelper.checkAndLaunchRSILauncher(state.rsiLauncherInstalledPath); } - Future _rsiLogFix(BuildContext context) async { - state = state.copyWith(working: true); - final path = await SCLoggerHelper.getLogFilePath(); - if (!await File(path!).exists()) { - if (!context.mounted) return; - showToast(context, S.current.tools_action_info_log_file_not_exist); - return; - } - try { - SystemHelper.killRSILauncher(); - await File(path).delete(recursive: true); - if (!context.mounted) return; - showToast(context, S.current.tools_action_info_cleanup_complete); - SystemHelper.checkAndLaunchRSILauncher(state.rsiLauncherInstalledPath); - } catch (_) { - if (!context.mounted) return; - showToast(context, S.current.tools_action_info_cleanup_failed(path)); - } - - state = state.copyWith(working: false); - } - openDir(path) async { SystemHelper.openDir(path); }