private async void BT_CompareFriends_Click(object sender, RoutedEventArgs e)
        {
            var ofd = new System.Windows.Forms.OpenFileDialog()
            {
                Filter = "Kakao Friend Data V2|*.kfd2",
                Title  = "친구 목록 불러오기"
            };

            if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                var    reader = new System.IO.StreamReader(ofd.FileName);
                string str    = reader.ReadToEnd();
                reader.Close();
                var                loadedFriends      = JsonConvert.DeserializeObject <List <string[]> >(str);
                StringBuilder      builder            = new StringBuilder("삭제된 친구 목록 : \n");
                int                count              = 0;
                int                countExpire        = 0;
                ProgressShowWindow progressShowWindow = new ProgressShowWindow();
                progressShowWindow.Show();
                progressShowWindow.Topmost = true;
                progressShowWindow.Title   = "삭제된 친구 조회";
                int progressCount = 0;
                foreach (string[] friendData in loadedFriends)
                {
                    try
                    {
                        KakaoRequestClass.notShowError = true;
                        var relationship = await KakaoRequestClass.GetProfileRelationship(friendData[1]);

                        KakaoRequestClass.notShowError = false;
                        if (!(relationship.relationship.Equals("F") || relationship.relationship.Equals("FE")))
                        {
                            KakaoRequestClass.notShowError = true;
                            var profile = await KakaoRequestClass.GetProfileFeed(friendData[1], null, true);

                            KakaoRequestClass.notShowError = false;
                            builder.Append(profile.profile.display_name);
                            builder.Append("(저장 당시 닉네임 : ");
                            builder.Append(friendData[2]);
                            builder.Append(") : ");
                            builder.Append(profile.profile.permalink);
                            builder.Append("\n");
                            count++;
                        }
                    }
                    catch (Exception) { countExpire++; }
                    progressCount++;
                    progressShowWindow.PB_Main.Value = ((double)progressCount / loadedFriends.Count) * 100.0;
                }
                Clipboard.SetDataObject(builder.ToString());
                progressShowWindow.isFinish = true;
                progressShowWindow.Close();
                MessageBox.Show($"삭제된 친구 목록이 클립보드에 복사되었습니다.\n삭제된 친구 수 : {count.ToString()}\n탈퇴한 친구 수 : {countExpire.ToString()}", "안내");
            }
        }
        private async void BT_BackupFriends_Click(object sender, RoutedEventArgs e)
        {
            StringBuilder      builder            = new StringBuilder();
            List <string[]>    ids                = new List <string[]>();
            var                friends            = JsonConvert.DeserializeObject <FriendData.Friends>(await KakaoRequestClass.GetFriendData());
            ProgressShowWindow progressShowWindow = new ProgressShowWindow();

            progressShowWindow.Show();
            progressShowWindow.Topmost = true;
            progressShowWindow.Title   = "친구 목록 백업중";
            int progressCount = 0;

            foreach (var friend in friends.profiles)
            {
                try
                {
                    KakaoRequestClass.notShowError = true;
                    var profile = await KakaoRequestClass.GetProfileFeed(friend.id, null, true);

                    KakaoRequestClass.notShowError = false;
                    builder.Append(profile.profile.display_name);
                    builder.Append(" : ");
                    builder.Append(profile.profile.permalink);
                    builder.Append("\n");
                    ids.Add(new string[] { profile.profile.permalink, profile.profile.id, profile.profile.display_name });
                }
                catch (Exception) { }
                progressCount++;
                progressShowWindow.PB_Main.Value = ((double)progressCount / friends.profiles.Count) * 100.0;
            }
            Clipboard.SetDataObject(builder.ToString());
            progressShowWindow.isFinish = true;
            progressShowWindow.Close();
            var sfd = new System.Windows.Forms.SaveFileDialog()
            {
                FileName = DateTime.Now.ToShortDateString() + ".kfd2",
                Filter   = "Kakao Friend Data V2|*.kfd2",
                Title    = "친구 목록 저장"
            };

            if (sfd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                var str    = JsonConvert.SerializeObject(ids);
                var writer = new System.IO.StreamWriter(sfd.FileName);
                writer.Write(str);
                writer.Close();
            }
            MessageBox.Show("클립보드에 친구 정보가 복사됐습니다.");
        }
示例#3
0
        private async void BT_Execute_Click(object sender, RoutedEventArgs e)
        {
            if (MessageBox.Show("작업을 실행하시겠습니까?\n이 작업은 되돌릴 수 없습니다!", "경고", MessageBoxButton.YesNo, MessageBoxImage.Warning) == MessageBoxResult.Yes)
            {
                SP_Progress.Visibility       = Visibility.Visible;
                BT_Execute.IsEnabled         = false;
                BT_Execute.Content           = "실행중..";
                CB_Task.IsEnabled            = false;
                CB_Target.IsEnabled          = false;
                CB_Range.IsEnabled           = false;
                CB_ExcludeFavorite.IsEnabled = false;

                TB_Progress.Text       = "준비중...";
                SP_Progress.Visibility = Visibility.Visible;
                PR_Main.IsActive       = true;

                List <CommentData.PostData> posts = new List <CommentData.PostData>();
                await Dispatcher.Invoke(async() =>
                {
                    if ((CB_Task.SelectedIndex == 1 || CB_Task.SelectedIndex == 2) && CB_Target.SelectedIndex == 5)
                    {
                        var bookmarkMain = await KakaoRequestClass.GetBookmark(MainWindow.UserProfile.id, null);
                        while (!isClosed)
                        {
                            foreach (var bookmark in bookmarkMain.bookmarks)
                            {
                                posts.Add(bookmark.activity);
                            }
                            TB_Progress.Text = $"게시글 조회 ({posts.Count})";
                            bookmarkMain     = await KakaoRequestClass.GetBookmark(MainWindow.UserProfile.id, bookmarkMain.bookmarks.Last().id);
                            if (bookmarkMain.bookmarks.Count == 0)
                            {
                                break;
                            }
                        }
                    }
                    else
                    {
                        var feeds = await KakaoRequestClass.GetProfileFeed(MainWindow.UserProfile.id, null);
                        while (!isClosed)
                        {
                            posts.AddRange(feeds.activities);
                            TB_Progress.Text = $"게시글 조회 ({posts.Count})";
                            feeds            = await KakaoRequestClass.GetProfileFeed(MainWindow.UserProfile.id, feeds.activities[feeds.activities.Count - 1].id);
                            if (feeds.activities.Count == 0)
                            {
                                break;
                            }
                        }
                    }
                    PR_Main.IsActive   = false;
                    PR_Main.Visibility = Visibility.Collapsed;

                    PB_Main.Visibility = Visibility.Visible;
                    if (!isClosed)
                    {
                        FeedLoop(posts);
                    }
                });
            }
        }
示例#4
0
        private async void BT_Confirm_Click(object sender, RoutedEventArgs e)
        {
            BT_Confirm.IsEnabled = false;
            if (MainWindow.IsLoggedIn && !MainWindow.IsOffline)
            {
                int deleted = 0;
                int counted = 0;
                var feed    = await KakaoRequestClass.GetProfileFeed(MainWindow.UserProfile.id, null);

                if (feed.activities.Count == 0)
                {
                    MessageBox.Show("삭제할 게시글이 존재하지 않습니다.");
                    BT_Confirm.IsEnabled = true;
                    return;
                }
                else
                {
                    if (MessageBox.Show("조건에 맞는 게시글을 전부 삭제하시겠습니까?\n이 작업은 되돌릴 수 없습니다!", "경고", MessageBoxButton.YesNo, MessageBoxImage.Warning) == MessageBoxResult.Yes)
                    {
                        CB_Category.IsEnabled  = false;
                        CB_Exclude.IsEnabled   = false;
                        CB_Include.IsEnabled   = false;
                        CB_Favorite.IsEnabled  = false;
                        TB_Filter.IsEnabled    = false;
                        SP_Progress.Visibility = Visibility.Visible;
                        TB_Progress.Text       = "삭제 준비중...";
                        try
                        {
                            MainWindow.IsLoggedIn = false;
                            async void Delete()
                            {
                                foreach (var activity in feed.activities)
                                {
                                    bool     willDelete = true;
                                    string[] shareIndex = { null, "A", "F", "P", "M" };
                                    if (CB_Category.SelectedIndex == 5)
                                    {
                                        if (!activity.blinded)
                                        {
                                            willDelete = false;
                                        }
                                    }
                                    else if (CB_Category.SelectedIndex > 0 && !activity.permission.Equals(shareIndex[CB_Category.SelectedIndex]))
                                    {
                                        willDelete = false;
                                    }
                                    if (CB_Include.IsChecked == true && !activity.content.Contains(TB_Filter.Text))
                                    {
                                        willDelete = false;
                                    }
                                    if (CB_Exclude.IsChecked == true && activity.content.Contains(TB_Filter.Text))
                                    {
                                        willDelete = false;
                                    }
                                    if (CB_Favorite.IsChecked == true && activity.pinned)
                                    {
                                        willDelete = false;
                                    }

                                    if (willDelete)
                                    {
                                        await Task.Delay(100);

                                        await KakaoRequestClass.DeletePost(activity.id);

                                        deleted++;
                                    }
                                    counted++;
                                    TB_Progress.Text = $"삭제된 게시글/전체 게시글 : {deleted}/{counted}";
                                    if (!activate)
                                    {
                                        break;
                                    }
                                }
                                if (!activate)
                                {
                                    MessageBox.Show("게시글 삭제가 취소됐습니다.", "안내");
                                    MainWindow.IsLoggedIn = true;
                                    await MainWindow.UpdateProfile();

                                    return;
                                }
                                feed = await KakaoRequestClass.GetProfileFeed(MainWindow.UserProfile.id, feed.activities[feed.activities.Count - 1].id);

                                if (feed != null && (feed.activities?.Count ?? 0) > 0)
                                {
                                    Delete();
                                }
                                else
                                {
                                    MessageBox.Show("삭제가 모두 완료됐습니다.", "안내");
                                    MainWindow.IsLoggedIn = true;
                                    await MainWindow.UpdateProfile();

                                    Close();
                                }
                            }
                            Delete();
                        } catch (Exception e2) { MessageBox.Show("작업 도중 알 수 없는 오류가 발생했습니다.\n" + e2.Message); }
                    }
                }
            }
        }
        public async Task RefreshTimeline(string from, bool isClear)
        {
            if (from == null)
            {
                lastOffset = -1;
            }
            BT_Refresh.IsEnabled = false;
            PR_Loading.IsActive  = true;
            TB_RefreshBT.Text    = "갱신중...";
            IC_Refresh.Kind      = MaterialDesignThemes.Wpf.PackIconKind.ProgressClock;

            List <CommentData.PostData> feeds;

            if (!isProfile)
            {
                TimeLineData.TimeLine feedData = await KakaoRequestClass.GetFeed(from);

                nextRequest = feedData.next_since;
                feeds       = feedData.feeds;
            }
            else
            {
                string from2 = from;
                if (showBookmarked)
                {
                    from2 = null;
                }
                var profile = await KakaoRequestClass.GetProfileFeed(profileID, from2);

                relationship = await KakaoRequestClass.GetProfileRelationship(profileID);

                if (profile.profile.bg_image_url != null)
                {
                    string imgUri = profile.profile.profile_video_url_square_small ?? profile.profile.profile_image_url2;
                    if (Properties.Settings.Default.GIFProfile && profile.profile.profile_video_url_square_small != null)
                    {
                        imgUri = profile.profile.profile_video_url_square_small;
                    }
                    GlobalHelper.AssignImage(IMG_Profile, imgUri);
                    GlobalHelper.AssignImage(IMG_ProfileBG, profile.profile.bg_image_url);
                    IMG_Profile.MouseLeftButtonDown   += GlobalHelper.SaveImageHandler;
                    IMG_ProfileBG.MouseLeftButtonDown += GlobalHelper.SaveImageHandler;

                    TB_Name.Text = profile.profile.display_name;

                    if (profile.profile.status_objects?.Count > 0)
                    {
                        TB_Desc.Text = profile.profile.status_objects?[0]?.message ?? "한줄 소개 없음";
                    }
                    else
                    {
                        TB_Desc.Text = "한줄 소개 없음";
                    }

                    TB_Desc2.Text  = profile.mutual_friend?.message ?? "함께 아는 친구 없음";
                    TB_Desc2.Text += "/ " + profile.profile.activity_count.ToString() + "개의 스토리";
                }
                GD_Favorite.Visibility = Visibility.Collapsed;
                if (relationship.relationship.Equals("F"))
                {
                    IC_Friend.Kind         = MaterialDesignThemes.Wpf.PackIconKind.AccountMinus;
                    IC_Friend.ToolTip      = "친구 삭제";
                    GD_Favorite.Visibility = Visibility.Visible;
                    if (profile.profile.is_favorite)
                    {
                        IC_Favorite.Fill = Brushes.OrangeRed;
                    }
                    else
                    {
                        IC_Favorite.Fill = Brushes.Gray;
                    }
                    MainWindow.SetClickObject(IC_Favorite);
                    ICP_Favorite.MouseEnter += (s, e) =>
                    {
                        Mouse.OverrideCursor = Cursors.Hand;
                        e.Handled            = true;
                    };
                    async void onMouseDown(object s, MouseButtonEventArgs e)
                    {
                        await KakaoRequestClass.FavoriteRequest(profile.profile.id, profile.profile.is_favorite);

                        await RefreshTimeline(null, true);

                        e.Handled = true;
                    }

                    IC_Favorite.MouseLeftButtonDown  += onMouseDown;
                    ICP_Favorite.MouseLeftButtonDown += onMouseDown;
                }
                else if (relationship.relationship.Equals("R"))
                {
                    IC_Friend.Kind    = MaterialDesignThemes.Wpf.PackIconKind.AccountRemove;
                    IC_Friend.ToolTip = "친구 신청 취소";
                }
                else if (relationship.relationship.Equals("C"))
                {
                    IC_Friend.Kind    = MaterialDesignThemes.Wpf.PackIconKind.AccountQuestionMark;
                    IC_Friend.ToolTip = "친구 신청 처리";
                }
                else if (relationship.relationship.Equals("N"))
                {
                    IC_Friend.Kind    = MaterialDesignThemes.Wpf.PackIconKind.AccountPlus;
                    IC_Friend.ToolTip = "친구 추가";
                }
                else
                {
                    IC_Friend.Visibility = Visibility.Collapsed;
                }

                BT_Write.Visibility = Visibility.Collapsed;
                if (profile.activities.Count > 15)
                {
                    nextRequest = profile.activities.Last().id;
                }

                if (MainWindow.UserProfile.id.Equals(profileID) && showBookmarked != true)
                {
                    Title         = "내 프로필";
                    TB_Desc2.Text = profile.profile.activity_count.ToString() + "개의 스토리";
                }
                else
                {
                    Title = profile.profile.display_name + "님의 프로필";
                }
                if (showBookmarked)
                {
                    Title = "관심글 조회";
                    var bookmarks = await KakaoRequestClass.GetBookmark(profileID, from);

                    var feedsNow = new List <CommentData.PostData>();
                    foreach (var bookmark in bookmarks.bookmarks)
                    {
                        if (bookmark.status == 0)
                        {
                            feedsNow.Add(bookmark.activity);
                        }
                    }
                    feeds       = feedsNow;
                    nextRequest = bookmarks.bookmarks.Last().id;
                }
                else
                {
                    feeds = profile.activities;
                }
            }

            if (isProfile && feeds.Count != 18)
            {
                scrollEnd = true;
            }

            if (isClear)
            {
                SP_Content.Children.Clear();
                SV_Content.ScrollToVerticalOffset(0);
            }
            foreach (var feed in feeds)
            {
                if (feed.verb.Equals("post") || feed.verb.Equals("share"))
                {
                    TimeLinePageControl tlp = GenerateTimeLinePageControl(feed);
                    SP_Content.Children.Add(tlp);
                    SP_Content.Children.Add(new Rectangle()
                    {
                        Height = 10,
                        Fill   = Brushes.Transparent
                    });
                }
                else if (feed.verb.Equals("bundled_feed"))
                {
                    try
                    {
                        if (feed.bundled_feed != null && feed.bundled_feed.type.Equals("share"))
                        {
                            CommentData.PostData feedNow = feed.bundled_feed.activities?[0];
                            if (feedNow != null)
                            {
                                feedNow.@object = feed.bundled_feed.original_activity;
                                TimeLinePageControl tlp = GenerateTimeLinePageControl(feedNow);
                                GlobalHelper.SetShareFriendsTB(tlp.TB_Title, feed.bundled_feed.title_decorators);
                                tlp.TB_Title.Visibility    = Visibility.Visible;
                                tlp.TB_TitleSep.Visibility = Visibility.Visible;
                                SP_Content.Children.Add(tlp);
                                SP_Content.Children.Add(new Rectangle()
                                {
                                    Height = 10,
                                    Fill   = Brushes.Transparent
                                });
                            }
                        }
                        else if (feed.bundled_feed != null && feed.bundled_feed.type.Equals("up"))
                        {
                            CommentData.PostData feedNow = feed.bundled_feed.original_activity;
                            if (feedNow != null)
                            {
                                TimeLinePageControl tlp = GenerateTimeLinePageControl(feedNow);
                                GlobalHelper.SetShareFriendsTB(tlp.TB_Title, feed.bundled_feed.title_decorators);
                                tlp.TB_Title.Visibility    = Visibility.Visible;
                                tlp.TB_TitleSep.Visibility = Visibility.Visible;
                                SP_Content.Children.Add(tlp);
                                SP_Content.Children.Add(new Rectangle()
                                {
                                    Height = 10,
                                    Fill   = Brushes.Transparent
                                });
                            }
                        }
                    }
                    catch (Exception) { }
                }
            }
            BT_Refresh.IsEnabled = true;
            TB_RefreshBT.Text    = "새로고침";
            IC_Refresh.Kind      = MaterialDesignThemes.Wpf.PackIconKind.Refresh;

            PR_Loading.IsActive = false;
            return;
        }