mirror of
https://ghfast.top/https://github.com/StarCitizenToolBox/app.git
synced 2025-06-28 17:14:48 +08:00
feat:riverpod 迁移
This commit is contained in:
@ -1,419 +0,0 @@
|
||||
import 'package:starcitizen_doctor/base/ui.dart';
|
||||
import 'package:starcitizen_doctor/data/sc_localization_data.dart';
|
||||
|
||||
import 'localization_ui_model.dart';
|
||||
|
||||
class LocalizationUI extends BaseUI<LocalizationUIModel> {
|
||||
@override
|
||||
Widget? buildBody(BuildContext context, LocalizationUIModel model) {
|
||||
final curInstallInfo = model.apiLocalizationData?[model.patchStatus?.value];
|
||||
return ContentDialog(
|
||||
title: makeTitle(context, model),
|
||||
constraints: BoxConstraints(
|
||||
maxWidth: MediaQuery.of(context).size.width * .7,
|
||||
minHeight: MediaQuery.of(context).size.height * .9),
|
||||
content: Padding(
|
||||
padding: const EdgeInsets.only(left: 12, right: 12, top: 12),
|
||||
child: SingleChildScrollView(
|
||||
child: Column(
|
||||
children: [
|
||||
AnimatedSize(
|
||||
duration: const Duration(milliseconds: 130),
|
||||
child: model.patchStatus?.key == true &&
|
||||
model.patchStatus?.value == "游戏内置"
|
||||
? Padding(
|
||||
padding: const EdgeInsets.only(bottom: 12),
|
||||
child: InfoBar(
|
||||
title: const Text("警告"),
|
||||
content: const Text(
|
||||
"您正在使用游戏内置文本,官方文本目前为机器翻译(截至3.21.0),建议您在下方安装社区汉化。"),
|
||||
severity: InfoBarSeverity.info,
|
||||
style: InfoBarThemeData(decoration: (severity) {
|
||||
return const BoxDecoration(
|
||||
color: Color.fromRGBO(155, 7, 7, 1.0));
|
||||
}, iconColor: (severity) {
|
||||
return Colors.white;
|
||||
}),
|
||||
),
|
||||
)
|
||||
: SizedBox(
|
||||
width: MediaQuery.of(context).size.width,
|
||||
),
|
||||
),
|
||||
makeListContainer("汉化状态", [
|
||||
if (model.patchStatus == null)
|
||||
makeLoading(context)
|
||||
else ...[
|
||||
const SizedBox(height: 6),
|
||||
Row(
|
||||
children: [
|
||||
Center(
|
||||
child: Text(
|
||||
"启用(${LocalizationUIModel.languageSupport[model.selectedLanguage]}):"),
|
||||
),
|
||||
const Spacer(),
|
||||
ToggleSwitch(
|
||||
checked: model.patchStatus?.key == true,
|
||||
onChanged: model.updateLangCfg,
|
||||
)
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
Row(
|
||||
children: [
|
||||
Text("已安装版本:${model.patchStatus?.value}"),
|
||||
const Spacer(),
|
||||
if (model.patchStatus?.value != "游戏内置")
|
||||
Row(
|
||||
children: [
|
||||
Button(
|
||||
onPressed: model.goFeedback,
|
||||
child: const Padding(
|
||||
padding: EdgeInsets.all(4),
|
||||
child: Row(
|
||||
children: [
|
||||
Icon(FluentIcons.feedback),
|
||||
SizedBox(width: 6),
|
||||
Text("汉化反馈"),
|
||||
],
|
||||
),
|
||||
)),
|
||||
const SizedBox(width: 16),
|
||||
Button(
|
||||
onPressed: model.doDelIniFile(),
|
||||
child: const Padding(
|
||||
padding: EdgeInsets.all(4),
|
||||
child: Row(
|
||||
children: [
|
||||
Icon(FluentIcons.delete),
|
||||
SizedBox(width: 6),
|
||||
Text("卸载汉化"),
|
||||
],
|
||||
),
|
||||
)),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
AnimatedSize(
|
||||
duration: const Duration(milliseconds: 130),
|
||||
child: (curInstallInfo != null &&
|
||||
curInstallInfo.note != null &&
|
||||
curInstallInfo.note!.isNotEmpty)
|
||||
? Padding(
|
||||
padding: const EdgeInsets.only(top: 12),
|
||||
child: Container(
|
||||
width: MediaQuery.of(context).size.width,
|
||||
decoration: BoxDecoration(
|
||||
color: FluentTheme.of(context).cardColor,
|
||||
borderRadius: BorderRadius.circular(7)),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(12),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
const Text(
|
||||
"备注:",
|
||||
style: TextStyle(fontSize: 18),
|
||||
),
|
||||
const SizedBox(height: 6),
|
||||
Text(
|
||||
"${curInstallInfo.note}",
|
||||
style: TextStyle(
|
||||
color: Colors.white.withOpacity(.8)),
|
||||
)
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
)
|
||||
: SizedBox(
|
||||
width: MediaQuery.of(context).size.width,
|
||||
),
|
||||
),
|
||||
],
|
||||
]),
|
||||
makeListContainer("社区汉化", [
|
||||
if (model.apiLocalizationData == null)
|
||||
makeLoading(context)
|
||||
else if (model.apiLocalizationData!.isEmpty)
|
||||
Center(
|
||||
child: Text(
|
||||
"该语言/版本 暂无可用汉化,敬请期待!",
|
||||
style: TextStyle(
|
||||
fontSize: 13, color: Colors.white.withOpacity(.8)),
|
||||
),
|
||||
)
|
||||
else
|
||||
for (final item in model.apiLocalizationData!.entries)
|
||||
makeRemoteList(context, model, item),
|
||||
]),
|
||||
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,
|
||||
)
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget makeRemoteList(BuildContext context, LocalizationUIModel model,
|
||||
MapEntry<String, ScLocalizationData> item) {
|
||||
final isWorking = model.workingVersion.isNotEmpty;
|
||||
final isMineWorking = model.workingVersion == item.key;
|
||||
final isInstalled = model.patchStatus?.value == item.key;
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(bottom: 12),
|
||||
child: Column(
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
"${item.value.info}",
|
||||
style: const TextStyle(fontSize: 19),
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
Text(
|
||||
"版本号:${item.value.versionName}",
|
||||
style: TextStyle(color: Colors.white.withOpacity(.6)),
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
Text(
|
||||
"通道:${item.value.gameChannel}",
|
||||
style: TextStyle(color: Colors.white.withOpacity(.6)),
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
Text(
|
||||
"更新时间:${item.value.updateAt}",
|
||||
style: TextStyle(color: Colors.white.withOpacity(.6)),
|
||||
),
|
||||
],
|
||||
),
|
||||
const Spacer(),
|
||||
if (isMineWorking)
|
||||
const Padding(
|
||||
padding: EdgeInsets.only(right: 12),
|
||||
child: ProgressRing(),
|
||||
)
|
||||
else
|
||||
Button(
|
||||
onPressed: ((item.value.enable == true &&
|
||||
!isWorking &&
|
||||
!isInstalled)
|
||||
? model.doRemoteInstall(item.value)
|
||||
: null),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.only(
|
||||
left: 8, right: 8, top: 4, bottom: 4),
|
||||
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) ? "安装" : "不可用")),
|
||||
],
|
||||
),
|
||||
)),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 6),
|
||||
Container(
|
||||
color: Colors.white.withOpacity(.05),
|
||||
height: 1,
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget makeListContainer(String title, List<Widget> children,
|
||||
{List<Widget> actions = const []}) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(bottom: 12),
|
||||
child: AnimatedSize(
|
||||
duration: const Duration(milliseconds: 130),
|
||||
child: Container(
|
||||
decoration: BoxDecoration(
|
||||
color: FluentTheme.of(context).cardColor,
|
||||
borderRadius: BorderRadius.circular(7)),
|
||||
child: Padding(
|
||||
padding:
|
||||
const EdgeInsets.only(top: 12, bottom: 12, left: 24, right: 24),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
Text(
|
||||
title,
|
||||
style: const TextStyle(fontSize: 22),
|
||||
),
|
||||
const Spacer(),
|
||||
if (actions.isNotEmpty) ...actions,
|
||||
],
|
||||
),
|
||||
const SizedBox(
|
||||
height: 6,
|
||||
),
|
||||
Container(
|
||||
color: Colors.white.withOpacity(.1),
|
||||
height: 1,
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
...children
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget makeTitle(BuildContext context, LocalizationUIModel model) {
|
||||
return Row(
|
||||
children: [
|
||||
IconButton(
|
||||
icon: const Icon(
|
||||
FluentIcons.back,
|
||||
size: 22,
|
||||
),
|
||||
onPressed: model.onBack()),
|
||||
const SizedBox(width: 12),
|
||||
Text(getUITitle(context, model)),
|
||||
const SizedBox(width: 24),
|
||||
Text(
|
||||
model.scInstallPath,
|
||||
style: const TextStyle(fontSize: 13),
|
||||
),
|
||||
const Spacer(),
|
||||
SizedBox(
|
||||
height: 36,
|
||||
child: Row(
|
||||
children: [
|
||||
const Text(
|
||||
"语言: ",
|
||||
style: TextStyle(fontSize: 16),
|
||||
),
|
||||
ComboBox<String>(
|
||||
value: model.selectedLanguage,
|
||||
items: [
|
||||
for (final lang
|
||||
in LocalizationUIModel.languageSupport.entries)
|
||||
ComboBoxItem(
|
||||
value: lang.key,
|
||||
child: Text(lang.value),
|
||||
)
|
||||
],
|
||||
onChanged: model.workingVersion.isNotEmpty
|
||||
? null
|
||||
: (v) {
|
||||
if (v == null) return;
|
||||
model.selectLang(v);
|
||||
},
|
||||
)
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
Button(
|
||||
onPressed: model.doRefresh(),
|
||||
child: const Padding(
|
||||
padding: EdgeInsets.all(6),
|
||||
child: Icon(FluentIcons.refresh),
|
||||
)),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
String getUITitle(BuildContext context, LocalizationUIModel model) => "汉化管理";
|
||||
}
|
@ -1,394 +0,0 @@
|
||||
import 'dart:async';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:archive/archive_io.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:starcitizen_doctor/api/analytics.dart';
|
||||
import 'package:starcitizen_doctor/api/api.dart';
|
||||
import 'package:starcitizen_doctor/base/ui_model.dart';
|
||||
import 'package:starcitizen_doctor/common/conf/app_conf.dart';
|
||||
import 'package:starcitizen_doctor/common/conf/url_conf.dart';
|
||||
import 'package:starcitizen_doctor/common/helper/system_helper.dart';
|
||||
import 'package:starcitizen_doctor/common/io/rs_http.dart';
|
||||
import 'package:starcitizen_doctor/data/sc_localization_data.dart';
|
||||
import 'package:url_launcher/url_launcher_string.dart';
|
||||
import 'package:starcitizen_doctor/common/utils/log.dart' as log_utils;
|
||||
|
||||
class LocalizationUIModel extends BaseUIModel {
|
||||
final String scInstallPath;
|
||||
|
||||
static const languageSupport = {
|
||||
"chinese_(simplified)": "简体中文",
|
||||
"chinese_(traditional)": "繁體中文",
|
||||
};
|
||||
|
||||
late String selectedLanguage;
|
||||
|
||||
Map<String, ScLocalizationData>? apiLocalizationData;
|
||||
|
||||
LocalizationUIModel(this.scInstallPath);
|
||||
|
||||
String workingVersion = "";
|
||||
|
||||
final downloadDir =
|
||||
Directory("${AppConf.applicationSupportDir}\\Localizations");
|
||||
|
||||
late final customizeDir =
|
||||
Directory("${downloadDir.absolute.path}\\Customize_ini");
|
||||
|
||||
late final scDataDir = Directory("$scInstallPath\\data");
|
||||
|
||||
late final cfgFile = File("${scDataDir.absolute.path}\\system.cfg");
|
||||
|
||||
MapEntry<bool, String>? patchStatus;
|
||||
|
||||
List<String>? customizeList;
|
||||
|
||||
StreamSubscription? customizeDirListenSub;
|
||||
|
||||
bool enableCustomize = false;
|
||||
|
||||
@override
|
||||
void initModel() {
|
||||
selectedLanguage = languageSupport.entries.first.key;
|
||||
if (!customizeDir.existsSync()) {
|
||||
customizeDir.createSync(recursive: true);
|
||||
}
|
||||
customizeDirListenSub = customizeDir.watch().listen((event) {
|
||||
_scanCustomizeDir();
|
||||
});
|
||||
super.initModel();
|
||||
}
|
||||
|
||||
@override
|
||||
Future loadData() async {
|
||||
await _updateStatus();
|
||||
_checkUserCfg();
|
||||
_scanCustomizeDir();
|
||||
final l =
|
||||
await handleError(() => Api.getScLocalizationData(selectedLanguage));
|
||||
if (l != null) {
|
||||
apiLocalizationData = {};
|
||||
for (var element in l) {
|
||||
final isPTU = !scInstallPath.contains("LIVE");
|
||||
if (isPTU && element.gameChannel == "PTU") {
|
||||
apiLocalizationData![element.versionName ?? ""] = element;
|
||||
} else if (!isPTU && element.gameChannel == "PU") {
|
||||
apiLocalizationData![element.versionName ?? ""] = element;
|
||||
}
|
||||
}
|
||||
}
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
@override
|
||||
dispose() {
|
||||
customizeDirListenSub?.cancel();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
_scanCustomizeDir() {
|
||||
final fileList = customizeDir.listSync();
|
||||
customizeList = [];
|
||||
for (var value in fileList) {
|
||||
if (value is File && value.path.endsWith(".ini")) {
|
||||
customizeList?.add(value.absolute.path);
|
||||
}
|
||||
}
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
String getCustomizeFileName(String path) {
|
||||
return path.split("\\").last;
|
||||
}
|
||||
|
||||
_updateStatus() async {
|
||||
patchStatus = MapEntry(
|
||||
await getLangCfgEnableLang(lang: selectedLanguage),
|
||||
await getInstalledIniVersion(
|
||||
"${scDataDir.absolute.path}\\Localization\\$selectedLanguage\\global.ini"));
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
VoidCallback? onBack() {
|
||||
if (workingVersion.isNotEmpty) return null;
|
||||
return () {
|
||||
Navigator.pop(context!);
|
||||
};
|
||||
}
|
||||
|
||||
void selectLang(String v) {
|
||||
selectedLanguage = v;
|
||||
apiLocalizationData = null;
|
||||
notifyListeners();
|
||||
reloadData();
|
||||
}
|
||||
|
||||
VoidCallback? doRefresh() {
|
||||
if (workingVersion.isNotEmpty) return null;
|
||||
return () {
|
||||
apiLocalizationData = null;
|
||||
notifyListeners();
|
||||
reloadData();
|
||||
};
|
||||
}
|
||||
|
||||
VoidCallback? doRemoteInstall(ScLocalizationData value) {
|
||||
return () async {
|
||||
AnalyticsApi.touch("install_localization");
|
||||
final downloadUrl =
|
||||
"${URLConf.gitlabLocalizationUrl}/archive/${value.versionName}.tar.gz";
|
||||
final savePath =
|
||||
File("${downloadDir.absolute.path}\\${value.versionName}.sclang");
|
||||
try {
|
||||
workingVersion = value.versionName!;
|
||||
notifyListeners();
|
||||
if (!await savePath.exists()) {
|
||||
// download
|
||||
dPrint("downloading file to $savePath");
|
||||
final r = await RSHttp.get(downloadUrl);
|
||||
if (r.statusCode == 200 && r.data != null) {
|
||||
await savePath.writeAsBytes(r.data!);
|
||||
} else {
|
||||
throw "statusCode Error : ${r.statusCode}";
|
||||
}
|
||||
} else {
|
||||
dPrint("use cache $savePath");
|
||||
}
|
||||
await Future.delayed(const Duration(milliseconds: 300));
|
||||
// check file
|
||||
final globalIni = await compute(_readArchive, savePath.absolute.path);
|
||||
if (globalIni.isEmpty) {
|
||||
throw "文件受损,请重新下载";
|
||||
}
|
||||
await _installFormString(globalIni, value.versionName ?? "");
|
||||
} catch (e) {
|
||||
await showToast(context!, "安装出错!\n\n $e");
|
||||
if (await savePath.exists()) await savePath.delete();
|
||||
}
|
||||
workingVersion = "";
|
||||
notifyListeners();
|
||||
};
|
||||
}
|
||||
|
||||
Future<bool> getLangCfgEnableLang({String lang = ""}) async {
|
||||
if (!await cfgFile.exists()) return false;
|
||||
final str = (await cfgFile.readAsString()).replaceAll(" ", "");
|
||||
return str.contains("sys_languages=$lang") &&
|
||||
str.contains("g_language=$lang") &&
|
||||
str.contains("g_languageAudio=english");
|
||||
}
|
||||
|
||||
static Future<String> 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--) {
|
||||
if (iniStringSplit[i]
|
||||
.contains("_starcitizen_doctor_localization_version=")) {
|
||||
final v = iniStringSplit[i]
|
||||
.trim()
|
||||
.split("_starcitizen_doctor_localization_version=")[1];
|
||||
return v;
|
||||
}
|
||||
}
|
||||
return "自定义文件";
|
||||
}
|
||||
|
||||
_installFormString(StringBuffer globalIni, String versionName) async {
|
||||
final iniFile = File(
|
||||
"${scDataDir.absolute.path}\\Localization\\$selectedLanguage\\global.ini");
|
||||
if (versionName.isNotEmpty) {
|
||||
if (!globalIni.toString().endsWith("\n")) {
|
||||
globalIni.write("\n");
|
||||
}
|
||||
globalIni.write("_starcitizen_doctor_localization_version=$versionName");
|
||||
}
|
||||
|
||||
/// write cfg
|
||||
if (await cfgFile.exists()) {}
|
||||
|
||||
/// write ini
|
||||
if (await iniFile.exists()) {
|
||||
await iniFile.delete();
|
||||
}
|
||||
await iniFile.create(recursive: true);
|
||||
await iniFile.writeAsString("\uFEFF${globalIni.toString().trim()}",
|
||||
flush: true);
|
||||
await updateLangCfg(true);
|
||||
await _updateStatus();
|
||||
}
|
||||
|
||||
openDir() async {
|
||||
showToast(context!,
|
||||
"即将打开本地化文件夹,请将自定义的 任意名称.ini 文件放入 Customize_ini 文件夹。\n\n添加新文件后未显示请使用右上角刷新按钮。\n\n安装时请确保选择了正确的语言。");
|
||||
await Process.run(SystemHelper.powershellPath,
|
||||
["explorer.exe", "/select,\"${customizeDir.absolute.path}\"\\"]);
|
||||
}
|
||||
|
||||
updateLangCfg(bool enable) async {
|
||||
final status = await getLangCfgEnableLang(lang: selectedLanguage);
|
||||
final exists = await cfgFile.exists();
|
||||
if (status == enable) {
|
||||
await _updateStatus();
|
||||
return;
|
||||
}
|
||||
StringBuffer newStr = StringBuffer();
|
||||
var str = <String>[];
|
||||
if (exists) {
|
||||
str = (await cfgFile.readAsString()).replaceAll(" ", "").split("\n");
|
||||
}
|
||||
if (enable) {
|
||||
if (exists) {
|
||||
for (var value in str) {
|
||||
if (value.contains("sys_languages")) {
|
||||
value = "sys_languages=$selectedLanguage";
|
||||
} else if (value.contains("g_language")) {
|
||||
value = "g_language=$selectedLanguage";
|
||||
} else if (value.contains("g_languageAudio")) {
|
||||
value = "g_language=english";
|
||||
}
|
||||
if (value.trim().isNotEmpty) newStr.writeln(value);
|
||||
}
|
||||
}
|
||||
if (!newStr.toString().contains("sys_languages=$selectedLanguage")) {
|
||||
newStr.writeln("sys_languages=$selectedLanguage");
|
||||
}
|
||||
if (!newStr.toString().contains("g_language=$selectedLanguage")) {
|
||||
newStr.writeln("g_language=$selectedLanguage");
|
||||
}
|
||||
if (!newStr.toString().contains("g_languageAudio")) {
|
||||
newStr.writeln("g_languageAudio=english");
|
||||
}
|
||||
} else {
|
||||
if (exists) {
|
||||
for (var value in str) {
|
||||
if (value.contains("sys_languages=")) {
|
||||
continue;
|
||||
} else if (value.contains("g_language")) {
|
||||
continue;
|
||||
}
|
||||
newStr.writeln(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (exists) await cfgFile.delete(recursive: true);
|
||||
await cfgFile.create(recursive: true);
|
||||
await cfgFile.writeAsString(newStr.toString());
|
||||
await _updateStatus();
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
VoidCallback? doDelIniFile() {
|
||||
return () async {
|
||||
final iniFile = File(
|
||||
"${scDataDir.absolute.path}\\Localization\\$selectedLanguage\\global.ini");
|
||||
if (await iniFile.exists()) await iniFile.delete();
|
||||
await updateLangCfg(false);
|
||||
await _updateStatus();
|
||||
};
|
||||
}
|
||||
|
||||
/// read locale active
|
||||
static StringBuffer _readArchive(String savePath) {
|
||||
final inputStream = InputFileStream(savePath);
|
||||
final archive =
|
||||
TarDecoder().decodeBytes(GZipDecoder().decodeBuffer(inputStream));
|
||||
StringBuffer globalIni = StringBuffer("");
|
||||
for (var element in archive.files) {
|
||||
if (element.name.contains("global.ini")) {
|
||||
for (var value
|
||||
in (element.rawContent?.readString() ?? "").split("\n")) {
|
||||
final tv = value.trim();
|
||||
if (tv.isNotEmpty) globalIni.writeln(tv);
|
||||
}
|
||||
}
|
||||
}
|
||||
archive.clear();
|
||||
return globalIni;
|
||||
}
|
||||
|
||||
VoidCallback? doLocalInstall(String filePath) {
|
||||
if (workingVersion.isNotEmpty) return null;
|
||||
return () async {
|
||||
final f = File(filePath);
|
||||
if (!await f.exists()) return;
|
||||
workingVersion = filePath;
|
||||
notifyListeners();
|
||||
final str = await f.readAsString();
|
||||
await _installFormString(
|
||||
StringBuffer(str), "自定义_${getCustomizeFileName(filePath)}");
|
||||
workingVersion = "";
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static Future<MapEntry<String, bool>?> checkLocalizationUpdates(
|
||||
List<String> gameInstallPaths) async {
|
||||
final updateInfo = <String, bool>{};
|
||||
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;
|
||||
}
|
||||
}
|
||||
log_utils.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;
|
||||
}
|
||||
|
||||
void goFeedback() {
|
||||
launchUrlString(URLConf.feedbackUrl);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user