可以下载模组了,修复了一些已知问题
This commit is contained in:
parent
28e6054ed6
commit
2407c99e6d
Binary file not shown.
Before Width: | Height: | Size: 19 KiB |
Binary file not shown.
Before Width: | Height: | Size: 21 KiB |
Binary file not shown.
Before Width: | Height: | Size: 113 KiB |
|
@ -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"));
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
<DefaultLanguage>zh-cn</DefaultLanguage>
|
||||
|
||||
|
||||
<GenerateAppInstallerFile>True</GenerateAppInstallerFile>
|
||||
<GenerateAppInstallerFile>False</GenerateAppInstallerFile>
|
||||
<AppxPackageSigningEnabled>True</AppxPackageSigningEnabled>
|
||||
<PackageCertificateThumbprint>3386EC79D3BB9691D0A8DA634167500B242E109D</PackageCertificateThumbprint>
|
||||
<AppxPackageSigningTimestampDigestAlgorithm>SHA256</AppxPackageSigningTimestampDigestAlgorithm>
|
||||
|
|
|
@ -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"));
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -108,5 +108,14 @@
|
|||
PlacementMargin="20"
|
||||
PreferredPlacement="Auto"
|
||||
Subtitle="消息" />
|
||||
<ContentDialog
|
||||
x:Name="DownloadDialog"
|
||||
Title="下载中"
|
||||
SecondaryButtonText="取消">
|
||||
<StackPanel>
|
||||
<TextBlock Name="DownloadDialogText" Text="下载完成后会自动导入到你配置的模组路径,请勿取消" />
|
||||
<ProgressBar Margin="0,6,0,0" IsIndeterminate="True" />
|
||||
</StackPanel>
|
||||
</ContentDialog>
|
||||
</Grid>
|
||||
</windowex:WindowEx>
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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<string> action;
|
||||
|
||||
private DispatcherQueue _dispatcherQueue;
|
||||
public Mod(XamlRoot xamlRoot, Action<string> 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;
|
||||
|
|
|
@ -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<long, long> 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);
|
||||
//}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user