WIn_RustTools/RustTools/WindowUI/ImportModule.xaml.cs

73 lines
1.9 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
namespace RustTools.WindowUI;
public sealed partial class ImportModule : WindowEx
{
public ImportModule(string file)
{
InitializeComponent();
ExtendsContentIntoTitleBar = true;
if (file == string.Empty) {
Close();
return;
}
var fileInfo = new FileInfo(file);
var iniHelper = new IniHelper();
iniHelper.Load(IniHelper.FILE.Config);
if (file.EndsWith(".rwmod"))
{
var l = " | ";
var formattedSize = FormatFileSize(fileInfo.Length);
MessageText.Text="类型:模组"+ l+ "大小"+ formattedSize;
var v = iniHelper.GetValue(IniHelper.CODE.Rust, IniHelper.KEY.ModFileUrl);
if (v == string.Empty) {
return;
}
InfoText.Text = string.Format("原位置 {0} --> {1} \n在处理的时候请不要关闭此窗口 导成功后会自动关闭 失败则会提示权限等错误问题",
file,v);
}
NameText.Text =
fileInfo.Name;
}
private async void Dialog()
{
ContentDialog dialog = new ContentDialog
{
Title = "警告",
Content = "这是一个示例内容",
PrimaryButtonText = "确定",
SecondaryButtonText = "取消",
CloseButtonText = "关闭"
};
// 设置 XamlRoot确保对话框显示在正确的窗口中
dialog.XamlRoot = Grid.XamlRoot;
// 显示对话框
await dialog.ShowAsync();
}
private static string FormatFileSize(long bytes)
{
return bytes switch
{
< 1024 => $"{bytes} B",
< 1024 * 1024 => $"{bytes / 1024.0:F2} KB",
< 1024 * 1024 * 1024 => $"{bytes / (1024.0 * 1024.0):F2} MB",
_ => $"{bytes / (1024.0 * 1024.0 * 1024.0):F2} GB"
};
}
private void Button_Click(object sender, RoutedEventArgs e)
{
Dialog();
}
}