MainWindow.xaml.cs 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Diagnostics;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using System.Windows;
  8. using System.Windows.Controls;
  9. using System.Windows.Data;
  10. using System.Windows.Documents;
  11. using System.Windows.Input;
  12. using System.Windows.Media;
  13. using System.Windows.Media.Imaging;
  14. using System.Windows.Navigation;
  15. using System.IO;
  16. using System.Threading;
  17. using System.Windows.Threading;
  18. namespace WPFTestUpdate
  19. {
  20. /// <summary>
  21. /// MainWindow.xaml 的交互逻辑
  22. /// </summary>
  23. public partial class MainWindow : Window
  24. {
  25. public MainWindow()
  26. {
  27. InitializeComponent();
  28. }
  29. private void ButtonBase_OnClick(object sender, RoutedEventArgs e)
  30. {
  31. string exeBasePath = txtBasePath.Text;
  32. var dirList = new List<string>();
  33. #region 获取需要打包的文件夹列表
  34. string dirstr = txtDirs.Text;
  35. var dirstrs = dirstr.Split(';');
  36. foreach (string s in dirstrs)
  37. {
  38. if (!string.IsNullOrEmpty(s))
  39. {
  40. dirList.Add(Path.Combine(exeBasePath, s));
  41. }
  42. }
  43. if (!dirList.Any())
  44. {
  45. RefrushState("打包文件夹不能为空,请检查");
  46. return;
  47. }
  48. #endregion
  49. Thread thread = new Thread(
  50. () =>
  51. {
  52. RefrushState("准备");
  53. string exePath =Path.Combine(exeBasePath,@"OutputDll\SAGA.MBI.exe");
  54. if (!File.Exists(exePath))
  55. {
  56. RefrushState("可执行的Exe文件不存在,请检查");
  57. return;
  58. }
  59. //string version;
  60. var canUpload = Untility.CheckVision(exePath, out string version);
  61. this.Dispatcher.Invoke(() =>
  62. txtVersion.Text = version
  63. );
  64. if (!canUpload)
  65. {
  66. RefrushState("请检查本地版本号!安装包不需要重新上传。");
  67. return;
  68. }
  69. try
  70. {
  71. string package = $"{Const.Key}";
  72. string compressName =Untility.GetFileVersion(exePath).ToString().ToCompressKey();
  73. RefrushState("正在进行压缩");
  74. string compressPath = @"C:\VersionsTest";
  75. string compressFullPath = Path.Combine(compressPath, compressName);
  76. Untility.CompressDir(compressFullPath, dirList.ToArray(), RefrushState);
  77. RefrushState("删除旧的安装包");
  78. Untility.DeleteCompress();
  79. RefrushState("正在进行上传");
  80. Untility.UploadCompress(compressFullPath,RefrushState);
  81. Untility.SaveVision(package, compressName);
  82. RefrushState("删除压缩");
  83. File.Delete(compressFullPath);
  84. }
  85. catch (Exception exception)
  86. {
  87. MessageBox.Show("上传出错了");
  88. }
  89. RefrushState("上传成功");
  90. //MessageBox.Show("上传成功");
  91. });
  92. thread.Start();
  93. }
  94. private void BtnReset_OnClick(object sender, RoutedEventArgs e)
  95. {
  96. Untility.DeleteCompress();
  97. string package = $"{Const.Key}";
  98. string compressName = textbox.Text.ToCompressKey();
  99. Untility.SaveVision(package, compressName);
  100. MessageBox.Show("设置成功");
  101. }
  102. private void RefrushState(string str)
  103. {
  104. this.Dispatcher.Invoke(() => { txtDiscription.Text = str ; }, DispatcherPriority.Send);
  105. }
  106. }
  107. }