先写到这里吧,更新了模组碎片
This commit is contained in:
parent
2407c99e6d
commit
095bb741f2
|
@ -91,6 +91,9 @@ public partial class App : Microsoft.UI.Xaml.Application
|
|||
services.AddTransient<RankingPage>();
|
||||
services.AddTransient<UserViewModel>();
|
||||
services.AddTransient<UserPage>();
|
||||
//模组碎片
|
||||
services.AddTransient<ModuleViewModel>();
|
||||
services.AddTransient<ModulePage>();
|
||||
|
||||
services.AddTransient<ShellPage>();
|
||||
services.AddTransient<ShellViewModel>();
|
||||
|
|
Binary file not shown.
Before Width: | Height: | Size: 264 KiB After Width: | Height: | Size: 206 KiB |
|
@ -4,15 +4,16 @@ using System.Linq;
|
|||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace RustTools.ViewModels;
|
||||
namespace RustTools.DataList;
|
||||
public class MovingInfo
|
||||
{
|
||||
public class Data
|
||||
{
|
||||
public string name;
|
||||
public Data(string name) {
|
||||
public Data(string name)
|
||||
{
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
|
@ -29,10 +29,6 @@
|
|||
<AppInstallerUri>C:\\RustTools</AppInstallerUri>
|
||||
<AppxPackageDir>D:\RustTools</AppxPackageDir>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Content Remove="Assets\Icon.ico" />
|
||||
<Content Remove="Assets\WindowIcon.ico" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Remove="Assets\image\image_106.svg" />
|
||||
<None Remove="Styles\ItemView.xaml" />
|
||||
|
@ -64,17 +60,11 @@
|
|||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Update="appsettings.json">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="Assets\tool.png">
|
||||
<Pack>True</Pack>
|
||||
<PackagePath>\</PackagePath>
|
||||
</None>
|
||||
<None Update="README.md">
|
||||
<Pack>True</Pack>
|
||||
<PackagePath>\</PackagePath>
|
||||
</None>
|
||||
|
||||
|
||||
<Page Update="Views\ModulePage.xaml">
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
</Page>
|
||||
<Page Update="Styles\TitleSubtitleControlStyle.xaml">
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
</Page>
|
||||
|
@ -87,9 +77,6 @@
|
|||
<Page Update="WindowUI\ImportModule.xaml">
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
</Page>
|
||||
<Page Update="Views\ModulePage.xaml">
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
</Page>
|
||||
<Page Update="Views\ConcernPage.xaml">
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
</Page>
|
||||
|
|
|
@ -20,6 +20,7 @@ public class PageService : IPageService
|
|||
Configure<ConcernViewModel, ConcernPage>();
|
||||
Configure<RankingViewModel, RankingPage>();
|
||||
Configure<UserViewModel, UserPage>();
|
||||
Configure<ModuleViewModel, ModulePage>();
|
||||
|
||||
Configure<SettingsViewModel, SettingsPage>();
|
||||
}
|
||||
|
|
18
RustTools/ViewModels/ModuleViewModel.cs
Normal file
18
RustTools/ViewModels/ModuleViewModel.cs
Normal file
|
@ -0,0 +1,18 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
|
||||
namespace RustTools.ViewModels;
|
||||
/// <summary>
|
||||
/// 模组界面配置
|
||||
/// </summary>
|
||||
public class ModuleViewModel : ObservableRecipient
|
||||
{
|
||||
public ModuleViewModel()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
|
@ -13,10 +13,16 @@ public partial class RankingViewModel : ObservableRecipient
|
|||
{
|
||||
Init();
|
||||
}
|
||||
private async void Init()
|
||||
private void Init()
|
||||
{
|
||||
ListTab("downloadNumber");
|
||||
}
|
||||
|
||||
public async void ListTab(string tab)
|
||||
{
|
||||
RankingList.Clear();
|
||||
//List必须小于10才能重新加载
|
||||
var StringList = await ApiFox.mod.list("downloadNumber", "10", "");
|
||||
var StringList = await ApiFox.mod.list(tab, "10", "");
|
||||
var modData = JsonConvert.DeserializeObject<ModListResponse>(StringList);
|
||||
foreach (var item in modData.Data)
|
||||
{
|
||||
|
@ -24,4 +30,6 @@ public partial class RankingViewModel : ObservableRecipient
|
|||
RankingList.Add(item);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -48,7 +48,7 @@ public sealed partial class HomePage : Page
|
|||
if (e.ClickedItem is not ModListResponse.ModData item) { return; }
|
||||
|
||||
// 查找已存在的 ModulePage,如果存在则激活它
|
||||
var existingWindow = ModulePage.ModulePageList.FirstOrDefault(window => window.Mod.Id == item.Id);
|
||||
var existingWindow = ModuleInfoWin.ModulePageList.FirstOrDefault(window => window.Mod.Id == item.Id);
|
||||
if (existingWindow != null)
|
||||
{
|
||||
// 如果窗口已经存在,则激活它
|
||||
|
@ -57,7 +57,7 @@ public sealed partial class HomePage : Page
|
|||
else
|
||||
{
|
||||
// 如果窗口不存在,则创建新窗口并添加到列表中
|
||||
var newWindow = new ModulePage(item.Id);
|
||||
var newWindow = new ModuleInfoWin(item.Id);
|
||||
//newWindow.Activated += (s, args) =>
|
||||
//{
|
||||
// // 当窗口被激活时,确保它在列表中
|
||||
|
@ -67,7 +67,7 @@ public sealed partial class HomePage : Page
|
|||
// }
|
||||
//};
|
||||
newWindow.Activate();
|
||||
ModulePage.ModulePageList.Add(newWindow);
|
||||
ModuleInfoWin.ModulePageList.Add(newWindow);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
89
RustTools/Views/ModulePage.xaml
Normal file
89
RustTools/Views/ModulePage.xaml
Normal file
|
@ -0,0 +1,89 @@
|
|||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<Page
|
||||
x:Class="RustTools.Views.ModulePage"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:local="using:RustTools.Views"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
mc:Ignorable="d">
|
||||
|
||||
<Page.Resources>
|
||||
<!-- 模组 -->
|
||||
<DataTemplate x:Key="RwmodItem">
|
||||
<Button
|
||||
Background="{ThemeResource SystemColorWindowColor}"
|
||||
Click="Button_Click_RwmodItem"
|
||||
CornerRadius="9">
|
||||
<Grid
|
||||
Width="160"
|
||||
Height="190"
|
||||
Padding="9">
|
||||
<FontIcon Glyph="" />
|
||||
<Button
|
||||
HorizontalAlignment="Right"
|
||||
VerticalAlignment="Top"
|
||||
Background="Transparent"
|
||||
Click="Button_Click">
|
||||
<FontIcon Glyph="" />
|
||||
</Button>
|
||||
<StackPanel HorizontalAlignment="Center" VerticalAlignment="Bottom">
|
||||
<TextBlock Style="{StaticResource BodyTextBlockStyle}" Text="{Binding Name}" />
|
||||
<TextBlock Style="{StaticResource CaptionTextBlockStyle}" Text="{Binding Info}" />
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
</Button>
|
||||
</DataTemplate>
|
||||
<!-- 文件夹 -->
|
||||
<DataTemplate x:Key="FolderItem">
|
||||
<Button Background="{ThemeResource SystemColorWindowColor}" CornerRadius="9">
|
||||
<Button.Flyout>
|
||||
<MenuFlyout>
|
||||
<MenuFlyoutItem Text="打开" />
|
||||
<MenuFlyoutItem Text="打包" />
|
||||
<MenuFlyoutItem Text="发布" />
|
||||
<MenuFlyoutItem Click="Button_Delete" Text="删除" />
|
||||
</MenuFlyout>
|
||||
</Button.Flyout>
|
||||
<Grid
|
||||
Width="160"
|
||||
Height="190"
|
||||
Padding="9">
|
||||
<FontIcon Glyph="" />
|
||||
<StackPanel HorizontalAlignment="Center" VerticalAlignment="Bottom">
|
||||
<TextBlock Style="{StaticResource BodyTextBlockStyle}" Text="{Binding Name}" />
|
||||
<TextBlock Style="{StaticResource CaptionTextBlockStyle}" Text="{Binding Info}" />
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
</Button>
|
||||
</DataTemplate>
|
||||
|
||||
|
||||
<CommandBarFlyout x:Name="CommandBarFlyout1" Placement="Right">
|
||||
<AppBarButton
|
||||
Icon="Share"
|
||||
Label="分享"
|
||||
ToolTipService.ToolTip="分享" />
|
||||
<AppBarButton
|
||||
Icon="Delete"
|
||||
Label="删除"
|
||||
ToolTipService.ToolTip="删除" />
|
||||
<CommandBarFlyout.SecondaryCommands>
|
||||
<AppBarButton Label="重命名" />
|
||||
</CommandBarFlyout.SecondaryCommands>
|
||||
</CommandBarFlyout>
|
||||
</Page.Resources>
|
||||
<Grid Margin="16">
|
||||
<GridView
|
||||
x:Name="BasicGridView"
|
||||
IsItemClickEnabled="False"
|
||||
ItemsSource="{x:Bind ListMod}"
|
||||
SelectionMode="None">
|
||||
<GridView.ItemTemplateSelector>
|
||||
<local:MyItemTemplateSelector Template1="{StaticResource RwmodItem}" Template2="{StaticResource FolderItem}" />
|
||||
</GridView.ItemTemplateSelector>
|
||||
</GridView>
|
||||
<ContentDialog Name="AAAA" Title="aaaa" />
|
||||
</Grid>
|
||||
|
||||
</Page>
|
212
RustTools/Views/ModulePage.xaml.cs
Normal file
212
RustTools/Views/ModulePage.xaml.cs
Normal file
|
@ -0,0 +1,212 @@
|
|||
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Reflection.Metadata.Ecma335;
|
||||
using Microsoft.UI.Xaml;
|
||||
using Microsoft.UI.Xaml.Controls;
|
||||
using Microsoft.UI.Xaml.Controls.Primitives;
|
||||
using Microsoft.UI.Xaml.Media;
|
||||
using RustTools.muqing;
|
||||
using RustTools.ViewModels;
|
||||
namespace RustTools.Views;
|
||||
/// <summary>
|
||||
/// 模组碎片
|
||||
/// </summary>
|
||||
public class DataObject
|
||||
{
|
||||
//路径
|
||||
public string Dri
|
||||
{
|
||||
get; set;
|
||||
}
|
||||
public string Name
|
||||
{
|
||||
get; set;
|
||||
}
|
||||
public string Info
|
||||
{
|
||||
get; set;
|
||||
}
|
||||
public bool IsRwmod
|
||||
{
|
||||
get; set;
|
||||
}
|
||||
public DataObject()
|
||||
{
|
||||
IsRwmod = true;
|
||||
}
|
||||
public DataObject(FileInfo fileInfo)
|
||||
{
|
||||
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}";
|
||||
Dri = fileInfo.FullName;
|
||||
}
|
||||
// ... Methods ...
|
||||
}
|
||||
public sealed partial class ModulePage : Page
|
||||
{
|
||||
public ObservableCollection<DataObject> ListMod = new();
|
||||
public ModuleViewModel ViewModel { get; set; }
|
||||
public ModulePage()
|
||||
{
|
||||
ViewModel = App.GetService<ModuleViewModel>();
|
||||
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 Button_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
var button = sender as Button;
|
||||
if (button != null)
|
||||
{
|
||||
var container = VisualTreeHelper.GetParent(button) as FrameworkElement;
|
||||
if (container != null && container.DataContext is DataObject dataItem)
|
||||
{
|
||||
|
||||
FlyoutShowOptions myOption = new FlyoutShowOptions();
|
||||
myOption.ShowMode = FlyoutShowMode.Standard;
|
||||
CommandBarFlyout1.ShowAt(button, myOption);
|
||||
}
|
||||
}
|
||||
}
|
||||
private void Button_Delete(object sender, RoutedEventArgs e)
|
||||
{
|
||||
|
||||
|
||||
MenuFlyoutItem menuItem = sender as MenuFlyoutItem;
|
||||
if (menuItem != null)
|
||||
{
|
||||
// 获取相关的文件夹项
|
||||
var folderItem = menuItem.DataContext as DataObject; // 假设你的文件夹项类型为 FolderItem
|
||||
if (folderItem != null)
|
||||
{
|
||||
// 这里可以添加删除文件夹逻辑
|
||||
gj.sc("删除文件夹"+folderItem.Dri);
|
||||
Directory.Delete(folderItem.Dri,true);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
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.Content = CreateCheckboxContent();
|
||||
var contentDialogResult = await dialog.ShowAsync();
|
||||
if (contentDialogResult == ContentDialogResult.Primary)
|
||||
{
|
||||
|
||||
var button = sender as Button;
|
||||
if (button != null)
|
||||
{
|
||||
var container = VisualTreeHelper.GetParent(button) as FrameworkElement;
|
||||
if (container != null && container.DataContext is DataObject dataItem)
|
||||
{
|
||||
CheckBox checkbox = (dialog.Content as StackPanel)?.Children[1] as CheckBox;
|
||||
if (checkbox.IsChecked == true)
|
||||
{
|
||||
File.Delete(dataItem.Dri);
|
||||
ListMod.Remove(dataItem);
|
||||
}
|
||||
gj.sc("确定");
|
||||
// 获取文件的名称(不包括扩展名)
|
||||
var fileNameWithoutExtension = Path.GetFileNameWithoutExtension(dataItem.Dri);
|
||||
var GetDirectoryName = Path.GetDirectoryName(dataItem.Dri);
|
||||
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)));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private FrameworkElement CreateCheckboxContent()
|
||||
{
|
||||
// 创建 CheckBox
|
||||
var checkbox = new CheckBox
|
||||
{
|
||||
Content = "删除源文件",
|
||||
IsChecked = false, // 默认未选中
|
||||
Margin=new Thickness(0,16,0,0),
|
||||
|
||||
};
|
||||
var text = new TextBlock
|
||||
{
|
||||
Text = "你可以在本次解压中选择是否删除源文件",
|
||||
};
|
||||
|
||||
// 创建 StackPanel 作为容器
|
||||
var stackPanel = new StackPanel();
|
||||
stackPanel.Children.Add(text);
|
||||
stackPanel.Children.Add(checkbox);
|
||||
return stackPanel;
|
||||
}
|
||||
}
|
||||
public class MyItemTemplateSelector : DataTemplateSelector
|
||||
{
|
||||
public DataTemplate Template1
|
||||
{
|
||||
get; set;
|
||||
} = new();
|
||||
public DataTemplate Template2
|
||||
{
|
||||
get; set;
|
||||
} = new();
|
||||
|
||||
protected override DataTemplate SelectTemplateCore(object item)
|
||||
{
|
||||
if (item is not DataObject dataObject)
|
||||
{
|
||||
return base.SelectTemplateCore(item);
|
||||
}
|
||||
if (dataObject.IsRwmod)
|
||||
return Template1;
|
||||
else
|
||||
return Template2;
|
||||
}
|
||||
}
|
|
@ -27,10 +27,22 @@
|
|||
ToolTipService.ToolTip="Sort">
|
||||
<AppBarButton.Flyout>
|
||||
<MenuFlyout>
|
||||
<MenuFlyoutItem Tag="rating" Text="下载量" />
|
||||
<MenuFlyoutItem Tag="match" Text="投币数" />
|
||||
<MenuFlyoutItem Tag="distance" Text="单位数" />
|
||||
<MenuFlyoutItem Tag="d" Text="更新次数" />
|
||||
<MenuFlyoutItem
|
||||
Click="MenuFlyoutItem_Click"
|
||||
Tag="downloadNumber "
|
||||
Text="下载量" />
|
||||
<MenuFlyoutItem
|
||||
Click="MenuFlyoutItem_Click"
|
||||
Tag="coinNumber"
|
||||
Text="投币数" />
|
||||
<MenuFlyoutItem
|
||||
Click="MenuFlyoutItem_Click"
|
||||
Tag="unitNumber"
|
||||
Text="单位数" />
|
||||
<MenuFlyoutItem
|
||||
Click="MenuFlyoutItem_Click"
|
||||
Tag="updateNumber"
|
||||
Text="更新次数" />
|
||||
</MenuFlyout>
|
||||
</AppBarButton.Flyout>
|
||||
</AppBarButton>
|
||||
|
|
|
@ -44,4 +44,15 @@ public sealed partial class RankingPage : Page
|
|||
{
|
||||
list.Height = ActualHeight - 100;
|
||||
}
|
||||
|
||||
|
||||
private void MenuFlyoutItem_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
var menu = (MenuFlyoutItem)sender;
|
||||
if (menu != null && menu.Tag != null)
|
||||
{
|
||||
var tag =(string) menu.Tag;
|
||||
ViewModel.ListTab(tag);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -48,7 +48,7 @@
|
|||
<NavigationViewItem
|
||||
x:Uid="Concern"
|
||||
helpers:NavigationHelper.NavigateTo="RustTools.ViewModels.ConcernViewModel"
|
||||
Icon="Contact" />
|
||||
Icon="ContactInfo" />
|
||||
<NavigationViewItem
|
||||
x:Uid="Ranking"
|
||||
helpers:NavigationHelper.NavigateTo="RustTools.ViewModels.RankingViewModel"
|
||||
|
@ -57,6 +57,13 @@
|
|||
x:Uid="User"
|
||||
helpers:NavigationHelper.NavigateTo="RustTools.ViewModels.UserViewModel"
|
||||
Icon="Contact2" />
|
||||
<NavigationViewItem x:Uid="Module" helpers:NavigationHelper.NavigateTo="RustTools.ViewModels.ModuleViewModel">
|
||||
|
||||
<NavigationViewItem.Icon>
|
||||
<FontIcon Glyph="" />
|
||||
<!-- 假设这是FolderOpen的Unicode码 -->
|
||||
</NavigationViewItem.Icon>
|
||||
</NavigationViewItem>
|
||||
</NavigationView.MenuItems>
|
||||
<NavigationView.HeaderTemplate>
|
||||
<DataTemplate>
|
||||
|
|
|
@ -26,7 +26,7 @@ public sealed partial class ImportModule : WindowEx
|
|||
if (file.EndsWith(".rwmod"))
|
||||
{
|
||||
var l = " | ";
|
||||
var formattedSize = FormatFileSize(fileInfo.Length);
|
||||
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在处理的时候请不要关闭此窗口 导成功后会自动关闭 失败则会提示权限等错误问题",
|
||||
|
@ -83,17 +83,6 @@ public sealed partial class ImportModule : WindowEx
|
|||
}
|
||||
|
||||
|
||||
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 async void Button_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (fileInfo == null)
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<windowex:WindowEx
|
||||
x:Class="RustTools.WindowUI.ModulePage"
|
||||
x:Class="RustTools.WindowUI.ModuleInfoWin"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
|
@ -108,6 +108,7 @@
|
|||
PlacementMargin="20"
|
||||
PreferredPlacement="Auto"
|
||||
Subtitle="消息" />
|
||||
|
||||
<ContentDialog
|
||||
x:Name="DownloadDialog"
|
||||
Title="下载中"
|
|
@ -20,16 +20,14 @@ namespace RustTools.WindowUI;
|
|||
/// An empty page that can be used on its own or navigated to within a Frame.
|
||||
/// </summary>
|
||||
|
||||
public sealed partial class ModulePage : WindowEx
|
||||
public sealed partial class ModuleInfoWin : WindowEx
|
||||
{
|
||||
public static List<ModulePage> ModulePageList = new();
|
||||
public static List<ModuleInfoWin> ModulePageList = new();
|
||||
public ObservableCollection<string> ScreenshotsList = new();
|
||||
public ModInfo.Data Mod { get; set; } = new();
|
||||
public ModulePage(string v)
|
||||
public ModuleInfoWin(string v)
|
||||
{
|
||||
|
||||
|
||||
// ÉèÖô°¿Ú±³¾°ÑÕÉ«
|
||||
InitializeComponent();
|
||||
ExtendsContentIntoTitleBar = true;
|
||||
gj.SetBackTheme(this);
|
||||
|
@ -40,12 +38,7 @@ public sealed partial class ModulePage : WindowEx
|
|||
gj.UpdateTitleBar(this, frame.ActualTheme);
|
||||
grid.RequestedTheme = frame.ActualTheme;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static bool IsColorLight(Windows.UI.Color clr)
|
||||
{
|
||||
return (((5 * clr.G) + (2 * clr.R) + clr.B) > (8 * 128));
|
||||
// ÉèÖô°¿Ú±³¾°ÑÕÉ«
|
||||
}
|
||||
private async void init(string v)
|
||||
{
|
||||
|
@ -143,7 +136,7 @@ public sealed partial class ModulePage : WindowEx
|
|||
var cancellationTokenSource = new CancellationTokenSource();
|
||||
gj.sc("下载此模组:" + Mod.Link);
|
||||
var downloader = new FileDownloader();
|
||||
|
||||
DownloadDialog.XamlRoot = grid.XamlRoot;
|
||||
var asyncOperation = DownloadDialog.ShowAsync();
|
||||
DownloadDialog.Closing += DownloadDialog_Closing;
|
||||
DownloadDialog.SecondaryButtonClick += (a, b) =>
|
||||
|
@ -154,13 +147,19 @@ public sealed partial class ModulePage : WindowEx
|
|||
};
|
||||
try
|
||||
{
|
||||
var PathMod = Path.Combine(v, Mod.Name);
|
||||
if (File.Exists(PathMod + ".rwmod"))
|
||||
{
|
||||
File.Delete(PathMod + ".rwmod");
|
||||
}
|
||||
//下载链接 保存文件的本地路径
|
||||
await downloader.DownloadFileAsync(Mod.Link, Path.Combine(v, Mod.Name), (totalBytesRead, totalBytes) =>
|
||||
await downloader.DownloadFileAsync(Mod.Link,PathMod, (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("文件下载完成");
|
||||
File.Move(PathMod, PathMod + ".rwmod");
|
||||
DownloadDialog.Closing -= DownloadDialog_Closing;
|
||||
// 手动隐藏对话框
|
||||
DownloadDialog.Hide();
|
|
@ -56,7 +56,7 @@ public class Mod
|
|||
|
||||
Debug.WriteLine("开始执行文件搜索引擎");
|
||||
//先找steam中的位置
|
||||
//steam();
|
||||
steam();
|
||||
if (FileDir == string.Empty) {
|
||||
//找不到执行搜索引擎
|
||||
gj.sc("找不到执行搜索引擎");
|
||||
|
@ -88,6 +88,10 @@ public class Mod
|
|||
//thread.Start();
|
||||
//thread.Join();
|
||||
}
|
||||
else
|
||||
{
|
||||
action?.Invoke(FileDir);
|
||||
}
|
||||
//dialog.Closing -= Dialog_Closing;
|
||||
//if (FileDir != string.Empty) {
|
||||
// dialog.Content = FileDir;
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.IO.Compression;
|
||||
using Windows.Storage;
|
||||
namespace RustTools.muqing;
|
||||
|
||||
|
@ -50,5 +51,44 @@ class wj
|
|||
return File.Exists(Path.Combine(CD,name));
|
||||
}
|
||||
|
||||
public 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"
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 解压缩 ZIP 文件到指定的目录。 其实Rwmod就是zip格式
|
||||
/// </summary>
|
||||
/// <param name="zipFilePath">ZIP 文件的完整路径。</param>
|
||||
/// <param name="targetDirectory">解压缩的目标目录。</param>
|
||||
/// <returns>如果解压成功,则返回 true;否则返回 false。</returns>
|
||||
public static bool UnzipFile(string zipFilePath, string targetDirectory)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
||||
// 确保目标目录存在
|
||||
Directory.CreateDirectory(targetDirectory);
|
||||
|
||||
// 使用 ZipFile.ExtractToDirectory 方法进行解压
|
||||
ZipFile.ExtractToDirectory(zipFilePath, targetDirectory);
|
||||
|
||||
return true; // 解压成功
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Debug.WriteLine($"解压过程中出现错误: {ex.Message}");
|
||||
return false; // 解压失败
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user