Kaynağa Gözat

添加自动更新

ltwork 1 yıl önce
ebeveyn
işleme
d814c5c256

+ 3 - 0
BlankApp1/BlankApp1/PLCTool.csproj

@@ -5,6 +5,8 @@
     <UseWPF>true</UseWPF>
     <UseWindowsForms>True</UseWindowsForms>
     <ApplicationIcon>bin\Debug\net6.0-windows\Images\TB0228.ico</ApplicationIcon>
+	<AssemblyVersion>2.0.0.1</AssemblyVersion>
+	<FileVersion>2.0.0.1</FileVersion>
   </PropertyGroup>
   <ItemGroup>
     <None Remove="Assets\Fonts\iconfont.ttf" />
@@ -27,6 +29,7 @@
   </ItemGroup>
   <ItemGroup>
     <PackageReference Include="AutoMapper" Version="12.0.1" />
+    <PackageReference Include="Autoupdater.NET.Official" Version="1.8.0" />
     <PackageReference Include="HandyControl" Version="3.4.0" />
     <PackageReference Include="LiveCharts.Wpf" Version="0.9.7" />
     <PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="7.0.0" />

+ 19 - 2
BlankApp1/BlankApp1/ViewModels/MainWindowViewModel.cs

@@ -1,4 +1,5 @@
 using AutoMapper;
+using AutoUpdaterDotNET;
 using BizService;
 using BlankApp1.Common;
 using BlankApp1.Events;
@@ -18,6 +19,7 @@ using System;
 using System.Collections.Generic;
 using System.Collections.ObjectModel;
 using System.IO;
+using System.Reflection;
 using System.Threading.Tasks;
 using System.Windows;
 
@@ -49,13 +51,21 @@ namespace BlankApp1.ViewModels
             BreadChangedCommand = new DelegateCommand<object>(BreadChangedC);
             LoginOutCommand = new DelegateCommand<object>(LoginOut);
             OnLoadCommand = new DelegateCommand(OnLoad);
+            VersisonCommand = new DelegateCommand(UpdateVersion);
             JudgePLC();
             logger.LogInformation("info");
             logger.LogError("error");
 
             aggregator.GetEvent<BreadEvent>().Subscribe(RecvBreadMsg);
             aggregator.GetEvent<MaskEvent>().Subscribe(DisplayMask);
-         
+            //检查更新版本
+            AutoUpdater.Start("http://127.0.0.1/Updates/AutoUpdaterStarter.xml");
+
+        }
+
+        private void UpdateVersion()
+        {
+            AutoUpdater.Start("http://127.0.0.1/Updates/AutoUpdaterStarter.xml");
         }
 
         private void OnLoad()
@@ -163,6 +173,8 @@ namespace BlankApp1.ViewModels
         public DelegateCommand OnLoadCommand { set; get; }
         public DelegateCommand<object> BreadChangedCommand { set; get; }
         public DelegateCommand<object> LoginOutCommand { set; get; }
+
+        public DelegateCommand VersisonCommand { set; get; }
         
 
         #endregion
@@ -203,7 +215,12 @@ namespace BlankApp1.ViewModels
             get { return userName; }
             set { userName = value; RaisePropertyChanged(); }
         }
-        
+        private string? version = Assembly.GetExecutingAssembly()?.GetName()?.Version?.ToString();
+        public string Version
+        {
+            get { return $"版本:V{version}"; }
+            set { version = value; RaisePropertyChanged(); }
+        }
 
         #endregion
     }

+ 2 - 1
BlankApp1/BlankApp1/Views/MainWindow.xaml

@@ -174,7 +174,8 @@
                         </EllipseGeometry>
                     </Path.Data>
                 </Path>
-                <TextBlock Text="V2.1" Style="{StaticResource txtHeadStyle}" Width="60" Margin="30,0,12,0"/>
+                <TextBlock Text="{Binding Version}" Style="{StaticResource txtHeadStyle}" Width="auto" Margin="20,0,5,0"/>
+                <Button Content="版本更新" Width="60" Height="25"    Command="{Binding VersisonCommand}" Style="{StaticResource NormalButtonStyle}" />
             </StackPanel>
 
         </Border>