123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117 |
- using System;
- using System.Collections.Generic;
- using System.Diagnostics;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows;
- using System.Windows.Controls;
- using System.Windows.Data;
- using System.Windows.Documents;
- using System.Windows.Input;
- using System.Windows.Media;
- using System.Windows.Media.Imaging;
- using System.Windows.Navigation;
- using System.IO;
- using System.Threading;
- using System.Windows.Threading;
- namespace WPFTestUpdate
- {
- /// <summary>
- /// MainWindow.xaml 的交互逻辑
- /// </summary>
- public partial class MainWindow : Window
- {
- public MainWindow()
- {
- InitializeComponent();
- }
- private void ButtonBase_OnClick(object sender, RoutedEventArgs e)
- {
- string exeBasePath = txtBasePath.Text;
- var dirList = new List<string>();
- #region 获取需要打包的文件夹列表
- string dirstr = txtDirs.Text;
- var dirstrs = dirstr.Split(';');
- foreach (string s in dirstrs)
- {
- if (!string.IsNullOrEmpty(s))
- {
- dirList.Add(Path.Combine(exeBasePath, s));
- }
- }
- if (!dirList.Any())
- {
- RefrushState("打包文件夹不能为空,请检查");
- return;
- }
- #endregion
- Thread thread = new Thread(
- () =>
- {
- RefrushState("准备");
- string exePath =Path.Combine(exeBasePath,@"OutputDll\SAGA.MBI.exe");
- if (!File.Exists(exePath))
- {
- RefrushState("可执行的Exe文件不存在,请检查");
- return;
- }
- //string version;
- var canUpload = Untility.CheckVision(exePath, out string version);
- this.Dispatcher.Invoke(() =>
- txtVersion.Text = version
- );
- if (!canUpload)
- {
- RefrushState("请检查本地版本号!安装包不需要重新上传。");
- return;
- }
- try
- {
- string package = $"{Const.Key}";
- string compressName =Untility.GetFileVersion(exePath).ToString().ToCompressKey();
- RefrushState("正在进行压缩");
- string compressPath = @"C:\VersionsTest";
- string compressFullPath = Path.Combine(compressPath, compressName);
-
- Untility.CompressDir(compressFullPath, dirList.ToArray(), RefrushState);
- RefrushState("删除旧的安装包");
- Untility.DeleteCompress();
- RefrushState("正在进行上传");
- Untility.UploadCompress(compressFullPath,RefrushState);
- Untility.SaveVision(package, compressName);
- RefrushState("删除压缩");
- File.Delete(compressFullPath);
- }
- catch (Exception exception)
- {
- MessageBox.Show("上传出错了");
- }
- RefrushState("上传成功");
- //MessageBox.Show("上传成功");
- });
- thread.Start();
- }
- private void BtnReset_OnClick(object sender, RoutedEventArgs e)
- {
- Untility.DeleteCompress();
- string package = $"{Const.Key}";
- string compressName = textbox.Text.ToCompressKey();
- Untility.SaveVision(package, compressName);
- MessageBox.Show("设置成功");
- }
- private void RefrushState(string str)
- {
- this.Dispatcher.Invoke(() => { txtDiscription.Text = str ; }, DispatcherPriority.Send);
- }
- }
- }
|