MainWindow.xaml.cs 6.1 KB

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