Skip to content

Commit efb4e11

Browse files
author
panwenbo
committed
One.Toolbox
新增显示当前系统使用的IP; 其他内存问题优化; 移除不必要的组件;
1 parent 451edfe commit efb4e11

File tree

7 files changed

+129
-442
lines changed

7 files changed

+129
-442
lines changed

One.Core/Helpers/NetHelpers/NetHelper.cs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,20 @@ namespace One.Core.Helpers.NetHelpers
1111
public class NetHelper
1212
{
1313
/// <summary> 获取本机所有IPv4地址 </summary>
14-
public static List<IPAddress> GetIPv4AdList()
14+
/// <returns> </returns>
15+
public static List<IPAddress> GetIPv4AddressList()
1516
{
16-
string hostName = Dns.GetHostName();//本机名
17+
string hostName = Dns.GetHostName();
1718
IPAddress[] addressList = Dns.GetHostAddresses(hostName);//会返回所有地址,包括IPv4和IPv6
18-
List<IPAddress> address4List = new List<IPAddress>();
19-
foreach (IPAddress ipa in addressList)
19+
List<IPAddress> ipv4AddressList = new List<IPAddress>();
20+
foreach (IPAddress ipAddress in addressList)
2021
{
21-
if (ipa.AddressFamily == AddressFamily.InterNetwork)
22+
if (ipAddress.AddressFamily == AddressFamily.InterNetwork)
2223
{
23-
//LocalIP = ipa;
24-
//return ipa.ToString();
25-
address4List.Add(ipa);
26-
//return ipa;
24+
ipv4AddressList.Add(ipAddress);
2725
}
2826
}
29-
return address4List;
27+
return ipv4AddressList;
3028
}
3129

3230
/// <summary> 获取本机所有IPv6地址 </summary>
@@ -48,7 +46,7 @@ public static List<IPAddress> GetIPv6AdList()
4846
return address4List;
4947
}
5048

51-
/// <summary> 获取当前使用的IP,Ping baidu </summary>
49+
/// <summary> 通过Ping baidu 获取当前使用的IP </summary>
5250
/// <returns> </returns>
5351
public static string GetLocalIP()
5452
{
@@ -272,6 +270,8 @@ public IPAddress BroadcastPoint
272270
get { return GetBroadcastPoint(); }
273271
}
274272

273+
/// <summary> This function calculates and returns the broadcast point IP address based on the given IP address and IPv4 mask. </summary>
274+
/// <returns> The broadcast point IP address as an instance of IPAddress, or null if either the IP or the IPv4 mask is null. </returns>
275275
private IPAddress GetBroadcastPoint()
276276
{
277277
if (IP != null && IPv4Mask != null)

One.Toolbox/One.Toolbox.csproj

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<Nullable>enable</Nullable>
88
<UseWPF>true</UseWPF>
99
<AllowUnsafeBlocks>True</AllowUnsafeBlocks>
10-
<Version>2.6.5</Version>
10+
<Version>2.6.6</Version>
1111
<ImplicitUsings>enable</ImplicitUsings>
1212
<SatelliteResourceLanguages>zh-Hans;en-us</SatelliteResourceLanguages>
1313
<ApplicationIcon>Icon.ico</ApplicationIcon>
@@ -33,13 +33,11 @@
3333
<PackageReference Include="AvalonEdit" Version="6.3.0.90" />
3434
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.2.1" />
3535
<PackageReference Include="HandyControl" Version="3.4.0" />
36-
<PackageReference Include="LibUsbDotNet" Version="3.0.102-alpha" />
3736
<PackageReference Include="Microsoft.AppCenter.Analytics" Version="5.0.2" />
3837
<PackageReference Include="Microsoft.AppCenter.Crashes" Version="5.0.2" />
3938
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="7.0.0" />
4039
<PackageReference Include="Microsoft.Windows.CsWin32" Version="0.3.49-beta">
4140
<PrivateAssets>all</PrivateAssets>
42-
4341
</PackageReference>
4442
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
4543
<PackageReference Include="NLog" Version="5.2.4" />

One.Toolbox/ViewModels/BingImage/BingImageVM.cs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public override void OnNavigatedEnter()
2525
[ObservableProperty]
2626
private ObservableCollection<UsefullImageInfoVM> obImageListInfo = new ObservableCollection<UsefullImageInfoVM>();
2727

28-
private List<UsefullImageInfoVM> ImageList = new List<UsefullImageInfoVM>();
28+
private List<UsefullImageInfoVM> ImageList = [];
2929
//public ObservableCollection<UsefullImageInfoViewModel> ObImageListInfo { get; set; } = new ObservableCollection<UsefullImageInfoViewModel>();
3030

3131
async void InitData()
@@ -143,7 +143,7 @@ private List<UsefullImageInfoVM> FilterImageInfoAndSave(BingImageOriginalModel b
143143
return listVM;
144144
}
145145

146-
private async Task DownloadImage(UsefullImageInfoVM usefullImageInfos)
146+
private static async Task DownloadImage(UsefullImageInfoVM usefullImageInfos)
147147
{
148148
//查看图片是否已经下载,path为路径
149149
if (File.Exists(usefullImageInfos.LocalImagePath))
@@ -165,14 +165,12 @@ private async Task DownloadImage(UsefullImageInfoVM usefullImageInfos)
165165
{
166166
return;
167167
}
168-
//创造图片
169-
using (FileStream fileStream = new FileStream(usefullImageInfos.LocalImagePath, FileMode.Create))
168+
169+
using (var fileStream = new FileStream(usefullImageInfos.LocalImagePath, FileMode.Create))
170+
using (var binaryWriter = new BinaryWriter(fileStream))
170171
{
171-
BinaryWriter binaryWriter = new BinaryWriter(fileStream);
172-
//写入图片信息
173172
binaryWriter.Write(timeline);
174173
}
175-
176174
return;
177175
}
178176
}

One.Toolbox/ViewModels/Dashboard/DashboardVM.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ void InitData()
2929
Text = a.hitokoto;
3030
Author = "--" + a.from;
3131
});
32+
33+
_ = Task.Run(GetCurrentUseIP);
3234
}
3335

3436
private void Register()
@@ -89,4 +91,16 @@ private static async Task<YiyanAPIM> GetEveryDayYiyan()
8991

9092
return timeline;
9193
}
94+
95+
#region StatusBar
96+
97+
[ObservableProperty]
98+
private string currentUseIP;
99+
100+
private void GetCurrentUseIP()
101+
{
102+
CurrentUseIP = One.Core.Helpers.NetHelpers.NetHelper.GetLocalIP();
103+
}
104+
105+
#endregion StatusBar
92106
}

One.Toolbox/Views/Dashboard/DashboardPage.xaml

Lines changed: 98 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -11,83 +11,103 @@
1111
d:Height="548"
1212
d:Width="733"
1313
mc:Ignorable="d">
14-
<ScrollViewer>
15-
<Grid Margin="20">
16-
<Grid.RowDefinitions>
17-
<RowDefinition Height="Auto" />
18-
<RowDefinition Height="Auto" />
19-
<RowDefinition Height="Auto" />
20-
<RowDefinition Height="Auto" />
21-
<RowDefinition Height="Auto" />
22-
</Grid.RowDefinitions>
23-
24-
<Border Grid.Row="0" Height="150" CornerRadius="8">
25-
<Border.Background>
26-
<ImageBrush ImageSource="pack://application:,,,/Resources/pexels-johannes-plenio-1103970.jpg" RenderOptions.BitmapScalingMode="HighQuality" Stretch="UniformToFill" />
27-
</Border.Background>
28-
<Border CornerRadius="8">
29-
<Border.Background>
30-
<RadialGradientBrush>
31-
<GradientStop Offset="0" Color="#1F000000" />
32-
<GradientStop Offset="1" Color="#4F000000" />
33-
</RadialGradientBrush>
34-
</Border.Background>
35-
<Grid>
36-
<StackPanel Margin="48,0" HorizontalAlignment="Left" VerticalAlignment="Center" Background="Transparent">
37-
<!--<TextBlock FontSize="18" Foreground="#B7FFFFFF" Text="Windows Presentation Foundation" />-->
38-
<TextBlock FontSize="28" FontWeight="Bold" Foreground="#FFFFFF" Text="One.Toolbox" />
39-
<!--<TextBlock FontSize="18" Foreground="#B7FFFFFF" Text="Build Fluent experiences on Windows using WPF UI." />-->
40-
<StackPanel VerticalAlignment="Center" Orientation="Horizontal">
41-
<TextBlock FontSize="14" Foreground="#B7FFFFFF" Text="{Binding Text}" />
42-
<!--<TextBlock VerticalAlignment="Center" FontSize="12" Text=" " />-->
43-
44-
<TextBlock VerticalAlignment="Center" FontSize="12" Foreground="#B7FFFFFF" Text="{Binding Author}" />
45-
</StackPanel>
46-
</StackPanel>
47-
<TextBlock Margin="12" HorizontalAlignment="Right" VerticalAlignment="Bottom" FontSize="10"
48-
Foreground="#57FFFFFF" Text="Created by pwb" />
49-
<Button HorizontalAlignment="Right" VerticalAlignment="Bottom" Background="Transparent" BorderThickness="0"
50-
Command="{Binding TestCommand}"
51-
Visibility="Visible" />
14+
<Grid>
15+
<Grid.RowDefinitions>
16+
<RowDefinition Height="*" />
17+
<RowDefinition Height="Auto" />
18+
19+
</Grid.RowDefinitions>
20+
<Border Style="{StaticResource BorderRegion}">
21+
<ScrollViewer>
22+
<Grid Margin="20">
23+
<Grid.RowDefinitions>
24+
<RowDefinition Height="Auto" />
25+
<RowDefinition Height="Auto" />
26+
<RowDefinition Height="Auto" />
27+
<RowDefinition Height="Auto" />
28+
<RowDefinition Height="Auto" />
29+
30+
</Grid.RowDefinitions>
31+
32+
<Border Grid.Row="0" Height="150" CornerRadius="8">
33+
<Border.Background>
34+
<ImageBrush ImageSource="pack://application:,,,/Resources/pexels-johannes-plenio-1103970.jpg" RenderOptions.BitmapScalingMode="HighQuality" Stretch="UniformToFill" />
35+
</Border.Background>
36+
<Border CornerRadius="8">
37+
<Border.Background>
38+
<RadialGradientBrush>
39+
<GradientStop Offset="0" Color="#1F000000" />
40+
<GradientStop Offset="1" Color="#4F000000" />
41+
</RadialGradientBrush>
42+
</Border.Background>
43+
<Grid>
44+
<StackPanel Margin="48,0" HorizontalAlignment="Left" VerticalAlignment="Center" Background="Transparent">
45+
<!--<TextBlock FontSize="18" Foreground="#B7FFFFFF" Text="Windows Presentation Foundation" />-->
46+
<TextBlock FontSize="28" FontWeight="Bold" Foreground="#FFFFFF" Text="One.Toolbox" />
47+
<!--<TextBlock FontSize="18" Foreground="#B7FFFFFF" Text="Build Fluent experiences on Windows using WPF UI." />-->
48+
<StackPanel VerticalAlignment="Center" Orientation="Horizontal">
49+
<TextBlock FontSize="14" Foreground="#B7FFFFFF" Text="{Binding Text}" />
50+
<!--<TextBlock VerticalAlignment="Center" FontSize="12" Text=" " />-->
51+
52+
<TextBlock VerticalAlignment="Center" FontSize="12" Foreground="#B7FFFFFF" Text="{Binding Author}" />
53+
</StackPanel>
54+
</StackPanel>
55+
<TextBlock Margin="12" HorizontalAlignment="Right" VerticalAlignment="Bottom" FontSize="10"
56+
Foreground="#57FFFFFF" Text="Created by pwb" />
57+
<Button HorizontalAlignment="Right" VerticalAlignment="Bottom" Background="Transparent" BorderThickness="0"
58+
Command="{Binding TestCommand}"
59+
Visibility="Visible" />
60+
</Grid>
61+
</Border>
62+
</Border>
63+
64+
<Grid Grid.Row="1" Margin="0,24,0,0">
65+
<Grid.ColumnDefinitions>
66+
<ColumnDefinition Width="*" />
67+
<ColumnDefinition Width="*" />
68+
<ColumnDefinition Width="*" />
69+
</Grid.ColumnDefinitions>
70+
<Grid.RowDefinitions>
71+
<RowDefinition Height="Auto" />
72+
</Grid.RowDefinitions>
5273
</Grid>
53-
</Border>
54-
</Border>
55-
56-
<Grid Grid.Row="1" Margin="0,24,0,0">
57-
<Grid.ColumnDefinitions>
58-
<ColumnDefinition Width="*" />
59-
<ColumnDefinition Width="*" />
60-
<ColumnDefinition Width="*" />
61-
</Grid.ColumnDefinitions>
62-
<Grid.RowDefinitions>
63-
<RowDefinition Height="Auto" />
64-
</Grid.RowDefinitions>
65-
</Grid>
66-
67-
<StackPanel Grid.Row="2" Margin="0,24,0,0">
68-
69-
<TextBlock FontSize="18" FontWeight="DemiBold" Text="One.Core" />
70-
71-
<uc:Hyperlink Padding="4" Content="Documentation" NavigateUri="https://kleinpan.github.io/One/api/index.html" ToolTip="https://kleinpan.github.io/One/api/index.html" />
72-
<uc:Hyperlink Padding="4" Content="GitHub" NavigateUri="https://github.com/KleinPan/One" ToolTip="https://github.com/KleinPan/One" />
73-
74-
<uc:Hyperlink Padding="4" Content="NuGet" NavigateUri="https://www.nuget.org/packages/One.Core/" ToolTip="https://www.nuget.org/packages/One.Core/" />
75-
</StackPanel>
76-
<StackPanel Grid.Row="3" Margin="0,24,0,0">
77-
<TextBlock FontSize="18" FontWeight="DemiBold" Text="One.Control" />
78-
79-
<uc:Hyperlink Content="Documentation" NavigateUri="https://kleinpan.github.io/One/api/index.html" ToolTip="https://kleinpan.github.io/One/api/index.html" />
80-
81-
<uc:Hyperlink Content="GitHub" NavigateUri="https://github.com/KleinPan/One" ToolTip="https://github.com/KleinPan/One" />
82-
83-
<uc:Hyperlink Content="NuGet" NavigateUri="https://www.nuget.org/packages/One.Control/" ToolTip="https://www.nuget.org/packages/One.Control/" />
84-
</StackPanel>
85-
86-
<StackPanel Grid.Row="4" Margin="0,24,0,0">
87-
<TextBlock FontSize="18" FontWeight="DemiBold" Text="One.Toolbox" />
88-
<uc:Hyperlink Content="Documentation" NavigateUri="https://github.com/KleinPan/One" ToolTip="https://github.com/KleinPan/One" />
89-
<uc:Hyperlink Content="GitHub" NavigateUri="https://github.com/KleinPan/One" ToolTip="https://github.com/KleinPan/One" />
90-
</StackPanel>
91-
</Grid>
92-
</ScrollViewer>
74+
75+
<StackPanel Grid.Row="2" Margin="0,24,0,0">
76+
77+
<TextBlock FontSize="18" FontWeight="DemiBold" Text="One.Core" />
78+
79+
<uc:Hyperlink Padding="4" Content="Documentation" NavigateUri="https://kleinpan.github.io/One/api/index.html" ToolTip="https://kleinpan.github.io/One/api/index.html" />
80+
<uc:Hyperlink Padding="4" Content="GitHub" NavigateUri="https://github.com/KleinPan/One" ToolTip="https://github.com/KleinPan/One" />
81+
82+
<uc:Hyperlink Padding="4" Content="NuGet" NavigateUri="https://www.nuget.org/packages/One.Core/" ToolTip="https://www.nuget.org/packages/One.Core/" />
83+
</StackPanel>
84+
<StackPanel Grid.Row="3" Margin="0,24,0,0">
85+
<TextBlock FontSize="18" FontWeight="DemiBold" Text="One.Control" />
86+
87+
<uc:Hyperlink Content="Documentation" NavigateUri="https://kleinpan.github.io/One/api/index.html" ToolTip="https://kleinpan.github.io/One/api/index.html" />
88+
89+
<uc:Hyperlink Content="GitHub" NavigateUri="https://github.com/KleinPan/One" ToolTip="https://github.com/KleinPan/One" />
90+
91+
<uc:Hyperlink Content="NuGet" NavigateUri="https://www.nuget.org/packages/One.Control/" ToolTip="https://www.nuget.org/packages/One.Control/" />
92+
</StackPanel>
93+
94+
<StackPanel Grid.Row="4" Margin="0,24,0,0">
95+
<TextBlock FontSize="18" FontWeight="DemiBold" Text="One.Toolbox" />
96+
<uc:Hyperlink Content="Documentation" NavigateUri="https://github.com/KleinPan/One" ToolTip="https://github.com/KleinPan/One" />
97+
<uc:Hyperlink Content="GitHub" NavigateUri="https://github.com/KleinPan/One" ToolTip="https://github.com/KleinPan/One" />
98+
</StackPanel>
99+
100+
</Grid>
101+
</ScrollViewer>
102+
</Border>
103+
104+
105+
<StatusBar Grid.Row="1">
106+
<StatusBarItem>
107+
<TextBlock Text="{Binding CurrentUseIP,StringFormat={}LocalIP: {0}}"></TextBlock>
108+
109+
</StatusBarItem>
110+
</StatusBar>
111+
</Grid>
112+
93113
</UserControl>

0 commit comments

Comments
 (0)