2024-08-01 14:28:39 +00:00
|
|
|
|
|
|
|
|
|
|
2024-08-02 03:00:33 +00:00
|
|
|
|
using System.Diagnostics;
|
|
|
|
|
using System.IO;
|
2024-08-01 14:28:39 +00:00
|
|
|
|
using Microsoft.UI.Xaml;
|
|
|
|
|
using Microsoft.UI.Xaml.Controls;
|
2024-08-02 03:00:33 +00:00
|
|
|
|
using RustTools.muqing;
|
2024-08-01 14:28:39 +00:00
|
|
|
|
|
|
|
|
|
namespace RustTools.WindowUI;
|
|
|
|
|
public sealed partial class ImportModule : WindowEx
|
|
|
|
|
{
|
2024-08-02 03:00:33 +00:00
|
|
|
|
private readonly FileInfo? fileInfo;
|
|
|
|
|
private readonly string ImpUrl= string.Empty;
|
2024-08-01 14:28:39 +00:00
|
|
|
|
public ImportModule(string file)
|
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
ExtendsContentIntoTitleBar = true;
|
|
|
|
|
if (file == string.Empty) {
|
|
|
|
|
Close();
|
|
|
|
|
return;
|
|
|
|
|
}
|
2024-08-02 03:00:33 +00:00
|
|
|
|
fileInfo = new FileInfo(file);
|
2024-08-01 14:28:39 +00:00
|
|
|
|
var iniHelper = new IniHelper();
|
|
|
|
|
iniHelper.Load(IniHelper.FILE.Config);
|
2024-08-02 03:00:33 +00:00
|
|
|
|
ImpUrl = string.Empty;
|
2024-08-01 14:28:39 +00:00
|
|
|
|
if (file.EndsWith(".rwmod"))
|
|
|
|
|
{
|
|
|
|
|
var l = " | ";
|
2024-08-07 02:31:13 +00:00
|
|
|
|
var formattedSize = wj.FormatFileSize(fileInfo.Length);
|
2024-08-01 14:28:39 +00:00
|
|
|
|
MessageText.Text="<22><><EFBFBD><EFBFBD>:ģ<><C4A3>"+ l+ "<22><>С"+ formattedSize;
|
2024-08-02 03:00:33 +00:00
|
|
|
|
ImpUrl = iniHelper.GetValue(IniHelper.CODE.Rust, IniHelper.KEY.ModFileUrl);
|
2024-08-01 14:28:39 +00:00
|
|
|
|
InfoText.Text = string.Format("ԭλ<D4AD><CEBB> {0} --> {1} \n<>ڴ<EFBFBD><DAB4><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD>벻Ҫ<EBB2BB>رմ˴<D5B4><CBB4><EFBFBD> <20><><EFBFBD>ɹ<EFBFBD><C9B9><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Զ<EFBFBD><D4B6>ر<EFBFBD> ʧ<><CAA7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʾȨ<CABE>ȴ<DEB5><C8B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>",
|
2024-08-02 03:00:33 +00:00
|
|
|
|
file,ImpUrl);
|
2024-08-01 14:28:39 +00:00
|
|
|
|
}
|
|
|
|
|
NameText.Text =
|
|
|
|
|
fileInfo.Name;
|
2024-08-02 03:00:33 +00:00
|
|
|
|
|
|
|
|
|
GridView.Loaded += GridView_Loaded;
|
|
|
|
|
// <20><><EFBFBD><EFBFBD> Loaded <20>¼<EFBFBD><C2BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
2024-08-01 14:28:39 +00:00
|
|
|
|
}
|
2024-08-02 03:00:33 +00:00
|
|
|
|
|
|
|
|
|
private void GridView_Loaded(object sender, RoutedEventArgs e)
|
2024-08-01 14:28:39 +00:00
|
|
|
|
{
|
2024-08-02 03:00:33 +00:00
|
|
|
|
Init(ImpUrl);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private async void Init(string v)
|
|
|
|
|
{
|
|
|
|
|
if (fileInfo == null)
|
|
|
|
|
{
|
|
|
|
|
await Dialog("û<><C3BB><EFBFBD>㹻<EFBFBD><E3B9BB>Ȩ<EFBFBD><C8A8>");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (v == string.Empty)
|
|
|
|
|
{
|
|
|
|
|
await Dialog("û<>а<EFBFBD><D0B0><EFBFBD>ģ<EFBFBD><C4A3>·<EFBFBD><C2B7>");
|
|
|
|
|
}
|
|
|
|
|
else if (fileInfo.DirectoryName == v)
|
|
|
|
|
{
|
|
|
|
|
await Dialog("ԭ·<D4AD><C2B7><EFBFBD>뵼<EFBFBD><EBB5BC>·<EFBFBD><C2B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB>");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
private async Task Dialog(string content)
|
|
|
|
|
{
|
|
|
|
|
if (GridView.XamlRoot == null)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
var dialog = new ContentDialog
|
2024-08-01 14:28:39 +00:00
|
|
|
|
{
|
|
|
|
|
Title = "<22><><EFBFBD><EFBFBD>",
|
2024-08-02 03:00:33 +00:00
|
|
|
|
Content = content,
|
|
|
|
|
CloseButtonText = "<22>ر<EFBFBD>",
|
|
|
|
|
XamlRoot = GridView.XamlRoot
|
|
|
|
|
};
|
|
|
|
|
dialog.CloseButtonClick += (a, b) =>
|
|
|
|
|
{
|
|
|
|
|
Close();
|
2024-08-01 14:28:39 +00:00
|
|
|
|
};
|
|
|
|
|
// <20><>ʾ<EFBFBD>Ի<EFBFBD><D4BB><EFBFBD>
|
|
|
|
|
await dialog.ShowAsync();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2024-08-02 03:00:33 +00:00
|
|
|
|
private async void Button_Click(object sender, RoutedEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (fileInfo == null)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
var button=sender as Button;
|
|
|
|
|
if (button == null) { return; }
|
|
|
|
|
|
|
|
|
|
button.IsEnabled=false;
|
|
|
|
|
gj.sc(fileInfo.ToString());
|
|
|
|
|
|
|
|
|
|
// ȷ<><C8B7>Ŀ<EFBFBD><C4BF><EFBFBD>ļ<EFBFBD><C4BC>д<EFBFBD><D0B4><EFBFBD>
|
|
|
|
|
Directory.CreateDirectory(ImpUrl);
|
|
|
|
|
|
|
|
|
|
var destinationZipPath = Path.Combine(ImpUrl, fileInfo.Name);
|
|
|
|
|
|
|
|
|
|
await CopyFileWithProgressAsync( fileInfo.ToString() ,destinationZipPath, (percentage) =>
|
|
|
|
|
{
|
|
|
|
|
button.Content = $"{percentage:F2}%";
|
|
|
|
|
Debug.WriteLine($"<22><><EFBFBD>ƽ<EFBFBD><C6BD><EFBFBD>: {percentage:F2}%");
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
button.Content = "<22><><EFBFBD><EFBFBD><EFBFBD>ɹ<EFBFBD>";
|
|
|
|
|
await Task.Delay(1500);
|
|
|
|
|
Close();
|
|
|
|
|
Debug.WriteLine("<22>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɡ<EFBFBD>");
|
|
|
|
|
}
|
|
|
|
|
public static async Task CopyFileWithProgressAsync(string sourcePath, string destinationPath, Action<double> progressCallback)
|
2024-08-01 14:28:39 +00:00
|
|
|
|
{
|
2024-08-02 03:00:33 +00:00
|
|
|
|
const int bufferSize = 81920; // 80KB
|
|
|
|
|
byte[] buffer = new byte[bufferSize];
|
|
|
|
|
|
|
|
|
|
using (FileStream sourceStream = new FileStream(sourcePath, FileMode.Open, FileAccess.Read))
|
|
|
|
|
{
|
|
|
|
|
long totalBytes = sourceStream.Length;
|
|
|
|
|
long totalBytesRead = 0;
|
2024-08-01 14:28:39 +00:00
|
|
|
|
|
2024-08-02 03:00:33 +00:00
|
|
|
|
using (FileStream destinationStream = new FileStream(destinationPath, FileMode.Create, FileAccess.Write))
|
|
|
|
|
{
|
|
|
|
|
int bytesRead;
|
|
|
|
|
while ((bytesRead = await sourceStream.ReadAsync(buffer, 0, buffer.Length)) > 0)
|
|
|
|
|
{
|
|
|
|
|
await destinationStream.WriteAsync(buffer, 0, bytesRead);
|
|
|
|
|
totalBytesRead += bytesRead;
|
|
|
|
|
double percentage = (double)totalBytesRead / totalBytes * 100;
|
|
|
|
|
progressCallback(percentage);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-08-01 14:28:39 +00:00
|
|
|
|
}
|
|
|
|
|
}
|