212 lines
6.3 KiB
C#
212 lines
6.3 KiB
C#
|
|
|||
|
using System.Collections.ObjectModel;
|
|||
|
using System.Reflection.Metadata.Ecma335;
|
|||
|
using Microsoft.UI.Xaml;
|
|||
|
using Microsoft.UI.Xaml.Controls;
|
|||
|
using Microsoft.UI.Xaml.Controls.Primitives;
|
|||
|
using Microsoft.UI.Xaml.Media;
|
|||
|
using RustTools.muqing;
|
|||
|
using RustTools.ViewModels;
|
|||
|
namespace RustTools.Views;
|
|||
|
/// <summary>
|
|||
|
/// ģ<><C4A3><EFBFBD><EFBFBD>Ƭ
|
|||
|
/// </summary>
|
|||
|
public class DataObject
|
|||
|
{
|
|||
|
//·<><C2B7>
|
|||
|
public string Dri
|
|||
|
{
|
|||
|
get; set;
|
|||
|
}
|
|||
|
public string Name
|
|||
|
{
|
|||
|
get; set;
|
|||
|
}
|
|||
|
public string Info
|
|||
|
{
|
|||
|
get; set;
|
|||
|
}
|
|||
|
public bool IsRwmod
|
|||
|
{
|
|||
|
get; set;
|
|||
|
}
|
|||
|
public DataObject()
|
|||
|
{
|
|||
|
IsRwmod = true;
|
|||
|
}
|
|||
|
public DataObject(FileInfo fileInfo)
|
|||
|
{
|
|||
|
Name = fileInfo.Name;
|
|||
|
IsRwmod=true;
|
|||
|
Info = $"<22>ļ<EFBFBD><C4BC><EFBFBD>С:{wj.FormatFileSize(fileInfo.Length)}";
|
|||
|
Dri = fileInfo.FullName;
|
|||
|
}
|
|||
|
public DataObject(DirectoryInfo fileInfo)
|
|||
|
{
|
|||
|
Name = fileInfo.Name;
|
|||
|
IsRwmod = false;
|
|||
|
Info = $"<22><><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>:{fileInfo.CreationTime}";
|
|||
|
Dri = fileInfo.FullName;
|
|||
|
}
|
|||
|
// ... Methods ...
|
|||
|
}
|
|||
|
public sealed partial class ModulePage : Page
|
|||
|
{
|
|||
|
public ObservableCollection<DataObject> ListMod = new();
|
|||
|
public ModuleViewModel ViewModel { get; set; }
|
|||
|
public ModulePage()
|
|||
|
{
|
|||
|
ViewModel = App.GetService<ModuleViewModel>();
|
|||
|
InitializeComponent();
|
|||
|
var iniHelper = new IniHelper();
|
|||
|
iniHelper.Load(IniHelper.FILE.Config);
|
|||
|
var v = iniHelper.GetValue(IniHelper.CODE.Rust, IniHelper.KEY.ModFileUrl);
|
|||
|
|
|||
|
var subfolders = Directory.GetDirectories(v);
|
|||
|
foreach (var item in subfolders)
|
|||
|
{
|
|||
|
var info = new DirectoryInfo(item);
|
|||
|
ListMod.Add(new DataObject(info));
|
|||
|
}
|
|||
|
var files = Directory.GetFiles(v);
|
|||
|
foreach (var item in files)
|
|||
|
{
|
|||
|
var info = new FileInfo(item);
|
|||
|
if (info.Name.EndsWith(".rwmod"))
|
|||
|
{
|
|||
|
ListMod.Add(new DataObject(info));
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
}
|
|||
|
private void ShowMenu(bool isTransient, GridViewItem dataTemplate)
|
|||
|
{
|
|||
|
FlyoutShowOptions myOption = new FlyoutShowOptions();
|
|||
|
myOption.ShowMode = isTransient ? FlyoutShowMode.Transient : FlyoutShowMode.Standard;
|
|||
|
CommandBarFlyout1.ShowAt(dataTemplate, myOption);
|
|||
|
}
|
|||
|
|
|||
|
private void Button_Click(object sender, RoutedEventArgs e)
|
|||
|
{
|
|||
|
var button = sender as Button;
|
|||
|
if (button != null)
|
|||
|
{
|
|||
|
var container = VisualTreeHelper.GetParent(button) as FrameworkElement;
|
|||
|
if (container != null && container.DataContext is DataObject dataItem)
|
|||
|
{
|
|||
|
|
|||
|
FlyoutShowOptions myOption = new FlyoutShowOptions();
|
|||
|
myOption.ShowMode = FlyoutShowMode.Standard;
|
|||
|
CommandBarFlyout1.ShowAt(button, myOption);
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
private void Button_Delete(object sender, RoutedEventArgs e)
|
|||
|
{
|
|||
|
|
|||
|
|
|||
|
MenuFlyoutItem menuItem = sender as MenuFlyoutItem;
|
|||
|
if (menuItem != null)
|
|||
|
{
|
|||
|
// <20><>ȡ<EFBFBD><C8A1><EFBFBD>ص<EFBFBD><D8B5>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
var folderItem = menuItem.DataContext as DataObject; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ FolderItem
|
|||
|
if (folderItem != null)
|
|||
|
{
|
|||
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɾ<EFBFBD><C9BE><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
gj.sc("ɾ<><C9BE><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD>"+folderItem.Dri);
|
|||
|
Directory.Delete(folderItem.Dri,true);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
private async void Button_Click_RwmodItem(object sender, RoutedEventArgs e)
|
|||
|
{
|
|||
|
ContentDialog dialog = new ContentDialog();
|
|||
|
dialog.XamlRoot=XamlRoot;
|
|||
|
dialog.Title = "<22><>ѹ";
|
|||
|
//dialog. = "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڱ<EFBFBD><DAB1>ν<EFBFBD>ѹ<EFBFBD><D1B9>ѡ<EFBFBD><D1A1><EFBFBD>Ƿ<EFBFBD>ɾ<EFBFBD><C9BE>Դ<EFBFBD>ļ<EFBFBD>";
|
|||
|
dialog.PrimaryButtonText = "ȷ<><C8B7>";
|
|||
|
dialog.SecondaryButtonText = "ȡ<><C8A1>";
|
|||
|
dialog.Content = CreateCheckboxContent();
|
|||
|
var contentDialogResult = await dialog.ShowAsync();
|
|||
|
if (contentDialogResult == ContentDialogResult.Primary)
|
|||
|
{
|
|||
|
|
|||
|
var button = sender as Button;
|
|||
|
if (button != null)
|
|||
|
{
|
|||
|
var container = VisualTreeHelper.GetParent(button) as FrameworkElement;
|
|||
|
if (container != null && container.DataContext is DataObject dataItem)
|
|||
|
{
|
|||
|
CheckBox checkbox = (dialog.Content as StackPanel)?.Children[1] as CheckBox;
|
|||
|
if (checkbox.IsChecked == true)
|
|||
|
{
|
|||
|
File.Delete(dataItem.Dri);
|
|||
|
ListMod.Remove(dataItem);
|
|||
|
}
|
|||
|
gj.sc("ȷ<><C8B7>");
|
|||
|
// <20><>ȡ<EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ƣ<EFBFBD><C6A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>չ<EFBFBD><D5B9><EFBFBD><EFBFBD>
|
|||
|
var fileNameWithoutExtension = Path.GetFileNameWithoutExtension(dataItem.Dri);
|
|||
|
var GetDirectoryName = Path.GetDirectoryName(dataItem.Dri);
|
|||
|
if (Directory.Exists(GetDirectoryName)&& fileNameWithoutExtension!=null)
|
|||
|
{
|
|||
|
var targetDirectory = Path.Combine(GetDirectoryName, fileNameWithoutExtension);
|
|||
|
var v = wj.UnzipFile(dataItem.Dri, targetDirectory);
|
|||
|
gj.sc(v);
|
|||
|
if (v)
|
|||
|
{
|
|||
|
ListMod.Add(new DataObject(new DirectoryInfo(targetDirectory)));
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
private FrameworkElement CreateCheckboxContent()
|
|||
|
{
|
|||
|
// <20><><EFBFBD><EFBFBD> CheckBox
|
|||
|
var checkbox = new CheckBox
|
|||
|
{
|
|||
|
Content = "ɾ<><C9BE>Դ<EFBFBD>ļ<EFBFBD>",
|
|||
|
IsChecked = false, // Ĭ<><C4AC>δѡ<CEB4><D1A1>
|
|||
|
Margin=new Thickness(0,16,0,0),
|
|||
|
|
|||
|
};
|
|||
|
var text = new TextBlock
|
|||
|
{
|
|||
|
Text = "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڱ<EFBFBD><DAB1>ν<EFBFBD>ѹ<EFBFBD><D1B9>ѡ<EFBFBD><D1A1><EFBFBD>Ƿ<EFBFBD>ɾ<EFBFBD><C9BE>Դ<EFBFBD>ļ<EFBFBD>",
|
|||
|
};
|
|||
|
|
|||
|
// <20><><EFBFBD><EFBFBD> StackPanel <20><>Ϊ<EFBFBD><CEAA><EFBFBD><EFBFBD>
|
|||
|
var stackPanel = new StackPanel();
|
|||
|
stackPanel.Children.Add(text);
|
|||
|
stackPanel.Children.Add(checkbox);
|
|||
|
return stackPanel;
|
|||
|
}
|
|||
|
}
|
|||
|
public class MyItemTemplateSelector : DataTemplateSelector
|
|||
|
{
|
|||
|
public DataTemplate Template1
|
|||
|
{
|
|||
|
get; set;
|
|||
|
} = new();
|
|||
|
public DataTemplate Template2
|
|||
|
{
|
|||
|
get; set;
|
|||
|
} = new();
|
|||
|
|
|||
|
protected override DataTemplate SelectTemplateCore(object item)
|
|||
|
{
|
|||
|
if (item is not DataObject dataObject)
|
|||
|
{
|
|||
|
return base.SelectTemplateCore(item);
|
|||
|
}
|
|||
|
if (dataObject.IsRwmod)
|
|||
|
return Template1;
|
|||
|
else
|
|||
|
return Template2;
|
|||
|
}
|
|||
|
}
|