예제 #1
0
        private void Flow(IProgressWindow prgWin)
        {
            prgWin.AppendLog("获取信息中", 10);
            IUpdateInfo info = InfoGetter.Get();

            prgWin.AppendLog("获取信息完毕,正在解析", 20);
            prgWin.SetUpdateContent(info.UpdateContent);

            IEnumerable <IFile> needUpdateFile = Differ.Diff(info.Files, GetLocalFiles());

            if (needUpdateFile.Count() == 0)
            {
                prgWin.AppendLog("无需更新!", 100);
                Thread.Sleep(4000);
                prgWin.Finish();
                return;
            }
            int downloadingFile = 0;

            Downloader.DownloadedAFile += (s, e) =>
            {
                downloadingFile++;
                prgWin.SetProgress(20 + (100 / needUpdateFile.Count() * downloadingFile * 80));
                prgWin.AppendLog($"正在下载并更新{downloadingFile}/{needUpdateFile.Count()}");
            };

            Downloader.Download(needUpdateFile);
            prgWin.AppendLog("结束,三秒后退出", 100);
            Thread.Sleep(3000);
            prgWin.Finish();
        }
예제 #2
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());
            }
        }