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>
|
|
/// 模组碎片
|
|
/// </summary>
|
|
public class DataObject
|
|
{
|
|
//路径
|
|
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 = $"文件大小:{wj.FormatFileSize(fileInfo.Length)}";
|
|
Dri = fileInfo.FullName;
|
|
}
|
|
public DataObject(DirectoryInfo fileInfo)
|
|
{
|
|
Name = fileInfo.Name;
|
|
IsRwmod = false;
|
|
Info = $"创建时间:{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)
|
|
{
|
|
// 获取相关的文件夹项
|
|
var folderItem = menuItem.DataContext as DataObject; // 假设你的文件夹项类型为 FolderItem
|
|
if (folderItem != null)
|
|
{
|
|
// 这里可以添加删除文件夹逻辑
|
|
gj.sc("删除文件夹"+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 = "解压";
|
|
//dialog. = "你可以在本次解压中选择是否删除源文件";
|
|
dialog.PrimaryButtonText = "确定";
|
|
dialog.SecondaryButtonText = "取消";
|
|
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("确定");
|
|
// 获取文件的名称(不包括扩展名)
|
|
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()
|
|
{
|
|
// 创建 CheckBox
|
|
var checkbox = new CheckBox
|
|
{
|
|
Content = "删除源文件",
|
|
IsChecked = false, // 默认未选中
|
|
Margin=new Thickness(0,16,0,0),
|
|
|
|
};
|
|
var text = new TextBlock
|
|
{
|
|
Text = "你可以在本次解压中选择是否删除源文件",
|
|
};
|
|
|
|
// 创建 StackPanel 作为容器
|
|
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;
|
|
}
|
|
} |