示例#1
0
        private void Downloader_DownloadFileCompleted(object sender, AsyncCompletedEventArgs e)
        {
            Status = "正在校验...";
            if (Bas.GetFileHash(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\zhangbudademao.com\\BiliUPDesktopTool\\update.zip") == jobj["data"]["hash"].ToString())
            {
                Status = "正在解压...";
                if (Bas.UnZip(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\zhangbudademao.com\\BiliUPDesktopTool\\update.zip", Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\zhangbudademao.com\\BiliUPDesktopTool\\UpdateTemp\\", ""))
                {
                    Status = "正在安装...";
                    File.Delete(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\zhangbudademao.com\\BiliUPDesktopTool\\update.zip");
                    File.WriteAllText(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\zhangbudademao.com\\BiliUPDesktopTool\\update.bat", "@echo off\r\n" +
                                      "choice /t 5 /d y /n >nul\r\n" +                                                                                                                                                                    //等待5s开始
                                      "xcopy \"" + Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\zhangbudademao.com\\BiliUPDesktopTool\\UpdateTemp" + "\" \"" + Application.StartupPath + "\" /s /e /y\r\n" + //覆盖程序
                                      "rmdir /s /q \"" + Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\zhangbudademao.com\\BiliUPDesktopTool\\UpdateTemp\\" + "\"\r\n" +                                      //删除更新缓存
                                      "start \"\" \"" + Application.ExecutablePath + "\" -s\r\n" +                                                                                                                                        //启动程序
                                      "del %0", Encoding.Default);
                    Process p = new Process();

                    p.StartInfo.FileName       = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\zhangbudademao.com\\BiliUPDesktopTool\\update.bat";
                    p.StartInfo.CreateNoWindow = true;
                    p.StartInfo.WindowStyle    = ProcessWindowStyle.Hidden;
                    p.StartInfo.Verb           = "runas";//管理员启动
                    p.Start();

                    Environment.Exit(2);
                }
            }
            else
            {
                MsgBoxPushHelper.RaisePushMsg("校验错误,请稍后再试!");
                IsFinished = true;
            }
            (sender as WebClient).Dispose();
        }
示例#2
0
        /// <summary>
        /// 更新下载完成
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Client_DownloadFileCompleted(object sender, System.ComponentModel.AsyncCompletedEventArgs e)
        {
            if (Bas.GetFileHash(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + $"\\zhangbudademao.com\\BiliUPDesktopTool\\Plug-ins\\{name}\\update.zip") == updateinfo.hash)
            {
                SendMsg("Q");

                if (Bas.UnZip(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + $"\\zhangbudademao.com\\BiliUPDesktopTool\\Plug-ins\\{name}\\update.zip", Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + $"\\zhangbudademao.com\\BiliUPDesktopTool\\Plug-ins\\{name}\\", ""))
                {
                    version     = updateinfo.version;
                    version_str = updateinfo.version_str;
                    Save();

                    NeedUpdate = false;
                    updateinfo = null;
                    MsgBoxPushHelper.RaisePushMsg($"插件{name}更新成功!");
                }
                else
                {
                    MsgBoxPushHelper.RaisePushMsg($"插件{name}更新失败,解压或文件错误!");
                }
            }
            else
            {
                MsgBoxPushHelper.RaisePushMsg($"插件{name}更新失败,文件校验失败!");
            }
        }