diff --git a/RustTools/App.xaml.cs b/RustTools/App.xaml.cs index e3d00d5..28b3ab3 100644 --- a/RustTools/App.xaml.cs +++ b/RustTools/App.xaml.cs @@ -52,10 +52,10 @@ public partial class App : Microsoft.UI.Xaml.Application public App() { InitializeComponent(); - if (!Directory.Exists(wj.CD)) - { - Directory.CreateDirectory(wj.CD); - } + //if (!Directory.Exists(wj.CD)) + //{ + // Directory.CreateDirectory(wj.CD); + //} // 注册激活事件处理程序 Host = Microsoft.Extensions.Hosting.Host. CreateDefaultBuilder(). diff --git a/RustTools/Assets/image/folder.svg b/RustTools/Assets/image/folder.svg new file mode 100644 index 0000000..a831684 --- /dev/null +++ b/RustTools/Assets/image/folder.svg @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/RustTools/Assets/image/rwmod.svg b/RustTools/Assets/image/rwmod.svg new file mode 100644 index 0000000..e587930 --- /dev/null +++ b/RustTools/Assets/image/rwmod.svg @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/RustTools/MainWindow.xaml.cs b/RustTools/MainWindow.xaml.cs index ea31f31..3a33ce2 100644 --- a/RustTools/MainWindow.xaml.cs +++ b/RustTools/MainWindow.xaml.cs @@ -17,8 +17,6 @@ public sealed partial class MainWindow : WindowEx { InitializeComponent(); gj.SetBackTheme(this); - //gj.sc("lujing"+ AppContext.BaseDirectory); - //Resources AppWindow.SetIcon(Path.Combine(AppContext.BaseDirectory, "Assets/WindowIcon.ico")); //AppWindow.SetIcon(Path.Combine(AppContext.BaseDirectory, "Assets/Icon.ico")); Content = null; diff --git a/RustTools/RustTools.csproj b/RustTools/RustTools.csproj index 9f5aeef..731408f 100644 --- a/RustTools/RustTools.csproj +++ b/RustTools/RustTools.csproj @@ -4,11 +4,13 @@ net7.0-windows10.0.19041.0 10.0.17763.0 RustTools + x64 x86;x64;arm64 + true win10-x86;win10-x64;win10-arm64 - enable - enable - true + enable + enable + true true RustTools app.manifest @@ -16,8 +18,8 @@ Assets\WindowIcon.ico README.md zh-cn - - + + False True 3386EC79D3BB9691D0A8DA634167500B242E109D @@ -29,20 +31,7 @@ C:\\RustTools D:\RustTools - - - - - - - - - - - - - - + @@ -58,19 +47,18 @@ - - - + + Always + + + MSBuild:Compile MSBuild:Compile - - MSBuild:Compile - MSBuild:Compile @@ -94,9 +82,10 @@ - + + true - - + + \ No newline at end of file diff --git a/RustTools/Themes/Generic.xaml b/RustTools/Themes/Generic.xaml deleted file mode 100644 index 71528c2..0000000 --- a/RustTools/Themes/Generic.xaml +++ /dev/null @@ -1,19 +0,0 @@ - - - - diff --git a/RustTools/ViewModels/ModuleViewModel.cs b/RustTools/ViewModels/ModuleViewModel.cs index 799013a..a6a37f1 100644 --- a/RustTools/ViewModels/ModuleViewModel.cs +++ b/RustTools/ViewModels/ModuleViewModel.cs @@ -1,9 +1,14 @@ 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; /// @@ -11,8 +16,71 @@ namespace RustTools.ViewModels; /// public class ModuleViewModel : ObservableRecipient { + + public ObservableCollection 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))); + } + } + } } } diff --git a/RustTools/Views/HomePage.xaml.cs b/RustTools/Views/HomePage.xaml.cs index a0085e4..b21e7d5 100644 --- a/RustTools/Views/HomePage.xaml.cs +++ b/RustTools/Views/HomePage.xaml.cs @@ -27,11 +27,15 @@ public sealed partial class HomePage : Page Pictures.Add(item); } } - ViewModel.random(); - ViewModel.Latest(); InitializeComponent(); ListA.ItemClick += ListAClick; ListB.ItemClick += ListAClick; + //Ϊ˽ʡԵʱ򲻼Щ + if (false) + { + ViewModel.random(); + ViewModel.Latest(); + } } private void Page_SizeChanged(object sender, SizeChangedEventArgs e) diff --git a/RustTools/Views/ModulePage.xaml b/RustTools/Views/ModulePage.xaml index db11e3a..e38c38d 100644 --- a/RustTools/Views/ModulePage.xaml +++ b/RustTools/Views/ModulePage.xaml @@ -16,10 +16,15 @@ Click="Button_Click_RwmodItem" CornerRadius="9"> - + - - + + - @@ -65,6 +94,7 @@ Label="分享" ToolTipService.ToolTip="分享" /> @@ -74,16 +104,16 @@ + - diff --git a/RustTools/Views/ModulePage.xaml.cs b/RustTools/Views/ModulePage.xaml.cs index 10a6daf..59c268e 100644 --- a/RustTools/Views/ModulePage.xaml.cs +++ b/RustTools/Views/ModulePage.xaml.cs @@ -1,5 +1,6 @@ using System.Collections.ObjectModel; +using System.Diagnostics; using System.Reflection.Metadata.Ecma335; using Microsoft.UI.Xaml; using Microsoft.UI.Xaml.Controls; @@ -7,13 +8,14 @@ using Microsoft.UI.Xaml.Controls.Primitives; using Microsoft.UI.Xaml.Media; using RustTools.muqing; using RustTools.ViewModels; +using static IniHelper; +using static System.Collections.Specialized.BitVector32; namespace RustTools.Views; /// -/// ģƬ +/// 模组碎片 /// public class DataObject { - //· public string Dri { get; set; @@ -30,61 +32,67 @@ public class DataObject { get; set; } - public DataObject() + public string Icon { - IsRwmod = true; + get; set; } + + public override bool Equals(object obj) + { + if (obj is DataObject other) + { + return Dri == other.Dri; + } + return false; + } +#pragma warning disable CS8618 // 在退出构造函数时,不可为 null 的字段必须包含非 null 值。请考虑声明为可以为 null。 public DataObject(FileInfo fileInfo) { - Name = fileInfo.Name; - IsRwmod=true; - Info = $"ļС:{wj.FormatFileSize(fileInfo.Length)}"; + Name = Path.GetFileNameWithoutExtension(fileInfo.Name); + //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}"; + Info = $"{fileInfo.CreationTime}"; Dri = fileInfo.FullName; + Icon = File.Exists(Path.Combine(Dri, "icon.png")) ? Path.Combine(Dri, "icon.png") : "/Assets/image/folder.svg"; + var modinfo = Path.Combine(Dri, "mod-info.txt"); + if (File.Exists(modinfo)) + { + var dictionary = gj.IniInfo(modinfo); + if (dictionary.TryGetValue("mod", out var sectionValues)) + { + gj.sc(sectionValues); + Name =sectionValues.TryGetValue("title", out var value) ? value : Name; + gj.sc(value); + Info = sectionValues.TryGetValue("description", out var description) ? description : Info; + } + } } - // ... Methods ... } public sealed partial class ModulePage : Page { - public ObservableCollection ListMod = new(); - public ModuleViewModel ViewModel { get; set; } + public ModuleViewModel ViewModel + { + get; set; + } public ModulePage() { ViewModel = App.GetService(); 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 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) { @@ -103,18 +111,22 @@ public sealed partial class ModulePage : Page } private void Button_Delete(object sender, RoutedEventArgs e) { - - - MenuFlyoutItem menuItem = sender as MenuFlyoutItem; + var menuItem = sender as ButtonBase; if (menuItem != null) { - // ȡصļ - var folderItem = menuItem.DataContext as DataObject; // ļΪ FolderItem - if (folderItem != null) + if (menuItem.DataContext is DataObject folderItem) { - // ɾļ߼ - gj.sc("ɾļ"+folderItem.Dri); - Directory.Delete(folderItem.Dri,true); + if (Directory.Exists(folderItem.Dri)) + { + // 删除文件夹 + Directory.Delete(folderItem.Dri, true); + } + else if (File.Exists(folderItem.Dri)) + { + //删除文件 + File.Delete(folderItem.Dri); + } + ViewModel.ListMod.Remove(folderItem); } } @@ -123,16 +135,15 @@ public sealed partial class ModulePage : Page 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.XamlRoot = XamlRoot; + dialog.Title = "提示"; + dialog.PrimaryButtonText = "确定"; + dialog.SecondaryButtonText = "取消"; dialog.Content = CreateCheckboxContent(); var contentDialogResult = await dialog.ShowAsync(); if (contentDialogResult == ContentDialogResult.Primary) { - + var button = sender as Button; if (button != null) { @@ -143,20 +154,18 @@ public sealed partial class ModulePage : Page if (checkbox.IsChecked == true) { File.Delete(dataItem.Dri); - ListMod.Remove(dataItem); + ViewModel.ListMod.Remove(dataItem); } - gj.sc("ȷ"); - // ȡļƣչ var fileNameWithoutExtension = Path.GetFileNameWithoutExtension(dataItem.Dri); var GetDirectoryName = Path.GetDirectoryName(dataItem.Dri); - if (Directory.Exists(GetDirectoryName)&& fileNameWithoutExtension!=null) + 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))); + ViewModel.ListMod.Add(new DataObject(new DirectoryInfo(targetDirectory))); } } } @@ -167,25 +176,24 @@ public sealed partial class ModulePage : Page private FrameworkElement CreateCheckboxContent() { - // CheckBox var checkbox = new CheckBox { - Content = "ɾԴļ", - IsChecked = false, // Ĭδѡ - Margin=new Thickness(0,16,0,0), + Content = "是否删除源文件", + IsChecked = false, + Margin = new Thickness(0, 16, 0, 0), }; var text = new TextBlock { - Text = "ڱνѹѡǷɾԴļ", + Text = "解压模组到目录", }; - // StackPanel Ϊ var stackPanel = new StackPanel(); stackPanel.Children.Add(text); stackPanel.Children.Add(checkbox); return stackPanel; } + } public class MyItemTemplateSelector : DataTemplateSelector { diff --git a/RustTools/Views/SettingsPage.xaml.cs b/RustTools/Views/SettingsPage.xaml.cs index 63493ff..0922d8b 100644 --- a/RustTools/Views/SettingsPage.xaml.cs +++ b/RustTools/Views/SettingsPage.xaml.cs @@ -18,14 +18,15 @@ public sealed partial class SettingsPage : Page { None, } - public SettingsPage() { - //this.windowEx = windowEx; ViewModel = App.GetService(); InitializeComponent(); + Init(); - //BackgroundRadioButtons + } + private async void Init() + { var iniHelper = new IniHelper(); iniHelper.Load(IniHelper.FILE.Config); var v = iniHelper.GetValue(IniHelper.CODE.Settings, IniHelper.KEY.SystemBackdrop); @@ -47,10 +48,10 @@ public sealed partial class SettingsPage : Page } BackgroundRadioButtons.SelectionChanged += BackgroundColor_SelectionChanged; ModFileUrlText.Text = iniHelper.GetValue(IniHelper.CODE.Rust, IniHelper.KEY.ModFileUrl); - MapsFileUrlText.Text = iniHelper.GetValue(IniHelper.CODE.Rust,IniHelper.KEY.MapsFileUrl); + MapsFileUrlText.Text = iniHelper.GetValue(IniHelper.CODE.Rust, IniHelper.KEY.MapsFileUrl); } private bool Backone = false; - private void BackgroundColor_SelectionChanged(object sender, SelectionChangedEventArgs e) + private async void BackgroundColor_SelectionChanged(object sender, SelectionChangedEventArgs e) { if (Backone) { @@ -121,20 +122,20 @@ public sealed partial class SettingsPage : Page } } - private void SaveModAndMaps() + private async void SaveModAndMaps() { var iniHelper = new IniHelper(); - iniHelper.Load(IniHelper.FILE.Config); + iniHelper.Load(IniHelper.FILE.Config); iniHelper.SetValue(IniHelper.CODE.Rust, IniHelper.KEY.MapsFileUrl, MapsFileUrlText.Text); iniHelper.SetValue(IniHelper.CODE.Rust, IniHelper.KEY.ModFileUrl, ModFileUrlText.Text); iniHelper.Save(); } - private void ModFileUrlText_LostFocus(object sender, RoutedEventArgs e) + private async void ModFileUrlText_LostFocus(object sender, RoutedEventArgs e) { var a=(AutoSuggestBox) sender; var iniHelper = new IniHelper(); - iniHelper.Load(IniHelper.FILE.Config); + iniHelper.Load(IniHelper.FILE.Config); if (a.Name.Equals("MapsFileUrlText")) { var Url = MapsFileUrlText.Text; diff --git a/RustTools/Views/UserPage.xaml b/RustTools/Views/UserPage.xaml index dee02d9..47ebbd0 100644 --- a/RustTools/Views/UserPage.xaml +++ b/RustTools/Views/UserPage.xaml @@ -31,12 +31,14 @@ - + Background="BlanchedAlmond" + CornerRadius="16"> + + {1} \nڴʱ벻Ҫرմ˴ ɹԶر ʧʾȨ޵ȴ", - file,ImpUrl); - } - NameText.Text = - fileInfo.Name; - GridView.Loaded += GridView_Loaded; - // Loaded ¼ + iniHelper.Load(IniHelper.FILE.Config); + if (file.EndsWith(".rwmod")) + { + var l = " | "; + var formattedSize = wj.FormatFileSize(fileInfo.Length); + MessageText.Text = ":ģ" + l + "С" + formattedSize; + ImpUrl = iniHelper.GetValue(IniHelper.CODE.Rust, IniHelper.KEY.ModFileUrl); + InfoText.Text = string.Format("ԭλ {0} --> {1} \nڴʱ벻Ҫرմ˴ ɹԶر ʧʾȨ޵ȴ", + file, ImpUrl); + } + NameText.Text = + fileInfo.Name; + + GridView.Loaded += GridView_Loaded; + // Loaded ¼ } private void GridView_Loaded(object sender, RoutedEventArgs e) diff --git a/RustTools/WindowUI/ModuleInfoWin.xaml b/RustTools/WindowUI/ModuleInfoWin.xaml index 9ffe2e6..07d4dc0 100644 --- a/RustTools/WindowUI/ModuleInfoWin.xaml +++ b/RustTools/WindowUI/ModuleInfoWin.xaml @@ -12,50 +12,57 @@ Closed="WindowEx_Closed" SizeChanged="WindowEx_SizeChanged" mc:Ignorable="d"> - + - - - + + + - - + + - + - - + + + Text="加载中"/> + Text="加载中"/> - - + + + TextWrapping="Wrap"/> + Visibility="Collapsed"/> - + @@ -83,19 +91,19 @@ Name="ReportButton" Click="AppBarButton_Click" Icon="ReportHacked" - Label="举报" /> - + Label="举报"/> + - + Label="支持"/> + + Label="下载"/> + Subtitle="消息"/> - - + + diff --git a/RustTools/muqing/IniHelper.cs b/RustTools/muqing/IniHelper.cs index 3cdcdb0..c39a6eb 100644 --- a/RustTools/muqing/IniHelper.cs +++ b/RustTools/muqing/IniHelper.cs @@ -35,7 +35,6 @@ public class IniHelper public IniHelper() { - _sections = new Dictionary>(); /*用法 //IniHelper iniHelper = new IniHelper(); // 设置配置数据 节 key value @@ -62,12 +61,13 @@ public class IniHelper /// public void Load(string a) { - filePath = Path.Combine(wj.CD,a); + + filePath = Path.Combine(ApplicationData.Current.LocalFolder.Path, a); if (!File.Exists(filePath)) - { - File.Create(filePath); + {// 使用 File.Create 创建文件并立即关闭 + using var fs = File.Create(filePath); + // 文件创建成功,但在这里不做任何操作 文件已经关闭 return; - //throw new FileNotFoundException("The specified file does not exist.", filePath); } if (filePath == null || filePath == string.Empty) { @@ -107,8 +107,8 @@ public class IniHelper /// public void Save() { - if (filePath==null) { - throw new FileNotFoundException("不存在或者filePath没有定义"); + if (filePath==null||filePath==string.Empty) { + return; } using var sw = new StreamWriter(filePath); diff --git a/RustTools/muqing/gj.cs b/RustTools/muqing/gj.cs index af3e06b..8109580 100644 --- a/RustTools/muqing/gj.cs +++ b/RustTools/muqing/gj.cs @@ -12,12 +12,16 @@ using Windows.UI.ViewManagement; using System.Runtime.InteropServices; using Windows.UI; -class gj +using System.Text.RegularExpressions; + +#pragma warning disable CS8981 // 该类型名称仅包含小写 ascii 字符。此类名称可能会成为该语言的保留值。 +#pragma warning disable IDE1006 // 命名样式 +public class gj { public static void sc(object? obj) { obj ??= "null"; - Debug.WriteLine(obj); + Debug.WriteLine("Debug:" + obj); } @@ -25,12 +29,10 @@ class gj { try { - using (var searcher = new ManagementObjectSearcher("select UUID from Win32_ComputerSystemProduct")) + using var searcher = new ManagementObjectSearcher("select UUID from Win32_ComputerSystemProduct"); + foreach (var obj in searcher.Get().Cast()) { - foreach (ManagementObject obj in searcher.Get()) - { - return obj["UUID"].ToString(); - } + return obj["UUID"] != null ? (string)obj["UUID"] : ""; } } catch (Exception ex) @@ -38,7 +40,7 @@ class gj Console.WriteLine($"An error occurred while retrieving the UUID: {ex.Message}"); } - return null; + return string.Empty; } @@ -85,7 +87,7 @@ class gj public static void SetBackColor(WindowEx windowEx) { - UISettings uISettings = new UISettings(); + var uISettings = new UISettings(); // 获取当前的背景颜色 var backgroundColor = uISettings.GetColorValue(UIColorType.Background); @@ -178,6 +180,47 @@ class gj [DllImport("user32.dll", CharSet = CharSet.Auto)] private static extern IntPtr SendMessage(IntPtr hWnd, int msg, int wParam, IntPtr lParam); + + + + /// + /// 简单的ini读取器 + /// + /// + /// + /// + public static Dictionary> IniInfo(string filePath) + { + + var sections=new Dictionary>(); + using (var reader = new StreamReader(filePath)) + { + string? line; + string? currentSection = null; + + while ((line = reader.ReadLine()) != null) + { + if (line.StartsWith("[") && line.EndsWith("]")) + { + // New section found + currentSection = line.Trim('[', ']'); + sections[currentSection] = new Dictionary(); + } + else if (!string.IsNullOrWhiteSpace(line) && currentSection != null) + { + // Key-value pair found + var delimiterIndex = line.IndexOf(':'); + if (delimiterIndex > 0) + { + var key = line.Substring(0, delimiterIndex).Trim(); + var value = line.Substring(delimiterIndex + 1).Trim(); + sections[currentSection][key] = value; + } + } + } + } + return sections; + } } public enum BackTheme diff --git a/RustTools/muqing/wj.cs b/RustTools/muqing/wj.cs index 60d8198..23cde15 100644 --- a/RustTools/muqing/wj.cs +++ b/RustTools/muqing/wj.cs @@ -3,17 +3,20 @@ using System.Collections.Generic; using System.Diagnostics; using System.IO.Compression; using Windows.Storage; +using Windows.Storage.Streams; namespace RustTools.muqing; -class wj +#pragma warning disable CS8981 // 该类型名称仅包含小写 ascii 字符。此类名称可能会成为该语言的保留值。 +#pragma warning disable IDE1006 // 命名样式 +public class wj { //存储主要文件的路径 - public static string CD = "C:\\RustTools"; + public static string CD = ""; //缓存路径 public const string Cache = ""; //不知道为什么会保存到这里的路径 废弃了 , 找到了新的文件夹路径 - //public const string CachePath= "C:/Users/账号/AppData/Local/VirtualStore/Windows/SysWOW64"; + //public const string CachePath= "C:/Users/19669/AppData/Local/VirtualStore/Windows/SysWOW64"; /// /// 存储文件名字的路径 @@ -91,4 +94,44 @@ class wj } + /// + /// 压缩zip + /// + /// + /// + public static string ZipExample(string folderPath, string zipFileName) + { + try + { + + zipFileName = Path.Combine(Path.Combine(Path.GetDirectoryName(folderPath), zipFileName)); + // 创建一个新的 Zip 文件 + + using (FileStream fs = File.Create(zipFileName)) + { + using (ZipArchive archive = new ZipArchive(fs, ZipArchiveMode.Create, true)) + { + string[] files = Directory.GetFiles(folderPath, "*", SearchOption.AllDirectories); + + foreach (string file in files) + { + string relativePath = file.Substring(folderPath.Length + 1); + + ZipArchiveEntry entry = archive.CreateEntry(relativePath); + using (FileStream sourceStream = File.OpenRead(file)) + using (Stream entryStream = entry.Open()) + { + sourceStream.CopyTo(entryStream); + } + } + } + } + return zipFileName; + } + catch (Exception ex) + { + return string.Empty; + } + } + } diff --git a/RustTools/muqing/wl.cs b/RustTools/muqing/wl.cs index 16ff0ab..bf0c9c3 100644 --- a/RustTools/muqing/wl.cs +++ b/RustTools/muqing/wl.cs @@ -1,7 +1,9 @@ -using System.Threading; +using System.Text.RegularExpressions; +using System.Threading; using RestSharp; namespace RustTools.muqing; +#pragma warning disable CS8981 // 该类型名称仅包含小写 ascii 字符。此类名称可能会成为该语言的保留值。 class wl { public static string api = "https://rust.coldmint.top"; @@ -102,4 +104,5 @@ class wl //} } } + }