fix: SCLoggerHelper

This commit is contained in:
xkeyC 2024-06-16 12:11:19 +08:00
parent 2e69068209
commit c7d70084d8

View File

@ -32,19 +32,24 @@ class SCLoggerHelper {
static Future<List?> getLauncherLogList() async { static Future<List?> getLauncherLogList() async {
if (!Platform.isWindows) return []; if (!Platform.isWindows) return [];
final jsonLogPath = await getLogFilePath(); try {
if (jsonLogPath == null) return null; final jsonLogPath = await getLogFilePath();
var jsonString = utf8.decode(await File(jsonLogPath).readAsBytes()); if (jsonLogPath == null) throw "no file path";
if (jsonString.endsWith("\n")) { var jsonString = utf8.decode(await File(jsonLogPath).readAsBytes());
jsonString = jsonString.substring(0, jsonString.length - 3); 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]");
} catch (e) {
dPrint(e);
return [];
} }
if (jsonString.endsWith(" ")) {
jsonString = jsonString.substring(0, jsonString.length - 3);
}
if (jsonString.endsWith(",")) {
jsonString = jsonString.substring(0, jsonString.length - 3);
}
return json.decode("[$jsonString]");
} }
static Future<List<String>> getGameInstallPath(List listData, static Future<List<String>> getGameInstallPath(List listData,
@ -94,25 +99,25 @@ class SCLoggerHelper {
await checkAndAddPath(installPath, checkExists); await checkAndAddPath(installPath, checkExists);
} }
} }
}
} catch (e) {
dPrint(e);
if (scInstallPaths.isEmpty) rethrow;
}
if (scInstallPaths.isNotEmpty) { if (scInstallPaths.isNotEmpty) {
// //
for (var v in withVersion) { for (var v in withVersion) {
for (var fileName in List.from(scInstallPaths)) { 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);
}
}
} }
} }
} }
} }
} catch (e) {
dPrint(e);
if (scInstallPaths.isEmpty) rethrow;
} }
return scInstallPaths; return scInstallPaths;