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();
|
final jsonLogPath = await getLogFilePath();
|
||||||
if (jsonLogPath == null) throw "no file path";
|
if (jsonLogPath == null) throw "no file path";
|
||||||
var jsonString = utf8.decode(await File(jsonLogPath).readAsBytes());
|
var jsonString = utf8.decode(await File(jsonLogPath).readAsBytes());
|
||||||
if (jsonString.endsWith("\n")) {
|
return jsonString.split("\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]");
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
dPrint(e);
|
dPrint(e);
|
||||||
return [];
|
return [];
|
||||||
@ -58,6 +49,8 @@ class SCLoggerHelper {
|
|||||||
List<String> scInstallPaths = [];
|
List<String> scInstallPaths = [];
|
||||||
|
|
||||||
checkAndAddPath(String path, bool checkExists) async {
|
checkAndAddPath(String path, bool checkExists) async {
|
||||||
|
// 将所有连续的 \\ 替换为 \
|
||||||
|
path = path.replaceAll(RegExp(r'\\+'), "\\");
|
||||||
if (path.isNotEmpty && !scInstallPaths.contains(path)) {
|
if (path.isNotEmpty && !scInstallPaths.contains(path)) {
|
||||||
if (!checkExists) {
|
if (!checkExists) {
|
||||||
dPrint("find installPath == $path");
|
dPrint("find installPath == $path");
|
||||||
@ -80,36 +73,27 @@ class SCLoggerHelper {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
for (var v in withVersion) {
|
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--) {
|
for (var i = listData.length - 1; i > 0; i--) {
|
||||||
final m = listData[i];
|
final line = listData[i];
|
||||||
final info = m["[browser][info] "];
|
final matches = regExp.allMatches(line);
|
||||||
if (info is String) {
|
for (var match in matches) {
|
||||||
String installPath = "";
|
await checkAndAddPath(match.group(0)!, checkExists);
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (scInstallPaths.isNotEmpty) {
|
if (scInstallPaths.isNotEmpty) {
|
||||||
// 动态检测更多位置
|
// 动态检测更多位置
|
||||||
|
for (var fileName in List.from(scInstallPaths)) {
|
||||||
for (var v in withVersion) {
|
for (var v in withVersion) {
|
||||||
for (var fileName in List.from(scInstallPaths)) {
|
if (fileName.toString().endsWith(v)) {
|
||||||
if (fileName.toString().endsWith(v)) {
|
for (var nv in withVersion) {
|
||||||
for (var nv in withVersion) {
|
final nextName =
|
||||||
final nextName =
|
"${fileName.toString().replaceAll("\\$v", "")}\\$nv";
|
||||||
"${fileName.toString().replaceAll("\\$v", "")}\\$nv";
|
await checkAndAddPath(nextName, true);
|
||||||
await checkAndAddPath(nextName, true);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -129,9 +129,6 @@ class ToolsUIModel extends _$ToolsUIModel {
|
|||||||
items.add(await _addPhotographyCard(context));
|
items.add(await _addPhotographyCard(context));
|
||||||
state = state.copyWith(items: items);
|
state = state.copyWith(items: items);
|
||||||
if (!context.mounted) return;
|
if (!context.mounted) return;
|
||||||
items.addAll(await _addLogCard(context));
|
|
||||||
state = state.copyWith(items: items);
|
|
||||||
if (!context.mounted) return;
|
|
||||||
items.addAll(await _addNvmePatchCard(context));
|
items.addAll(await _addNvmePatchCard(context));
|
||||||
state = state.copyWith(items: items, isItemLoading: false);
|
state = state.copyWith(items: items, isItemLoading: false);
|
||||||
} catch (e) {
|
} 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 {
|
Future<List<ToolsItemData>> _addNvmePatchCard(BuildContext context) async {
|
||||||
final nvmePatchStatus = await SystemHelper.checkNvmePatchStatus();
|
final nvmePatchStatus = await SystemHelper.checkNvmePatchStatus();
|
||||||
return [
|
return [
|
||||||
@ -353,28 +330,6 @@ class ToolsUIModel extends _$ToolsUIModel {
|
|||||||
SystemHelper.checkAndLaunchRSILauncher(state.rsiLauncherInstalledPath);
|
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 {
|
openDir(path) async {
|
||||||
SystemHelper.openDir(path);
|
SystemHelper.openDir(path);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user