Пример #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
        private PluginManager()
        {
            Plugins = new List <PluginInfo>();

            if (!Directory.Exists(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\zhangbudademao.com\\BiliUPDesktopTool\\Plug-ins\\"))
            {
                Directory.CreateDirectory(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\zhangbudademao.com\\BiliUPDesktopTool\\Plug-ins\\");
                return;
            }

            DirectoryInfo[] directories = new DirectoryInfo(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\zhangbudademao.com\\BiliUPDesktopTool\\Plug-ins\\").GetDirectories();
            if (directories.Length > 0)
            {
                foreach (DirectoryInfo i in directories)
                {
                    try
                    {
                        string     str    = File.ReadAllText(i.FullName + "\\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("参数错误!");
                        }

                        Plugins.Add(plugin);
                    }
                    catch (Exception ex)
                    {
                        MsgBoxPushHelper.RaisePushMsg($"加载插件错误!{ex.Message}");
                    }
                }
            }
        }
Пример #3
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}更新失败,文件校验失败!");
            }
        }
Пример #4
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("安装插件失败,插件包不存在!");
            }
        }
Пример #5
0
        private void Btn_Login_MouseUp(object sender, System.Windows.Input.MouseButtonEventArgs e)
        {
            MsgBoxPushHelper.RaisePushMsg("登录中...");
            if (string.IsNullOrEmpty(TB_UName.Text))
            {
                MsgBoxPushHelper.RaisePushMsg("账号不能为空!");
                return;
            }
            if (string.IsNullOrEmpty(TB_Pwd.Password))
            {
                MsgBoxPushHelper.RaisePushMsg("密码不能为空!");
                return;
            }

            Account.Instance.UserName = TB_UName.Text;
            if ((bool)CB_MarkPwd.IsChecked)
            {
                Account.Instance.PassWord = TB_Pwd.Password;
            }

            BiliAccount.Account account = BiliAccount.Linq.ByPassword.LoginByPassword(TB_UName.Text, TB_Pwd.Password);

            switch (account.LoginStatus)
            {
            case BiliAccount.Account.LoginStatusEnum.WrongPassword:    //密码错误
                MsgBoxPushHelper.RaisePushMsg("账号或密码错误!");
                break;

            case BiliAccount.Account.LoginStatusEnum.ByPassword:
                Account.Instance.Cookies             = account.strCookies;
                Account.Instance.Csrf_Token          = account.CsrfToken;
                Account.Instance.Expires             = account.Expires_Cookies;
                Account.Instance.AccessToken         = account.AccessToken;
                Account.Instance.RefreshToken        = account.RefreshToken;
                Account.Instance.Expires_AccessToken = account.Expires_AccessToken;
                Account.Instance.Uid       = account.Uid;
                Account.Instance.LoginMode = Account.LOGINMODE.ByPassword;
                Account.Instance.Islogin   = true;
                Account.Instance.GetInfo();

                Account.Instance.Save();

                MsgBoxPushHelper.PushMsg -= MsgBoxPushHelper_PushMsg;
                Close();

                MsgBoxPushHelper.RaisePushMsg($"登录成功!{account.LoginStatus}");
                break;

            default:
                MsgBoxPushHelper.RaisePushMsg($"登录错误,请尝试使用二维码登录。{account.LoginStatus}");
                Btn_TabChange_MouseUp(null, null);
                break;
            }
        }
Пример #6
0
        /// <summary>
        /// 卸载插件
        /// </summary>
        /// <param name="plugin">插件信息</param>
        public void Uninstall(PluginInfo plugin)
        {
            Plugins.Remove(plugin);

            try
            {
                Directory.Delete(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + $"\\zhangbudademao.com\\BiliUPDesktopTool\\Plug-ins\\{plugin.name}\\");
                MsgBoxPushHelper.RaisePushMsg("卸载插件成功!");
            }
            catch (Exception ex)
            {
                MsgBoxPushHelper.RaisePushMsg($"卸载插件失败,{ex.Message}!");
            }
        }
Пример #7
0
        /// <summary>
        /// 修改简介
        /// </summary>
        /// <param name="NewDesc">新简介文本</param>
        public void ChangeDesc(string NewDesc)
        {
            string str = Bas.PostHTTPBody("https://api.bilibili.com/x/member/web/sign/update", "user_sign=" + NewDesc + "&jsonp=jsonp&csrf=" + Csrf_Token, Cookies);

            if (!string.IsNullOrEmpty(str))
            {
                JObject obj = JObject.Parse(str);
                if ((int)obj["code"] == 0)
                {
                    MsgBoxPushHelper.RaisePushMsg("修改简介成功!");
                    return;
                }
            }
            MsgBoxPushHelper.RaisePushMsg("修改简介失败!" + str);
        }
Пример #8
0
        private void Btn_SignOut_MouseUp(object sender, MouseButtonEventArgs e)
        {
            Account.Instance.SignOut();

            if (Account.Instance.Islogin)
            {
                InfoBox.Visibility      = Visibility.Visible;
                NeedLoginBox.Visibility = Visibility.Hidden;
            }
            else
            {
                InfoBox.Visibility      = Visibility.Hidden;
                NeedLoginBox.Visibility = Visibility.Visible;
            }

            MsgBoxPushHelper.RaisePushMsg("已成功注销登录!");
        }
Пример #9
0
        /// <summary>
        /// 二维码登陆状态刷新
        /// </summary>
        /// <param name="status"></param>
        /// <param name="account"></param>
        private void ByQRCode_QrCodeStatus_Changed(BiliAccount.Linq.ByQRCode.QrCodeStatus status, BiliAccount.Account account = null)
        {
            switch (status)
            {
            case BiliAccount.Linq.ByQRCode.QrCodeStatus.Scaned:
                if (!HasScaned)
                {
                    Dispatcher?.Invoke(() =>
                    {
                        HasScaned = true;
                        MsgBoxPushHelper.RaisePushMsg("扫描成功,请在手机上确认登录。");
                    });
                }
                break;

            case BiliAccount.Linq.ByQRCode.QrCodeStatus.Success:
                Dispatcher?.Invoke(() =>
                {
                    Account.Instance.Uid        = account.Uid;
                    Account.Instance.Expires    = account.Expires_Cookies;
                    Account.Instance.Cookies    = account.strCookies;
                    Account.Instance.Csrf_Token = account.CsrfToken;
                    Account.Instance.Islogin    = true;
                    Account.Instance.LoginMode  = Account.LOGINMODE.ByQrcode;
                    Account.Instance.Save();

                    MsgBoxPushHelper.PushMsg -= MsgBoxPushHelper_PushMsg;
                    Close();

                    MsgBoxPushHelper.RaisePushMsg($"登录成功!{account.LoginStatus}");
                });
                break;

            default:
                break;
            }
        }
Пример #10
0
 private void Btn_Upload_MouseUp(object sender, MouseButtonEventArgs e)
 {
     MsgBoxPushHelper.RaisePushMsg("功能暂未开放");
 }
Пример #11
0
 /// <summary>
 /// 显示模式窗口
 /// </summary>
 /// <param name="info">提示信息</param>
 /// <returns>操作是否成功</returns>
 public bool?ShowDialog(string info)
 {
     MsgBoxPushHelper.RaisePushMsg(info);
     return(ShowDialog());
 }