什麼是GeneralUpdate:
GeneralUpdate是基于.net framwork4.5.2開發的一款(c/s應用)自動更新程式。
第一個版本叫Autoupdate(原部落格: WPF自動更新程式)有人會奇怪為什麼會改名稱,稍微解釋一下是因為在nuget上有重名的項目再者就是新版本更新功能不僅限于wpf程式的更新。
将更新的核心部分抽離出來友善應用于多種項目當中目前适用于wpf,控制台應用,winfrom。相比以前更友善的是不需要在過分關注源碼可直接通過nuget直接使用。
如果有任何使用問題可以在Github的issues上進行提問我會每周統一找時間解決并解答bug或者問題。或者聯系文章末尾的聯系方式會有人解答。
如何使用:
Gitee(碼雲)位址:https://gitee.com/Juster-zhu/GeneralUpdate
Nuget位址:https://www.nuget.org/packages/GeneralUpdate.Core/
GitHub位址: https://github.com/WELL-E/AutoUpdater GeneralUpdate版本在 Branch:Autoupdate2。
issues:https://github.com/WELL-E/AutoUpdater/issues

運作截圖:
快速啟動:
#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).//這裡的參數保留了之前的參數數組集合
Launch();//啟動更新
#endregion
#region Launch2
/*
* Launch2
* 新增了第二種啟動方式
* 流程:
* 1.指定更新位址,https://api.com/GeneralUpdate?version=1.0.0.1 在webapi中傳入用戶端目前版本号
* 2.如果需要更新api回傳回給你所有的更新資訊(詳情内容參考 /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}個,更新檔案總數:{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}");
}
關于調試:
調試本程式如果沒有服務端支援可用hfs這款軟體,作為臨時伺服器進行調試使用方式非常簡單下載下傳好了之後界面如下
開發作者: JusterZhu & WELL-E
聯系我們:
QQ群:
- WELL-E
- 1群 130108655
- 2群 960655709
- Git: https://github.com/WELL-E
- juster.chu
- E-Mail:[email protected]
- QQ: 580749909(個人群)
- Blog: https://www.cnblogs.com/justzhuzhu/
- Git: https://github.com/JusterZhu
- 微信公衆号