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
{
///
/// MainWindow.xaml 的交互逻辑
///
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();
#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);
}
}
}