Exemplo n.º 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();
        }
Exemplo n.º 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}更新失败,文件校验失败!");
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// 安装插件
        /// </summary>
        /// <param name="packet">插件包位置</param>
        /// <returns>插件信息</returns>
        public void Install(string packet)
        {
            if (File.Exists(packet))
            {
                if (Bas.UnZip(packet, Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\zhangbudademao.com\\BiliUPDesktopTool\\Plug-ins\\InstallTemp\\", ""))
                {
                    if (File.Exists(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\zhangbudademao.com\\BiliUPDesktopTool\\Plug-ins\\InstallTemp\\mainfirst.json"))
                    {
                        try
                        {
                            string     str    = File.ReadAllText(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\zhangbudademao.com\\BiliUPDesktopTool\\Plug-ins\\InstallTemp\\mainfirst.json");
                            PluginInfo plugin = JsonConvert.DeserializeObject <PluginInfo>(str);

                            if (string.IsNullOrEmpty(plugin.name) || string.IsNullOrEmpty(plugin.launch_file) || string.IsNullOrEmpty(plugin.version_str) || plugin.version == null)
                            {
                                throw new Exception("参数错误!");
                            }

                            Directory.Move(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\zhangbudademao.com\\BiliUPDesktopTool\\Plug-ins\\InstallTemp\\", Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + $"\\zhangbudademao.com\\BiliUPDesktopTool\\Plug-ins\\{plugin.name}\\");

                            MsgBoxPushHelper.RaisePushMsg("安装插件成功!");
                            Plugins.Add(plugin);
                        }
                        catch (Exception ex)
                        {
                            MsgBoxPushHelper.RaisePushMsg($"安装插件错误!{ex.Message}");
                            if (Directory.Exists(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\zhangbudademao.com\\BiliUPDesktopTool\\Plug-ins\\InstallTemp\\"))
                            {
                                Directory.Delete(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\zhangbudademao.com\\BiliUPDesktopTool\\Plug-ins\\InstallTemp\\");
                            }
                        }
                    }
                    else
                    {
                        MsgBoxPushHelper.RaisePushMsg("安装插件失败,插件包不完整!");
                        if (Directory.Exists(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\zhangbudademao.com\\BiliUPDesktopTool\\Plug-ins\\InstallTemp\\"))
                        {
                            Directory.Delete(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\zhangbudademao.com\\BiliUPDesktopTool\\Plug-ins\\InstallTemp\\");
                        }
                    }
                }
                else
                {
                    MsgBoxPushHelper.RaisePushMsg("安装插件失败,解压包失败!");
                    if (Directory.Exists(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\zhangbudademao.com\\BiliUPDesktopTool\\Plug-ins\\InstallTemp\\"))
                    {
                        Directory.Delete(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\zhangbudademao.com\\BiliUPDesktopTool\\Plug-ins\\InstallTemp\\");
                    }
                }
            }
            else
            {
                MsgBoxPushHelper.RaisePushMsg("安装插件失败,插件包不存在!");
            }
        }