什么是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這款軟件,作為臨時服務器進行調試使用方式非常簡單下載好了之后界面如下
聯系我們:
QQ群:
-
WELL-E
- 1群 130108655
- 2群 960655709
- Git: https://github.com/WELL-E
-
juster.chu
- E-Mail:zhuzhen723723@outlook.com
- QQ: 580749909(個人群)
- Blog: https://www.cnblogs.com/justzhuzhu/
- Git: https://github.com/JusterZhu
- 微信公眾號