WIn_RustTools/RustTools/ViewModels/ModuleViewModel.cs
2024-08-08 12:29:27 +08:00

87 lines
2.6 KiB
C#
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using CommunityToolkit.Mvvm.ComponentModel;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using RustTools.muqing;
using RustTools.Views;
namespace RustTools.ViewModels;
/// <summary>
/// 模组界面配置
/// </summary>
public class ModuleViewModel : ObservableRecipient
{
public ObservableCollection<DataObject> ListMod = new();
public ModuleViewModel()
{
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");
if (v!=string.Empty)
{
ListMod.Remove(new DataObject(new FileInfo(filepath)));
ListMod.Insert(0,new DataObject(new FileInfo(v)));
}
}
}
}
}