mirror of
https://mirror.ghproxy.com/https://github.com/StarCitizenToolBox/app.git
synced 2024-12-23 04:13:43 +08:00
output log to files
This commit is contained in:
parent
6e909eb41b
commit
e7016ccfe2
@ -1,7 +1,7 @@
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:starcitizen_doctor/common/conf/url_conf.dart';
|
||||
import 'package:starcitizen_doctor/common/io/rs_http.dart';
|
||||
import 'package:starcitizen_doctor/common/utils/base_utils.dart';
|
||||
import 'package:starcitizen_doctor/common/utils/log.dart';
|
||||
|
||||
class AnalyticsApi {
|
||||
static touch(String key) async {
|
||||
|
@ -2,6 +2,8 @@ import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:starcitizen_doctor/main.dart';
|
||||
import 'package:starcitizen_doctor/widgets/my_page_route.dart';
|
||||
import 'package:window_manager/window_manager.dart';
|
||||
import '../common/utils/log.dart' as log_utils;
|
||||
|
||||
import 'dart:ui' as ui;
|
||||
|
||||
import 'ui_model.dart';
|
||||
@ -178,4 +180,8 @@ abstract class BaseUI<T extends BaseUIModel>
|
||||
makeSvgColor(Color color, {BlendMode blendMode = BlendMode.color}) {
|
||||
return ui.ColorFilter.mode(color, blendMode);
|
||||
}
|
||||
|
||||
dPrint(src) {
|
||||
log_utils.dPrint("<$runtimeType> $src");
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:grpc/grpc.dart';
|
||||
|
||||
import 'ui.dart';
|
||||
import '../common/utils/log.dart' as log_utils;
|
||||
|
||||
export '../common/utils/base_utils.dart';
|
||||
export 'ui.dart';
|
||||
@ -133,4 +134,8 @@ class BaseUIModel extends ChangeNotifier {
|
||||
dismissKeyBoard() {
|
||||
FocusManager.instance.primaryFocus?.unfocus();
|
||||
}
|
||||
|
||||
dPrint(src) {
|
||||
log_utils.dPrint("<$runtimeType> $src");
|
||||
}
|
||||
}
|
||||
|
@ -10,6 +10,7 @@ import 'package:starcitizen_doctor/api/api.dart';
|
||||
import 'package:starcitizen_doctor/common/helper/system_helper.dart';
|
||||
import 'package:starcitizen_doctor/common/io/rs_http.dart';
|
||||
import 'package:starcitizen_doctor/common/rust/frb_generated.dart';
|
||||
import 'package:starcitizen_doctor/common/utils/log.dart';
|
||||
import 'package:starcitizen_doctor/data/app_version_data.dart';
|
||||
import 'package:starcitizen_doctor/global_ui_model.dart';
|
||||
import 'package:starcitizen_doctor/base/ui.dart';
|
||||
@ -27,6 +28,10 @@ class AppConf {
|
||||
|
||||
static late final String applicationSupportDir;
|
||||
|
||||
static late final String applicationBinaryModuleDir;
|
||||
|
||||
static File? appLogFile;
|
||||
|
||||
static AppVersionData? networkVersionData;
|
||||
|
||||
static bool offlineMode = false;
|
||||
@ -51,9 +56,21 @@ class AppConf {
|
||||
} catch (_) {}
|
||||
|
||||
/// init Data
|
||||
final userProfileDir = Platform.environment["USERPROFILE"];
|
||||
applicationSupportDir =
|
||||
(await getApplicationSupportDirectory()).absolute.path;
|
||||
final logFile = File(
|
||||
"$applicationSupportDir\\logs\\${DateTime.now().millisecondsSinceEpoch}.log");
|
||||
await logFile.create(recursive: true);
|
||||
appLogFile = logFile;
|
||||
if (AppConf.isMSE && userProfileDir != null) {
|
||||
applicationBinaryModuleDir =
|
||||
"$userProfileDir\\AppData\\Local\\Temp\\SCToolbox\\modules";
|
||||
} else {
|
||||
applicationBinaryModuleDir = "$applicationSupportDir\\modules";
|
||||
}
|
||||
dPrint("applicationSupportDir == $applicationSupportDir");
|
||||
dPrint("applicationBinaryModuleDir == $applicationBinaryModuleDir");
|
||||
try {
|
||||
Hive.init("$applicationSupportDir/db");
|
||||
final box = await Hive.openBox("app_conf");
|
||||
|
@ -3,7 +3,7 @@ import 'dart:io';
|
||||
import 'package:archive/archive.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:starcitizen_doctor/common/conf/app_conf.dart';
|
||||
import 'package:starcitizen_doctor/common/utils/base_utils.dart';
|
||||
import 'package:starcitizen_doctor/common/utils/log.dart';
|
||||
|
||||
class BinaryModuleConf {
|
||||
static const _modules = {
|
||||
@ -11,7 +11,7 @@ class BinaryModuleConf {
|
||||
};
|
||||
|
||||
static Future extractModule(List<String> modules) async {
|
||||
final workingDir = "${AppConf.applicationSupportDir}\\modules";
|
||||
final workingDir = AppConf.applicationBinaryModuleDir;
|
||||
for (var m in _modules.entries) {
|
||||
if (!modules.contains(m.key)) continue;
|
||||
final name = m.key;
|
||||
|
@ -1,6 +1,6 @@
|
||||
import 'package:starcitizen_doctor/base/ui_model.dart';
|
||||
import 'package:starcitizen_doctor/common/io/rs_http.dart';
|
||||
import 'package:starcitizen_doctor/common/rust/http_package.dart';
|
||||
import 'package:starcitizen_doctor/common/utils/log.dart';
|
||||
|
||||
class URLConf {
|
||||
/// HOME API
|
||||
|
@ -2,8 +2,8 @@ import 'dart:convert';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:hive/hive.dart';
|
||||
import 'package:starcitizen_doctor/common/utils/log.dart';
|
||||
|
||||
import '../utils/base_utils.dart';
|
||||
|
||||
class SCLoggerHelper {
|
||||
static Future<String?> getLogFilePath() async {
|
||||
|
@ -1,7 +1,7 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:hive/hive.dart';
|
||||
import 'package:starcitizen_doctor/common/utils/base_utils.dart';
|
||||
import 'package:starcitizen_doctor/common/utils/log.dart';
|
||||
|
||||
class SystemHelper {
|
||||
static String powershellPath = "powershell.exe";
|
||||
|
@ -5,19 +5,19 @@ import 'package:aria2/aria2.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:hive/hive.dart';
|
||||
import 'package:starcitizen_doctor/api/api.dart';
|
||||
import 'package:starcitizen_doctor/base/ui.dart';
|
||||
import 'package:starcitizen_doctor/common/conf/app_conf.dart';
|
||||
import 'package:starcitizen_doctor/common/conf/binary_conf.dart';
|
||||
import 'package:starcitizen_doctor/common/helper/system_helper.dart';
|
||||
|
||||
import 'package:starcitizen_doctor/common/rust/api/process_api.dart'
|
||||
as rs_process;
|
||||
import 'package:starcitizen_doctor/common/utils/log.dart';
|
||||
|
||||
class Aria2cManager {
|
||||
static bool _isDaemonRunning = false;
|
||||
|
||||
static final String _aria2cDir =
|
||||
"${AppConf.applicationSupportDir}\\modules\\aria2c";
|
||||
"${AppConf.applicationBinaryModuleDir}\\aria2c";
|
||||
|
||||
static Aria2c? _aria2c;
|
||||
|
||||
@ -86,6 +86,8 @@ class Aria2cManager {
|
||||
],
|
||||
workingDirectory: _aria2cDir);
|
||||
|
||||
String launchError = "";
|
||||
|
||||
stream.listen((event) {
|
||||
dPrint("Aria2cManager.rs_process event === $event");
|
||||
if (event.startsWith("output:")) {
|
||||
@ -95,14 +97,17 @@ class Aria2cManager {
|
||||
} else if (event.startsWith("error:")) {
|
||||
_isDaemonRunning = false;
|
||||
_aria2c = null;
|
||||
launchError = event;
|
||||
} else if (event.startsWith("exit:")) {
|
||||
_isDaemonRunning = false;
|
||||
_aria2c = null;
|
||||
launchError = event;
|
||||
}
|
||||
});
|
||||
|
||||
while (true) {
|
||||
if (_isDaemonRunning) return;
|
||||
if (launchError.isNotEmpty) throw launchError;
|
||||
await Future.delayed(const Duration(milliseconds: 100));
|
||||
}
|
||||
}
|
||||
|
@ -1,16 +1,11 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:fluent_ui/fluent_ui.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/rendering.dart';
|
||||
import 'dart:ui' as ui;
|
||||
|
||||
import 'package:flutter/services.dart';
|
||||
|
||||
void dPrint(src) {
|
||||
if (kDebugMode) {
|
||||
print(src);
|
||||
}
|
||||
}
|
||||
|
||||
Future showToast(BuildContext context, String msg,
|
||||
{BoxConstraints? constraints, String? title}) async {
|
||||
return showBaseDialog(context,
|
||||
|
19
lib/common/utils/log.dart
Normal file
19
lib/common/utils/log.dart
Normal file
@ -0,0 +1,19 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:synchronized/synchronized.dart';
|
||||
|
||||
import '../conf/app_conf.dart';
|
||||
|
||||
var _logLock = Lock();
|
||||
|
||||
void dPrint(src) async {
|
||||
if (kDebugMode) {
|
||||
print(src);
|
||||
}
|
||||
try {
|
||||
await _logLock.synchronized(() async {
|
||||
await AppConf.appLogFile?.writeAsString("$src\n", mode: FileMode.append);
|
||||
});
|
||||
} catch (_) {}
|
||||
}
|
@ -8,9 +8,9 @@ import 'dart:convert';
|
||||
import 'dart:ffi';
|
||||
|
||||
import 'package:ffi/ffi.dart';
|
||||
import 'package:starcitizen_doctor/common/utils/log.dart';
|
||||
import 'package:win32/win32.dart';
|
||||
|
||||
import '../utils/base_utils.dart';
|
||||
|
||||
class Win32Credentials {
|
||||
static void write(
|
||||
|
@ -162,9 +162,10 @@ class GameDoctorUIModel extends BaseUIModel {
|
||||
var result = await Process.run('powershell', [
|
||||
"(fsutil fsinfo sectorinfo $element: | Select-String 'PhysicalBytesPerSectorForPerformance').ToString().Split(':')[1].Trim()"
|
||||
]);
|
||||
dPrint(result.stdout);
|
||||
dPrint(
|
||||
"fsutil info sector info: ->>> ${result.stdout.toString().trim()}");
|
||||
if (result.stderr == "") {
|
||||
final rs = result.stdout.toString();
|
||||
final rs = result.stdout.toString().trim();
|
||||
final physicalBytesPerSectorForPerformance = (int.tryParse(rs) ?? 0);
|
||||
if (physicalBytesPerSectorForPerformance > 4096) {
|
||||
checkResult?.add(MapEntry("nvme_PhysicalBytes", element));
|
||||
|
@ -12,6 +12,7 @@ import 'package:starcitizen_doctor/common/helper/system_helper.dart';
|
||||
import 'package:starcitizen_doctor/common/io/rs_http.dart';
|
||||
import 'package:starcitizen_doctor/data/sc_localization_data.dart';
|
||||
import 'package:url_launcher/url_launcher_string.dart';
|
||||
import 'package:starcitizen_doctor/common/utils/log.dart' as log_utils;
|
||||
|
||||
class LocalizationUIModel extends BaseUIModel {
|
||||
final String scInstallPath;
|
||||
@ -372,7 +373,7 @@ class LocalizationUIModel extends BaseUIModel {
|
||||
updateInfo[value] = hasUpdate;
|
||||
}
|
||||
}
|
||||
dPrint("checkLocalizationUpdates ==== $updateInfo");
|
||||
log_utils.dPrint("checkLocalizationUpdates ==== $updateInfo");
|
||||
for (var v in updateInfo.entries) {
|
||||
if (v.value) {
|
||||
for (var element in AppConf.gameChannels) {
|
||||
|
@ -11,6 +11,7 @@ import 'package:local_auth/local_auth.dart';
|
||||
import 'package:starcitizen_doctor/common/conf/app_conf.dart';
|
||||
import 'package:starcitizen_doctor/common/conf/url_conf.dart';
|
||||
import 'package:starcitizen_doctor/common/io/rs_http.dart';
|
||||
import 'package:starcitizen_doctor/common/utils/log.dart';
|
||||
import 'package:starcitizen_doctor/common/win32/credentials.dart';
|
||||
import 'package:starcitizen_doctor/data/app_web_localization_versions_data.dart';
|
||||
|
||||
|
@ -76,6 +76,7 @@ dependencies:
|
||||
#git: https://github.com/xkeyC/dart_aria2_rpc.git
|
||||
path: ../../xkeyC/dart_aria2_rpc
|
||||
intl: ^0.18.0
|
||||
synchronized: ^3.1.0+1
|
||||
dependency_overrides:
|
||||
http: ^1.1.2
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user