检查 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(),
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<LocalizationUIModel> {
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<LocalizationUIModel> {
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) ? "安装" : "不可用")),
],
),
)),
],
),

View File

@ -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();
}
}
}
}
}

View File

@ -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