fix: game path scan

This commit is contained in:
xkeyC 2024-09-11 20:41:14 +08:00
parent ba102bbab8
commit ffd32ec7ff
2 changed files with 19 additions and 80 deletions

View File

@ -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<String> 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,30 +73,22 @@ 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";
final line = listData[i];
final matches = regExp.allMatches(line);
for (var match in matches) {
await checkAndAddPath(match.group(0)!, checkExists);
}
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);
}
}
if (scInstallPaths.isNotEmpty) {
//
for (var v in withVersion) {
for (var fileName in List.from(scInstallPaths)) {
for (var v in withVersion) {
if (fileName.toString().endsWith(v)) {
for (var nv in withVersion) {
final nextName =
@ -114,7 +99,6 @@ class SCLoggerHelper {
}
}
}
}
} catch (e) {
dPrint(e);
if (scInstallPaths.isEmpty) rethrow;

View File

@ -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<List<ToolsItemData>> _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<List<ToolsItemData>> _addNvmePatchCard(BuildContext context) async {
final nvmePatchStatus = await SystemHelper.checkNvmePatchStatus();
return [
@ -353,28 +330,6 @@ class ToolsUIModel extends _$ToolsUIModel {
SystemHelper.checkAndLaunchRSILauncher(state.rsiLauncherInstalledPath);
}
Future<void> _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);
}