2024-04-14 19:52:42 +08:00
|
|
|
import 'dart:io';
|
|
|
|
|
|
|
|
import 'package:file_sizes/file_sizes.dart';
|
|
|
|
import 'package:fluent_ui/fluent_ui.dart';
|
|
|
|
import 'package:flutter_hooks/flutter_hooks.dart';
|
|
|
|
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
|
|
|
import 'package:re_editor/re_editor.dart';
|
2024-05-07 21:08:16 +08:00
|
|
|
import 'package:starcitizen_doctor/api/analytics.dart';
|
2024-04-14 19:52:42 +08:00
|
|
|
import 'package:starcitizen_doctor/common/helper/system_helper.dart';
|
2024-05-05 16:47:42 +08:00
|
|
|
import 'package:starcitizen_doctor/data/app_unp4k_p4k_item_data.dart';
|
2024-04-14 19:52:42 +08:00
|
|
|
import 'package:starcitizen_doctor/provider/unp4kc.dart';
|
|
|
|
import 'package:starcitizen_doctor/widgets/widgets.dart';
|
|
|
|
import 'package:super_sliver_list/super_sliver_list.dart';
|
2024-05-06 20:21:35 +08:00
|
|
|
import 'package:url_launcher/url_launcher_string.dart';
|
2024-04-14 19:52:42 +08:00
|
|
|
|
|
|
|
class UnP4kcUI extends HookConsumerWidget {
|
|
|
|
const UnP4kcUI({super.key});
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context, WidgetRef ref) {
|
|
|
|
final state = ref.watch(unp4kCModelProvider);
|
|
|
|
final model = ref.read(unp4kCModelProvider.notifier);
|
|
|
|
final files = model.getFiles();
|
|
|
|
final paths = state.curPath.trim().split("\\");
|
2024-05-07 21:08:16 +08:00
|
|
|
|
|
|
|
useEffect(() {
|
|
|
|
AnalyticsApi.touch("unp4k_launch");
|
|
|
|
return null;
|
|
|
|
}, const []);
|
|
|
|
|
2024-04-14 19:52:42 +08:00
|
|
|
return makeDefaultPage(context,
|
2024-05-05 16:34:38 +08:00
|
|
|
title: S.current.tools_unp4k_title(model.getGamePath()),
|
2024-04-14 19:52:42 +08:00
|
|
|
useBodyContainer: false,
|
2024-05-05 16:47:42 +08:00
|
|
|
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) {
|
2024-05-06 20:21:35 +08:00
|
|
|
return UnP4kErrorWidget(errorMessage: state.errorMessage);
|
2024-05-05 16:47:42 +08:00
|
|
|
}
|
|
|
|
return state.files == null
|
|
|
|
? Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: [
|
|
|
|
Expanded(child: makeLoading(context)),
|
|
|
|
if (state.endMessage != null)
|
|
|
|
Padding(
|
|
|
|
padding: const EdgeInsets.all(8.0),
|
|
|
|
child: Text(
|
|
|
|
"${state.endMessage}",
|
|
|
|
style: const TextStyle(fontSize: 12),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
)
|
|
|
|
: Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: [
|
|
|
|
Container(
|
|
|
|
decoration: BoxDecoration(
|
2024-12-14 13:48:24 +08:00
|
|
|
color: FluentTheme.of(context)
|
|
|
|
.cardColor
|
|
|
|
.withValues(alpha: .06)),
|
2024-05-05 16:47:42 +08:00
|
|
|
height: 36,
|
|
|
|
padding: const EdgeInsets.only(left: 12, right: 12),
|
|
|
|
child: SuperListView.builder(
|
|
|
|
itemCount: paths.length - 1,
|
|
|
|
scrollDirection: Axis.horizontal,
|
|
|
|
itemBuilder: (BuildContext context, int index) {
|
|
|
|
var path = paths[index];
|
|
|
|
if (path.isEmpty) {
|
|
|
|
path = "\\";
|
|
|
|
}
|
|
|
|
final fullPath =
|
|
|
|
"${paths.sublist(0, index + 1).join("\\")}\\";
|
|
|
|
return Row(
|
|
|
|
children: [
|
|
|
|
IconButton(
|
|
|
|
icon: Text(path),
|
|
|
|
onPressed: () {
|
|
|
|
model.changeDir(fullPath, fullPath: true);
|
|
|
|
},
|
|
|
|
),
|
|
|
|
const Icon(
|
|
|
|
FluentIcons.chevron_right,
|
|
|
|
size: 12,
|
|
|
|
),
|
|
|
|
],
|
|
|
|
);
|
|
|
|
},
|
|
|
|
),
|
|
|
|
),
|
|
|
|
Expanded(
|
|
|
|
child: Row(
|
2024-04-14 19:52:42 +08:00
|
|
|
children: [
|
|
|
|
Container(
|
2024-05-05 16:47:42 +08:00
|
|
|
width: MediaQuery.of(context).size.width * .3,
|
2024-04-14 19:52:42 +08:00
|
|
|
decoration: BoxDecoration(
|
2024-12-14 13:48:24 +08:00
|
|
|
color: FluentTheme.of(context)
|
|
|
|
.cardColor
|
|
|
|
.withValues(alpha: .01),
|
2024-05-05 16:47:42 +08:00
|
|
|
),
|
2024-04-14 19:52:42 +08:00
|
|
|
child: SuperListView.builder(
|
2024-05-05 16:47:42 +08:00
|
|
|
padding: const EdgeInsets.only(
|
|
|
|
top: 6, bottom: 6, left: 3, right: 12),
|
2024-04-14 19:52:42 +08:00
|
|
|
itemBuilder: (BuildContext context, int index) {
|
2024-05-05 16:47:42 +08:00
|
|
|
final item = files![index];
|
|
|
|
final fileName =
|
|
|
|
item.name?.replaceAll(state.curPath.trim(), "") ??
|
|
|
|
"?";
|
|
|
|
return Container(
|
|
|
|
margin: const EdgeInsets.only(top: 4, bottom: 4),
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
color: FluentTheme.of(context)
|
|
|
|
.cardColor
|
2024-12-14 13:48:24 +08:00
|
|
|
.withValues(alpha: .05),
|
2024-05-05 16:47:42 +08:00
|
|
|
),
|
|
|
|
child: IconButton(
|
|
|
|
onPressed: () {
|
|
|
|
if (item.isDirectory ?? false) {
|
|
|
|
model.changeDir(fileName);
|
|
|
|
} else {
|
|
|
|
model.openFile(item.name ?? "");
|
|
|
|
}
|
|
|
|
},
|
|
|
|
icon: Padding(
|
|
|
|
padding: const EdgeInsets.only(left: 4, right: 4),
|
|
|
|
child: Row(
|
|
|
|
children: [
|
|
|
|
if (item.isDirectory ?? false)
|
|
|
|
const Icon(
|
|
|
|
FluentIcons.folder_fill,
|
|
|
|
color: Color.fromRGBO(255, 224, 138, 1),
|
|
|
|
)
|
|
|
|
else if (fileName.endsWith(".xml"))
|
|
|
|
const Icon(
|
|
|
|
FluentIcons.file_code,
|
|
|
|
)
|
|
|
|
else
|
|
|
|
const Icon(
|
|
|
|
FluentIcons.open_file,
|
|
|
|
),
|
|
|
|
const SizedBox(width: 12),
|
|
|
|
Expanded(
|
|
|
|
child: Column(
|
|
|
|
crossAxisAlignment:
|
|
|
|
CrossAxisAlignment.start,
|
|
|
|
children: [
|
|
|
|
Row(
|
|
|
|
children: [
|
|
|
|
Expanded(
|
|
|
|
child: Text(
|
|
|
|
fileName,
|
|
|
|
style: const TextStyle(
|
|
|
|
fontSize: 13),
|
|
|
|
textAlign: TextAlign.start,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
if (!(item.isDirectory ?? true)) ...[
|
|
|
|
const SizedBox(height: 1),
|
|
|
|
Row(
|
|
|
|
children: [
|
|
|
|
Text(
|
|
|
|
FileSize.getSize(item.size),
|
|
|
|
style: TextStyle(
|
|
|
|
fontSize: 10,
|
|
|
|
color: Colors.white
|
2024-12-14 13:48:24 +08:00
|
|
|
.withValues(alpha: .6)),
|
2024-05-05 16:47:42 +08:00
|
|
|
),
|
|
|
|
const SizedBox(width: 12),
|
|
|
|
Text(
|
|
|
|
"${item.dateTime}",
|
|
|
|
style: TextStyle(
|
|
|
|
fontSize: 10,
|
|
|
|
color: Colors.white
|
2024-12-14 13:48:24 +08:00
|
|
|
.withValues(alpha: .6)),
|
2024-05-05 16:47:42 +08:00
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
],
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
const SizedBox(width: 3),
|
|
|
|
Icon(
|
|
|
|
FluentIcons.chevron_right,
|
|
|
|
size: 14,
|
2024-12-14 13:48:24 +08:00
|
|
|
color: Colors.white.withValues(alpha: .6),
|
2024-05-05 16:47:42 +08:00
|
|
|
)
|
|
|
|
],
|
|
|
|
),
|
2024-04-14 19:52:42 +08:00
|
|
|
),
|
2024-05-05 16:47:42 +08:00
|
|
|
),
|
2024-04-14 19:52:42 +08:00
|
|
|
);
|
|
|
|
},
|
2024-05-05 16:47:42 +08:00
|
|
|
itemCount: files?.length ?? 0,
|
2024-04-14 19:52:42 +08:00
|
|
|
),
|
|
|
|
),
|
|
|
|
Expanded(
|
2024-05-05 16:47:42 +08:00
|
|
|
child: Container(
|
|
|
|
child: state.tempOpenFile == null
|
|
|
|
? Center(
|
|
|
|
child: Text(S.current.tools_unp4k_view_file),
|
|
|
|
)
|
|
|
|
: state.tempOpenFile?.key == "loading"
|
|
|
|
? makeLoading(context)
|
|
|
|
: Padding(
|
|
|
|
padding: const EdgeInsets.all(12),
|
|
|
|
child: Column(
|
|
|
|
children: [
|
|
|
|
if (state.tempOpenFile?.key == "text")
|
2024-04-14 19:52:42 +08:00
|
|
|
Expanded(
|
2024-05-05 16:47:42 +08:00
|
|
|
child: _TextTempWidget(
|
|
|
|
state.tempOpenFile?.value ?? ""))
|
|
|
|
else
|
|
|
|
Expanded(
|
|
|
|
child: Center(
|
|
|
|
child: Column(
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
|
|
|
children: [
|
|
|
|
Text(S.current
|
|
|
|
.tools_unp4k_msg_unknown_file_type(
|
|
|
|
state.tempOpenFile
|
|
|
|
?.value ??
|
|
|
|
"")),
|
|
|
|
const SizedBox(height: 32),
|
|
|
|
FilledButton(
|
|
|
|
child: Padding(
|
|
|
|
padding:
|
|
|
|
const EdgeInsets.all(4),
|
|
|
|
child: Text(S.current
|
|
|
|
.action_open_folder),
|
2024-04-14 19:52:42 +08:00
|
|
|
),
|
2024-05-05 16:47:42 +08:00
|
|
|
onPressed: () {
|
|
|
|
SystemHelper.openDir(state
|
|
|
|
.tempOpenFile
|
|
|
|
?.value ??
|
|
|
|
"");
|
|
|
|
})
|
2024-04-14 19:52:42 +08:00
|
|
|
],
|
2024-05-05 16:47:42 +08:00
|
|
|
),
|
2024-04-14 19:52:42 +08:00
|
|
|
),
|
|
|
|
)
|
2024-05-05 16:47:42 +08:00
|
|
|
],
|
2024-04-14 19:52:42 +08:00
|
|
|
),
|
|
|
|
),
|
2024-05-05 16:47:42 +08:00
|
|
|
))
|
2024-04-14 19:52:42 +08:00
|
|
|
],
|
2024-05-05 16:47:42 +08:00
|
|
|
)),
|
|
|
|
if (state.endMessage != null)
|
|
|
|
Padding(
|
|
|
|
padding: const EdgeInsets.all(8.0),
|
|
|
|
child: Text(
|
|
|
|
"${state.endMessage}",
|
|
|
|
style: const TextStyle(fontSize: 12),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
);
|
2024-04-14 19:52:42 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class _TextTempWidget extends HookConsumerWidget {
|
|
|
|
final String filePath;
|
|
|
|
|
|
|
|
const _TextTempWidget(this.filePath);
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context, WidgetRef ref) {
|
|
|
|
final textData = useState<String?>(null);
|
|
|
|
|
|
|
|
useEffect(() {
|
|
|
|
File(filePath).readAsString().then((value) {
|
|
|
|
textData.value = value;
|
|
|
|
}).catchError((err) {
|
|
|
|
textData.value = "Error: $err";
|
|
|
|
});
|
|
|
|
return null;
|
|
|
|
}, const []);
|
|
|
|
|
|
|
|
if (textData.value == null) return makeLoading(context);
|
|
|
|
|
|
|
|
return CodeEditor(
|
|
|
|
controller: CodeLineEditingController.fromText('${textData.value}'),
|
2024-05-05 14:59:07 +08:00
|
|
|
readOnly: true,
|
2024-04-14 19:52:42 +08:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2024-05-06 20:21:35 +08:00
|
|
|
|
|
|
|
class UnP4kErrorWidget extends StatelessWidget {
|
|
|
|
final String errorMessage;
|
|
|
|
|
|
|
|
const UnP4kErrorWidget({super.key, required this.errorMessage});
|
|
|
|
|
|
|
|
static const _downloadUrl =
|
|
|
|
"https://aka.ms/dotnet-core-applaunch?missing_runtime=true&arch=x64&rid=win-x64&os=win10&apphost_version=8.0.0";
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return Padding(
|
|
|
|
padding: const EdgeInsets.all(24),
|
|
|
|
child: Center(
|
|
|
|
child: Column(
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
|
|
|
children: [
|
2024-06-16 09:14:51 +08:00
|
|
|
if (Unp4kCModel.checkRunTimeError(errorMessage)) ...[
|
2024-05-06 20:29:32 +08:00
|
|
|
Text(
|
|
|
|
S.current.tools_unp4k_missing_runtime,
|
|
|
|
style: const TextStyle(fontSize: 16),
|
2024-05-06 20:21:35 +08:00
|
|
|
),
|
|
|
|
const SizedBox(height: 6),
|
2024-05-06 20:29:32 +08:00
|
|
|
Text(S.current.tools_unp4k_missing_runtime_info),
|
2024-05-06 20:21:35 +08:00
|
|
|
const SizedBox(height: 16),
|
|
|
|
FilledButton(
|
2024-05-06 20:29:32 +08:00
|
|
|
child: Padding(
|
2024-05-07 21:08:16 +08:00
|
|
|
padding:
|
|
|
|
const EdgeInsets.symmetric(horizontal: 12, vertical: 3),
|
2024-05-06 20:29:32 +08:00
|
|
|
child: Text(
|
|
|
|
S.current.tools_unp4k_missing_runtime_action_install),
|
2024-05-06 20:21:35 +08:00
|
|
|
),
|
|
|
|
onPressed: () {
|
|
|
|
launchUrlString(_downloadUrl);
|
|
|
|
}),
|
|
|
|
] else
|
|
|
|
Text(errorMessage),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|