WIn_RustTools/RustTools/Views/CodeDataPage.xaml.cs

141 lines
4.3 KiB
C#
Raw Normal View History

2024-08-19 14:30:11 +00:00
using System.Collections.ObjectModel;
using Microsoft.UI.Xaml.Controls;
using Newtonsoft.Json;
using RustTools.DataList;
using RustTools.Helpers;
using RustTools.muqing;
using RustTools.ViewModels;
using Windows.Storage;
using Windows.UI.Popups;
namespace RustTools.Views;
/// <summary>
/// <20><><EFBFBD>ݼ<EFBFBD><DDBC><EFBFBD>Ƭ
/// </summary>
public sealed partial class CodeDataPage : Page
{
public CodeDataViewModel ViewModel
{
get; set;
}
public ObservableCollection<DataBaseManifest> DataConfig { get; set; } = new();
public static DataBaseManifest codetable = new();
public CodeDataPage()
{
ViewModel = new CodeDataViewModel();
InitializeComponent();
var filePath = Path.Combine(ApplicationData.Current.LocalFolder.Path, "CodeTable");
if (!Directory.Exists(filePath)) { return; }
var directoryInfo = new DirectoryInfo(filePath);
var directoryInfos = directoryInfo.GetDirectories();
foreach (var item in directoryInfos)
{
var v = Path.Combine(item.FullName, "DataBaseManifest.json");
if (File.Exists(v))
{
var json = JsonConvert.DeserializeObject<DataBaseManifest>(File.ReadAllText(v));
json.Dir = item.FullName;
//gj.sc(json.Dir);
DataConfig.Add(json);
}
}
var FirstOrDefault = DataConfig.FirstOrDefault(any => any.id == "official");
if (FirstOrDefault != null)
{
DataConfig.Remove(FirstOrDefault);
DataConfig.Insert(0, FirstOrDefault);
}
var aa = DataConfig.FirstOrDefault(any => any.Dir == codetable.Dir);
if (aa?.Dir == codetable.Dir)
{
listview.SelectedItem = aa;
}
}
private void listview_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (e.AddedItems[0] is DataBaseManifest item)
{
var iniHelper = new IniHelper(IniHelper.FILE.Config);
iniHelper.SetValue("CodeTable", "Dir", item.Dir ?? string.Empty);
iniHelper.Save();
gj.sc(item.Dir);
codetable = item;
}
}
private async void MenuFlyoutItem_Click(object sender, Microsoft.UI.Xaml.RoutedEventArgs e)
{
if (sender is MenuFlyoutItem item)
{
if (item.DataContext is DataBaseManifest data)
{
var str = item.Text;
if (str == "<22>༭")
{
//<2F><><EFBFBD><EFBFBD>ϵͳ<CFB5>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>û<EFBFBD><C3BB>Լ<EFBFBD>ѡ<EFBFBD><D1A1>Json<6F><6E><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
wj.OpenFileExplorer(data.Dir);
}
else if (str == <><C9BE>")
{
var contentDialog = new ContentDialog()
{
XamlRoot = Content.XamlRoot,
Title = "<22><>ʾ",
Content = $"<22>Ƿ<EFBFBD>ɾ<EFBFBD><C9BE> {data.name}\nλ<6E><CEBB> {data.Dir}",
CloseButtonText = <><C8A1>"
};
if (data.id == "official")
{
contentDialog.Title = "<22><><EFBFBD><EFBFBD>";
contentDialog.Content = "<22>޷<EFBFBD>ɾ<EFBFBD><C9BE><EFBFBD>ٷ<EFBFBD><D9B7><EFBFBD><EFBFBD>ݼ<EFBFBD>";
}
else
{
contentDialog.PrimaryButtonText = <><C8B7>";
}
var contentDialogResult = await contentDialog.ShowAsync();
if (contentDialogResult == ContentDialogResult.Primary)
{
gj.sc(<><C9BE><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD>" + data.Dir);
}
}
}
}
}
private async void AppBarButton_Click(object sender, Microsoft.UI.Xaml.RoutedEventArgs e)
{
if (sender is AppBarButton item)
{
var v = item.Tag.ToString();
if (v == "0")
{
//<2F>½<EFBFBD>
}
else if (v == "1")
{
//<2F><><EFBFBD><EFBFBD>
var v1 = Path.Combine(wj.LocalFolder, "CodeTable");
if (Directory.Exists(v1))
{
wj.OpenFileExplorer(v1);
}
else
{
await Dialog.DialogWarn("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD>", XamlRoot);
}
}
else if (v == "2")
{
}
}
}
}