示例#1
0
文件: Program.cs 项目: pjy612/XCoder
        private static async Task CheckUpgrade(StarClient client, String channel)
        {
            var ug = new Stardust.Web.Upgrade {
                Log = XTrace.Log
            };

            // 检查更新
            var ur = await client.Upgrade(channel);

            if (ur != null && ur.Version != _lastVersion)
            {
                ug.Url = ur.Source;
                await ug.Download();

                // 检查文件完整性
                if (ur.FileHash.IsNullOrEmpty() || ug.CheckFileHash(ur.FileHash))
                {
                    // 执行更新,解压缩覆盖文件
                    var rs = ug.Update();
                    if (rs && !ur.Executor.IsNullOrEmpty())
                    {
                        ug.Run(ur.Executor);
                    }
                    _lastVersion = ur.Version;

                    // 去除多余入口文件
                    ug.Trim("StarAgent");

                    // 强制更新时,马上重启
                    if (rs && ur.Force)
                    {
                        //StopWork("Upgrade");

                        // 重新拉起进程
                        var star = "XCoder.exe";
                        XTrace.WriteLine("强制升级,拉起进程 {0} -upgrade", star.GetFullPath());
                        Process.Start(star.GetFullPath(), "-upgrade");

                        //var p = Process.GetCurrentProcess();
                        //p.Close();
                        //p.Kill();
                        Application.Exit();
                    }
                }
            }
        }
示例#2
0
        private static void CheckUpgrade(StarClient client, String channel)
        {
            // 检查更新
            var ur = client.Upgrade(channel).Result;

            if (ur != null)
            {
                var rs = client.ProcessUpgrade(ur);

                // 强制更新时,马上重启
                if (rs && ur.Force)
                {
                    var p = Process.GetCurrentProcess();
                    p.Close();
                    p.Kill(true);
                }
            }
        }