Beispiel #1
0
        public async void Start(IProgressWindow prgWin)
        {
            try
            {
                UpdateInfo uInfo = null;
                prgWin.SetTip("正在获取更新信息", 10);
                await Task.Run(() => uInfo = UpdateInfo.Parse(webClient.DownloadString(api)));

                prgWin.SetTip("获取完成", 15);
                prgWin.SetUpdateContent($"{uInfo.Title}{Environment.NewLine}{uInfo.UpdateContent}");
                if (Directory.Exists(updateTmpDir))
                {
                    Directory.Delete(updateTmpDir, true);
                }
                if (!Directory.Exists(updateTmpDir))
                {
                    Directory.CreateDirectory(updateTmpDir);
                }
                prgWin.SetTip("正在下载更新", 30);
                await Task.Run(() => webClient.DownloadFile(uInfo.DownloadUrl, Path.Combine(updateTmpDir, tmpFilePath)));

                prgWin.SetTip("正在应用更新", 80);
                await Task.Run(() =>
                {
                    using (var zip = new ZipFile("..\\update\\tmp.zip"))
                    {
                        zip.ExtractAll(Path.Combine(updateTmpDir));
                    }
                });

                Process.Start(new ProcessStartInfo("cmd.exe")
                {
                    Arguments        = "/c " + uInfo.Bat,
                    WorkingDirectory = "..\\",
                }).Start();
                prgWin.Finish();
            }
            catch (Exception ex)
            {
                Trace.Fail(ex.ToString());
            }
        }