diff --git a/lib/ui/home/localization/localization_ui.dart b/lib/ui/home/localization/localization_ui.dart index 00d8937..d82b2f6 100644 --- a/lib/ui/home/localization/localization_ui.dart +++ b/lib/ui/home/localization/localization_ui.dart @@ -67,13 +67,19 @@ class LocalizationUI extends BaseUI { onPressed: model.doDelIniFile(), child: const Padding( padding: EdgeInsets.all(4), - child: Icon(FluentIcons.delete), + child: Row( + children: [ + Icon(FluentIcons.delete), + SizedBox(width: 6), + Text("删除"), + ], + ), )), ], ), ], ]), - makeListContainer("最新版本", [ + makeListContainer("社区汉化", [ if (model.apiLocalizationData == null) makeLoading(context) else if (model.apiLocalizationData!.isEmpty) @@ -88,49 +94,87 @@ class LocalizationUI extends BaseUI { for (final item in model.apiLocalizationData!.entries) makeRemoteList(context, model, item), ]), - makeListContainer("自定义", [ - if (model.customizeList == null) - makeLoading(context) - else if (model.customizeList!.isEmpty) - Center( - child: Text( - "请将 任意名称.ini 文件放入 Customize_ini 文件夹,即可使用此工具快捷安装 / 切换。", - style: TextStyle( - fontSize: 13, color: Colors.white.withOpacity(.8)), - ), - ) - else ...[ - for (final file in model.customizeList!) - Row( - children: [ - Text( - model.getCustomizeFileName(file), - ), - const Spacer(), - if (model.workingVersion == file) - const Padding( - padding: EdgeInsets.only(right: 12), - child: ProgressRing(), + const SizedBox(height: 12), + IconButton( + icon: Row( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Icon(model.enableCustomize + ? FluentIcons.chevron_up + : FluentIcons.chevron_down), + const SizedBox(width: 12), + const Text("高级功能"), + ], + ), + onPressed: () { + model.enableCustomize = !model.enableCustomize; + model.notifyListeners(); + }), + AnimatedSize( + duration: const Duration(milliseconds: 130), + child: Column( + children: [ + const SizedBox(height: 12), + model.enableCustomize + ? makeListContainer("自定义文本", [ + if (model.customizeList == null) + makeLoading(context) + else if (model.customizeList!.isEmpty) + Center( + child: Text( + "暂无自定义文本", + style: TextStyle( + fontSize: 13, + color: Colors.white.withOpacity(.8)), + ), + ) + else ...[ + for (final file in model.customizeList!) + Row( + children: [ + Text( + model.getCustomizeFileName(file), + ), + const Spacer(), + if (model.workingVersion == file) + const Padding( + padding: EdgeInsets.only(right: 12), + child: ProgressRing(), + ) + else + Button( + onPressed: model.doLocalInstall(file), + child: const Padding( + padding: EdgeInsets.only( + left: 8, + right: 8, + top: 4, + bottom: 4), + child: Text("安装"), + )) + ], + ) + ], + ], actions: [ + Button( + onPressed: () => model.openDir(), + child: const Padding( + padding: EdgeInsets.all(4), + child: Row( + children: [ + Icon(FluentIcons.folder_open), + SizedBox(width: 6), + Text("打开文件夹"), + ], + ), + )), + ]) + : SizedBox( + width: MediaQuery.of(context).size.width, ) - else - Button( - onPressed: model.doLocalInstall(file), - child: const Padding( - padding: EdgeInsets.only( - left: 8, right: 8, top: 4, bottom: 4), - child: Text("安装"), - )) - ], - ) - ], - ], actions: [ - Button( - onPressed: () => model.openDir(), - child: const Padding( - padding: EdgeInsets.all(4), - child: Icon(FluentIcons.folder_open), - )), - ]), + ], + ), + ), const SizedBox(height: 12), ], ), @@ -190,9 +234,21 @@ class LocalizationUI extends BaseUI { child: Padding( padding: const EdgeInsets.only( left: 8, right: 8, top: 4, bottom: 4), - child: Text(isInstalled - ? "已安装" - : ((item.value.enable ?? false) ? "安装" : "不可用")), + child: Row( + children: [ + Padding( + padding: const EdgeInsets.only(right: 6), + child: Icon(isInstalled + ? FluentIcons.check_mark + : (item.value.enable ?? false) + ? FluentIcons.download + : FluentIcons.disable_updates), + ), + Text(isInstalled + ? "已安装" + : ((item.value.enable ?? false) ? "安装" : "不可用")), + ], + ), )), ], ), diff --git a/lib/ui/home/localization/localization_ui_model.dart b/lib/ui/home/localization/localization_ui_model.dart index 2930416..5b25da9 100644 --- a/lib/ui/home/localization/localization_ui_model.dart +++ b/lib/ui/home/localization/localization_ui_model.dart @@ -41,6 +41,8 @@ class LocalizationUIModel extends BaseUIModel { StreamSubscription? customizeDirListenSub; + bool enableCustomize = false; + @override void initModel() { selectedLanguage = languageSupport.entries.first.key; @@ -56,6 +58,7 @@ class LocalizationUIModel extends BaseUIModel { @override Future loadData() async { await _updateStatus(); + _checkUserCfg(); _scanCustomizeDir(); final l = await handleError(() => Api.getScLocalizationData(selectedLanguage)); @@ -263,6 +266,7 @@ class LocalizationUIModel extends BaseUIModel { "${scDataDir.absolute.path}\\Localization\\$selectedLanguage\\global.ini"); return () async { if (await iniFile.exists()) await iniFile.delete(); + await updateLangCfg(false); await _updateStatus(); }; } @@ -300,4 +304,33 @@ class LocalizationUIModel extends BaseUIModel { notifyListeners(); }; } + + void _checkUserCfg() async { + final userCfgFile = File("$scInstallPath\\USER.cfg"); + if (await userCfgFile.exists()) { + final cfgString = await userCfgFile.readAsString(); + if (cfgString.contains("g_language=") && + !cfgString.contains("g_language=$selectedLanguage")) { + final ok = await showConfirmDialogs( + context!, + "是否移除不兼容的汉化参数", + const Text( + "USER.cfg 包含不兼容的汉化参数,这可能是以前的汉化文件的残留信息。\n\n这将可能导致汉化无效或乱码,点击确认为您一键移除(不会影响其他配置)。"), + constraints: BoxConstraints( + maxWidth: MediaQuery.of(context!).size.width * .35)); + if (ok == true) { + var finalString = ""; + for (var item in cfgString.split("\n")) { + if (!item.trim().startsWith("g_language=")) { + finalString = "$finalString$item\n"; + } + } + await userCfgFile.delete(); + await userCfgFile.create(); + await userCfgFile.writeAsString(finalString, flush: true); + reloadData(); + } + } + } + } } diff --git a/pubspec.yaml b/pubspec.yaml index b6f5f44..d1f04f3 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -44,7 +44,7 @@ dependencies: markdown_widget: ^2.2.0 extended_image: ^8.1.1 hyper_thread_downloader: ^1.0.5 - device_info_plus: ^10.0.0 + device_info_plus: ^9.0.3 file_picker: ^5.5.0 file_sizes: ^1.0.6 desktop_webview_window: ^0.2.3