mirror of
https://mirror.ghproxy.com/https://github.com/StarCitizenToolBox/app.git
synced 2024-12-23 00:33:42 +08:00
fix: game path scan
This commit is contained in:
parent
ba102bbab8
commit
ffd32ec7ff
@ -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,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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user