WIn_RustTools/RustTools/Themes/PostRwmod.xaml.cs

101 lines
3.4 KiB
C#
Raw Normal View History

2024-08-31 10:32:38 +00:00
using System.Globalization;
2024-08-26 09:41:33 +00:00
using Microsoft.UI.Xaml.Controls;
2024-08-31 10:32:38 +00:00
using RustTools.muqing;
using SharpCompress.Common;
using TinyPinyin;
using static IniHelper;
2024-08-26 09:41:33 +00:00
// To learn more about WinUI, the WinUI project structure,
// and more about our project templates, see: http://aka.ms/winui-project-info.
namespace RustTools.Themes;
public sealed partial class PostRwmod : UserControl
{
2024-08-31 10:32:38 +00:00
private readonly ContentDialog contentDialog;
public PostRwmod(ContentDialog contentDialog)
{
this.contentDialog = contentDialog;
InitializeComponent();
}
Dictionary<string, Dictionary<string, string>> IniInfo = new();
string path;
public void Init(string path)
2024-08-26 09:41:33 +00:00
{
2024-08-31 10:32:38 +00:00
this.path = path;
var directoryInfo = new DirectoryInfo(path);
//
var id = PinyinHelper.GetPinyin(directoryInfo.Name, "_");
//<2F><>ȡ
var v = Path.Combine(directoryInfo.FullName, "mod-info.txt");
if (File.Exists(v))
{
var fileInfo = new FileInfo(v);
IniInfo = gj.IniInfo(v);
if(IniInfo.TryGetValue("mod",out var mod))
{
var Name = mod.TryGetValue("title", out var value) ? value : fileInfo.Name;
TextBoxName.Text= Name;
//\n
var Info = mod.TryGetValue("description", out var description) ? description : "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ";
TextBoxInfo.AcceptsReturn = true;
TextBoxInfo.Text= Info.Replace("\\n", "\n");
if(mod.TryGetValue("minVersion", out var minVersion))
{
TextBoxYouxiVersion.Text= minVersion;
}
//Version
TextBoxVersion.Text = mod.TryGetValue("Version", out var version) ? version : "1.0.0";
}
}
TextBoxID.Text = id;
}
private void AppBarButton_Click(object sender, Microsoft.UI.Xaml.RoutedEventArgs e)
{
if (sender is AppBarButton button)
{
contentDialog.Closing -= Dialog.DialogNotEsc;
switch (button.Tag)
{
case <><C8A1>":
contentDialog.Hide();
break;
case "<22>ύ":
var modstr = "mod";
if (!IniInfo.TryGetValue(modstr, out var value))
{
value = new Dictionary<string, string>();
IniInfo[modstr] = value;
}
value["title"] = TextBoxName.Text;
value["description"] = TextBoxInfo.Text.ToString().Replace("\n", "\n");
gj.sc(TextBoxInfo.Text.ToString().Replace("\n", "\\n"));
value["minVersion"] = TextBoxYouxiVersion.Text;
using (var sw = new StreamWriter(Path.Combine(path, "mod-info.txt")))
{
foreach (var section in IniInfo)
{
sw.WriteLine($"[{section.Key}]");
foreach (var keyValue in section.Value)
{
sw.WriteLine($"{keyValue.Key}:{keyValue.Value}");
}
sw.WriteLine();
}
}
contentDialog.Hide();
break;
}
}
2024-08-26 09:41:33 +00:00
}
}