private void CtlWebBrowser_LoadCompleted(object sender, NavigationEventArgs e) { if (!e.Uri.Host.EndsWith("twitter.com")) { this.ctlWebBrowser.Navigate("https://mobile.twitter.com/login?redirect_after_login=https%3A%2F%2Ftwitter.com%2F"); return; } if (e.Uri.AbsolutePath == "/") { Task.Factory.StartNew(() => { lock (this.m_loginLock) { try { var cookie = NativeMethods.GetCookies(TwitterClient.TwitterUri).GetCookieHeader(TwitterClient.TwitterUri); this.TwitterClient = new TwitterClient(cookie); if (this.TwitterClient.VerifyCredentials()) { this.Dispatcher.Invoke(() => { this.DialogResult = true; this.Close(); }); return; } } catch { } } }); } }
protected override async void OnContentRendered(EventArgs e) { base.OnContentRendered(e); if (this.m_shown) { return; } this.m_shown = true; this.taskBarItemInfo.ProgressState = TaskbarItemProgressState.Paused; ////////////////////////////////////////////////// var obj = await Task.Factory.StartNew(LastRelease.CheckNewVersion); if (obj != null) { MessageBox.Show(this, "새 버전이 출시되었습니다.\n\n정상적인 작동을 위해 업데이트해주세요!", "Flackhole (관심글 청소기)", MessageBoxButton.OK, MessageBoxImage.Information); try { Process.Start(new ProcessStartInfo { FileName = obj.HtmlUrl, UseShellExecute = true }).Dispose(); } catch { } this.Close(); return; } var form = new Login { Owner = this }; if (!form.ShowDialog() ?? false) { this.Close(); return; } this.m_twitterClient = form.TwitterClient; this.m_mutex = new Mutex(true, MutexNamePrefix + form.TwitterClient.Id, out var muxteIsCreatedNew); if (!muxteIsCreatedNew) { MessageBox.Show(this, "이 계정은 이미 작업중입니다!\n\n로그인 한 아이디 : " + form.TwitterClient.ScreenName, "Flackhole (관심글 청소기)", MessageBoxButton.OK, MessageBoxImage.Error); this.Close(); return; } ////////////////////////////////////////////////// var dfd = new OpenFileDialog() { CheckFileExists = true, Filter = "like.js|like.js", }; if (!dfd.ShowDialog() ?? false) { this.Close(); return; } var lst = new List <FavObject>(); var r = await Task.Factory.StartNew(() => { try { using (var fs = File.OpenRead(dfd.FileName)) using (var rd = new StreamReader(fs)) { while (rd.Read() != '=') { ; } App.JsonSerializer.Populate(rd, lst); } return(true); } catch { return(false); } }); if (!r) { MessageBox.Show(this, "파일을 읽지 못하였습니다.", "Flackhole (관심글 청소기)", MessageBoxButton.OK, MessageBoxImage.Error); this.Close(); return; } this.m_favCount = lst.Count; ////////////////////////////////////////////////// var msgResult = MessageBox.Show( this, "삭제하기 전에 사진과 동영상을 저장할까요?", "Flackhole (관심글 청소기)", MessageBoxButton.YesNo, MessageBoxImage.Question, MessageBoxResult.Yes); if (msgResult != MessageBoxResult.Yes && msgResult != MessageBoxResult.No) { this.Close(); return; } var withDownload = msgResult == MessageBoxResult.Yes; if (!withDownload) { this.ctlSaveCapacity.TextDecorations = TextDecorations.Strikethrough; this.ctlSaveSucc.TextDecorations = TextDecorations.Strikethrough; this.ctlSaveFail.TextDecorations = TextDecorations.Strikethrough; } if (withDownload) { var sfd = new System.Windows.Forms.FolderBrowserDialog(); if (sfd.ShowDialog() != System.Windows.Forms.DialogResult.OK) { return; } this.m_baseDirectory = Path.Combine(@"\\?\" + sfd.SelectedPath, $"Flackhole {this.m_twitterClient.ScreenName}"); int i = 2; while (Directory.Exists(this.m_baseDirectory)) { this.m_baseDirectory = Path.Combine(@"\\?\" + sfd.SelectedPath, $"Flackhole {this.m_twitterClient.ScreenName} ({i++})"); } this.m_failDirectory = Path.Combine(this.m_baseDirectory, "[작업오류]"); try { Directory.CreateDirectory(this.m_baseDirectory); } catch (Exception) { MessageBox.Show(this, "저장할 폴더를 생성하지 못하였습니다.", "Flackhole (관심글 청소기)", MessageBoxButton.OK, MessageBoxImage.Error); this.Close(); return; } } ////////////////////////////////////////////////// this.taskBarItemInfo.ProgressState = TaskbarItemProgressState.Normal; this.m_startTime = DateTime.Now; this.ctlProgress.Value = 0; this.ctlProgress.Maximum = lst.Count; this.UpdateDefaultStyle(); _ = Task.Factory.StartNew(() => { while (true) { Thread.Sleep(TimeSpan.FromSeconds(1)); var dt = DateTime.Now - this.m_startTime; var str = string.Format("작업 시간 : {0:0}시간 {1:0}분 {2:0}초", dt.Hours, dt.Minutes, dt.Seconds); this.Dispatcher.Invoke(() => this.ctlTime.Text = str); } }); await Task.Factory.StartNew(() => { lst.Sort((a, b) => a.Like.TweetId.CompareTo(b.Like.TweetId)); if (withDownload) { foreach (var fav in lst) { if (!string.IsNullOrWhiteSpace(fav.Like.FullText) && regTCo.IsMatch(fav.Like.FullText)) { this.m_todoLookup.Push(fav); } else { this.m_todoDestory.Push(fav.Like.TweetId); } } } else { foreach (var fav in lst) { this.m_todoDestory.Push(fav.Like.TweetId); } } }); this.ctlStatus.Text = "작동중"; this.m_workerDestory = WorkerDestory; if (withDownload) { this.m_workerDownloader = WorkerDownloader; this.m_workerLookup = 1; } for (var i = 0; i < WorkerDestory; i++) { new Thread(this.ThreadDestroyer) { IsBackground = true, Priority = ThreadPriority.Lowest, }.Start(); } if (withDownload) { for (var i = 0; i < WorkerDownloader; i++) { new Thread(this.ThreadDownloader) { IsBackground = true, Priority = ThreadPriority.Lowest, }.Start(); } new Thread(this.ThreadLookup) { IsBackground = true, Priority = ThreadPriority.Lowest, }.Start(); } }