1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374 |
- using System;
- using System.IO;
- using System.Windows;
- using System.Windows.Controls;
- namespace AIPractice.LabellerServer.WPF
- {
- /// <summary>
- /// Interaction logic for UpgradeView.xaml
- /// </summary>
- public partial class UpgradeView : UserControl
- {
- public UpgradeView()
- {
- InitializeComponent();
- LoadUpgradeFile();
- }
- private void OnSelectFileClick(object sender, RoutedEventArgs e)
- {
- Microsoft.Win32.OpenFileDialog ofd = new Microsoft.Win32.OpenFileDialog();
- ofd.Filter = "*.exe|*.exe";
- if(ofd.ShowDialog() == true)
- {
- ClientFile.Text = ofd.FileName;
- }
- }
- private void OnImportClick(object sender, RoutedEventArgs e)
- {
- if(string.IsNullOrEmpty(ClientFile.Text) || !File.Exists(ClientFile.Text))
- {
- MessageBox.Show("请选择客户端安装文件。", "错误", MessageBoxButton.OK, MessageBoxImage.Error);
- return;
- }
- if(string.IsNullOrEmpty(VersionInfo.Text) || !Version.TryParse(VersionInfo.Text, out _))
- {
- MessageBox.Show("请输入合法的版本号。", "错误", MessageBoxButton.OK, MessageBoxImage.Error);
- return;
- }
- var version = VersionInfo.Text;
- var upgradeFolder = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Upgrade");
- if (!Directory.Exists(upgradeFolder))
- {
- Directory.CreateDirectory(upgradeFolder);
- }
- var upgradeFile = Path.Combine(upgradeFolder, "Setup.exe");
- var upgradeVersionFile = Path.Combine(upgradeFolder, "Version.txt");
- File.Copy(ClientFile.Text, upgradeFile,true);
- File.WriteAllText(upgradeVersionFile,version);
- LabellerService.SetCurrentClient(version, File.ReadAllBytes(upgradeFile));
- UpgradeInfo.Content = $"当前更新包版本: {version}";
- LogManager.WriteLog($"更新包{ClientFile.Text}, 版本:{VersionInfo.Text} 已导入");
- }
- private void LoadUpgradeFile()
- {
- var upgradeFolder = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Upgrade");
- if (Directory.Exists(upgradeFolder))
- {
- var upgradeFile = Path.Combine(upgradeFolder, "Setup.exe");
- var upgradeVersionFile = Path.Combine(upgradeFolder, "Version.txt");
- if (File.Exists(upgradeFile) && File.Exists(upgradeVersionFile))
- {
- var version = File.ReadAllText(upgradeVersionFile);
- LabellerService.SetCurrentClient(version, File.ReadAllBytes(upgradeFile));
- UpgradeInfo.Content = $"当前更新包版本: {version}";
- }
- }
- }
- }
- }
|