feat: Unp4kcState errorMessage

This commit is contained in:
xkeyC 2024-05-05 16:47:42 +08:00
parent 8d2b4983c0
commit 3e5a258cf8
7 changed files with 259 additions and 223 deletions

View File

@ -8,7 +8,7 @@ import 'package:starcitizen_doctor/common/utils/log.dart';
class BinaryModuleConf { class BinaryModuleConf {
static const _modules = { static const _modules = {
"aria2c": "0", "aria2c": "0",
"unp4kc": "0", "unp4kc": "1",
}; };
static Future extractModule(List<String> modules, String workingDir) async { static Future extractModule(List<String> modules, String workingDir) async {

View File

@ -29,6 +29,7 @@ class Unp4kcState with _$Unp4kcState {
required String curPath, required String curPath,
String? endMessage, String? endMessage,
MapEntry<String, String>? tempOpenFile, MapEntry<String, String>? tempOpenFile,
@Default("") String errorMessage,
}) = _Unp4kcState; }) = _Unp4kcState;
} }
@ -72,6 +73,12 @@ class Unp4kCModel extends _$Unp4kCModel {
break; break;
case RsProcessStreamDataType.error: case RsProcessStreamDataType.error:
dPrint("[unp4kc] stderr: ${event.data}"); dPrint("[unp4kc] stderr: ${event.data}");
if (state.errorMessage.isEmpty) {
state = state.copyWith(errorMessage: event.data);
} else {
state = state.copyWith(
errorMessage: "${state.errorMessage}\n${event.data}");
}
break; break;
case RsProcessStreamDataType.exit: case RsProcessStreamDataType.exit:
dPrint("[unp4kc] exit: ${event.data}"); dPrint("[unp4kc] exit: ${event.data}");

View File

@ -24,6 +24,7 @@ mixin _$Unp4kcState {
String? get endMessage => throw _privateConstructorUsedError; String? get endMessage => throw _privateConstructorUsedError;
MapEntry<String, String>? get tempOpenFile => MapEntry<String, String>? get tempOpenFile =>
throw _privateConstructorUsedError; throw _privateConstructorUsedError;
String get errorMessage => throw _privateConstructorUsedError;
@JsonKey(ignore: true) @JsonKey(ignore: true)
$Unp4kcStateCopyWith<Unp4kcState> get copyWith => $Unp4kcStateCopyWith<Unp4kcState> get copyWith =>
@ -42,7 +43,8 @@ abstract class $Unp4kcStateCopyWith<$Res> {
MemoryFileSystem? fs, MemoryFileSystem? fs,
String curPath, String curPath,
String? endMessage, String? endMessage,
MapEntry<String, String>? tempOpenFile}); MapEntry<String, String>? tempOpenFile,
String errorMessage});
} }
/// @nodoc /// @nodoc
@ -64,6 +66,7 @@ class _$Unp4kcStateCopyWithImpl<$Res, $Val extends Unp4kcState>
Object? curPath = null, Object? curPath = null,
Object? endMessage = freezed, Object? endMessage = freezed,
Object? tempOpenFile = freezed, Object? tempOpenFile = freezed,
Object? errorMessage = null,
}) { }) {
return _then(_value.copyWith( return _then(_value.copyWith(
startUp: null == startUp startUp: null == startUp
@ -90,6 +93,10 @@ class _$Unp4kcStateCopyWithImpl<$Res, $Val extends Unp4kcState>
? _value.tempOpenFile ? _value.tempOpenFile
: tempOpenFile // ignore: cast_nullable_to_non_nullable : tempOpenFile // ignore: cast_nullable_to_non_nullable
as MapEntry<String, String>?, as MapEntry<String, String>?,
errorMessage: null == errorMessage
? _value.errorMessage
: errorMessage // ignore: cast_nullable_to_non_nullable
as String,
) as $Val); ) as $Val);
} }
} }
@ -108,7 +115,8 @@ abstract class _$$Unp4kcStateImplCopyWith<$Res>
MemoryFileSystem? fs, MemoryFileSystem? fs,
String curPath, String curPath,
String? endMessage, String? endMessage,
MapEntry<String, String>? tempOpenFile}); MapEntry<String, String>? tempOpenFile,
String errorMessage});
} }
/// @nodoc /// @nodoc
@ -128,6 +136,7 @@ class __$$Unp4kcStateImplCopyWithImpl<$Res>
Object? curPath = null, Object? curPath = null,
Object? endMessage = freezed, Object? endMessage = freezed,
Object? tempOpenFile = freezed, Object? tempOpenFile = freezed,
Object? errorMessage = null,
}) { }) {
return _then(_$Unp4kcStateImpl( return _then(_$Unp4kcStateImpl(
startUp: null == startUp startUp: null == startUp
@ -154,6 +163,10 @@ class __$$Unp4kcStateImplCopyWithImpl<$Res>
? _value.tempOpenFile ? _value.tempOpenFile
: tempOpenFile // ignore: cast_nullable_to_non_nullable : tempOpenFile // ignore: cast_nullable_to_non_nullable
as MapEntry<String, String>?, as MapEntry<String, String>?,
errorMessage: null == errorMessage
? _value.errorMessage
: errorMessage // ignore: cast_nullable_to_non_nullable
as String,
)); ));
} }
} }
@ -167,7 +180,8 @@ class _$Unp4kcStateImpl with DiagnosticableTreeMixin implements _Unp4kcState {
this.fs, this.fs,
required this.curPath, required this.curPath,
this.endMessage, this.endMessage,
this.tempOpenFile}) this.tempOpenFile,
this.errorMessage = ""})
: _files = files; : _files = files;
@override @override
@ -190,10 +204,13 @@ class _$Unp4kcStateImpl with DiagnosticableTreeMixin implements _Unp4kcState {
final String? endMessage; final String? endMessage;
@override @override
final MapEntry<String, String>? tempOpenFile; final MapEntry<String, String>? tempOpenFile;
@override
@JsonKey()
final String errorMessage;
@override @override
String toString({DiagnosticLevel minLevel = DiagnosticLevel.info}) { String toString({DiagnosticLevel minLevel = DiagnosticLevel.info}) {
return 'Unp4kcState(startUp: $startUp, files: $files, fs: $fs, curPath: $curPath, endMessage: $endMessage, tempOpenFile: $tempOpenFile)'; return 'Unp4kcState(startUp: $startUp, files: $files, fs: $fs, curPath: $curPath, endMessage: $endMessage, tempOpenFile: $tempOpenFile, errorMessage: $errorMessage)';
} }
@override @override
@ -206,7 +223,8 @@ class _$Unp4kcStateImpl with DiagnosticableTreeMixin implements _Unp4kcState {
..add(DiagnosticsProperty('fs', fs)) ..add(DiagnosticsProperty('fs', fs))
..add(DiagnosticsProperty('curPath', curPath)) ..add(DiagnosticsProperty('curPath', curPath))
..add(DiagnosticsProperty('endMessage', endMessage)) ..add(DiagnosticsProperty('endMessage', endMessage))
..add(DiagnosticsProperty('tempOpenFile', tempOpenFile)); ..add(DiagnosticsProperty('tempOpenFile', tempOpenFile))
..add(DiagnosticsProperty('errorMessage', errorMessage));
} }
@override @override
@ -221,7 +239,9 @@ class _$Unp4kcStateImpl with DiagnosticableTreeMixin implements _Unp4kcState {
(identical(other.endMessage, endMessage) || (identical(other.endMessage, endMessage) ||
other.endMessage == endMessage) && other.endMessage == endMessage) &&
(identical(other.tempOpenFile, tempOpenFile) || (identical(other.tempOpenFile, tempOpenFile) ||
other.tempOpenFile == tempOpenFile)); other.tempOpenFile == tempOpenFile) &&
(identical(other.errorMessage, errorMessage) ||
other.errorMessage == errorMessage));
} }
@override @override
@ -232,7 +252,8 @@ class _$Unp4kcStateImpl with DiagnosticableTreeMixin implements _Unp4kcState {
fs, fs,
curPath, curPath,
endMessage, endMessage,
tempOpenFile); tempOpenFile,
errorMessage);
@JsonKey(ignore: true) @JsonKey(ignore: true)
@override @override
@ -248,7 +269,8 @@ abstract class _Unp4kcState implements Unp4kcState {
final MemoryFileSystem? fs, final MemoryFileSystem? fs,
required final String curPath, required final String curPath,
final String? endMessage, final String? endMessage,
final MapEntry<String, String>? tempOpenFile}) = _$Unp4kcStateImpl; final MapEntry<String, String>? tempOpenFile,
final String errorMessage}) = _$Unp4kcStateImpl;
@override @override
bool get startUp; bool get startUp;
@ -263,6 +285,8 @@ abstract class _Unp4kcState implements Unp4kcState {
@override @override
MapEntry<String, String>? get tempOpenFile; MapEntry<String, String>? get tempOpenFile;
@override @override
String get errorMessage;
@override
@JsonKey(ignore: true) @JsonKey(ignore: true)
_$$Unp4kcStateImplCopyWith<_$Unp4kcStateImpl> get copyWith => _$$Unp4kcStateImplCopyWith<_$Unp4kcStateImpl> get copyWith =>
throw _privateConstructorUsedError; throw _privateConstructorUsedError;

View File

@ -6,7 +6,7 @@ part of 'unp4kc.dart';
// RiverpodGenerator // RiverpodGenerator
// ************************************************************************** // **************************************************************************
String _$unp4kCModelHash() => r'be71e2f9c2060df5ed8f1b64cce993058320bac4'; String _$unp4kCModelHash() => r'24f5043f687a5f652a0741b8e6f4a3855fca0101';
/// See also [Unp4kCModel]. /// See also [Unp4kCModel].
@ProviderFor(Unp4kCModel) @ProviderFor(Unp4kCModel)

View File

@ -7,7 +7,7 @@ part of 'advanced_localization_ui_model.dart';
// ************************************************************************** // **************************************************************************
String _$advancedLocalizationUIModelHash() => String _$advancedLocalizationUIModelHash() =>
r'acf91fc467108c3669d8ddd6fed3c24434be4ae8'; r'9fbbeca3af90f992717710633bcf2cd0e1cb06eb';
/// See also [AdvancedLocalizationUIModel]. /// See also [AdvancedLocalizationUIModel].
@ProviderFor(AdvancedLocalizationUIModel) @ProviderFor(AdvancedLocalizationUIModel)

View File

@ -6,7 +6,7 @@ part of 'tools_ui_model.dart';
// RiverpodGenerator // RiverpodGenerator
// ************************************************************************** // **************************************************************************
String _$toolsUIModelHash() => r'4c27a3df07cb000ac58b74b3da48d926d0b01ea8'; String _$toolsUIModelHash() => r'bef6b6cf35ae13d7100fa8db85b7f6c04f244b27';
/// See also [ToolsUIModel]. /// See also [ToolsUIModel].
@ProviderFor(ToolsUIModel) @ProviderFor(ToolsUIModel)

View File

@ -6,6 +6,7 @@ import 'package:flutter_hooks/flutter_hooks.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart'; import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:re_editor/re_editor.dart'; import 'package:re_editor/re_editor.dart';
import 'package:starcitizen_doctor/common/helper/system_helper.dart'; import 'package:starcitizen_doctor/common/helper/system_helper.dart';
import 'package:starcitizen_doctor/data/app_unp4k_p4k_item_data.dart';
import 'package:starcitizen_doctor/provider/unp4kc.dart'; import 'package:starcitizen_doctor/provider/unp4kc.dart';
import 'package:starcitizen_doctor/widgets/widgets.dart'; import 'package:starcitizen_doctor/widgets/widgets.dart';
import 'package:super_sliver_list/super_sliver_list.dart'; import 'package:super_sliver_list/super_sliver_list.dart';
@ -22,7 +23,20 @@ class UnP4kcUI extends HookConsumerWidget {
return makeDefaultPage(context, return makeDefaultPage(context,
title: S.current.tools_unp4k_title(model.getGamePath()), title: S.current.tools_unp4k_title(model.getGamePath()),
useBodyContainer: false, useBodyContainer: false,
content: state.files == null content: makeBody(context, state, model, files, paths));
}
Widget makeBody(BuildContext context, Unp4kcState state, Unp4kCModel model,
List<AppUnp4kP4kItemData>? files, List<String> paths) {
if (state.errorMessage.isNotEmpty) {
return Padding(
padding: const EdgeInsets.all(24),
child: Center(
child: Text(state.errorMessage),
),
);
}
return state.files == null
? Column( ? Column(
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
children: [ children: [
@ -42,8 +56,7 @@ class UnP4kcUI extends HookConsumerWidget {
children: [ children: [
Container( Container(
decoration: BoxDecoration( decoration: BoxDecoration(
color: color: FluentTheme.of(context).cardColor.withOpacity(.06)),
FluentTheme.of(context).cardColor.withOpacity(.06)),
height: 36, height: 36,
padding: const EdgeInsets.only(left: 12, right: 12), padding: const EdgeInsets.only(left: 12, right: 12),
child: SuperListView.builder( child: SuperListView.builder(
@ -79,17 +92,15 @@ class UnP4kcUI extends HookConsumerWidget {
Container( Container(
width: MediaQuery.of(context).size.width * .3, width: MediaQuery.of(context).size.width * .3,
decoration: BoxDecoration( decoration: BoxDecoration(
color: FluentTheme.of(context) color: FluentTheme.of(context).cardColor.withOpacity(.01),
.cardColor
.withOpacity(.01),
), ),
child: SuperListView.builder( child: SuperListView.builder(
padding: const EdgeInsets.only( padding: const EdgeInsets.only(
top: 6, bottom: 6, left: 3, right: 12), top: 6, bottom: 6, left: 3, right: 12),
itemBuilder: (BuildContext context, int index) { itemBuilder: (BuildContext context, int index) {
final item = files![index]; final item = files![index];
final fileName = item.name final fileName =
?.replaceAll(state.curPath.trim(), "") ?? item.name?.replaceAll(state.curPath.trim(), "") ??
"?"; "?";
return Container( return Container(
margin: const EdgeInsets.only(top: 4, bottom: 4), margin: const EdgeInsets.only(top: 4, bottom: 4),
@ -107,15 +118,13 @@ class UnP4kcUI extends HookConsumerWidget {
} }
}, },
icon: Padding( icon: Padding(
padding: padding: const EdgeInsets.only(left: 4, right: 4),
const EdgeInsets.only(left: 4, right: 4),
child: Row( child: Row(
children: [ children: [
if (item.isDirectory ?? false) if (item.isDirectory ?? false)
const Icon( const Icon(
FluentIcons.folder_fill, FluentIcons.folder_fill,
color: color: Color.fromRGBO(255, 224, 138, 1),
Color.fromRGBO(255, 224, 138, 1),
) )
else if (fileName.endsWith(".xml")) else if (fileName.endsWith(".xml"))
const Icon( const Icon(
@ -143,8 +152,7 @@ class UnP4kcUI extends HookConsumerWidget {
), ),
], ],
), ),
if (!(item.isDirectory ?? if (!(item.isDirectory ?? true)) ...[
true)) ...[
const SizedBox(height: 1), const SizedBox(height: 1),
Row( Row(
children: [ children: [
@ -188,8 +196,7 @@ class UnP4kcUI extends HookConsumerWidget {
child: Container( child: Container(
child: state.tempOpenFile == null child: state.tempOpenFile == null
? Center( ? Center(
child: child: Text(S.current.tools_unp4k_view_file),
Text(S.current.tools_unp4k_view_file),
) )
: state.tempOpenFile?.key == "loading" : state.tempOpenFile?.key == "loading"
? makeLoading(context) ? makeLoading(context)
@ -200,8 +207,7 @@ class UnP4kcUI extends HookConsumerWidget {
if (state.tempOpenFile?.key == "text") if (state.tempOpenFile?.key == "text")
Expanded( Expanded(
child: _TextTempWidget( child: _TextTempWidget(
state.tempOpenFile?.value ?? state.tempOpenFile?.value ?? ""))
""))
else else
Expanded( Expanded(
child: Center( child: Center(
@ -217,14 +223,13 @@ class UnP4kcUI extends HookConsumerWidget {
FilledButton( FilledButton(
child: Padding( child: Padding(
padding: padding:
const EdgeInsets const EdgeInsets.all(4),
.all(4),
child: Text(S.current child: Text(S.current
.action_open_folder), .action_open_folder),
), ),
onPressed: () { onPressed: () {
SystemHelper.openDir( SystemHelper.openDir(state
state.tempOpenFile .tempOpenFile
?.value ?? ?.value ??
""); "");
}) })
@ -247,7 +252,7 @@ class UnP4kcUI extends HookConsumerWidget {
), ),
), ),
], ],
)); );
} }
} }