2024-08-15 01:40:33 +00:00
|
|
|
|
using System.Collections.ObjectModel;
|
2024-08-07 02:31:13 +00:00
|
|
|
|
using CommunityToolkit.Mvvm.ComponentModel;
|
2024-08-08 04:29:27 +00:00
|
|
|
|
using Microsoft.UI.Xaml;
|
|
|
|
|
using Microsoft.UI.Xaml.Controls;
|
|
|
|
|
using RustTools.muqing;
|
|
|
|
|
using RustTools.Views;
|
2024-08-07 02:31:13 +00:00
|
|
|
|
|
|
|
|
|
namespace RustTools.ViewModels;
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 模组界面配置
|
|
|
|
|
/// </summary>
|
2024-08-15 01:40:33 +00:00
|
|
|
|
public class ModuleViewModel : ObservableRecipient
|
2024-08-07 02:31:13 +00:00
|
|
|
|
{
|
2024-08-08 04:29:27 +00:00
|
|
|
|
|
|
|
|
|
public ObservableCollection<DataObject> ListMod = new();
|
2024-08-07 02:31:13 +00:00
|
|
|
|
public ModuleViewModel()
|
|
|
|
|
{
|
2024-08-08 04:29:27 +00:00
|
|
|
|
|
|
|
|
|
var iniHelper = new IniHelper();
|
|
|
|
|
iniHelper.Load(IniHelper.FILE.Config);
|
|
|
|
|
var v = iniHelper.GetValue(IniHelper.CODE.Rust, IniHelper.KEY.ModFileUrl);
|
|
|
|
|
if (v == string.Empty)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async void Button_Rwmod(object sender, RoutedEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
var menuItem = sender as MenuFlyoutItem;
|
|
|
|
|
if (menuItem != null)
|
|
|
|
|
{
|
|
|
|
|
if (menuItem.DataContext is DataObject folderItem)
|
|
|
|
|
{
|
|
|
|
|
var filepath = Path.Combine(Path.GetDirectoryName(folderItem.Dri), folderItem.Name + ".rwmod");
|
|
|
|
|
if (File.Exists(filepath))
|
|
|
|
|
{
|
|
|
|
|
var show = await new ContentDialog()
|
|
|
|
|
{
|
|
|
|
|
XamlRoot = menuItem.XamlRoot,
|
|
|
|
|
Title = "警告",
|
|
|
|
|
Content = "已经存在必须覆盖",
|
|
|
|
|
PrimaryButtonText = "确定",
|
|
|
|
|
SecondaryButtonText = "取消"
|
|
|
|
|
}.ShowAsync();
|
|
|
|
|
if (show == ContentDialogResult.Primary)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// 压缩zip
|
|
|
|
|
var v = wj.ZipExample(folderItem.Dri, folderItem.Name + ".rwmod");
|
2024-08-15 01:40:33 +00:00
|
|
|
|
if (v != string.Empty)
|
2024-08-08 04:29:27 +00:00
|
|
|
|
{
|
|
|
|
|
ListMod.Remove(new DataObject(new FileInfo(filepath)));
|
2024-08-15 01:40:33 +00:00
|
|
|
|
ListMod.Insert(0, new DataObject(new FileInfo(v)));
|
2024-08-08 04:29:27 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-08-07 02:31:13 +00:00
|
|
|
|
}
|
|
|
|
|
}
|