905086
2026-11-03 262ce70998fa52dec3120589f51c47e96fb96df4
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
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/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) {
  final lines = [
    '公网IP: 获取中...',
    '地区: 中国',
    '运营商: 联通',
  ];
  _greenInfoDialog(context, '电脑网络信息', Icons.wifi, lines);
}
 
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)),
      ],
    );
  }
}