import 'dart:io';
|
|
import 'package:file_picker/file_picker.dart';
|
import 'package:flutter/material.dart';
|
import 'package:fluttergamebox/common/theme.dart';
|
import 'package:fluttergamebox/utils/network_info.dart';
|
import 'package:fluttergamebox/utils/util.dart';
|
|
String _wmic(String cmd, String arg) {
|
try {
|
final result = Process.runSync(cmd, arg.split(' '));
|
final lines = result.stdout
|
.toString()
|
.split('\n')
|
.map((l) => l.trim())
|
.where((l) => l.isNotEmpty)
|
.toList();
|
if (lines.length > 1) return lines[1];
|
} catch (_) {}
|
return '';
|
}
|
|
/// 电脑设备配置弹窗
|
void showDeviceConfigDialog(BuildContext context) {
|
final cpu = _wmic('wmic', 'cpu get Name');
|
final ramBytes = int.tryParse(_wmic('wmic', 'ComputerSystem get TotalPhysicalMemory')) ?? 0;
|
final lines = [
|
'操作系统: ${Platform.operatingSystemVersion}',
|
'CPU: ${cpu.isEmpty ? '未知' : cpu}',
|
'内存: ${(ramBytes / 1024 / 1024 / 1024).toStringAsFixed(1)} GiB',
|
'主机名: ${Platform.localHostname}',
|
'设备序列号: ${_deviceSerial()}',
|
'客户端版本号: V2.2.5',
|
];
|
_greenInfoDialog(context, '电脑设备配置', Icons.computer, lines);
|
}
|
|
String _deviceSerial() {
|
try {
|
final result = Process.runSync('wmic', ['csproduct', 'get', 'UUID']);
|
final out = result.stdout.toString();
|
final lines =
|
out.split('\n').map((l) => l.trim()).where((l) => l.isNotEmpty).toList();
|
if (lines.length > 1) return lines[1];
|
} catch (_) {}
|
return '00326-60000-00000-AA068';
|
}
|
|
/// 电脑网络信息弹窗(获取真实网络信息)
|
void showNetworkInfoDialog(BuildContext context) {
|
showDialog(
|
context: context,
|
builder: (context) => const _NetworkInfoDialog(),
|
);
|
}
|
|
class _NetworkInfoDialog extends StatefulWidget {
|
const _NetworkInfoDialog();
|
@override
|
State<_NetworkInfoDialog> createState() => _NetworkInfoDialogState();
|
}
|
|
class _NetworkInfoDialogState extends State<_NetworkInfoDialog> {
|
List<String> _lines = ['正在获取网络信息...'];
|
|
@override
|
void initState() {
|
super.initState();
|
_load();
|
}
|
|
Future<void> _load() async {
|
final n = await getNetworkInfo();
|
final lines = [
|
'连接方式: ${n.connType}',
|
'内网IP: ${n.localIp}',
|
'网关: ${n.gateway}',
|
'DNS: ${n.dns}',
|
'公网IP: ${n.publicIp}',
|
'地区: ${n.location}',
|
'运营商: ${n.isp}',
|
];
|
if (mounted) setState(() => _lines = lines);
|
}
|
|
@override
|
Widget build(BuildContext context) {
|
return Dialog(
|
backgroundColor: const Color(0xFF14161F),
|
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(6)),
|
child: Container(
|
width: 420,
|
padding: EdgeInsets.zero,
|
child: Column(
|
mainAxisSize: MainAxisSize.min,
|
children: [
|
// 标题栏
|
Container(
|
height: 40,
|
padding: const EdgeInsets.symmetric(horizontal: 12),
|
decoration: BoxDecoration(
|
color: const Color(0xFF191C2B),
|
borderRadius:
|
const BorderRadius.vertical(top: Radius.circular(6)),
|
),
|
child: Row(
|
children: [
|
const Icon(Icons.wifi, size: 16, color: AppColors.textGray),
|
const SizedBox(width: 8),
|
const Text('电脑网络信息',
|
style: TextStyle(color: Colors.white, fontSize: 13)),
|
const Spacer(),
|
GestureDetector(
|
onTap: () => Navigator.pop(context),
|
child: const Icon(Icons.close,
|
size: 16, color: AppColors.textGray),
|
),
|
],
|
),
|
),
|
Padding(
|
padding: const EdgeInsets.all(20),
|
child: Column(
|
crossAxisAlignment: CrossAxisAlignment.start,
|
children: _lines
|
.map((l) => Padding(
|
padding: const EdgeInsets.symmetric(vertical: 3),
|
child: Text(l,
|
style: const TextStyle(
|
color: Color(0xFF33FF66),
|
fontSize: 13,
|
fontFamily: 'Consolas')),
|
))
|
.toList(),
|
),
|
),
|
],
|
),
|
),
|
);
|
}
|
}
|
|
void _greenInfoDialog(
|
BuildContext context, String title, IconData icon, List<String> lines) {
|
showDialog(
|
context: context,
|
builder: (context) => Dialog(
|
backgroundColor: const Color(0xFF14161F),
|
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(6)),
|
child: Container(
|
width: 420,
|
padding: EdgeInsets.zero,
|
child: Column(
|
mainAxisSize: MainAxisSize.min,
|
children: [
|
// 标题栏
|
Container(
|
height: 40,
|
padding: const EdgeInsets.symmetric(horizontal: 12),
|
decoration: BoxDecoration(
|
color: const Color(0xFF191C2B),
|
borderRadius:
|
const BorderRadius.vertical(top: Radius.circular(6)),
|
),
|
child: Row(
|
children: [
|
Icon(icon, size: 16, color: AppColors.textGray),
|
const SizedBox(width: 8),
|
Text(title,
|
style: const TextStyle(
|
color: Colors.white, fontSize: 13)),
|
const Spacer(),
|
GestureDetector(
|
onTap: () => Navigator.pop(context),
|
child: const Icon(Icons.close,
|
size: 16, color: AppColors.textGray),
|
),
|
],
|
),
|
),
|
Padding(
|
padding: const EdgeInsets.all(20),
|
child: Column(
|
crossAxisAlignment: CrossAxisAlignment.start,
|
children: lines
|
.map((l) => Padding(
|
padding: const EdgeInsets.symmetric(vertical: 3),
|
child: Text(l,
|
style: const TextStyle(
|
color: Color(0xFF33FF66),
|
fontSize: 13,
|
fontFamily: 'Consolas')),
|
))
|
.toList(),
|
),
|
),
|
],
|
),
|
),
|
),
|
);
|
}
|
|
/// 下载安装路径设置弹窗
|
void showPathDialog(BuildContext context) {
|
showDialog(
|
context: context,
|
builder: (context) => const _PathDialog(),
|
);
|
}
|
|
class _PathDialog extends StatefulWidget {
|
const _PathDialog();
|
@override
|
State<_PathDialog> createState() => _PathDialogState();
|
}
|
|
class _PathDialogState extends State<_PathDialog> {
|
final _dlCtrl = TextEditingController();
|
final _insCtrl = TextEditingController();
|
bool _diskCheck = true;
|
bool _hddCheck = false;
|
|
@override
|
void initState() {
|
super.initState();
|
_load();
|
}
|
|
Future<void> _load() async {
|
final dl = await AppPrefs.getDownloadPath();
|
final ins = await AppPrefs.getInstallPath();
|
setState(() {
|
_dlCtrl.text = dl.isEmpty ? 'C:\\99GameBox\\99GameD' : dl;
|
_insCtrl.text = ins.isEmpty ? 'C:\\99GameBox\\99GameI' : ins;
|
});
|
}
|
|
Future<void> _pick(TextEditingController ctrl) async {
|
final dir = await FilePicker.platform.getDirectoryPath();
|
if (dir != null) {
|
setState(() => ctrl.text = dir);
|
}
|
}
|
|
@override
|
Widget build(BuildContext context) {
|
return Dialog(
|
backgroundColor: const Color(0xFF1E2130),
|
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(6)),
|
child: Container(
|
width: 480,
|
padding: const EdgeInsets.all(24),
|
child: Column(
|
mainAxisSize: MainAxisSize.min,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
children: [
|
Row(
|
children: [
|
const Icon(Icons.folder_open,
|
size: 16, color: AppColors.textGray),
|
const SizedBox(width: 8),
|
const Text('下载安装路径',
|
style: TextStyle(
|
color: Colors.white,
|
fontSize: 14,
|
fontWeight: FontWeight.w500)),
|
const Spacer(),
|
GestureDetector(
|
onTap: () => Navigator.pop(context),
|
child: const Icon(Icons.close,
|
size: 16, color: AppColors.textGray),
|
),
|
],
|
),
|
const SizedBox(height: 20),
|
const Text('下载路径:',
|
style: TextStyle(color: AppColors.textWhite, fontSize: 13)),
|
const SizedBox(height: 8),
|
Row(
|
children: [
|
Expanded(
|
child: TextField(
|
controller: _dlCtrl,
|
style: const TextStyle(
|
color: Colors.black, fontSize: 13),
|
decoration: InputDecoration(
|
filled: true,
|
fillColor: Colors.white,
|
contentPadding: const EdgeInsets.symmetric(
|
horizontal: 10, vertical: 10),
|
border: OutlineInputBorder(
|
borderRadius: BorderRadius.circular(4),
|
borderSide: BorderSide.none),
|
),
|
),
|
),
|
const SizedBox(width: 8),
|
ElevatedButton(
|
onPressed: () => _pick(_dlCtrl),
|
style: ElevatedButton.styleFrom(
|
backgroundColor: AppColors.accent,
|
foregroundColor: Colors.white,
|
padding: const EdgeInsets.symmetric(
|
horizontal: 14, vertical: 11),
|
),
|
child: const Text('选择目录', style: TextStyle(fontSize: 12)),
|
),
|
],
|
),
|
const SizedBox(height: 14),
|
const Text('安装路径:',
|
style: TextStyle(color: AppColors.textWhite, fontSize: 13)),
|
const SizedBox(height: 8),
|
Row(
|
children: [
|
Expanded(
|
child: TextField(
|
controller: _insCtrl,
|
style: const TextStyle(
|
color: Colors.black, fontSize: 13),
|
decoration: InputDecoration(
|
filled: true,
|
fillColor: Colors.white,
|
contentPadding: const EdgeInsets.symmetric(
|
horizontal: 10, vertical: 10),
|
border: OutlineInputBorder(
|
borderRadius: BorderRadius.circular(4),
|
borderSide: BorderSide.none),
|
),
|
),
|
),
|
const SizedBox(width: 8),
|
ElevatedButton(
|
onPressed: () => _pick(_insCtrl),
|
style: ElevatedButton.styleFrom(
|
backgroundColor: AppColors.accent,
|
foregroundColor: Colors.white,
|
padding: const EdgeInsets.symmetric(
|
horizontal: 14, vertical: 11),
|
),
|
child: const Text('选择目录', style: TextStyle(fontSize: 12)),
|
),
|
],
|
),
|
const SizedBox(height: 14),
|
Row(
|
children: [
|
_checkbox('磁盘检测', _diskCheck,
|
(v) => setState(() => _diskCheck = v ?? false)),
|
const SizedBox(width: 20),
|
_checkbox('机械硬盘勾选', _hddCheck,
|
(v) => setState(() => _hddCheck = v ?? false)),
|
],
|
),
|
const SizedBox(height: 22),
|
Row(
|
mainAxisAlignment: MainAxisAlignment.end,
|
children: [
|
OutlinedButton(
|
onPressed: () => Navigator.pop(context),
|
style: OutlinedButton.styleFrom(
|
foregroundColor: AppColors.textGray,
|
side: const BorderSide(color: AppColors.bgLighter),
|
padding: const EdgeInsets.symmetric(
|
horizontal: 22, vertical: 10),
|
),
|
child: const Text('取消'),
|
),
|
const SizedBox(width: 12),
|
ElevatedButton(
|
onPressed: () async {
|
await AppPrefs.setPaths(_dlCtrl.text, _insCtrl.text);
|
if (context.mounted) Navigator.pop(context);
|
},
|
style: ElevatedButton.styleFrom(
|
backgroundColor: AppColors.accent,
|
foregroundColor: Colors.white,
|
padding: const EdgeInsets.symmetric(
|
horizontal: 22, vertical: 10),
|
),
|
child: const Text('确认'),
|
),
|
],
|
),
|
],
|
),
|
),
|
);
|
}
|
|
Widget _checkbox(String label, bool value, ValueChanged<bool?> onChanged) {
|
return Row(
|
children: [
|
SizedBox(
|
width: 16,
|
height: 16,
|
child: Checkbox(
|
value: value,
|
onChanged: onChanged,
|
activeColor: AppColors.accent,
|
side: const BorderSide(color: AppColors.textGray),
|
),
|
),
|
const SizedBox(width: 6),
|
Text(label, style: const TextStyle(color: AppColors.textGray, fontSize: 12)),
|
],
|
);
|
}
|
}
|