update: Unp4kCModel

This commit is contained in:
xkeyC 2024-04-17 23:09:28 +08:00
parent 097b9d9bce
commit a8e91d6332
2 changed files with 25 additions and 4 deletions

Binary file not shown.

View File

@ -56,9 +56,9 @@ class Unp4kCModel extends _$Unp4kCModel {
executable: exec, arguments: [], workingDirectory: execDir); executable: exec, arguments: [], workingDirectory: execDir);
stream.listen((event) async { stream.listen((event) async {
_rsPid = event.rsPid;
switch (event.dataType) { switch (event.dataType) {
case RsProcessStreamDataType.output: case RsProcessStreamDataType.output:
_rsPid = event.rsPid;
try { try {
final eventJson = await compute(json.decode, event.data); final eventJson = await compute(json.decode, event.data);
_handleMessage(eventJson, event.rsPid); _handleMessage(eventJson, event.rsPid);
@ -76,6 +76,7 @@ class Unp4kCModel extends _$Unp4kCModel {
}); });
ref.onDispose(() { ref.onDispose(() {
state = state.copyWith(fs: null);
if (_rsPid != null) { if (_rsPid != null) {
Process.killPid(_rsPid!); Process.killPid(_rsPid!);
dPrint("[unp4kc] kill ..."); dPrint("[unp4kc] kill ...");
@ -83,6 +84,8 @@ class Unp4kCModel extends _$Unp4kCModel {
}); });
} }
DateTime? _loadStartTime;
void _handleMessage(Map<String, dynamic> eventJson, int rsPid) async { void _handleMessage(Map<String, dynamic> eventJson, int rsPid) async {
final action = eventJson["action"]; final action = eventJson["action"];
final data = eventJson["data"]; final data = eventJson["data"];
@ -91,13 +94,20 @@ class Unp4kCModel extends _$Unp4kCModel {
switch (action.toString().trim()) { switch (action.toString().trim()) {
case "info: startup": case "info: startup":
rs_process.write(rsPid: rsPid, data: "$gameP4kPath\n"); rs_process.write(rsPid: rsPid, data: "$gameP4kPath\n");
break;
case "info: Reading_p4k_file":
_loadStartTime = DateTime.now();
state = state.copyWith(endMessage: "正在读取P4K 文件 ..."); state = state.copyWith(endMessage: "正在读取P4K 文件 ...");
break; break;
case "info: All Ready":
state = state.copyWith(endMessage: "正在处理文件 ...");
break;
case "data: P4K_Files": case "data: P4K_Files":
final p4kFiles = (data as List<dynamic>); final p4kFiles = (data as List<dynamic>);
final files = <String, AppUnp4kP4kItemData>{}; final files = <String, AppUnp4kP4kItemData>{};
final fs = MemoryFileSystem(style: FileSystemStyle.posix); final fs = MemoryFileSystem(style: FileSystemStyle.posix);
state = state.copyWith(endMessage: "正在处理文件 ...");
var nextAwait = 0;
for (var i = 0; i < p4kFiles.length; i++) { for (var i = 0; i < p4kFiles.length; i++) {
final item = AppUnp4kP4kItemData.fromJson(p4kFiles[i]); final item = AppUnp4kP4kItemData.fromJson(p4kFiles[i]);
item.name = "${item.name}"; item.name = "${item.name}";
@ -105,9 +115,20 @@ class Unp4kCModel extends _$Unp4kCModel {
await fs await fs
.file(item.name?.replaceAll("\\", "/") ?? "") .file(item.name?.replaceAll("\\", "/") ?? "")
.create(recursive: true); .create(recursive: true);
if (i == nextAwait) {
state = state.copyWith(
endMessage: "正在处理文件 ($i/${p4kFiles.length}) ...");
await Future.delayed(const Duration(microseconds: 0));
nextAwait += 20000;
}
} }
final endTime = DateTime.now();
state = state.copyWith( state = state.copyWith(
files: files, fs: fs, endMessage: "加载完毕:${files.length} 个文件"); files: files,
fs: fs,
endMessage:
"加载完毕:${files.length} 个文件,用时:${endTime.difference(_loadStartTime!).inMilliseconds} ms");
_loadStartTime = null;
break; break;
case "info: Extracted_Open": case "info: Extracted_Open":
final filePath = data.toString(); final filePath = data.toString();
@ -195,7 +216,7 @@ class Unp4kCModel extends _$Unp4kCModel {
dPrint("extractFile .... $filePath"); dPrint("extractFile .... $filePath");
if (_rsPid != null) { if (_rsPid != null) {
rs_process.write( rs_process.write(
rsPid: _rsPid!, data: "$mode<:,:>$filePath<:,:>$outputPath"); rsPid: _rsPid!, data: "$mode<:,:>$filePath<:,:>$outputPath\n");
} }
} }
} }