MainWindow.xaml.cs 5.4 KB

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