123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195 |
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.IO;
- using System.Linq;
- using System.Threading;
- using System.Windows;
- using System.Windows.Controls;
- using System.Windows.Threading;
- using SAGA.DotNetUtils.Extend;
- using Update;
- using WPFTestUpdate;
- using WPFTestUpdate.Utils;
- namespace PackageUploader
- {
- /// <summary>
- /// MainWindow.xaml 的交互逻辑
- /// </summary>
- public partial class MainWindow : INotifyPropertyChanged
- {
- public event PropertyChangedEventHandler PropertyChanged;
- public MainWindow()
- {
- InitializeComponent();
- LoadSetting();
- this.DataContext = this;
- }
- #region SavePath LoadPath
- private string m_ExeFullPathKey = nameof(ExeFullPath);
- private string m_BasePathKey = nameof(BasePath);
- private string m_DirNameKey = nameof(Dirs);
- private string m_ExeFullPath;
- public string ExeFullPath
- {
- get { return m_ExeFullPath; }
- set
- {
- m_ExeFullPath = value;
- PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(m_ExeFullPathKey));
- FileStoreHandler.SaveData(m_ExeFullPathKey, value);
- }
- }
- private string m_BasePath;
- public string BasePath
- {
- get { return m_BasePath; }
- set
- {
- m_BasePath = value;
- PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(m_BasePathKey));
- FileStoreHandler.SaveData(m_BasePathKey, value);
- }
- }
- private string m_Dirs;
- public string Dirs
- {
- get { return m_Dirs; }
- set
- {
- m_Dirs = value;
- PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(m_DirNameKey));
- FileStoreHandler.SaveData(m_DirNameKey, value);
- }
- }
- private void LoadSetting()
- {
- string value = FileStoreHandler.GetData(m_ExeFullPathKey);
- if (value.IsNullOrEmpty())
- {
- value = @"D:\Revit\saga\MBI\OutputDll\SAGA.MBI.exe";
- }
- ExeFullPath = value;
- value = FileStoreHandler.GetData(m_BasePathKey);
- if (value.IsNullOrEmpty())
- {
- value = @"D:\Revit\saga\MBI";
- }
- BasePath = value;
- value = FileStoreHandler.GetData(m_DirNameKey);
- if (value.IsNullOrEmpty())
- {
- value = @"MBIResource;Menu;OutputDll;RibbonImage";
- }
- Dirs = value;
- }
- #endregion
- private void ButtonBase_OnClick(object sender, RoutedEventArgs e)
- {
- string exeBasePath = BasePath;
- 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 = ExeFullPath;
- 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";
- if (!Directory.Exists(compressPath))
- Directory.CreateDirectory(compressPath);
- 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);
- }
- }
- }
|