GeneralUpdate2.1.0發布
GeneralUpdate
- GeneralUpdate是基於.net framwork開發的一款(c/s應用)自動升級程式。該組件將更新的核心部分抽離出來方便應用於多種項目當中目前適用於wpf,控制台應用,winfrom。相比以前更方便的是不需要在過分關注源碼可直接通過nuget直接使用。
- 如果有任何使用問題可以在Github的issues上進行提問我會每周統一找時間解決並解答bug或者問題。或者聯繫文章末尾的聯繫方式會有人解答。
- 每次迭代新版本doc文件夾中的幫助文檔也會隨之更新,各位開發者請多關注。
- 如果該組件能夠幫助到您,希望可以點個Strat和關注一下文檔末尾的聯繫方式。您的支援是對開源作者最大的支援與幫助。
How to use it:
Gitee(碼雲)地址:
- //gitee.com/Juster-zhu/GeneralUpdate
Nuget地址:
- //www.nuget.org/packages/GeneralUpdate.Core/
- //www.nuget.org/packages/GeneralUpdate.Single/
GitHub地址:
- Address://github.com/WELL-E/AutoUpdater/tree/autoupdate2
- Issues://github.com/WELL-E/AutoUpdater/issues
1.版本更新2020-8-30
-
在新的發布中,GeneralUpdate.Core-2.1.0版本新增斷點續傳功能。
-
在新的發布中,新增了組件 GeneralUpdate.Single-1.0.0,它將為程式帶來單例運行功能,防止自動更新程式開啟多個。
2.更新流程
1.客戶端程式啟動,向伺服器獲取更新資訊解析並比對是否需要更新。
2.解析進程傳參。例如:本機版本號、最新版本號、下載地址、解壓路徑、安裝路徑等。
3.客戶端程式啟動更新程式(GeneralUpdate),關閉自身(客戶端把自己關掉)。
4.自動更新程式(GeneralUpdate)根據傳遞的更新資訊進行, (1)下載、(2)MD5校驗、(3)解壓、(4)刪除更新文件、(5)替換更新文件、(6)關閉更新程式自身、(7)啟動客戶端。
5.完成更新
3.進程之間相互調用
此段程式碼來自於msdn
using System;
using System.Diagnostics;
using System.ComponentModel;
namespace MyProcessSample
{
class MyProcess
{
// Opens the Internet Explorer application.
void OpenApplication(string myFavoritesPath)
{
// Start Internet Explorer. Defaults to the home page.
Process.Start("IExplore.exe");
// Display the contents of the favorites folder in the browser.
Process.Start(myFavoritesPath);
}
// Opens urls and .html documents using Internet Explorer.
void OpenWithArguments()
{
// url's are not considered documents. They can only be opened
// by passing them as arguments.
Process.Start("IExplore.exe", "www.northwindtraders.com");
// Start a Web page using a browser associated with .html and .asp files.
Process.Start("IExplore.exe", "C:\\myPath\\myFile.htm");
Process.Start("IExplore.exe", "C:\\myPath\\myFile.asp");
}
// Uses the ProcessStartInfo class to start new processes,
// both in a minimized mode.
void OpenWithStartInfo()
{
ProcessStartInfo startInfo = new ProcessStartInfo("IExplore.exe");
startInfo.WindowStyle = ProcessWindowStyle.Minimized;
Process.Start(startInfo);
startInfo.Arguments = "www.northwindtraders.com";
Process.Start(startInfo);
}
static void Main()
{
// Get the path that stores favorite links.
string myFavoritesPath =
Environment.GetFolderPath(Environment.SpecialFolder.Favorites);
MyProcess myProcess = new MyProcess();
myProcess.OpenApplication(myFavoritesPath);
myProcess.OpenWithArguments();
myProcess.OpenWithStartInfo();
}
}
}
3.GeneralUpdate.Core-2.1.0使用方式
#region Launch1
args = new string[6] {
"0.0.0.0",
"1.1.1.1",
"//github.com/WELL-E",
"//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直接寫名稱即可
Option(UpdateOption.DownloadTimeOut,60).//下載超時時間(單位:秒),如果不指定則默認超時時間為30秒。
RemoteAddress(args).//這裡的參數保留了之前的參數數組集合
Launch();//啟動更新
#endregion
#region Launch2
/*
* Launch2
* 新增了第二種啟動方式
* 流程:
* 1.指定更新地址,//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, "").
// Option(UpdateOption.DownloadTimeOut,60).//下載超時時間(單位:秒),如果不指定則默認超時時間為30秒。
// RemoteAddress(@"//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}");
}
3.GeneralUpdate.Single-1.0.0使用方式
/// <summary>
/// App.xaml 的交互邏輯
/// </summary>
public partial class App : Application, ISingleInstanceApp
{
private const string AppId = "{7F280539-0814-4F9C-95BF-D2BB60023657}";
[STAThread]
protected override void OnStartup(StartupEventArgs e)
{
string[] resultArgs = null;
if (e.Args == null || e.Args.Length == 0)
{
resultArgs = new string[6] {
"0.0.0.0",
"1.1.1.1",
"//github.com/WELL-E",
"//192.168.50.225:7000/update.zip",
@"E:\PlatformPath",
"509f0ede227de4a662763a4abe3d8470",
};
}
else
{
resultArgs = e.Args;
}
if (resultArgs.Length != 6) return;
if (SingleInstance<App>.InitializeAsFirstInstance(AppId))
{
var win = new MainWindow();
var vm = new MainViewModel(resultArgs, win.Close);
win.DataContext = vm;
var application = new App();
application.InitializeComponent();
application.Run(win);
SingleInstance<App>.Cleanup();
}
}
public bool SignalExternalCommandLineArgs(IList<string> args)
{
if (this.MainWindow.WindowState == WindowState.Minimized)
{
this.MainWindow.WindowState = WindowState.Normal;
}
this.MainWindow.Activate();
return true;
}
}
4.問答Q&A
Q1.如果版本迭代多次,跨版本更新,該怎麼辦呢?
A1:只要不是框架級別的更新都是可以更新的。 不管你迭代多少次跨了多少個版本,你把最終的包放到伺服器上就行了。這個裡面沒有涉及到增量更新,所以你更新多了直接把所有的新文件覆蓋上去就行了。
Q2.GeneralUpdate是跟客戶端是一個整體嗎?
A2: 不是,GeneralUpdate是一個獨立於客戶端的程式。
Q3:能不能增量更新、失敗自動回滾、更新本地數據或配置文件?
A3: 目前不能。(該功能已在開發計劃當中)。
Q4:GeneralUpdate是如何更新的?
A4: 更新的方式為把本地原有的客戶端文件進行覆蓋。