检查 USER.cfg

This commit is contained in:
xkeyC 2023-10-12 20:18:00 +08:00
parent 659feeb42e
commit d7c70d7efc
3 changed files with 137 additions and 48 deletions

View File

@ -67,13 +67,19 @@ class LocalizationUI extends BaseUI<LocalizationUIModel> {
onPressed: model.doDelIniFile(), onPressed: model.doDelIniFile(),
child: const Padding( child: const Padding(
padding: EdgeInsets.all(4), padding: EdgeInsets.all(4),
child: Icon(FluentIcons.delete), child: Row(
children: [
Icon(FluentIcons.delete),
SizedBox(width: 6),
Text("删除"),
],
),
)), )),
], ],
), ),
], ],
]), ]),
makeListContainer("最新版本", [ makeListContainer("社区汉化", [
if (model.apiLocalizationData == null) if (model.apiLocalizationData == null)
makeLoading(context) makeLoading(context)
else if (model.apiLocalizationData!.isEmpty) else if (model.apiLocalizationData!.isEmpty)
@ -88,49 +94,87 @@ class LocalizationUI extends BaseUI<LocalizationUIModel> {
for (final item in model.apiLocalizationData!.entries) for (final item in model.apiLocalizationData!.entries)
makeRemoteList(context, model, item), makeRemoteList(context, model, item),
]), ]),
makeListContainer("自定义", [ const SizedBox(height: 12),
if (model.customizeList == null) IconButton(
makeLoading(context) icon: Row(
else if (model.customizeList!.isEmpty) mainAxisAlignment: MainAxisAlignment.center,
Center( children: [
child: Text( Icon(model.enableCustomize
"请将 任意名称.ini 文件放入 Customize_ini 文件夹,即可使用此工具快捷安装 / 切换。", ? FluentIcons.chevron_up
style: TextStyle( : FluentIcons.chevron_down),
fontSize: 13, color: Colors.white.withOpacity(.8)), const SizedBox(width: 12),
), const Text("高级功能"),
) ],
else ...[ ),
for (final file in model.customizeList!) onPressed: () {
Row( model.enableCustomize = !model.enableCustomize;
children: [ model.notifyListeners();
Text( }),
model.getCustomizeFileName(file), AnimatedSize(
), duration: const Duration(milliseconds: 130),
const Spacer(), child: Column(
if (model.workingVersion == file) children: [
const Padding( const SizedBox(height: 12),
padding: EdgeInsets.only(right: 12), model.enableCustomize
child: ProgressRing(), ? 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), const SizedBox(height: 12),
], ],
), ),
@ -190,9 +234,21 @@ class LocalizationUI extends BaseUI<LocalizationUIModel> {
child: Padding( child: Padding(
padding: const EdgeInsets.only( padding: const EdgeInsets.only(
left: 8, right: 8, top: 4, bottom: 4), left: 8, right: 8, top: 4, bottom: 4),
child: Text(isInstalled child: Row(
? "已安装" children: [
: ((item.value.enable ?? false) ? "安装" : "不可用")), 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) ? "安装" : "不可用")),
],
),
)), )),
], ],
), ),

View File

@ -41,6 +41,8 @@ class LocalizationUIModel extends BaseUIModel {
StreamSubscription? customizeDirListenSub; StreamSubscription? customizeDirListenSub;
bool enableCustomize = false;
@override @override
void initModel() { void initModel() {
selectedLanguage = languageSupport.entries.first.key; selectedLanguage = languageSupport.entries.first.key;
@ -56,6 +58,7 @@ class LocalizationUIModel extends BaseUIModel {
@override @override
Future loadData() async { Future loadData() async {
await _updateStatus(); await _updateStatus();
_checkUserCfg();
_scanCustomizeDir(); _scanCustomizeDir();
final l = final l =
await handleError(() => Api.getScLocalizationData(selectedLanguage)); await handleError(() => Api.getScLocalizationData(selectedLanguage));
@ -263,6 +266,7 @@ class LocalizationUIModel extends BaseUIModel {
"${scDataDir.absolute.path}\\Localization\\$selectedLanguage\\global.ini"); "${scDataDir.absolute.path}\\Localization\\$selectedLanguage\\global.ini");
return () async { return () async {
if (await iniFile.exists()) await iniFile.delete(); if (await iniFile.exists()) await iniFile.delete();
await updateLangCfg(false);
await _updateStatus(); await _updateStatus();
}; };
} }
@ -300,4 +304,33 @@ class LocalizationUIModel extends BaseUIModel {
notifyListeners(); 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();
}
}
}
}
} }

View File

@ -44,7 +44,7 @@ dependencies:
markdown_widget: ^2.2.0 markdown_widget: ^2.2.0
extended_image: ^8.1.1 extended_image: ^8.1.1
hyper_thread_downloader: ^1.0.5 hyper_thread_downloader: ^1.0.5
device_info_plus: ^10.0.0 device_info_plus: ^9.0.3
file_picker: ^5.5.0 file_picker: ^5.5.0
file_sizes: ^1.0.6 file_sizes: ^1.0.6
desktop_webview_window: ^0.2.3 desktop_webview_window: ^0.2.3