GUpdate自動升級程序
基于.net framwork4.5.2開發(fā)的一款(c/s應用)自動升級程序。
將更新的核心部分抽離出來方便應用于多種項目當中目前適用于wpf,控制臺應用,winfrom。相比以前更方便的是不需要在過分關注源碼可直接通過nuget直接使用。
快速啟動:
#region Launch1
args = new string[6] {
"0.0.0.0",
"1.1.1.1",
"https://github.com/WELL-E",
"http://192.168.50.225:7000/update.zip",
@"E:\PlatformPath",
"509f0ede227de4a662763a4abe3d8470",
};
GeneralUpdateBootstrap bootstrap = new GeneralUpdateBootstrap();//自動更新引導類
bootstrap.DownloadStatistics += OnDownloadStatistics;//下載進度通知事件
bootstrap.ProgressChanged += OnProgressChanged;//更新進度通知事件
bootstrap.Strategy<DefultStrategy>().//注冊策略,可自定義更新流程
Option(UpdateOption.Format, "zip").//指定更新包的格式,目前只支持zip
Option(UpdateOption.MainApp, "your application name").//指定更新完成后需要啟動的主程序名稱不需要加.exe直接寫名稱即可
RemoteAddress(args).//這里的參數(shù)保留了之前的參數(shù)數(shù)組集合
Launch();//啟動更新
#endregion
#region Launch2
/*
* Launch2
* 新增了第二種啟動方式
* 流程:
* 1.指定更新地址,https://api.com/GeneralUpdate?version=1.0.0.1 在webapi中傳入客戶端當前版本號
* 2.如果需要更新api回返回給你所有的更新信息(詳情內(nèi)容參考 /Models/UpdateInfo.cs)
* 3.拿到更新信息之后則開始http請求更新包
* 4.下載
* 5.解壓
* 6.更新本地文件
* 7.關閉更新程序
* 8.啟動配置好主程序
* 更新程序必須跟主程序放在同級目錄下
*/
//GeneralUpdateBootstrap bootstrap2 = new GeneralUpdateBootstrap();
//bootstrap2.DownloadStatistics += OnDownloadStatistics;
//bootstrap2.ProgressChanged += OnProgressChanged;
//bootstrap2.Strategy<DefultStrategy>().
// Option(UpdateOption.Format, "zip").
// Option(UpdateOption.MainApp, "").
// RemoteAddress(@"https://api.com/GeneralUpdate?version=1.0.0.1").//指定更新地址
// Launch();
#endregion
private static void OnProgressChanged(object sender, ProgressChangedEventArgs e)
{
if (e.Type == ProgressType.Updatefile)
{
var str = $"當前更新第:{e.ProgressValue}個,更新文件總數(shù):{e.TotalSize}";
Console.WriteLine(str);
}
if (e.Type == ProgressType.Done)
{
Console.WriteLine("更新完成");
}
}
private static void OnDownloadStatistics(object sender, DownloadStatisticsEventArgs e)
{
Console.WriteLine($"下載速度:{e.Speed},剩余時間:{e.Remaining.Minute}:{e.Remaining.Second}");
}評論
圖片
表情
