博客
关于我
GeneralUpdate2.1.0发布
阅读量:465 次
发布时间:2019-03-06

本文共 3950 字,大约阅读时间需要 13 分钟。

GeneralUpdate自动升级工具

GeneralUpdate 是一款基于 .NET Framework 开发的自动升级程序,适用于 WPF、控制台应用和 WinForm 开发项目。它的核心设计目标是将更新逻辑抽象化,便于多种应用场景使用。与传统方法不同,GeneralUpdate 不需要深入了解源码,可以直接通过 Nuget 包管理,极大提升了开发效率。

版本更新

  • v2.1.0:新增断点续传功能,支持中断更新后恢复。
  • v1.0.0(GeneralUpdate.Single):新增单例运行功能,防止多次启动更新程序。

使用方法

GeneralUpdate.Core 使用方式

using GeneralUpdate.Core;using GeneralUpdate.Core.Models;// 示例配置var 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"};// 创建 bootstrap 实例var bootstrap = new GeneralUpdateBootstrap();// 注册事件处理bootstrap.DownloadStatistics += OnDownloadStatistics;bootstrap.ProgressChanged += OnProgressChanged;// 配置更新策略bootstrap.Strategy()    .Option(UpdateOption.Format, "zip") // 指定更新包格式    .Option(UpdateOption.MainApp, "YourApplicationName") // 指定更新完成后启动的主程序    .Option(UpdateOption.DownloadTimeOut, 60) // 下载超时时间(默认30秒)// 启动更新bootstrap.RemoteAddress(args)    .Launch();

GeneralUpdate.Single 使用方式

using GeneralUpdate.Single;using System.Windows;// 确保只运行一个实例const string appId = "{7F280539-0814-4F9C-95BF-D2BB60023657}";public partial class App : Application, ISingleInstanceApp{    [STAThread]    protected override void OnStartup(StartupEventArgs e)    {        if (e.Args == null || e.Args.Length == 0)        {            // 示例参数配置            var 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"            };        }        else        {            // 从命令行获取参数            var args = e.Args;        }        if (args?.Length != 6)            return;        if (SingleInstance.InitializeAsFirstInstance(appId))        {            var mainWindow = new MainWindow();            var viewModel = new MainViewModel(args, mainWindow.Close);            mainWindow.DataContext = viewModel;            var app = new App();            app.InitializeComponent();            app.Run(mainWindow);            SingleInstance.Cleanup();        }    }    public bool SignalExternalCommandLineArgs(List
args) { if (mainWindow.WindowState == WindowState.Minimized) mainWindow.WindowState = WindowState.Normal; mainWindow.Activate(); return true; }}

更新流程

  • 客户端启动:获取服务器更新信息并解析。
  • 参数解析:包括本地版本号、最新版本号、下载地址等。
  • 启动更新程序:关闭客户端并运行 GeneralUpdate。
  • 更新程序执行
    • 下载更新包
    • MD5 校验
    • 解压
    • 删除旧文件
    • 替换新文件
    • 关闭更新程序
    • 启动客户端
  • 完成更新
  • 进程之间的调用示例

    using System;using System.Diagnostics;using System.ComponentModel;namespace MyProcessSample{    class MyProcess    {        void OpenApplication(string myFavoritesPath)        {            Process.Start("IExplore.exe");            Process.Start(myFavoritesPath);        }        void OpenWithArguments()        {            Process.Start("IExplore.exe", "www.northwindtraders.com");            Process.Start("IExplore.exe", "C:\myPath\myFile.htm");            Process.Start("IExplore.exe", "C:\myPath\myFile.asp");        }        void OpenWithStartInfo()        {            var startInfo = new ProcessStartInfo("IExplore.exe");            startInfo.WindowStyle = ProcessWindowStyle.Minimized;            Process.Start(startInfo);            startInfo.Arguments = "www.northwindtraders.com";            Process.Start(startInfo);        }        static void Main()        {            var myFavoritesPath = Environment.GetFolderPath(Environment.SpecialFolder.Favorites);            var myProcess = new MyProcess();            myProcess.OpenApplication(myFavoritesPath);            myProcess.OpenWithArguments();            myProcess.OpenWithStartInfo();        }    }}

    常见问题解答

    Q1:跨版本更新该怎么办?

    A1:只要不是框架级别的更新都可以直接更新。将最终版本的包发布到服务器即可,无需处理增量更新,直接覆盖即可。

    Q2:GeneralUpdate 是否与客户端整体化?

    A2:不是,GeneralUpdate 是独立程序,可单独运行。

    Q3:是否支持增量更新、失败回滚等功能?

    A3:目前不支持,但计划未来开发。

    Q4:更新方式是什么?

    A4:通过覆盖本地客户端文件实现。

    转载地址:http://kvkbz.baihongyu.com/

    你可能感兴趣的文章
    Objective-C实现聚类AP算法(附完整源码)
    查看>>