2023-11-21 23:36:26 +08:00
|
|
|
|
import 'package:file_picker/file_picker.dart';
|
2023-11-21 01:05:20 +08:00
|
|
|
|
import 'package:flutter/services.dart';
|
2023-11-07 20:47:28 +08:00
|
|
|
|
import 'package:hive/hive.dart';
|
|
|
|
|
import 'package:local_auth/local_auth.dart';
|
2023-10-09 09:32:07 +08:00
|
|
|
|
import 'package:starcitizen_doctor/base/ui_model.dart';
|
2023-11-07 22:49:09 +08:00
|
|
|
|
import 'package:starcitizen_doctor/common/conf.dart';
|
2023-11-07 20:47:28 +08:00
|
|
|
|
import 'package:starcitizen_doctor/common/win32/credentials.dart';
|
2023-10-09 09:32:07 +08:00
|
|
|
|
|
|
|
|
|
class SettingUIModel extends BaseUIModel {
|
2023-11-07 20:47:28 +08:00
|
|
|
|
var isDeviceSupportWinHello = false;
|
2023-10-09 09:32:07 +08:00
|
|
|
|
|
2023-11-07 20:47:28 +08:00
|
|
|
|
String autoLoginEmail = "-";
|
|
|
|
|
bool isEnableAutoLogin = false;
|
|
|
|
|
bool isEnableAutoLoginPwd = false;
|
2023-11-21 01:05:20 +08:00
|
|
|
|
String inputGameLaunchECore = "0";
|
2023-11-07 20:47:28 +08:00
|
|
|
|
|
2023-11-21 23:36:26 +08:00
|
|
|
|
String? customLauncherPath;
|
|
|
|
|
String? customGamePath;
|
|
|
|
|
|
2023-11-07 20:47:28 +08:00
|
|
|
|
@override
|
|
|
|
|
loadData() async {
|
|
|
|
|
final LocalAuthentication localAuth = LocalAuthentication();
|
|
|
|
|
isDeviceSupportWinHello = await localAuth.isDeviceSupported();
|
|
|
|
|
notifyListeners();
|
2023-11-07 22:49:09 +08:00
|
|
|
|
if (AppConf.isMSE) {
|
|
|
|
|
_updateAutoLoginAccount();
|
2023-11-21 01:05:20 +08:00
|
|
|
|
_updateGameLaunchECore();
|
2023-11-07 22:49:09 +08:00
|
|
|
|
}
|
2023-11-21 23:36:26 +08:00
|
|
|
|
_loadCustomPath();
|
2023-11-07 20:47:28 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Future<void> onResetAutoLogin() async {
|
2023-11-10 22:20:23 +08:00
|
|
|
|
final ok = await showConfirmDialogs(context!, "确认重置自动填充?",
|
|
|
|
|
const Text("这将会删除本地的账号记录,或在下次启动游戏时将自动填充选择 ‘否’ 以禁用自动填充。"));
|
|
|
|
|
if (ok) {
|
|
|
|
|
final userBox = await Hive.openBox("rsi_account_data");
|
|
|
|
|
await userBox.deleteFromDisk();
|
|
|
|
|
Win32Credentials.delete("SCToolbox_RSI_Account_secret");
|
|
|
|
|
showToast(context!, "已清理自动填充数据");
|
|
|
|
|
reloadData();
|
|
|
|
|
}
|
2023-11-07 20:47:28 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Future _updateAutoLoginAccount() async {
|
|
|
|
|
final userBox = await Hive.openBox("rsi_account_data");
|
|
|
|
|
autoLoginEmail = userBox.get("account_email", defaultValue: "-");
|
|
|
|
|
isEnableAutoLogin = userBox.get("enable", defaultValue: true);
|
|
|
|
|
isEnableAutoLoginPwd =
|
|
|
|
|
userBox.get("account_pwd_encrypted", defaultValue: "") != "";
|
|
|
|
|
notifyListeners();
|
|
|
|
|
}
|
2023-11-21 01:05:20 +08:00
|
|
|
|
|
|
|
|
|
Future<void> setGameLaunchECore() async {
|
|
|
|
|
final userBox = await Hive.openBox("app_conf");
|
|
|
|
|
final defaultInput =
|
|
|
|
|
userBox.get("gameLaunch_eCore_count", defaultValue: "0");
|
|
|
|
|
final input = await showInputDialogs(context!,
|
|
|
|
|
title: "请输入要忽略的 CPU 核心数",
|
2023-11-22 00:40:36 +08:00
|
|
|
|
content: "tip:您的设备拥有几个能效核心就输入几,非大小核设备请保持0",
|
2023-11-21 01:05:20 +08:00
|
|
|
|
initialValue: defaultInput,
|
|
|
|
|
inputFormatters: [FilteringTextInputFormatter.digitsOnly]);
|
|
|
|
|
if (input == null) return;
|
|
|
|
|
userBox.put("gameLaunch_eCore_count", input);
|
|
|
|
|
reloadData();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Future _updateGameLaunchECore() async {
|
|
|
|
|
final userBox = await Hive.openBox("app_conf");
|
|
|
|
|
inputGameLaunchECore =
|
|
|
|
|
userBox.get("gameLaunch_eCore_count", defaultValue: "0");
|
|
|
|
|
notifyListeners();
|
|
|
|
|
}
|
2023-11-21 23:36:26 +08:00
|
|
|
|
|
|
|
|
|
Future<void> setLauncherPath() async {
|
|
|
|
|
final r = await FilePicker.platform.pickFiles(
|
|
|
|
|
dialogTitle: "请选择RSI启动器位置(RSI Launcher.exe)",
|
|
|
|
|
type: FileType.custom,
|
|
|
|
|
allowedExtensions: ["exe"]);
|
|
|
|
|
if (r == null || r.files.firstOrNull?.path == null) return;
|
|
|
|
|
final fileName = r.files.first.path!;
|
|
|
|
|
if (fileName.endsWith("\\RSI Launcher.exe")) {
|
|
|
|
|
await _saveCustomPath("custom_launcher_path", fileName);
|
|
|
|
|
showToast(context!, "设置成功,在对应页面点击刷新即可扫描出新路径");
|
|
|
|
|
reloadData();
|
|
|
|
|
} else {
|
2023-11-21 23:41:20 +08:00
|
|
|
|
showToast(context!, "文件有误!");
|
2023-11-21 23:36:26 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Future<void> setGamePath() async {
|
|
|
|
|
final r = await FilePicker.platform.pickFiles(
|
|
|
|
|
dialogTitle: "请选择游戏安装位置(StarCitizen.exe)",
|
|
|
|
|
type: FileType.custom,
|
|
|
|
|
allowedExtensions: ["exe"]);
|
|
|
|
|
if (r == null || r.files.firstOrNull?.path == null) return;
|
|
|
|
|
final fileName = r.files.first.path!;
|
|
|
|
|
dPrint(fileName);
|
|
|
|
|
final fileNameRegExp =
|
|
|
|
|
RegExp(r"^(.*\\StarCitizen\\.*\\)Bin64\\StarCitizen\.exe$");
|
|
|
|
|
if (fileNameRegExp.hasMatch(fileName)) {
|
|
|
|
|
RegExp pathRegex = RegExp(r"\\[^\\]+\\Bin64\\StarCitizen\.exe$");
|
|
|
|
|
String extractedPath = fileName.replaceFirst(pathRegex, '');
|
|
|
|
|
await _saveCustomPath("custom_game_path", extractedPath);
|
|
|
|
|
showToast(context!, "设置成功,在对应页面点击刷新即可扫描出新路径");
|
|
|
|
|
reloadData();
|
|
|
|
|
} else {
|
2023-11-21 23:41:20 +08:00
|
|
|
|
showToast(context!, "文件有误!");
|
2023-11-21 23:36:26 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_saveCustomPath(String pathKey, String dir) async {
|
|
|
|
|
final confBox = await Hive.openBox("app_conf");
|
|
|
|
|
await confBox.put(pathKey, dir);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_loadCustomPath() async {
|
|
|
|
|
final confBox = await Hive.openBox("app_conf");
|
|
|
|
|
customLauncherPath = confBox.get("custom_launcher_path");
|
|
|
|
|
customGamePath = confBox.get("custom_game_path");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Future<void> delName(String key) async {
|
|
|
|
|
final confBox = await Hive.openBox("app_conf");
|
|
|
|
|
await confBox.delete(key);
|
|
|
|
|
reloadData();
|
|
|
|
|
}
|
2023-11-07 20:47:28 +08:00
|
|
|
|
}
|