feat: Linux Path Basic Support

modified:   lib/ui/settings/settings_ui_model.dart
This commit is contained in:
xkeyC
2025-12-23 16:44:37 +08:00
parent 062014f24a
commit 1a1f72a596
6 changed files with 224 additions and 218 deletions

View File

@@ -3,6 +3,7 @@ import 'dart:io';
import 'package:hive_ce/hive.dart';
import 'package:starcitizen_doctor/common/conf/conf.dart';
import 'package:starcitizen_doctor/common/utils/base_utils.dart';
import 'package:starcitizen_doctor/common/utils/log.dart';
class SCLoggerHelper {
@@ -43,20 +44,23 @@ class SCLoggerHelper {
}
}
static Future<List<String>> getGameInstallPath(List listData,
{bool checkExists = true,
List<String> withVersion = const ["LIVE"]}) async {
static Future<List<String>> getGameInstallPath(
List listData, {
bool checkExists = true,
List<String> withVersion = const ["LIVE"],
}) async {
List<String> scInstallPaths = [];
checkAndAddPath(String path, bool checkExists) async {
// 将所有连续的 \\ 替换为 \
path = path.replaceAll(RegExp(r'\\+'), "\\");
if (path.isNotEmpty && !scInstallPaths.contains(path)) {
// Normalize path separators to current platform format
path = path.platformPath;
// Case-insensitive check for existing paths
if (path.isNotEmpty && !scInstallPaths.any((p) => p.toLowerCase() == path.toLowerCase())) {
if (!checkExists) {
dPrint("find installPath == $path");
scInstallPaths.add(path);
} else if (await File("$path/Bin64/StarCitizen.exe").exists() &&
await File("$path/Data.p4k").exists()) {
} else if (await File("$path/Bin64/StarCitizen.exe").exists() && await File("$path/Data.p4k").exists()) {
dPrint("find installPath == $path");
scInstallPaths.add(path);
}
@@ -67,14 +71,14 @@ class SCLoggerHelper {
final path = confBox.get("custom_game_path");
if (path != null && path != "") {
for (var v in withVersion) {
await checkAndAddPath("$path\\$v", checkExists);
await checkAndAddPath("$path\\$v".platformPath, checkExists);
}
}
try {
for (var v in withVersion) {
String pattern =
r'([a-zA-Z]:\\\\[^\\\\]*\\\\[^\\\\]*\\\\StarCitizen\\\\' + v + r')';
// Match both Windows (\\) and Unix (/) path separators in log entries, case-insensitive
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 line = listData[i];
@@ -89,10 +93,14 @@ class SCLoggerHelper {
// 动态检测更多位置
for (var fileName in List.from(scInstallPaths)) {
for (var v in withVersion) {
if (fileName.toString().endsWith(v)) {
final suffix = '\\$v'.platformPath.toLowerCase();
if (fileName.toString().toLowerCase().endsWith(suffix)) {
for (var nv in withVersion) {
final nextName =
"${fileName.toString().replaceAll("\\$v", "")}\\$nv";
final basePath = fileName.toString().replaceAll(
RegExp('${RegExp.escape(suffix)}\$', caseSensitive: false),
'',
);
final nextName = "$basePath\\$nv".platformPath;
await checkAndAddPath(nextName, true);
}
}
@@ -108,9 +116,10 @@ class SCLoggerHelper {
}
static String getGameChannelID(String installPath) {
final pathLower = installPath.platformPath.toLowerCase();
for (var value in AppConf.gameChannels) {
if (installPath.endsWith("\\$value")) {
return value;
if (pathLower.endsWith('\\${value.toLowerCase()}'.platformPath)) {
return value.toUpperCase();
}
}
return "UNKNOWN";
@@ -121,8 +130,7 @@ class SCLoggerHelper {
if (!await logFile.exists()) {
return null;
}
return await logFile.readAsLines(
encoding: const Utf8Codec(allowMalformed: true));
return await logFile.readAsLines(encoding: const Utf8Codec(allowMalformed: true));
}
static MapEntry<String, String>? getGameRunningLogInfo(List<String> logs) {
@@ -138,47 +146,47 @@ class SCLoggerHelper {
static MapEntry<String, String>? _checkRunningLine(String line) {
if (line.contains("STATUS_CRYENGINE_OUT_OF_SYSMEM")) {
return MapEntry(S.current.doctor_game_error_low_memory,
S.current.doctor_game_error_low_memory_info);
return MapEntry(S.current.doctor_game_error_low_memory, S.current.doctor_game_error_low_memory_info);
}
if (line.contains("EXCEPTION_ACCESS_VIOLATION")) {
return MapEntry(S.current.doctor_game_error_generic_info,
"https://docs.qq.com/doc/DUURxUVhzTmZoY09Z");
return MapEntry(S.current.doctor_game_error_generic_info, "https://docs.qq.com/doc/DUURxUVhzTmZoY09Z");
}
if (line.contains("DXGI_ERROR_DEVICE_REMOVED")) {
return MapEntry(S.current.doctor_game_error_gpu_crash,
"https://www.bilibili.com/read/cv19335199");
return MapEntry(S.current.doctor_game_error_gpu_crash, "https://www.bilibili.com/read/cv19335199");
}
if (line.contains("Wakeup socket sendto error")) {
return MapEntry(S.current.doctor_game_error_socket_error,
S.current.doctor_game_error_socket_error_info);
return MapEntry(S.current.doctor_game_error_socket_error, S.current.doctor_game_error_socket_error_info);
}
if (line.contains("The requested operation requires elevated")) {
return MapEntry(S.current.doctor_game_error_permissions_error,
S.current.doctor_game_error_permissions_error_info);
return MapEntry(
S.current.doctor_game_error_permissions_error,
S.current.doctor_game_error_permissions_error_info,
);
}
if (line.contains(
"The process cannot access the file because is is being used by another process")) {
return MapEntry(S.current.doctor_game_error_game_process_error,
S.current.doctor_game_error_game_process_error_info);
if (line.contains("The process cannot access the file because is is being used by another process")) {
return MapEntry(
S.current.doctor_game_error_game_process_error,
S.current.doctor_game_error_game_process_error_info,
);
}
if (line.contains("0xc0000043")) {
return MapEntry(S.current.doctor_game_error_game_damaged_file,
S.current.doctor_game_error_game_damaged_file_info);
return MapEntry(
S.current.doctor_game_error_game_damaged_file,
S.current.doctor_game_error_game_damaged_file_info,
);
}
if (line.contains("option to verify the content of the Data.p4k file")) {
return MapEntry(S.current.doctor_game_error_game_damaged_p4k_file,
S.current.doctor_game_error_game_damaged_p4k_file_info);
return MapEntry(
S.current.doctor_game_error_game_damaged_p4k_file,
S.current.doctor_game_error_game_damaged_p4k_file_info,
);
}
if (line.contains("OUTOFMEMORY Direct3D could not allocate")) {
return MapEntry(S.current.doctor_game_error_low_gpu_memory,
S.current.doctor_game_error_low_gpu_memory_info);
return MapEntry(S.current.doctor_game_error_low_gpu_memory, S.current.doctor_game_error_low_gpu_memory_info);
}
if (line.contains(
"try disabling with r_vulkanDisableLayers = 1 in your user.cfg")) {
return MapEntry(S.current.doctor_game_error_gpu_vulkan_crash,
S.current.doctor_game_error_gpu_vulkan_crash_info);
if (line.contains("try disabling with r_vulkanDisableLayers = 1 in your user.cfg")) {
return MapEntry(S.current.doctor_game_error_gpu_vulkan_crash, S.current.doctor_game_error_gpu_vulkan_crash_info);
}
/// Unknown