Beispiel #1
0
        private void Pivot_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (pivot.SelectedIndex == 1)
            {
                LiPTT.GoToFavorite();
            }
            else
            {
                if (pivot_index == 1)
                {
                    LiPTT.Left();
                }

                switch (pivot.SelectedIndex)
                {
                case 2:
                    HotFrame.Navigate(typeof(HotPage));
                    break;

                case 3:
                    CreateSymbolList();
                    break;
                }
            }
        }
Beispiel #2
0
        private void BoardAutoSuggestBox_TextChanged(AutoSuggestBox sender, AutoSuggestBoxTextChangedEventArgs args)
        {
            if (args.Reason == AutoSuggestionBoxTextChangeReason.UserInput)
            {
                if (searching)
                {
                    return;
                }

                if (BoardAutoSuggestBox.Text.Length == 0)
                {
                    RelatedTable.Clear();
                    BoardAutoSuggestBox.ItemsSource = null;
                    return;
                }

                if (!AcceptString(BoardAutoSuggestBox.Text))
                {
                    return;
                }

                searching = true;

                RelatedTable.Clear();
                BoardAutoSuggestBox.ItemsSource = null;

                LiPTT.PttEventEchoed += SearchBoard;
                LiPTT.SendMessage('s', BoardAutoSuggestBox.Text, 0x20);
            }
        }
Beispiel #3
0
 private void OnPropertyChanged([CallerMemberName] String propertyName = "")
 {
     var action = LiPTT.RunInUIThread(() =>
     {
         PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
     });
 }
Beispiel #4
0
        private void ClearSearch()
        {
            string lastText = "";
            var    msg      = LiPTT.Screen.ToString(1, 34, 20).Trim();
            Regex  regex    = new Regex(@"([\w-_]+)");
            Match  match    = regex.Match(msg);

            if (match.Success)
            {
                lastText = msg.Substring(match.Index, match.Length);
            }
            else
            {
                return;
            }

            byte[] back = new byte[lastText.Length + 1];
            back[lastText.Length] = 0x0D;
            for (int i = 0; i < lastText.Length; i++)
            {
                back[i] = 0x08;
            }
            LiPTT.SendMessage(back);

            searching = false;
        }
Beispiel #5
0
        private void MyType_PropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            NotifyCollectionChangedEventArgs args = new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Replace, sender, sender, IndexOf((Article)sender));

            var t = LiPTT.RunInUIThread(() =>
            {
                OnCollectionChanged(args);
            });
        }
Beispiel #6
0
 private void Enter()
 {
     start        = false;
     LiPTT.IsExit = false;
     SaveUserAccount(UserText.Text, PasswordText.Password);
     enterAlreadyLogin     = enterWrongLog = enteruser = enterpswd = false;
     LiPTT.PttEventEchoed += EnterAccount;
     LiPTT.TryConnect();
 }
        private void DialogOpen_PttEventEchoed(PTTClient sender, LiPttEventArgs e)
        {
            var x = LiPTT.Screen.ToStringArray();

            if (e.State == PttState.EchoType)
            {
                LiPTT.PttEventEchoed -= DialogOpen_PttEventEchoed;
                LiPTT.Send(new byte[] { 0x0D, 0x0D });
            }
        }
Beispiel #8
0
        /// <summary>
        /// 在應用程式暫停執行時叫用。應用程式狀態會儲存起來,
        /// 但不知道應用程式即將結束或繼續,而且仍將記憶體
        /// 的內容保持不變。
        /// </summary>
        /// <param name="sender">暫停之要求的來源。</param>
        /// <param name="e">有關暫停之要求的詳細資料。</param>
        private void OnSuspending(object sender, SuspendingEventArgs e)
        {
            LiPTT.ReleaseInstance();

            DirectXFactory.ReleaseIndependentResource();

            var deferral = e.SuspendingOperation.GetDeferral();

            //TODO: 儲存應用程式狀態,並停止任何背景活動
            deferral.Complete();
        }
Beispiel #9
0
        private void PttUpdated(PTTClient sender, LiPttEventArgs e)
        {
            LiPTT.PttEventEchoed -= PttUpdated;

            if (e.State == PttState.Board)
            {
                var action = LiPTT.RunInUIThread(() =>
                {
                    Parse();
                    sem.Release();
                });
            }
        }
Beispiel #10
0
 private void Exit_echoed(PTTClient sender, LiPttEventArgs e)
 {
     if (e.State == PttState.Exit)
     {
         LiPTT.SendMessage('y', 0x0D);
     }
     else if (e.State == PttState.PressAny)
     {
         LiPTT.PttEventEchoed -= Exit_echoed;
         LiPTT.RemoveHandlerStateChecker();
         LiPTT.PressAnyKey();
         LiPTT.Client.Disconnected += GoToLogin;
     }
 }
Beispiel #11
0
        private void PttEventEchoed_UpdateArticleTag(PTTClient client, LiPttEventArgs e)
        {
            if (e.State == PttState.Board)
            {
                LiPTT.PttEventEchoed -= PttEventEchoed_UpdateArticleTag;

                ReLoadArticleTag(client.Screen);
                LiPTT.PageEnd();
                //LiPTT.SendMessage(LiPTT.ArticleCollection.CurrentIndex.ToString(), 0x0D);
                var action = LiPTT.RunInUIThread(() =>
                {
                    LiPTT.Frame.Navigate(typeof(BoardPage));
                });
            }
        }
Beispiel #12
0
        private void GridView_ItemClick(object sender, ItemClickEventArgs e)
        {
            if (ItemClick)
            {
                return;
            }

            ItemClick      = true;
            ControlVisible = Visibility.Collapsed;

            if (e.ClickedItem is MyKeyValuePair kv)
            {
                LiPTT.PttEventEchoed += GoToBoard;
                LiPTT.SendMessage('s', kv.Value, 0x0D);
            }
        }
Beispiel #13
0
        //進入文章
        private void ArticleList_ItemClick(object sender, ItemClickEventArgs e)
        {
            Article article = e.ClickedItem as Article;

            if (article.Deleted)
            {
                return;
            }

            LiPTT.CurrentArticle = article;
            LiPTT.CacheBoard     = true;

            if (article.AID is string s && s.Length > 0)
            {
                LiPTT.SendMessage(article.AID, 0x0D);
            }
Beispiel #14
0
        /// <summary>
        /// 在應用程式由終端使用者正常啟動時叫用。當啟動應用
        /// 將在例如啟動應用程式時使用以開啟特定檔案。
        /// </summary>
        /// <param name="e">關於啟動要求和處理序的詳細資料。</param>
        protected override void OnLaunched(LaunchActivatedEventArgs e)
        {
            Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);

            DirectXFactory.CreateIndependentResource();
            LiPTT.CreateInstance();
            LiPTT.ImageCache = new ImageCache();

            Frame rootFrame = Window.Current.Content as Frame;

            Application.Current.Resources["SystemControlHighlightListAccentLowBrush"]    = new SolidColorBrush(Windows.UI.Colors.Black);
            Application.Current.Resources["SystemControlHighlightListAccentMediumBrush"] = Application.Current.Resources["SystemControlHighlightListLowBrush"];
            Application.Current.Resources["SystemControlHighlightListAccentHighBrush"]   = Application.Current.Resources["SystemControlHighlightListLowBrush"];

            // 當視窗中已有內容時,不重複應用程式初始化,
            // 只確定視窗是作用中
            if (rootFrame == null)
            {
                // 建立框架做為巡覽內容,並巡覽至第一頁
                rootFrame = new Frame();

                rootFrame.NavigationFailed += OnNavigationFailed;

                if (e.PreviousExecutionState == ApplicationExecutionState.Terminated)
                {
                    //TODO: 從之前暫停的應用程式載入狀態
                }

                // 將框架放在目前視窗中
                Window.Current.Content = rootFrame;
            }

            if (e.PrelaunchActivated == false)
            {
                if (rootFrame.Content == null)
                {
                    // 在巡覽堆疊未還原時,巡覽至第一頁,
                    // 設定新的頁面,方式是透過傳遞必要資訊做為巡覽
                    // 參數
                    rootFrame.Navigate(typeof(MainPage), e.Arguments);
                }
                // 確定目前視窗是作用中
                Window.Current.Activate();
            }
        }
Beispiel #15
0
        private void ReLoadArticleTag(ScreenBuffer screen)
        {
            if (LiPTT.CurrentArticle.ID != int.MaxValue)
            {
                Article article = LiPTT.ArticleCollection.Single(i => i.AID == LiPTT.CurrentArticle.AID);
            }
            else //置底文
            {
                Article article = LiPTT.ArticleCollection.Single(i => (i.ID == int.MaxValue) && (i.Star == LiPTT.CurrentArticle.Star));
            }

            if (article != null)
            {
                var act = Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => {
                    article.State = LiPTT.GetReadSate((char)screen.CurrentBlocks[8].Content);
                });
            }
        }
Beispiel #16
0
        private void Exit()
        {
            LiPTT.PttEventEchoed -= Updated;

            if (LiPTT.IsExit == false)
            {
                LiPTT.IsExit          = true;
                LiPTT.PttEventEchoed += Exit_echoed;

                if (pivot.SelectedIndex == 1)
                {
                    LiPTT.SendMessage(0x71, 0x47, 0x0D);
                }
                else
                {
                    LiPTT.SendMessage(0x47, 0x0D);
                }
            }
        }
Beispiel #17
0
        protected override async void OnNavigatedTo(NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);

            ControlVisible = false;
            RingActive     = true;
            //冷靜一下,先喝杯咖啡
            await Task.Delay(50);

            article = LiPTT.CurrentArticle;

            ContentCollection.BeginLoaded += (a, b) =>
            {
                if (ArticleListView.Items.Count > 0)
                {
                    ArticleListView.ScrollIntoView(ArticleListView.Items[0]);
                }
                Window.Current.CoreWindow.PointerPressed += ArticlePage_PointerPressed;
                Window.Current.CoreWindow.KeyDown        += CoreWindow_KeyDown;
                RingActive = false;
            };

            ContentCollection.BugAlarmed += (a, b) => {
                var act = Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => {
                    FlyoutBase.ShowAttachedFlyout(RingGrid);
                });

                ThreadPoolTimer.CreateTimer((timer) => {
                    var acti = Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => {
                        FlyoutBase.GetAttachedFlyout(RingGrid).Hide();
                    });
                }, TimeSpan.FromMilliseconds(2000));
            };

            ContentCollection.FullScreenEntered += EnterFullScreen;
            ContentCollection.FullScreenExited  += ExitFullScreen;
            LoadingExtraData = false;
            pressAny         = false;

            LiPTT.PttEventEchoed += ReadAIDandExtra;
            LiPTT.Right();
        }
Beispiel #18
0
 private void ReadAIDandExtra(PTTClient client, LiPttEventArgs e)
 {
     if (e.State == PttState.Article && !LoadingExtraData)
     {
         LoadingExtraData = true;
         LiPTT.SendMessage('Q');
     }
     else if (!pressAny && e.State == PttState.AID && LoadingExtraData)
     {
         pressAny = true;
         ReadExtraData(client.Screen, (int)e.Others);
         LiPTT.PressAnyKey();
     }
     else if (e.State == PttState.Board && LoadingExtraData)
     {
         LiPTT.PttEventEchoed -= ReadAIDandExtra;
         LiPTT.PttEventEchoed += BrowseArticle;
         LiPTT.Right();
     }
 }
Beispiel #19
0
        private void PasswordText_KeyDown(object sender, KeyRoutedEventArgs e)
        {
            if (e.Key == VirtualKey.Enter && UserText.Text.Length >= 0)
            {
                var action = LiPTT.RunInUIThread(() =>
                {
                    UserText.IsEnabled     = false;
                    PasswordText.IsEnabled = false;
                    MemoAcount.IsEnabled   = false;
                    AutoLogin.IsEnabled    = false;
                });


                e.Handled = true;
                FocusManager.TryMoveFocus(FocusNavigationDirection.Next);
                FocusManager.TryMoveFocus(FocusNavigationDirection.Next);
                FocusManager.TryMoveFocus(FocusNavigationDirection.Next);
                Enter();
            }
        }
Beispiel #20
0
        private void ReadBoardInfomation()
        {
            if (LiPTT.State == PttState.Board)
            {
                string str   = LiPTT.Screen.ToString(2);
                Regex  regex = new Regex(@"\d+");
                Match  match = regex.Match(str);

                if (match.Success)
                {
                    int popu  = Convert.ToInt32(str.Substring(match.Index, match.Length));
                    var Board = CurrentBoard;
                    CurrentBoard.Popularity = popu;
                    NotifyPropertyChanged("CurrentBoard");
                }
            }

            LiPTT.PttEventEchoed += ReadBoardInfo;
            LiPTT.PressI();
        }
Beispiel #21
0
        private void GoBack()
        {
            if (!control_visible &&
                !ContentCollection.InitialLoaded &&
                ContentCollection.Loading &&
                ContentCollection.VideoRun == 0 &&
                LiPTT.Frame.CurrentSourcePageType != typeof(ArticlePage))
            {
                return;
            }

            if (back)
            {
                return;
            }
            back = true;
            StopVideo();
            LiPTT.PttEventEchoed += PttEventEchoed_UpdateArticleTag;
            LiPTT.Left();
        }
Beispiel #22
0
        private async Task <LoadMoreItemsResult> InnerLoadMoreItemsAsync(uint count)
        {
            if (InitialLoaded)
            {
                await Task.Run(() => {
                    LiPTT.PttEventEchoed += PttUpdated;
                    LiPTT.SendMessage(CurrentIndex.ToString(), 0x0D);
                });

                await sem.WaitAsync();

                return(new LoadMoreItemsResult {
                    Count = CurrentIndex
                });
            }
            else
            {
                return(new LoadMoreItemsResult {
                    Count = 0
                });
            }
        }
Beispiel #23
0
        private void BoardAutoSuggestBox_QuerySubmitted(AutoSuggestBox sender, AutoSuggestBoxQuerySubmittedEventArgs args)
        {
            if (args.QueryText == "")
            {
                return;
            }

            if (args.ChosenSuggestion is string chosen)
            {
                LiPTT.PttEventEchoed += GoToBoard;
                LiPTT.SendMessage('s', chosen, 0x0D);
            }
            else if (RelatedTable.Count > 0 && RelatedTable.First() == args.QueryText)
            {
                LiPTT.PttEventEchoed += GoToBoard;
                LiPTT.SendMessage('s', args.QueryText, 0x0D);
            }
            else if (RelatedTable.Count > 0)
            {
                BoardAutoSuggestBox.Text = RelatedTable.First();
            }
        }
Beispiel #24
0
        private void GoToBoard(PTTClient sender, LiPttEventArgs e)
        {
            switch (e.State)
            {
            case PttState.PressAny:
                if (!pressAny)
                {
                    pressAny = true;
                    LiPTT.PressAnyKey();
                }

                break;

            case PttState.Board:
                LiPTT.PageEnd();
                LiPTT.PttEventEchoed -= GoToBoard;
                var t = LiPTT.RunInUIThread(() => {
                    LiPTT.Frame.Navigate(typeof(BoardPage));
                });
                break;
            }
        }
Beispiel #25
0
        private void PanelKeyDown(CoreWindow sender, KeyEventArgs e)
        {
            bool Control_Down = (Window.Current.CoreWindow.GetKeyState(VirtualKey.Control) & CoreVirtualKeyStates.Down) != 0;
            bool Shift_Down   = (Window.Current.CoreWindow.GetKeyState(VirtualKey.Shift) & CoreVirtualKeyStates.Down) != 0;
            //bool Alt_Down; //Dispatcher.AcceleratorKeyActivated instead, it handles Alt key.

            bool CapsLocked = (Window.Current.CoreWindow.GetKeyState(VirtualKey.CapitalLock) & CoreVirtualKeyStates.Locked) != 0;

            int key = (int)e.VirtualKey;

            if (e.VirtualKey == VirtualKey.Enter)
            {
                LiPTT.Send(new byte[] { (byte)'\r' });
                return;
            }

            if (!Control_Down && !Shift_Down)
            {
                if (IsDigit(key))
                {
                    LiPTT.Send(new byte[] { (byte)key });
                }
                else if (IsUpperCase(key))
                {
                    if (CapsLocked)
                    {
                        LiPTT.Send(new byte[] { (byte)(key) }); //A-Z
                    }
                    else
                    {
                        LiPTT.Send(new byte[] { (byte)(key + 0x20) }); //a-z
                    }
                }
                else
                {
                    switch (key)
                    {
                    case 0xBA:     // ';:'
                        LiPTT.Send(new byte[] { (byte)';' });
                        break;

                    case 0xBB:     // '=+'
                        LiPTT.Send(new byte[] { (byte)'=' });
                        break;

                    case 0xBC:     // ',<'
                        LiPTT.Send(new byte[] { (byte)',' });
                        break;

                    case 0xBD:     // '-_'
                        LiPTT.Send(new byte[] { (byte)'-' });
                        break;

                    case 0xBE:     // '.>'
                        LiPTT.Send(new byte[] { (byte)'.' });
                        break;

                    case 0xBF:     // '/?'
                        LiPTT.Send(new byte[] { (byte)'/' });
                        break;

                    default:
                        //其他特殊鍵位
                        switch (e.VirtualKey)
                        {
                        case VirtualKey.Up:
                            LiPTT.Send(new byte[] { (byte)0x1B, (byte)'[', (byte)'A' });
                            break;

                        case VirtualKey.Down:
                            LiPTT.Send(new byte[] { (byte)0x1B, (byte)'[', (byte)'B' });
                            break;

                        case VirtualKey.Right:
                            LiPTT.Send(new byte[] { (byte)0x1B, (byte)'[', (byte)'C' });
                            break;

                        case VirtualKey.Left:
                            LiPTT.Send(new byte[] { (byte)0x1B, (byte)'[', (byte)'D' });
                            break;

                        case VirtualKey.Escape:
                            LiPTT.Send(new byte[] { (byte)0x1B, (byte)'[', (byte)'D' });
                            break;

                        case VirtualKey.Space:
                            LiPTT.Send(new byte[] { (byte)' ' });
                            break;

                        case VirtualKey.Back:
                            LiPTT.Send(new byte[] { (byte)0x08 });
                            break;

                        case VirtualKey.PageUp:
                            LiPTT.Send(new byte[] { (byte)0x02 });
                            break;

                        case VirtualKey.PageDown:
                            LiPTT.Send(new byte[] { (byte)0x06 });
                            break;

                        case VirtualKey.Insert:
                            break;

                        case VirtualKey.Home:
                            LiPTT.Send(new byte[] { (byte)'0', (byte)'\r' });
                            break;

                        case VirtualKey.End:
                            LiPTT.Send(new byte[] { (byte)'$' });
                            break;

                        default:
                            Debug.WriteLine("Not Implemented KeyDown 0x{0:X2} {1} {2}", key, Control_Down, Shift_Down);
                            break;
                        }
                        break;
                    }
                }
            }
            else if (!Control_Down && Shift_Down)
            {
                if (IsDigit(key))
                {
                    switch (e.VirtualKey)
                    {
                    case VirtualKey.Number1:
                        LiPTT.Send(new byte[] { (byte)'!' });
                        break;

                    case VirtualKey.Number2:
                        LiPTT.Send(new byte[] { (byte)'@' });
                        break;

                    case VirtualKey.Number3:
                        LiPTT.Send(new byte[] { (byte)'#' });
                        break;

                    case VirtualKey.Number4:
                        LiPTT.Send(new byte[] { (byte)'$' });
                        break;

                    case VirtualKey.Number5:
                        LiPTT.Send(new byte[] { (byte)'%' });
                        break;

                    case VirtualKey.Number6:
                        LiPTT.Send(new byte[] { (byte)'^' });
                        break;

                    case VirtualKey.Number7:
                        LiPTT.Send(new byte[] { (byte)'&' });
                        break;

                    case VirtualKey.Number8:
                        LiPTT.Send(new byte[] { (byte)'*' });
                        break;

                    case VirtualKey.Number9:
                        LiPTT.Send(new byte[] { (byte)'(' });
                        break;

                    case VirtualKey.Number0:
                        LiPTT.Send(new byte[] { (byte)')' });
                        break;

                    default:
                        break;
                    }
                }
                else if (IsUpperCase(key))
                {
                    if (CapsLocked)
                    {
                        LiPTT.Send(new byte[] { (byte)(key + 0x20) }); //a-z
                    }
                    else
                    {
                        LiPTT.Send(new byte[] { (byte)(key) }); //A-Z
                    }
                }
                else
                {
                    switch (key)
                    {
                    case 0xBA:     // ';:'
                        LiPTT.Send(new byte[] { (byte)':' });
                        break;

                    case 0xBB:     // '=+'
                        LiPTT.Send(new byte[] { (byte)'+' });
                        break;

                    case 0xBC:     // ',<'
                        LiPTT.Send(new byte[] { (byte)'<' });
                        break;

                    case 0xBD:     // '-_'
                        LiPTT.Send(new byte[] { (byte)'_' });
                        break;

                    case 0xBE:     // '.>'
                        LiPTT.Send(new byte[] { (byte)'>' });
                        break;

                    case 0xBF:     // '/?'
                        LiPTT.Send(new byte[] { (byte)'?' });
                        break;

                    default:
                        Debug.WriteLine("Not Implemented KeyDown 0x{0:X2} {1} {2}", key, Control_Down, Shift_Down);
                        break;
                    }
                }
            }
            else if (Control_Down && !Shift_Down)
            {
                if (IsUpperCase(key))
                {
                    LiPTT.Send(new byte[] { (byte)(key - 0x40) });
                }
                else if (IsDigit(key))
                {
                    Debug.WriteLine("Not Implemented KeyDown 0x{0:X2} {1} {2}", key, Control_Down, Shift_Down);
                }
                else
                {
                    switch (key)
                    {
                    default:
                        Debug.WriteLine("Not Implemented KeyDown 0x{0:X2} {1} {2}", key, Control_Down, Shift_Down);
                        break;
                    }
                }
            }
            else
            {
                Debug.WriteLine("Not Implemented KeyDown 0x{0:X2} {1} {2}", key, Control_Down, Shift_Down);
            }
        }
Beispiel #26
0
 private void App_Resuming(object sender, object e)
 {
     DirectXFactory.CreateIndependentResource();
     LiPTT.CreateInstance();
     LiPTT.ImageCache = new ImageCache();
 }
Beispiel #27
0
        public void Parse()
        {
            Regex        regex;
            Match        match;
            string       str;
            uint         id     = 0;
            ScreenBuffer screen = LiPTT.Screen;

            var x = screen.ToStringArray();

            /////////////////////////////
            ///置底文 and 其他文章
            ///
            for (int i = 22; i >= 3; i--)
            {
                Article article = new Article();

                //ID流水號
                str = screen.ToString(i, 0, 8);
                if (str.IndexOf('★') != -1)
                {
                    article.ID   = uint.MaxValue;
                    article.Star = StarCount++;
                }
                else
                {
                    regex = new Regex(@"(\d+)");
                    match = regex.Match(str);

                    if (match.Success)
                    {
                        id         = Convert.ToUInt32(str.Substring(match.Index, match.Length));
                        article.ID = id;

                        if (id > CurrentIndex)
                        {
                            continue;
                        }

                        if (id != CurrentIndex && CurrentIndex != uint.MaxValue) //id 被游標遮住
                        {
                            article.ID = CurrentIndex;
                        }

                        CurrentIndex = article.ID - 1;
                    }
                }

                //推文數
                str = screen.ToString(i, 9, 2);

                if (str[0] == '爆')
                {
                    article.Like = 100;
                }
                else if (str[0] == 'X')
                {
                    if (str[1] == 'X')
                    {
                        article.Like = -100;
                    }
                    else
                    {
                        article.Like = Convert.ToInt32(str[1].ToString());
                        article.Like = -article.Like * 10;
                    }
                }
                else
                {
                    regex = new Regex(@"(\d+)");
                    match = regex.Match(str);
                    if (match.Success)
                    {
                        article.Like = Convert.ToInt32(str.Substring(match.Index, match.Length));
                    }
                    else
                    {
                        article.Like = 0;
                    }
                }

                //未讀、已讀、M文 等等等
                article.State = LiPTT.GetReadSate((char)screen[i][8].Content);

                //文章日期
                str = screen.ToString(i, 11, 5);
                try
                {
                    article.Date = DateTimeOffset.Parse(str);
                }
                catch
                {
                    continue;
                }

                //作者
                str   = screen.ToString(i, 17, 13).Replace('\0', ' ');
                regex = new Regex(@"[\w\S]+");
                match = regex.Match(str);
                if (match.Success)
                {
                    article.Author = str.Substring(match.Index, match.Length);
                }

                //文章類型
                str = screen.ToString(i, 30, 2).Replace('\0', ' ');
                if (str.StartsWith("R:"))
                {
                    article.Type = ArticleType.回覆;
                }
                else if (str.StartsWith("□"))
                {
                    article.Type = ArticleType.一般;
                }
                else if (str.StartsWith("轉"))
                {
                    article.Type = ArticleType.轉文;
                }
                else
                {
                    article.Type = ArticleType.無;
                }
                //是否被刪除
                if (article.Author == "-")
                {
                    article.Deleted = true;
                }
                else
                {
                    article.Deleted = false;
                }

                str = screen.ToString(i, 30, screen.Width - 30).Replace('\0', ' ');

                if (article.Deleted)
                {
                    article.Title = str;
                    regex         = new Regex(LiPTT.bracket_regex);
                    match         = regex.Match(str);
                    string s = str.Substring(1);
                    if (match.Success)
                    {
                        article.Author = str.Substring(match.Index + 1, match.Length - 2);
                        s = s.Replace(match.ToString(), "");
                    }
                    article.Title = s;
                    article.Type  = ArticleType.無;
                }
                else
                {
                    //標題, 分類
                    regex = new Regex(LiPTT.bracket_regex);
                    match = regex.Match(str);
                    if (match.Success)
                    {
                        article.Category = str.Substring(match.Index + 1, match.Length - 2).Trim();
                        str = str.Substring(match.Index + match.Length);
                        int k = 0;
                        while (k < str.Length && str[k] == ' ')
                        {
                            k++;
                        }
                        int j = str.Length - 1;
                        while (j >= 0 && str[j] == ' ')
                        {
                            j--;
                        }
                        if (k <= j)
                        {
                            article.Title = str.Substring(k, j - k + 1);
                        }
                    }
                    else
                    {
                        article.Title = str.Substring(2);
                    }
                }

                Add(article);
            }

            CurrentIndex = id - 1;

            if (CurrentIndex > 0)
            {
                more = true;
            }
            else
            {
                more = false;
            }
        }
Beispiel #28
0
        private void SearchBoard(PTTClient sender, LiPttEventArgs e)
        {
            Regex        regex = new Regex(@"([\w-_]+)");
            Match        match;
            ScreenBuffer screen = sender.Screen;

            switch (e.State)
            {
            case PttState.SearchBoard:
                LiPTT.PttEventEchoed -= SearchBoard;
                var msg = screen.ToString(1, 34, 20).Trim();

                match = regex.Match(msg);

                if (match.Success)
                {
                    string suggestion = msg.Substring(match.Index, match.Length);

                    var action = LiPTT.RunInUIThread(() =>
                    {
                        if (BoardAutoSuggestBox.Text.Length <= suggestion.Length)
                        {
                            RelatedTable.Add(suggestion);
                        }
                    });
                }

                ClearSearch();

                var a = LiPTT.RunInUIThread(() =>
                {
                    BoardAutoSuggestBox.ItemsSource = RelatedTable;
                });

                break;

            case PttState.RelatedBoard:

                for (int i = 3; i < 23; i++)
                {
                    string k = screen.ToString(i).Replace('\0', ' ');

                    match = regex.Match(k, 0);
                    if (match.Success)
                    {
                        RelatedTable.Add(k.Substring(match.Index, match.Length));
                    }

                    match = regex.Match(k, 22);
                    if (match.Success)
                    {
                        RelatedTable.Add(k.Substring(match.Index, match.Length));
                    }

                    match = regex.Match(k, 44);
                    if (match.Success)
                    {
                        RelatedTable.Add(k.Substring(match.Index, match.Length));
                    }
                }

                if (new Regex("按空白鍵可列出更多項目").Match(screen.ToString(23)).Success)
                {
                    LiPTT.PressSpace();
                }
                else
                {
                    LiPTT.PttEventEchoed -= SearchBoard;

                    RelatedTable.Sort();
                    ClearSearch();

                    var t = LiPTT.RunInUIThread(() =>
                    {
                        BoardAutoSuggestBox.ItemsSource = RelatedTable;
                    });
                }
                break;
            }
        }
Beispiel #29
0
        private void ReadBoardInfo(PTTClient client, LiPttEventArgs e)
        {
            ScreenBuffer screen = client.Screen;

            if (e.State == PttState.BoardInfomation)
            {
                LiPTT.PttEventEchoed -= ReadBoardInfo;

                var action = Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                {
                    var Board = CurrentBoard;

                    //看板名稱
                    string str  = screen.ToString(3);
                    Match match = new Regex(LiPTT.bracket_regex).Match(str);
                    if (match.Success)
                    {
                        Board.Name = str.Substring(match.Index + 1, match.Length - 2);
                        Board.Nick = LiPTT.GetBoardNick(Board.Name);
                    }

                    //看板分類 中文敘述
                    Board.Category    = screen.ToString(5, 15, 4);
                    Board.Description = client.Screen.ToString(5, 22, screen.Width - 22).Replace('\0', ' ').Trim();

                    //版主名單
                    str = screen.ToString(6, 15, screen.Width - 15).Replace('\0', ' ').Trim();
                    if (!new Regex(LiPTT.bound_regex).Match(str).Success) //(無)
                    {
                        Board.Leaders = str.Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries);
                    }

                    if (screen.ToString(7, 25, 4) == "公開")
                    {
                        Board.公開 = true;
                    }

                    if (screen.ToString(8, 12, 4) == "可以")
                    {
                        Board.可進入十大排行榜 = true;
                    }

                    if (screen.ToString(9, 5, 4) == "開放")
                    {
                        Board.開放非看板會員發文 = true;
                    }

                    if (screen.ToString(10, 5, 4) == "開放")
                    {
                        Board.開放回文 = true;
                    }

                    if (screen.ToString(11, 5, 4) == "開放")
                    {
                        Board.開放自刪 = true;
                    }

                    if (screen.ToString(12, 5, 4) == "開放")
                    {
                        Board.開放推文 = true;
                    }

                    if (screen.ToString(13, 5, 4) == "開放")
                    {
                        Board.開放噓文 = true;
                    }

                    if (screen.ToString(14, 5, 4) == "開放")
                    {
                        Board.開放快速連推 = true;
                    }

                    if (screen.ToString(15, 12, 4) == "自動")
                    {
                        Board.IPVisible = true;
                    }

                    if (screen.ToString(16, 12, 4) == "對齊")
                    {
                        Board.自動對齊 = true;
                    }

                    if (screen.ToString(17, 10, 2) == "可")
                    {
                        Board.板主可刪除違規文字 = true;
                    }

                    if (screen.ToString(18, 14, 2) == "會")
                    {
                        Board.轉文自動記錄 = true;
                    }

                    if (screen.ToString(19, 5, 2) == "已")
                    {
                        Board.冷靜模式 = true;
                    }

                    if (screen.ToString(20, 5, 4) == "允許")
                    {
                        Board.允許十八歲進入 = true;
                    }

                    //發文限制 - 登入次數
                    str   = screen.ToString(12);
                    match = new Regex(@"\d+").Match(str);
                    if (match.Success)
                    {
                        try
                        {
                            Board.LimitLogin = Convert.ToInt32(str.Substring(match.Index, match.Length));
                        }
                        catch { Debug.WriteLine(str.Substring(match.Index, match.Length)); }
                    }

                    //發文限制 - 退文篇數
                    str   = screen.ToString(13);
                    match = new Regex(@"\d+").Match(str);
                    if (match.Success)
                    {
                        try
                        {
                            Board.LimitReject = Convert.ToInt32(str.Substring(match.Index, match.Length));
                        }
                        catch { Debug.WriteLine(str.Substring(match.Index, match.Length)); }
                    }

                    if (LiPTT.CacheBoard)
                    {
                        ControlVisible = true;
                        Window.Current.CoreWindow.KeyDown        += CoreWindow_KeyDown;
                        Window.Current.CoreWindow.PointerPressed += Board_PointerPressed;
                    }
                    else
                    {
                        ContentCollection.Clear();
                        LiPTT.PttEventEchoed += InitBoard;
                    }

                    LiPTT.PressAnyKey();
                });
            }
        }
Beispiel #30
0
        private void EnterAccount(PTTClient sender, LiPttEventArgs e)
        {
            switch (e.State)
            {
            case PttState.Login:
                if (!enteruser)
                {
                    enteruser = true;
                    var action = LiPTT.RunInUIThread(() =>
                    {
                        LiPTT.UserName = UserText.Text;
                        LiPTT.EnterUserName();
                    });
                }
                break;

            case PttState.Password:
                if (!enterpswd)
                {
                    enterpswd = true;
                    var action = LiPTT.RunInUIThread(() =>
                    {
                        LiPTT.Password = PasswordText.Password;
                        LiPTT.EnterPassword();
                    });
                }

                break;

            case PttState.WrongPassword:
            {
                LiPTT.Client.Dispose();

                var action = LiPTT.RunInUIThread(() => {
                        UserText.IsEnabled     = true;
                        PasswordText.IsEnabled = true;
                        MemoAcount.IsEnabled   = true;
                        AutoLogin.IsEnabled    = true;
                    });
            }
            break;

            case PttState.AlreadyLogin:
                if (!enterAlreadyLogin)
                {
                    enterAlreadyLogin = true;
                    LiPTT.Yes();
                }
                break;

            case PttState.WrongLog:
                if (!enterWrongLog)
                {
                    enterWrongLog = true;
                    LiPTT.Yes();
                }
                break;

            case PttState.Accept:
            {
                LiPTT.Logined = true;
            }
            break;

            case PttState.Loginning:
                break;

            case PttState.Synchronizing:
                break;

            case PttState.LoginSoMany:
            {
                LiPTT.Client.Dispose();

                var action = LiPTT.RunInUIThread(() => {
                        UserText.IsEnabled     = true;
                        PasswordText.IsEnabled = true;
                        MemoAcount.IsEnabled   = true;
                        AutoLogin.IsEnabled    = true;
                    });
            }
            break;

            case PttState.OverLoading:
            {
                LiPTT.Client.Dispose();

                var action = LiPTT.RunInUIThread(() => {
                        UserText.IsEnabled     = true;
                        PasswordText.IsEnabled = true;
                        MemoAcount.IsEnabled   = true;
                        AutoLogin.IsEnabled    = true;
                    });
            }
            break;

            case PttState.ConnectFailedTCP:
            case PttState.ConnectFailedWebSocket:
            {
                var action = LiPTT.RunInUIThread(() => {
                        UserText.IsEnabled     = true;
                        PasswordText.IsEnabled = true;
                        MemoAcount.IsEnabled   = true;
                        AutoLogin.IsEnabled    = true;
                    });
            }
            break;

            case PttState.PressAny:
                LiPTT.PressAnyKey();
                break;

            case PttState.MainPage:
                LiPTT.PttEventEchoed -= EnterAccount;
                {
                    var action = LiPTT.RunInUIThread(() =>
                    {
                        LiPTT.Frame.Navigate(typeof(PTTPage));
                    });

                    action.AsTask().Wait();
                }
                break;
            }
        }