101 lines
3.4 KiB
C#
101 lines
3.4 KiB
C#
|
|
using System.Globalization;
|
|
using Microsoft.UI.Xaml.Controls;
|
|
using RustTools.muqing;
|
|
using SharpCompress.Common;
|
|
using TinyPinyin;
|
|
using static IniHelper;
|
|
|
|
// 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
|
|
{
|
|
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)
|
|
{
|
|
this.path = path;
|
|
var directoryInfo = new DirectoryInfo(path);
|
|
//
|
|
var id = PinyinHelper.GetPinyin(directoryInfo.Name, "_");
|
|
//¶ÁÈ¡
|
|
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 : "ÎÞÃèÊöÐÅÏ¢";
|
|
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 "È¡Ïû":
|
|
contentDialog.Hide();
|
|
break;
|
|
case "Ìá½»":
|
|
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;
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|