MainWindow.xaml.cs 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. using SAGA.DotNetUtils.Extend;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.ComponentModel;
  5. using System.IO;
  6. using System.Linq;
  7. using System.Threading;
  8. using System.Windows;
  9. using System.Windows.Controls;
  10. using System.Windows.Threading;
  11. using WPFTestUpdate.Utils;
  12. namespace WPFTestUpdate
  13. {
  14. /// <summary>
  15. /// MainWindow.xaml 的交互逻辑
  16. /// </summary>
  17. public partial class MainWindow : INotifyPropertyChanged
  18. {
  19. public event PropertyChangedEventHandler PropertyChanged;
  20. public MainWindow()
  21. {
  22. InitializeComponent();
  23. LoadSetting();
  24. this.DataContext = this;
  25. }
  26. #region SavePath LoadPath
  27. private string m_BasePath;
  28. public string BasePath
  29. {
  30. get { return m_BasePath; }
  31. set
  32. {
  33. m_BasePath = value;
  34. PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(m_BasePathKey));
  35. FileStoreHandler.SaveData(m_BasePathKey, value);
  36. }
  37. }
  38. private string m_Dirs;
  39. public string Dirs
  40. {
  41. get { return m_Dirs; }
  42. set
  43. {
  44. m_Dirs = value;
  45. PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(m_DirNameKey));
  46. FileStoreHandler.SaveData(m_DirNameKey, value);
  47. }
  48. }
  49. private void SaveBasePath(Control uc, string path)
  50. {
  51. }
  52. private string m_BasePathKey = nameof(BasePath);
  53. private string m_DirNameKey = nameof(Dirs);
  54. private void LoadSetting()
  55. {
  56. string value = FileStoreHandler.GetData(m_BasePathKey);
  57. if (value.IsNullOrEmpty())
  58. {
  59. value = @"D:\Revit\saga\MBI";
  60. }
  61. BasePath = value;
  62. value = FileStoreHandler.GetData(m_DirNameKey);
  63. if (value.IsNullOrEmpty())
  64. {
  65. value = @"MBIResource;Menu;OutputDll;RibbonImage";
  66. }
  67. Dirs = value;
  68. }
  69. #endregion
  70. private void ButtonBase_OnClick(object sender, RoutedEventArgs e)
  71. {
  72. string exeBasePath = txtBasePath.Text;
  73. var dirList = new List<string>();
  74. #region 获取需要打包的文件夹列表
  75. string dirstr = txtDirs.Text;
  76. var dirstrs = dirstr.Split(';');
  77. foreach (string s in dirstrs)
  78. {
  79. if (!string.IsNullOrEmpty(s))
  80. {
  81. dirList.Add(Path.Combine(exeBasePath, s));
  82. }
  83. }
  84. if (!dirList.Any())
  85. {
  86. RefrushState("打包文件夹不能为空,请检查");
  87. return;
  88. }
  89. #endregion
  90. Thread thread = new Thread(
  91. () =>
  92. {
  93. RefrushState("准备");
  94. string exePath = Path.Combine(exeBasePath, @"OutputDll\SAGA.MBI.exe");
  95. if (!File.Exists(exePath))
  96. {
  97. RefrushState("可执行的Exe文件不存在,请检查");
  98. return;
  99. }
  100. //string version;
  101. var canUpload = Untility.CheckVision(exePath, out string version);
  102. this.Dispatcher.Invoke(() =>
  103. txtVersion.Text = version
  104. );
  105. if (!canUpload)
  106. {
  107. RefrushState("请检查本地版本号!安装包不需要重新上传。");
  108. return;
  109. }
  110. try
  111. {
  112. string package = $"{Const.Key}";
  113. string compressName = Untility.GetFileVersion(exePath).ToString().ToCompressKey();
  114. RefrushState("正在进行压缩");
  115. string compressPath = @"C:\VersionsTest";
  116. string compressFullPath = Path.Combine(compressPath, compressName);
  117. Untility.CompressDir(compressFullPath, dirList.ToArray(), RefrushState);
  118. RefrushState("删除旧的安装包");
  119. Untility.DeleteCompress();
  120. RefrushState("正在进行上传");
  121. Untility.UploadCompress(compressFullPath, RefrushState);
  122. Untility.SaveVision(package, compressName);
  123. RefrushState("删除压缩");
  124. File.Delete(compressFullPath);
  125. }
  126. catch (Exception exception)
  127. {
  128. MessageBox.Show("上传出错了");
  129. }
  130. RefrushState("上传成功");
  131. //MessageBox.Show("上传成功");
  132. });
  133. thread.Start();
  134. }
  135. private void BtnReset_OnClick(object sender, RoutedEventArgs e)
  136. {
  137. Untility.DeleteCompress();
  138. string package = $"{Const.Key}";
  139. string compressName = textbox.Text.ToCompressKey();
  140. Untility.SaveVision(package, compressName);
  141. MessageBox.Show("设置成功");
  142. }
  143. private void RefrushState(string str)
  144. {
  145. this.Dispatcher.Invoke(() => { txtDiscription.Text = str; }, DispatcherPriority.Send);
  146. }
  147. }
  148. }