新增摄影模式工具

This commit is contained in:
xkeyC 2023-12-11 22:48:49 +08:00
parent cda6240295
commit 41763e0f61
2 changed files with 72 additions and 0 deletions

View File

@ -11,6 +11,7 @@ import 'package:starcitizen_doctor/common/helper/log_helper.dart';
import 'package:starcitizen_doctor/common/helper/system_helper.dart';
import 'package:starcitizen_doctor/ui/tools/downloader/downloader_dialog_ui_model.dart';
import 'package:url_launcher/url_launcher_string.dart';
import 'package:xml/xml.dart';
import 'downloader/downloader_dialog_ui.dart';
@ -79,7 +80,10 @@ class ToolsUIModel extends BaseUIModel {
notifyListeners();
items.addAll(await _addNvmePatchCard());
notifyListeners();
items.add(await _addPhotographyCard());
notifyListeners();
items.add(await _addShaderCard());
// close loading
isItemLoading = false;
notifyListeners();
} catch (e) {
@ -169,6 +173,19 @@ class ToolsUIModel extends BaseUIModel {
);
}
Future<_ToolsItemData> _addPhotographyCard() async {
//
final isEnable = await _checkPhotographyStatus();
return _ToolsItemData(
"photography_mode",
isEnable ? "关闭摄影模式" : "开启摄影模式",
"一键修改镜游戏内镜头参数以便于摄影操作。\n\n @拉邦那 Lapernum 提供参数信息。",
const Icon(FontAwesomeIcons.camera, size: 28),
onTap: () => _onChangePhotographyMode(isEnable),
);
}
/// ---------------------------- func -------------------------------------------------------
/// -----------------------------------------------------------------------------------------
/// -----------------------------------------------------------------------------------------
@ -374,6 +391,60 @@ class ToolsUIModel extends BaseUIModel {
}
}
}
Future<bool> _checkPhotographyStatus({bool? setMode}) async {
const keys = ["AudioShakeStrength", "CameraSpringMovement", "ShakeScale"];
final attributesFile = File(
"$scInstalledPath\\USER\\Client\\0\\Profiles\\default\\attributes.xml");
if (setMode == null) {
bool isEnable = false;
if (scInstalledPath.isNotEmpty) {
if (await attributesFile.exists()) {
final xmlFile =
XmlDocument.parse(await attributesFile.readAsString());
isEnable = true;
for (var k in keys) {
if (!isEnable) break;
final e = xmlFile.rootElement.children
.where((element) => element.getAttribute("name") == k)
.firstOrNull;
if (e != null && e.getAttribute("value") == "0") {
} else {
isEnable = false;
}
}
}
}
return isEnable;
} else {
if (!await attributesFile.exists()) {
showToast(context!, "配置文件不存在,请尝试运行一次游戏");
return false;
}
final xmlFile = XmlDocument.parse(await attributesFile.readAsString());
// clear all
xmlFile.rootElement.children.removeWhere(
(element) => keys.contains(element.getAttribute("name")));
if (setMode) {
for (var element in keys) {
XmlElement newNode = XmlElement(XmlName('Attr'), [
XmlAttribute(XmlName('name'), element),
XmlAttribute(XmlName('value'), '0'),
]);
xmlFile.rootElement.children.add(newNode);
}
}
dPrint(xmlFile);
await attributesFile.delete();
await attributesFile.writeAsString(xmlFile.toXmlString(pretty: true));
}
return true;
}
_onChangePhotographyMode(bool isEnable) async {
await handleError(() => _checkPhotographyStatus(setMode: !isEnable));
reloadData();
}
}
class _ToolsItemData {

View File

@ -65,6 +65,7 @@ dependencies:
hexcolor: ^3.0.1
dart_rss: ^3.0.1
html: ^0.15.4
xml: ^6.5.0
dependency_overrides:
http: ^1.1.2