1 Star 0 Fork 178

Mike_W / GeneralUpdate

forked from General / GeneralUpdate 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

GeneralUpdate

组件介绍

GeneralUpdate是基于.net standard开发的一款(c/s应用)自动升级程序。该组件将更新的核心部分抽离出来方便应用于多种项目当中目前适用于wpf,控制台应用,winfrom。

功能介绍

  • GeneralUpdate.Core:断点续传、逐版本更新。
  • GeneralUpdate.ClientCore:断点续传、逐版本更新、更新组件自更新、便捷启动更新组件
  • GeneralUpdate.AspNetCore:服务端支持更新包下载地址、版本信息等内容。
  • GeneralUpdate.Zip:解压更新包、解压进度通知。
  • GeneralUpdate.Single:应用程序单例运行。
  • GeneralUpdate.Common:组件公共类、方法。
  • 源码"sql"目录下包含mysql数据库表内容的生成脚本。

帮助文档

讨论组

QQ群:580749909

开源地址

Nuget地址

更新流程图

运行效果及更新流程展示

快速启动

(1) Example GeneralUpdate.ClientCore

    private ClientParameter clientParameter;
    private GeneralClientBootstrap generalClientBootstrap;

    private void Button_Click(object sender, RoutedEventArgs e)
    {
        Task.Run(async()=> 
        {
            //主程序信息
            var mainVersion = "1.1.1";
            var mianType = 1;

            //该对象用于主程序客户端与更新组件进程之间交互用的对象
            clientParameter = new ClientParameter();
            //更新组件的版本号
            clientParameter.ClientVersion = "1.1.1";
            //客户端类型:1.主程序客户端 2.更新组件
            clientParameter.ClientType = 2;
            //更新程序exe名称
            clientParameter.AppName = "AutoUpdate.ConsoleApp";
            //主程序客户端exe名称
            clientParameter.MainAppName = "AutoUpdate.Test";
            //本机的客户端程序应用地址
            clientParameter.InstallPath = @"D:\update_test";
            //更新公告网页
            clientParameter.UpdateLogUrl = "https://www.baidu.com/";
            //更新组件请求验证更新的服务端地址
            clientParameter.ValidateUrl = $"https://127.0.0.1:5001/api/update/getUpdateValidate/{ clientParameter.ClientType }/{ clientParameter.ClientVersion }";
            //更新组件更新包下载地址
            clientParameter.UpdateUrl = $"https://127.0.0.1:5001/api/update/getUpdateVersions/{ clientParameter.ClientType }/{ clientParameter.ClientVersion }";
            //主程序客户端请求验证更新的服务端地址
            clientParameter.MainValidateUrl = $"https://127.0.0.1:5001/api/update/getUpdateValidate/{ mianType }/{ mainVersion }";
            //主程序客户端更新包下载地址
            clientParameter.MainUpdateUrl = $"https://127.0.0.1:5001/api/update/getUpdateVersions/{ mianType }/{ mainVersion }";

            generalClientBootstrap = new GeneralClientBootstrap();
            //单个或多个更新包下载通知事件
            generalClientBootstrap.MutiDownloadProgressChanged += OnMutiDownloadProgressChanged;
            //单个或多个更新包下载速度、剩余下载事件、当前下载版本信息通知事件
            generalClientBootstrap.MutiDownloadStatistics += OnMutiDownloadStatistics;
            //单个或多个更新包下载完成
            generalClientBootstrap.MutiDownloadCompleted += OnMutiDownloadCompleted;
            //完成所有的下载任务通知
            generalClientBootstrap.MutiAllDownloadCompleted += OnMutiAllDownloadCompleted;
            //下载过程出现的异常通知
            generalClientBootstrap.MutiDownloadError += OnMutiDownloadError;
            //整个更新过程出现的任何问题都会通过这个事件通知
            generalClientBootstrap.Exception += OnException;
            //ClientStrategy该更新策略将完成1.自动升级组件自更新 2.启动更新组件 3.配置好ClientParameter无需再像之前的版本写args数组进程通讯了。
            generalClientBootstrap.Config(clientParameter).
                Strategy<ClientStrategy>();
            await generalClientBootstrap.LaunchTaskAsync();
        });
    }

    private void OnMutiDownloadStatistics(object sender, MutiDownloadStatisticsEventArgs e)
    {
         //e.Remaining 剩余下载时间
         //e.Speed 下载速度
         //e.Version 当前下载的版本信息
    }

    private void OnMutiDownloadProgressChanged(object sender, MutiDownloadProgressChangedEventArgs e)
    {
        //e.TotalBytesToReceive 当前更新包需要下载的总大小
        //e.ProgressValue 当前进度值
        //e.ProgressPercentage 当前进度的百分比
        //e.Version 当前下载的版本信息
        //e.Type 当前正在执行的操作  1.ProgressType.Check 检查版本信息中 2.ProgressType.Donwload 正在下载当前版本 3. ProgressType.Updatefile 更新当前版本 4. ProgressType.Done更新完成 5.ProgressType.Fail 更新失败
        //e.BytesReceived 已下载大小
    }

(2) Example GeneralUpdate.Core

static void Main(string[] args)
{
    var resultBase64 = args[0];
    var bootstrap = new GeneralUpdateBootstrap();
    bootstrap.Exception += OnException;
    bootstrap.MutiDownloadError += OnMutiDownloadError;
    bootstrap.MutiDownloadCompleted += OnMutiDownloadCompleted;
    bootstrap.MutiDownloadStatistics += OnMutiDownloadStatistics;
    bootstrap.MutiDownloadProgressChanged += OnMutiDownloadProgressChanged;
    bootstrap.MutiAllDownloadCompleted += OnMutiAllDownloadCompleted;
    bootstrap.Strategy<DefaultStrategy>().
        Option(UpdateOption.DownloadTimeOut, 60).
        RemoteAddressBase64(resultBase64).
        LaunchAsync();
}

(3) Example GeneralUpdate.AspNetCore

Startup.cs
public void ConfigureServices(IServiceCollection services)
{
    services.AddControllers();
    services.AddSingleton<IUpdateService, GeneralUpdateService>();
}

UpdateController.cs

private readonly ILogger<UpdateController> _logger;
private readonly IUpdateService _updateService;

public UpdateController(ILogger<UpdateController> logger, IUpdateService updateService)
{
    _logger = logger;
    _updateService = updateService;
}

/// <summary>
/// https://localhost:5001/api/update/getUpdateVersions/1/1.1.1
/// </summary>
/// <param name="clientType"> 1:ClientApp 2:UpdateApp</param>
/// <param name="clientVersion"></param>
/// <returns></returns>
[HttpGet("getUpdateVersions/{clientType}/{clientVersion}")]
public async Task<IActionResult> GetUpdateVersions(int clientType, string clientVersion)
{
    _logger.LogInformation("Client request 'GetUpdateVersions'.");
    var resultJson = await _updateService.UpdateVersionsTaskAsync(clientType, clientVersion, UpdateVersions);
    return Ok(resultJson);
}

/// <summary>
/// https://localhost:5001/api/update/getUpdateValidate/1/1.1.1
/// </summary>
/// <param name="clientType"> 1:ClientApp 2:UpdateApp</param>
/// <param name="clientVersion"></param>
/// <returns></returns>
[HttpGet("getUpdateValidate/{clientType}/{clientVersion}")]
public async Task<IActionResult> GetUpdateValidate(int clientType, string clientVersion)
{
    _logger.LogInformation("Client request 'GetUpdateValidate'.");
    var lastVersion = GetLastVersion();
    var resultJson = await _updateService.UpdateValidateTaskAsync(clientType, clientVersion, lastVersion, true, GetValidateInfos);
    return Ok(resultJson);
}

支持作者

作者:Juster.zhu & Charles.Yu

MIT License Copyright (c) 2020 Juster.zhu Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

一款基于.net开发自动更新程序。wpf winfrom console均能更新。 展开 收起
C#
MIT
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
C#
1
https://gitee.com/Mike_W/GeneralUpdate.git
git@gitee.com:Mike_W/GeneralUpdate.git
Mike_W
GeneralUpdate
GeneralUpdate
master

搜索帮助