From eee1bfdeb077a3a63051cd399bb216c968357f58 Mon Sep 17 00:00:00 2001 From: xkeyC <3334969096@qq.com> Date: Wed, 6 Dec 2023 22:45:36 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E6=B1=89=E5=8C=96=E6=9B=B4?= =?UTF-8?q?=E6=96=B0=E6=8F=90=E7=A4=BA=20=E6=96=B0=E5=A2=9E=E5=91=A8?= =?UTF-8?q?=E6=9C=9F=E6=80=A7=E6=B1=89=E5=8C=96=E7=89=88=E6=9C=AC=E6=A3=80?= =?UTF-8?q?=E6=9F=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/common/conf.dart | 2 + lib/data/sc_localization_data.dart | 13 ++--- lib/ui/home/home_ui.dart | 11 +++++ lib/ui/home/home_ui_model.dart | 49 ++++++++++++++++++- .../localization/localization_ui_model.dart | 47 ++++++++++++++++-- pubspec.yaml | 1 + 6 files changed, 107 insertions(+), 16 deletions(-) diff --git a/lib/common/conf.dart b/lib/common/conf.dart index b5628ee..1063f14 100644 --- a/lib/common/conf.dart +++ b/lib/common/conf.dart @@ -46,6 +46,8 @@ class AppConf { static const rssTextUrl2 = "$_rssHomeUrl/baidu/tieba/user/%E7%81%AC%E7%81%ACG%E7%81%AC%E7%81%AC&"; + static const gameChannels = ["LIVE", "PTU", "EPTU"]; + static late final String applicationSupportDir; static AppVersionData? networkVersionData; diff --git a/lib/data/sc_localization_data.dart b/lib/data/sc_localization_data.dart index 297e51b..4bb77fb 100644 --- a/lib/data/sc_localization_data.dart +++ b/lib/data/sc_localization_data.dart @@ -1,10 +1,9 @@ /// enable : true -/// versionName : "3.21.1(PU)_CN_V2" +/// versionName : "3.21.1(PU)_CNE_V2" /// updateAt : "2023-12-03: 14:50:00" -/// info : "简体中文汉化(首选)" +/// info : "简体中文半汉化(物品名称英文版)" /// game_channel : "PU" -/// note : "·因游戏暂不支持3D字体汉化,F键交互将依旧为英文。\n·角色抬头显示器(HUD)的中文字体不显示。\n·某些元素字体过小。\n·搜索栏无法输入中文。\n·部位文本未翻译(在翻了,在翻了!)" -/// upgrade_channel : "CN" +/// note : "" class ScLocalizationData { ScLocalizationData({ @@ -13,8 +12,7 @@ class ScLocalizationData { this.updateAt, this.info, this.gameChannel, - this.note, - this.upgradeChannel,}); + this.note,}); ScLocalizationData.fromJson(dynamic json) { enable = json['enable']; @@ -23,7 +21,6 @@ class ScLocalizationData { info = json['info']; gameChannel = json['game_channel']; note = json['note']; - upgradeChannel = json['upgrade_channel']; } bool? enable; String? versionName; @@ -31,7 +28,6 @@ class ScLocalizationData { String? info; String? gameChannel; String? note; - String? upgradeChannel; Map toJson() { final map = {}; @@ -41,7 +37,6 @@ class ScLocalizationData { map['info'] = info; map['game_channel'] = gameChannel; map['note'] = note; - map['upgrade_channel'] = upgradeChannel; return map; } diff --git a/lib/ui/home/home_ui.dart b/lib/ui/home/home_ui.dart index 43570e9..5fb4d1c 100644 --- a/lib/ui/home/home_ui.dart +++ b/lib/ui/home/home_ui.dart @@ -466,6 +466,17 @@ class HomeUI extends BaseUI { Text(item.infoString), ], )), + if (item.key == "localization" && + model.localizationUpdateInfo != null) + Container( + padding: const EdgeInsets.only( + top: 3, bottom: 3, left: 8, right: 8), + decoration: BoxDecoration( + color: Colors.red, + borderRadius: BorderRadius.circular(12)), + child: + Text(model.localizationUpdateInfo?.key ?? " "), + ), const SizedBox(width: 12), if (item.key == "auto_check" && model.isChecking) const ProgressRing() diff --git a/lib/ui/home/home_ui_model.dart b/lib/ui/home/home_ui_model.dart index 439b0f8..863e982 100644 --- a/lib/ui/home/home_ui_model.dart +++ b/lib/ui/home/home_ui_model.dart @@ -29,6 +29,7 @@ import 'package:url_launcher/url_launcher_string.dart'; import 'package:html/parser.dart' as html; import 'package:html/dom.dart' as html_dom; +import 'package:windows_ui/windows_ui.dart'; import 'countdown/countdown_dialog_ui.dart'; import 'localization/localization_ui.dart'; @@ -67,6 +68,10 @@ class HomeUIModel extends BaseUIModel { List? countdownFestivalListData; + MapEntry? localizationUpdateInfo; + + bool _isSendLocalizationUpdateNotification = false; + final cnExp = RegExp(r"[^\x00-\xff]"); AppPlacardData? appPlacardData; @@ -74,6 +79,7 @@ class HomeUIModel extends BaseUIModel { List? scServerStatus; Timer? serverUpdateTimer; + Timer? appUpdateTimer; final statusCnName = const { "Platform": "平台", @@ -110,6 +116,8 @@ class HomeUIModel extends BaseUIModel { } catch (e) { dPrint(e); } + // check Localization update + _checkLocalizationUpdate(); notifyListeners(); } @@ -117,11 +125,15 @@ class HomeUIModel extends BaseUIModel { void initModel() { reScanPath(); serverUpdateTimer = Timer.periodic( - const Duration(minutes: 1), + const Duration(minutes: 10), (timer) { updateSCServerStatus(); }, ); + + appUpdateTimer = Timer.periodic(const Duration(minutes: 30), (timer) { + _checkLocalizationUpdate(); + }); super.initModel(); } @@ -129,6 +141,8 @@ class HomeUIModel extends BaseUIModel { void dispose() { serverUpdateTimer?.cancel(); serverUpdateTimer = null; + appUpdateTimer?.cancel(); + appUpdateTimer = null; super.dispose(); } @@ -384,7 +398,7 @@ class HomeUIModel extends BaseUIModel { showToast(context!, "该功能需要一个有效的安装位置"); return; } - showDialog( + await showDialog( context: context!, dismissWithEsc: false, builder: (BuildContext context) { @@ -392,6 +406,7 @@ class HomeUIModel extends BaseUIModel { uiCreate: () => LocalizationUI(), modelCreate: () => LocalizationUIModel(scInstalledPath)); }); + _checkLocalizationUpdate(); return; case "performance": if (scInstalledPath == "not_install") { @@ -612,4 +627,34 @@ class HomeUIModel extends BaseUIModel { title = title.replaceAll("】", " ] "); return title; } + + Future _checkLocalizationUpdate() async { + final info = await handleError( + () => LocalizationUIModel.checkLocalizationUpdates(scInstallPaths)); + dPrint("lUpdateInfo === $info"); + localizationUpdateInfo = info; + notifyListeners(); + + if (info?.value == true && !_isSendLocalizationUpdateNotification) { + final toastNotifier = + ToastNotificationManager.createToastNotifierWithId("SC汉化盒子"); + if (toastNotifier != null) { + final toastContent = ToastNotificationManager.getTemplateContent( + ToastTemplateType.toastText02); + if (toastContent != null) { + final xmlNodeList = toastContent.getElementsByTagName('text'); + const title = '汉化有新版本!'; + final content = '您在 ${info?.key} 安装的汉化有新版本啦!'; + xmlNodeList.item(0)?.appendChild(toastContent.createTextNode(title)); + xmlNodeList + .item(1) + ?.appendChild(toastContent.createTextNode(content)); + final toastNotification = + ToastNotification.createToastNotification(toastContent); + toastNotifier.show(toastNotification); + _isSendLocalizationUpdateNotification = true; + } + } + } + } } diff --git a/lib/ui/home/localization/localization_ui_model.dart b/lib/ui/home/localization/localization_ui_model.dart index 3dcd1c0..e4ac407 100644 --- a/lib/ui/home/localization/localization_ui_model.dart +++ b/lib/ui/home/localization/localization_ui_model.dart @@ -100,8 +100,10 @@ class LocalizationUIModel extends BaseUIModel { } _updateStatus() async { - patchStatus = MapEntry(await getLangCfgEnableLang(lang: selectedLanguage), - await getInstalledIniVersion()); + patchStatus = MapEntry( + await getLangCfgEnableLang(lang: selectedLanguage), + await getInstalledIniVersion( + "${scDataDir.absolute.path}\\Localization\\$selectedLanguage\\global.ini")); notifyListeners(); } @@ -169,9 +171,8 @@ class LocalizationUIModel extends BaseUIModel { str.contains("g_languageAudio=english"); } - Future getInstalledIniVersion() async { - final iniFile = File( - "${scDataDir.absolute.path}\\Localization\\$selectedLanguage\\global.ini"); + static Future getInstalledIniVersion(String iniPath) async { + final iniFile = File(iniPath); if (!await iniFile.exists()) return "游戏内置"; final iniStringSplit = (await iniFile.readAsString()).split("\n"); for (var i = iniStringSplit.length - 1; i > 0; i--) { @@ -342,4 +343,40 @@ class LocalizationUIModel extends BaseUIModel { } } } + + static Future?> checkLocalizationUpdates( + List gameInstallPaths) async { + final updateInfo = {}; + for (var kv in languageSupport.entries) { + final l = await Api.getScLocalizationData(kv.key); + for (var value in gameInstallPaths) { + final iniPath = "$value\\data\\Localization\\${kv.key}\\global.ini"; + if (!await File(iniPath).exists()) { + continue; + } + final installed = await getInstalledIniVersion(iniPath); + if (installed == "游戏内置" || installed == "自定义文件") { + continue; + } + final hasUpdate = l + .where((element) => element.versionName == installed) + .firstOrNull == + null; + updateInfo[value] = hasUpdate; + } + } + dPrint("checkLocalizationUpdates ==== $updateInfo"); + for (var v in updateInfo.entries) { + if (v.value) { + for (var element in AppConf.gameChannels) { + if (v.key.contains("StarCitizen\\$element")) { + return MapEntry(element, true); + }else { + return const MapEntry("", true); + } + } + } + } + return null; + } } diff --git a/pubspec.yaml b/pubspec.yaml index 7180367..3289570 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -58,6 +58,7 @@ dependencies: freezed_annotation: ^2.4.1 meta: ^1.9.1 win32: ^5.0.9 + windows_ui: ^0.2.0 local_auth: ^2.1.7 cryptography: ^2.7.0 cryptography_flutter: ^2.3.2