diff --git a/RustTools/Assets/image/a.jpeg b/RustTools/Assets/image/a.jpeg deleted file mode 100644 index 1c9ba48..0000000 Binary files a/RustTools/Assets/image/a.jpeg and /dev/null differ diff --git a/RustTools/Assets/image/b.jpeg b/RustTools/Assets/image/b.jpeg deleted file mode 100644 index e93e055..0000000 Binary files a/RustTools/Assets/image/b.jpeg and /dev/null differ diff --git a/RustTools/Assets/image/c.webp b/RustTools/Assets/image/c.webp deleted file mode 100644 index 14292db..0000000 Binary files a/RustTools/Assets/image/c.webp and /dev/null differ diff --git a/RustTools/MainWindow.xaml.cs b/RustTools/MainWindow.xaml.cs index ea02836..ea31f31 100644 --- a/RustTools/MainWindow.xaml.cs +++ b/RustTools/MainWindow.xaml.cs @@ -15,8 +15,8 @@ public sealed partial class MainWindow : WindowEx public MainWindow() { - gj.SetBackTheme(this); InitializeComponent(); + gj.SetBackTheme(this); //gj.sc("lujing"+ AppContext.BaseDirectory); //Resources AppWindow.SetIcon(Path.Combine(AppContext.BaseDirectory, "Assets/WindowIcon.ico")); diff --git a/RustTools/RustTools.csproj b/RustTools/RustTools.csproj index 06295a2..0aa1868 100644 --- a/RustTools/RustTools.csproj +++ b/RustTools/RustTools.csproj @@ -18,7 +18,7 @@ zh-cn - True + False True 3386EC79D3BB9691D0A8DA634167500B242E109D SHA256 diff --git a/RustTools/ViewModels/ConcernViewModel.cs b/RustTools/ViewModels/ConcernViewModel.cs index 355bc9a..9e00155 100644 --- a/RustTools/ViewModels/ConcernViewModel.cs +++ b/RustTools/ViewModels/ConcernViewModel.cs @@ -81,8 +81,6 @@ public partial class ConcernViewModel : ObservableRecipient //item.UserName item.HeadIcon= item.HeadIcon.Replace("..", wl.api); communitylist.Add(item); - communitylist.Add(item); - communitylist.Add(item); } MovingInfoList.Add(new MovingInfo.Data("123123")); diff --git a/RustTools/Views/SettingsPage.xaml.cs b/RustTools/Views/SettingsPage.xaml.cs index a9e7c62..63493ff 100644 --- a/RustTools/Views/SettingsPage.xaml.cs +++ b/RustTools/Views/SettingsPage.xaml.cs @@ -90,10 +90,16 @@ public sealed partial class SettingsPage : Page } private void Dialog_PrimaryButtonClick(ContentDialog sender, ContentDialogButtonClickEventArgs args){ - var mod = new Mod(); - ModFileUrlText.Text =mod.getUnitsDir(); - MapsFileUrlText.Text =mod.getMaps(); - SaveModAndMaps(); + sender.Hide(); + var mod = new Mod(XamlRoot, (FileDri) => + { + gj.sc("找到了QWQ:::"+FileDri); + var a = Path.Combine(FileDri, "mods\\units"); + ModFileUrlText.Text = a; + var b = Path.Combine(FileDri, "mods\\maps"); + MapsFileUrlText.Text = b; + SaveModAndMaps(); + }); } private async void Dialog_SecondaryButtonClick(ContentDialog sender, ContentDialogButtonClickEventArgs args){ @@ -131,13 +137,45 @@ public sealed partial class SettingsPage : Page iniHelper.Load(IniHelper.FILE.Config); if (a.Name.Equals("MapsFileUrlText")) { - iniHelper.SetValue(IniHelper.CODE.Rust, IniHelper.KEY.MapsFileUrl, MapsFileUrlText.Text); + var Url = MapsFileUrlText.Text; + if (!Directory.Exists(Url)&&Url!=string.Empty) { + Url = iniHelper.GetValue(IniHelper.CODE.Rust, IniHelper.KEY.MapsFileUrl); + MapsFileUrlText.Text= Url; + } + if (Url != string.Empty) + { + Url = Path.GetFullPath(Url); + } + iniHelper.SetValue(IniHelper.CODE.Rust, IniHelper.KEY.MapsFileUrl,Url); + MapsFileUrlText.Text = Url; } else if(a.Name.Equals("ModFileUrlText")) { - iniHelper.SetValue(IniHelper.CODE.Rust, IniHelper.KEY.ModFileUrl, ModFileUrlText.Text); + var Url = ModFileUrlText.Text; + if (!Directory.Exists(Url)&&Url!=string.Empty) + { + Url=iniHelper.GetValue(IniHelper.CODE.Rust, IniHelper.KEY.ModFileUrl); + ModFileUrlText.Text = Url; + } + if (Url != string.Empty) + { + Url = Path.GetFullPath(Url); + } + iniHelper.SetValue(IniHelper.CODE.Rust, IniHelper.KEY.ModFileUrl,Url); + ModFileUrlText.Text = Url; } // 获取 AutoSuggestBox 的当前文本 iniHelper.Save(); } + private async Task ModMapDialog() + { + var dialog = new ContentDialog() + { + XamlRoot = XamlRoot, + Title = "警告", + Content = "不正确的路径无法保存", + SecondaryButtonText = "取消" + }; + await dialog.ShowAsync(); + } } diff --git a/RustTools/WindowUI/ModulePage.xaml b/RustTools/WindowUI/ModulePage.xaml index f3005df..abffb17 100644 --- a/RustTools/WindowUI/ModulePage.xaml +++ b/RustTools/WindowUI/ModulePage.xaml @@ -108,5 +108,14 @@ PlacementMargin="20" PreferredPlacement="Auto" Subtitle="消息" /> + + + + + + diff --git a/RustTools/WindowUI/ModulePage.xaml.cs b/RustTools/WindowUI/ModulePage.xaml.cs index 508debc..fdb5a65 100644 --- a/RustTools/WindowUI/ModulePage.xaml.cs +++ b/RustTools/WindowUI/ModulePage.xaml.cs @@ -9,6 +9,8 @@ using System.Diagnostics; using Windows.UI.ViewManagement; using Microsoft.UI.Xaml.Media; using Microsoft.UI; +using static RustTools.muqing.wl; +using System.Threading; // To learn more about WinUI, the WinUI project structure, // and more about our project templates, see: http://aka.ms/winui-project-info. @@ -36,7 +38,7 @@ public sealed partial class ModulePage : WindowEx if (frame != null) { gj.UpdateTitleBar(this, frame.ActualTheme); - grid.RequestedTheme = frame.ActualTheme; + grid.RequestedTheme = frame.ActualTheme; } } @@ -98,7 +100,7 @@ public sealed partial class ModulePage : WindowEx ModulePageList.Remove(this); } - private void AppBarButton_Click(object sender, RoutedEventArgs e) + private async void AppBarButton_Click(object sender, RoutedEventArgs e) { var label = ((AppBarButton)sender).Name; gj.sc(label); @@ -121,7 +123,58 @@ public sealed partial class ModulePage : WindowEx break; case "DownLoadButton": + var iniHelper = new IniHelper(); + iniHelper.Load(IniHelper.FILE.Config); + var v = iniHelper.GetValue(IniHelper.CODE.Rust, IniHelper.KEY.ModFileUrl); + if (v == string.Empty) + { + var dialog=new ContentDialog() + { + XamlRoot = grid.XamlRoot, + Title="", + Content="úģ·", + SecondaryButtonText="ȡ" + + }; + await dialog.ShowAsync(); + return; + } + + var cancellationTokenSource = new CancellationTokenSource(); gj.sc("شģ:" + Mod.Link); + var downloader = new FileDownloader(); + + var asyncOperation = DownloadDialog.ShowAsync(); + DownloadDialog.Closing += DownloadDialog_Closing; + DownloadDialog.SecondaryButtonClick += (a, b) => + { + gj.sc("ɾ"); + cancellationTokenSource.Cancel(); + downloader.Delete(); + }; + try + { + // ļı· + await downloader.DownloadFileAsync(Mod.Link, Path.Combine(v, Mod.Name), (totalBytesRead, totalBytes) => + { + DownloadDialogText.Text = $"Downloaded {totalBytesRead} of {totalBytes} bytes. {(totalBytes > 0 ? (double)totalBytesRead / totalBytes * 100 : 0):0.00}% complete."; + //Debug.WriteLine($"Downloaded {totalBytesRead} of {totalBytes} bytes. {(totalBytes > 0 ? (double)totalBytesRead / totalBytes * 100 : 0):0.00}% complete."); + }, cancellationTokenSource.Token); + Debug.WriteLine("ļ"); + DownloadDialog.Closing -= DownloadDialog_Closing; + // ֶضԻ + DownloadDialog.Hide(); + + } + catch (Exception ex) + { + Debug.WriteLine($"Error downloading file: {ex.Message}"); + } + finally + { + DownloadDialog.Closing -= DownloadDialog_Closing; + DownloadDialog.Hide(); + } break; } } @@ -130,4 +183,15 @@ public sealed partial class ModulePage : WindowEx { } + + private void DownloadDialog_Closing(ContentDialog sender, ContentDialogClosingEventArgs args) + { + + // Prevent the dialog from closing + if (args.Result != ContentDialogResult.Secondary) + { + args.Cancel = true; + } + } + } diff --git a/RustTools/muqing/mod.cs b/RustTools/muqing/mod.cs index be39a12..3be50a9 100644 --- a/RustTools/muqing/mod.cs +++ b/RustTools/muqing/mod.cs @@ -1,7 +1,16 @@ +using System.Diagnostics; +using System.Reflection.Emit; +using Microsoft.UI.Xaml; +using Microsoft.UI.Xaml.Controls; +using Microsoft.UI.Xaml.Media; using Microsoft.Win32; - +using Newtonsoft.Json.Linq; +using RustTools.muqing; +using Windows.ApplicationModel.Core; +using Windows.UI.Core; +using Microsoft.UI.Dispatching; public class Mod { @@ -23,15 +32,81 @@ public class Mod "Windows", "Windows 10", "Steam", "Genshin Impact Game", "Godot", "Gradle", "WeGame", "Mental Omega", "WeGameApps", - "ramboplayGame", "QQ", "QQWORD" + "ramboplayGame", "QQ", "QQWORD","Microsoft SDKs","Creator","editors","AndroidSDK","SDK","Pr","PR","PS","Ps","WE", + "androidstudioword","ͼսƽ̨","xshell7" }; //Ϸλ - public string FileDir = ""; - public Mod() + public string FileDir =string.Empty; + private readonly ContentDialog? dialog =null; + //MainPageĺ̨code + public async void Invoke(Action action, Windows.UI.Core.CoreDispatcherPriority Priority = Windows.UI.Core.CoreDispatcherPriority.Normal) { + await Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(Priority, () => { action(); }); + } + XamlRoot xamlRoot; + Action action; + + private DispatcherQueue _dispatcherQueue; + public Mod(XamlRoot xamlRoot, Action action) + { + _dispatcherQueue = DispatcherQueue.GetForCurrentThread(); + this.xamlRoot = xamlRoot; + this.action = action; StartTime = DateTime.Now; - Console.WriteLine("ʼִļ"); + + Debug.WriteLine("ʼִļ"); //steamеλ + //steam(); + if (FileDir == string.Empty) { + //Ҳִ + gj.sc("Ҳִ"); + dialog = new ContentDialog() + { + XamlRoot = xamlRoot, + Title = "ʾ", + Content = "", + PrimaryButtonText = "ر" + }; + dialog.Closing += Dialog_Closing; + + dialog.ShowAsync(); + Task.Run(async () => + { + await init(); + // ʹ DispatcherQueue UI ίл UI ߳ + + _dispatcherQueue.TryEnqueue(() => { + dialog.Closing -= Dialog_Closing; + dialog.Hide(); + action?.Invoke(FileDir); + }); + }); + //if (IsSearch) + //{ + //} + //var thread = new Thread(init); + //thread.Start(); + //thread.Join(); + } + //dialog.Closing -= Dialog_Closing; + //if (FileDir != string.Empty) { + // dialog.Content = FileDir; + //} + //dialog.Hide(); + } + + + private void Dialog_Closing(ContentDialog sender, ContentDialogClosingEventArgs args){ + gj.sc(args.Result); + if (args.Result != ContentDialogResult.Primary) + { + IsSearch = false; + args.Cancel = true; + } + } + + private void steam() + { var steamPath = GetSteamInstallPath(); if (!string.IsNullOrEmpty(steamPath)) { @@ -41,59 +116,25 @@ public class Mod { //ʱ Console.WriteLine("ҵϷļ· " + steamPath + "\\steamapps\\common\\Rusted Warfare"); - FileDir = steamPath+ "\\steamapps\\common\\Rusted Warfare"; + FileDir = steamPath + "\\steamapps\\common\\Rusted Warfare"; EndTime(); } else { Console.WriteLine("δҵϷļ·"); - init(); } } else { Console.WriteLine("Ҳsteamİװλ"); - init(); } } - public string getUnitsDir() - { - if (FileDir==string.Empty) { - return string.Empty; - } - else - { - var v = Path.Combine(FileDir, "mods\\units"); - if (Directory.Exists(v)) - { - Directory.CreateDirectory(v); - } - return v; - } - } - public string getMaps() - { - if (FileDir == string.Empty) - { - return string.Empty; - } - else - { - var v = Path.Combine(FileDir, "mods\\maps"); - if (!Directory.Exists(v)) - { - Directory.CreateDirectory(v); - } - return v; - } - } - private void init() + private async Task init() { - - DriveInfo[] allDrives = DriveInfo.GetDrives(); - foreach (DriveInfo d in allDrives) + var allDrives = DriveInfo.GetDrives(); + foreach (var d in allDrives) { Console.WriteLine(); // Console.WriteLine(" Drive type: {0}", d.DriveType); @@ -107,17 +148,17 @@ public class Mod //ֻҪC if (name.Equals("C:\\")) { - Console.WriteLine("C̿Ϸļ·"); - FileSearch(name); + Debug.WriteLine("C̿Ϸļ·"); + //FileSearch(name); } else { - Console.WriteLine("пϷļ·"); + Debug.WriteLine("пϷļ·"); // steam\steamapps\common\Rusted Warfare // new FileSearch(name).Search(); if (Directory.Exists(name + "/Rusted Warfare")) { - Console.WriteLine("ҵϷļ·"); + Debug.WriteLine("ҵϷļ·"); EndTime(); break; } @@ -128,25 +169,20 @@ public class Mod } } - Console.WriteLine(); } } - //ǷҵϷλ - bool IsFind = false; + //Ƿ + public bool IsSearch = true; private void FileSearch(string path) { - if (IsFind) - { - return; - } - Console.WriteLine("ʼļ" + path); + Debug.WriteLine("ʼļ" + path); try { // ļ foreach (var file in Directory.EnumerateDirectories(path)) { - if (IsFind) + if (!IsSearch) { return; } @@ -160,19 +196,19 @@ public class Mod var name = Path.GetFileName(file); if (Isdot && name.StartsWith(".")) { - Console.WriteLine("ųͷļ" + file); + Debug.WriteLine("ųͷļ" + file); continue; } //ųбеļ if (ExcludeFile.Contains(name)) { - Console.WriteLine("ųбеļ" + file); + Debug.WriteLine("ųбеļ" + file); continue; } if (name.Equals("Rusted Warfare")) { - IsFind = true; - Console.WriteLine("ҵϷļ·" + file); + Debug.WriteLine("ҵϷļ·" + file); + FileDir = file; EndTime(); break; } @@ -198,7 +234,7 @@ public class Mod private static string GetSteamInstallPath() { - string installPath = GetInstallPathFromKey(@"Software\Valve\Steam"); + var installPath = GetInstallPathFromKey(@"Software\Valve\Steam"); if (string.IsNullOrEmpty(installPath)) { @@ -226,7 +262,7 @@ public class Mod { if (key != null) { - object path = key.GetValue("InstallPath"); + var path = key.GetValue("InstallPath"); if (path != null) { return (string)path; diff --git a/RustTools/muqing/wl.cs b/RustTools/muqing/wl.cs index f2bb281..16ff0ab 100644 --- a/RustTools/muqing/wl.cs +++ b/RustTools/muqing/wl.cs @@ -1,4 +1,5 @@ -using RestSharp; +using System.Threading; +using RestSharp; namespace RustTools.muqing; class wl @@ -55,4 +56,50 @@ class wl } return null; } + + + + public class FileDownloader + { + private readonly HttpClient _httpClient=new(); + private bool IsDelete = false; + public FileDownloader() + { + } + public void Delete() + { + IsDelete = true; + } + public async Task DownloadFileAsync(string fileUrl, string savePath, Action progress, CancellationToken cancellationToken) + { + using (var response = await _httpClient.GetAsync(fileUrl, HttpCompletionOption.ResponseHeadersRead)) + { + response.EnsureSuccessStatusCode(); + + var totalBytes = response.Content.Headers.ContentLength ?? -1L; + var totalBytesRead = 0L; + var buffer = new byte[8192]; + int bytesRead; + + using (var contentStream = await response.Content.ReadAsStreamAsync()) + using (var fileStream = new FileStream(savePath, FileMode.Create, FileAccess.Write, FileShare.None)) + { + while ((bytesRead = await contentStream.ReadAsync(buffer, 0, buffer.Length, cancellationToken)) > 0) + { + //if (IsDelete) { + // break; + //} + await fileStream.WriteAsync(buffer, 0, bytesRead,cancellationToken); + totalBytesRead += bytesRead; + progress?.Invoke(totalBytesRead, totalBytes); + } + } + + } + //if (IsDelete) + //{ + // File.Delete(savePath); + //} + } + } }