mirror of
https://ghfast.top/https://github.com/StarCitizenToolBox/app.git
synced 2025-06-28 07:54:44 +08:00
feat: Optimize RsProcess
This commit is contained in:
@ -8,7 +8,8 @@ import 'package:flutter/foundation.dart';
|
||||
import 'package:hive/hive.dart';
|
||||
import 'package:starcitizen_doctor/api/api.dart';
|
||||
import 'package:starcitizen_doctor/common/helper/system_helper.dart';
|
||||
import 'package:starcitizen_doctor/common/rust/api/rs_process.dart';
|
||||
import 'package:starcitizen_doctor/common/rust/api/rs_process.dart'
|
||||
as rs_process;
|
||||
|
||||
import 'package:starcitizen_doctor/common/utils/log.dart';
|
||||
import 'package:starcitizen_doctor/common/utils/provider.dart';
|
||||
@ -97,9 +98,7 @@ class Aria2cModel extends _$Aria2cModel {
|
||||
dPrint("trackerList === $trackerList");
|
||||
dPrint("Aria2cManager .----- aria2c start $port------");
|
||||
|
||||
final rsp = RsProcess();
|
||||
|
||||
final stream = rsp.start(
|
||||
final stream = rs_process.start(
|
||||
executable: exePath,
|
||||
arguments: [
|
||||
"-V",
|
||||
@ -124,16 +123,16 @@ class Aria2cModel extends _$Aria2cModel {
|
||||
stream.listen((event) {
|
||||
dPrint("Aria2cManager.rs_process event === $event");
|
||||
switch (event.dataType) {
|
||||
case RsProcessStreamDataType.output:
|
||||
case rs_process.RsProcessStreamDataType.output:
|
||||
if (event.data.contains("IPv4 RPC: listening on TCP port")) {
|
||||
_onLaunch(port, pwd, trackerList);
|
||||
}
|
||||
break;
|
||||
case RsProcessStreamDataType.error:
|
||||
case rs_process.RsProcessStreamDataType.error:
|
||||
launchError = event.data;
|
||||
state = state.copyWith(aria2c: null);
|
||||
break;
|
||||
case RsProcessStreamDataType.exit:
|
||||
case rs_process.RsProcessStreamDataType.exit:
|
||||
launchError = event.data;
|
||||
state = state.copyWith(aria2c: null);
|
||||
break;
|
||||
|
@ -11,6 +11,8 @@ import 'package:starcitizen_doctor/common/utils/log.dart';
|
||||
import 'package:starcitizen_doctor/common/utils/provider.dart';
|
||||
import 'package:starcitizen_doctor/data/app_unp4k_p4k_item_data.dart';
|
||||
import 'package:starcitizen_doctor/ui/tools/tools_ui_model.dart';
|
||||
import 'package:starcitizen_doctor/common/rust/api/rs_process.dart'
|
||||
as rs_process;
|
||||
|
||||
part 'unp4kc.freezed.dart';
|
||||
|
||||
@ -30,7 +32,7 @@ class Unp4kcState with _$Unp4kcState {
|
||||
|
||||
@riverpod
|
||||
class Unp4kCModel extends _$Unp4kCModel {
|
||||
RsProcess? _process;
|
||||
int? _rsPid;
|
||||
|
||||
@override
|
||||
Unp4kcState build() {
|
||||
@ -49,20 +51,17 @@ class Unp4kCModel extends _$Unp4kCModel {
|
||||
await BinaryModuleConf.extractModule(
|
||||
["unp4kc"], appGlobalState.applicationBinaryModuleDir!);
|
||||
final exec = "$execDir\\unp4kc.exe";
|
||||
// final ps = await Process.start(exec, []);
|
||||
// StringBuffer stringBuffer = StringBuffer();
|
||||
|
||||
_process = RsProcess();
|
||||
|
||||
final stream = _process?.start(
|
||||
final stream = rs_process.start(
|
||||
executable: exec, arguments: [], workingDirectory: execDir);
|
||||
|
||||
stream?.listen((event) async {
|
||||
stream.listen((event) async {
|
||||
_rsPid = event.rsPid;
|
||||
switch (event.dataType) {
|
||||
case RsProcessStreamDataType.output:
|
||||
try {
|
||||
final eventJson = await compute(json.decode, event.data);
|
||||
_handleMessage(eventJson);
|
||||
_handleMessage(eventJson, event.rsPid);
|
||||
} catch (e) {
|
||||
dPrint("[unp4kc] json error: $e");
|
||||
}
|
||||
@ -77,22 +76,21 @@ class Unp4kCModel extends _$Unp4kCModel {
|
||||
});
|
||||
|
||||
ref.onDispose(() {
|
||||
final pid = _process?.getPid();
|
||||
if (pid != null) {
|
||||
Process.killPid(pid);
|
||||
if (_rsPid != null) {
|
||||
Process.killPid(_rsPid!);
|
||||
dPrint("[unp4kc] kill ...");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void _handleMessage(Map<String, dynamic> eventJson) async {
|
||||
void _handleMessage(Map<String, dynamic> eventJson, int rsPid) async {
|
||||
final action = eventJson["action"];
|
||||
final data = eventJson["data"];
|
||||
final gamePath = getGamePath();
|
||||
final gameP4kPath = "$gamePath\\Data.p4k";
|
||||
switch (action.toString().trim()) {
|
||||
case "info: startup":
|
||||
_process?.write(data: "$gameP4kPath\n");
|
||||
rs_process.write(rsPid: rsPid, data: "$gameP4kPath\n");
|
||||
state = state.copyWith(endMessage: "正在读取P4K 文件 ...");
|
||||
break;
|
||||
case "data: P4K_Files":
|
||||
@ -195,6 +193,9 @@ class Unp4kCModel extends _$Unp4kCModel {
|
||||
}
|
||||
outputPath = "$outputPath$filePath";
|
||||
dPrint("extractFile .... $filePath");
|
||||
_process?.write(data: "$mode<:,:>$filePath<:,:>$outputPath");
|
||||
if (_rsPid != null) {
|
||||
rs_process.write(
|
||||
rsPid: _rsPid!, data: "$mode<:,:>$filePath<:,:>$outputPath");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user