예제 #1
0
        private async void connbtn_Click(object sender, RoutedEventArgs e)
        {
            User.UserList.Clear();
            Logger.DisplayText("", true);
            Logger.DisplayText("", true);
            Logger.DisplayText("", true);
            Logger.DisplayText("", true);
            Logger.DisplayText("", true);
            ConfigData.Room = LiverName.Text.Trim();
            Config.Write(ConfigData);
            //b = new Api(LiverName.Text.Trim());
            b = new XiguaAPI(LiverName.Text.Trim());
            logging("是否为房间号" + b.isRoomID.ToString(), "debug");

            ConnBtn.IsEnabled    = false;
            DisconnBtn.IsEnabled = false;
            var connectresult = false;

            logging("正在连接");
            connectresult = await b.ConnectAsync();

            if (connectresult)
            {
                logging("连接成功");
                AddDMText("提示", "连接成功", true);
                getDanmakuThread.Start();
                logging(b.RoomID.ToString(), "debug");
                isSaveToggle = false;
                if (!b.isRoomID)
                {
                    LiverName.Text = b.user.ToString();
                }
                b.UpdateAdminList();
                b.UpdateBrand();
                logging($"主播 {b.user.Name} , 正在直播 {b.Title} 。");
                logging(XiguaAPI.UserID.ToString(), "debug");
                logging(User.AdminList.Count.ToString(), "debug");
                logging(User.targetBrand, "debug");
            }
            else
            {
                logging("连接失败");
                AddDMText("提示", "连接失败", true);
                ConnBtn.IsEnabled = true;
            }
            DisconnBtn.IsEnabled = true;
        }
예제 #2
0
        public MainWindow()
        {
            InitializeComponent();

            Info.Text += version;
            //初始化日志
            //b = new Api();
            b = new XiguaAPI();
            overlay_enabled = true;
            OpenOverlay();
            overlay.Show();

            Closed += MainWindow_Closed;

            //Api.OnMessage += b_ReceivedDanmaku;
            //Api.OnLeave += OnLiveStop;
            //            b.OnMessage += ProcDanmaku;
            //Api.LogMessage += b_LogMessage;
            //Api.OnRoomCounting += b_ReceivedRoomCount;

            XiguaAPI.OnMessage      += b_ReceivedDanmaku;
            XiguaAPI.OnLeave        += OnLiveStop;
            XiguaAPI.LogMessage     += b_LogMessage;
            XiguaAPI.OnRoomCounting += b_ReceivedRoomCount;

            YuYin.LogMessage += b_LogMessage;
            //YuYin.Landu += Landu;

            timer = new DispatcherTimer(new TimeSpan(0, 0, 1), DispatcherPriority.Normal, FuckMicrosoft,
                                        Dispatcher);
            timer.Start();

            Log.DataContext = _messageQueue;

            releaseThread = new Thread(() =>
            {
                while (true)
                {
                    Utils.ReleaseMemory(true);
                    Thread.Sleep(30 * 1000);
                }
            });
            releaseThread.IsBackground = true;
            getDanmakuThread           = new Thread(() =>
            {
                while (true)
                {
                    if (b.isLive)
                    {
                        b.GetDanmaku();
                        Thread.Sleep(1000);
                    }
                    else
                    {
                        Thread.Sleep(100000);
                    }
                }
            });
            getDanmakuThread.IsBackground = true;
            //            releaseThread.Start();
            ProcDanmakuThread = new Thread(() =>
            {
                while (true)
                {
                    lock (_danmakuQueue)
                    {
                        var count = 0;
                        if (_danmakuQueue.Any())
                        {
                            count = (int)Math.Ceiling(_danmakuQueue.Count / 30.0);
                        }

                        for (var i = 0; i < count; i++)
                        {
                            if (_danmakuQueue.Any())
                            {
                                var danmaku = _danmakuQueue.Dequeue();
                                ProcDanmaku(danmaku);
                            }
                        }
                    }

                    Thread.Sleep(25);
                }
            })
            {
                IsBackground = true
            };
            ProcDanmakuThread.Start();

            for (var i = 0; i < 100; i++)
            {
                _messageQueue.Add("");
            }
            logging("可以点击日志复制到剪贴板");

            Loaded            += MainWindow_Loaded;
            Setting.GetConfig += GetConfig;
            Setting.GetYuyin  += GetYuyin;
            YuYin.GetConfig   += GetConfig;
            XiguaAPI.GetYuyin += GetYuyin;
            //Landu();
            YuYin.HeCheng();

            System.IO.Directory.CreateDirectory("log");    //创造日志文件夹
            System.IO.Directory.CreateDirectory("toggle"); //创造记录文件夹
            try
            {
                ConfigData = (ConfigData)Config.Read();
                UpdateUI();
            }
            catch
            {
                ConfigData = new ConfigData();
                Config.Write(ConfigData);
                UpdateUI();
                MessageBox.Show("    欢迎使用西瓜直非官方助手。\n    本软件原作者 q792602257 ,当前分支由 挂神 维护。\n    本软件完全开源,挂神不会以任何形式销售本软件,严禁倒卖。\n    更多说明请前往 更多设置-关于程序 查看,或翻阅软件附带的“说明”文件。\n    您可以在关闭软件后将原安装目录下的Config.json文件覆盖本目录下的Config.json进行配置迁移。", "关于本软件");
            }
#if DEBUG
            ConfigData.DeBug = true;
#endif

            BlackList        = ConfigData.BlackList.Split('|');
            User.targetBrand = ConfigData.Brand;
            YuYin.version    = version;
            YuYin.Connect();
        }