×

GUpdate自动升级程序

消耗积分:0 | 格式:zip | 大小:45.53 MB | 2022-04-28

陈霞

分享资料个

授权协议 MIT
开发语言 .NET
操作系统 Windows
软件类型 开源软件
所属分类 开发工具.NET开发工具

软件简介

基于.net framwork4.5.2开发的一款(c/s应用)自动升级程序。

将更新的核心部分抽离出来方便应用于多种项目当中目前适用于wpf,控制台应用,winfrom。相比以前更方便的是不需要在过分关注源码可直接通过nuget直接使用。

快速启动:

#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().//注册策略,可自定义更新流程
            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().
        //    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}");
    }
 

声明:本文内容及配图由入驻作者撰写或者入驻合作网站授权转载。文章观点仅代表作者本人,不代表电子发烧友网立场。文章及其配图仅供工程师学习之用,如有内容侵权或者其他违规问题,请联系本站处理。 举报投诉

评论(0)
发评论

下载排行榜

全部0条评论

快来发表一下你的评论吧 !