示例#1
0
        /// <summary>
        /// Downloads the image completed.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="System.ComponentModel.AsyncCompletedEventArgs" /> instance containing the event data.</param>
        private void DownloadImageCompleted(object sender, AsyncCompletedEventArgs e)
        {
            var cacheObject = (CacheObject)this.EventTable[this.ImageLinkURL];

            if (e.Error == null)
            {
                ((CacheObject)this.EventTable[this.ImageLinkURL]).IsDownloaded = true;

                Application.DoEvents();

                CacheController.Instance().LastPic = cacheObject.FilePath;
            }
            else
            {
                // Delete empty files

                /*if (File.Exists(cacheObject.FilePath))
                 * {
                 *  File.Delete(cacheObject.FilePath);
                 * }*/
                ((CacheObject)this.EventTable[this.ImageLinkURL]).IsDownloaded = false;
            }

            this.RemoveThread();

            Application.DoEvents();

            this.WebClient.Dispose();
        }
示例#2
0
        /// <summary>
        /// Check the FilePath for Length because if its more then 260 characters long it will crash
        /// </summary>
        /// <param name="filePath">
        /// Folder Path to check
        /// </param>
        /// <returns>
        /// The check path length.
        /// </returns>
        public static string CheckPathLength(string filePath)
        {
            if (filePath.Length <= 260)
            {
                return(filePath);
            }

            var shortFilePath = filePath.Substring(filePath.LastIndexOf("\\", StringComparison.Ordinal) + 1);

            filePath = Path.Combine(CacheController.Instance().UserSettings.DownloadFolder, shortFilePath);

            return(filePath);
        }
示例#3
0
        /// <summary>
        /// Gets the Security Token for the Thank You Button
        /// </summary>
        /// <param name="pageUrl">URL of the Post</param>
        /// <returns>The Security Token</returns>
        public static string GetSecurityToken(Uri pageUrl)
        {
            var webClient = new WebClient();

            webClient.Headers.Add($"Referer: {pageUrl}");

            if (!CacheController.Instance().UserSettings.GuestMode)
            {
                webClient.Headers.Add($"Cookie: {CookieManager.GetInstance().GetCookieString()}");
            }

            return(GetSecurityToken(webClient.DownloadString(pageUrl)));
        }
示例#4
0
        /// <summary>
        /// Extract the Links
        /// </summary>
        /// <param name="page">
        /// The page.
        /// </param>
        /// <returns>
        /// All Anchors on the Page
        /// </returns>
        public static List <LinkItem> ListAllLinks(string page)
        {
            var linkList = new List <LinkItem>();

            if (CacheController.Instance().UserSettings.CurrentForumUrl.Contains(@"halohul.com"))
            {
                var hrefMatchNew = Regex.Matches(page, @"src=\""(.*?)\""", RegexOptions.IgnoreCase);

                linkList.AddRange(
                    hrefMatchNew.Cast <Match>().Select(match => new LinkItem {
                    Href = match.Groups[1].Value
                }));
            }
            else
            {
                var linkMatch = Regex.Matches(page, @"(<a.*?>.*?</a>)", RegexOptions.Multiline);

                foreach (Match match in linkMatch)
                {
                    var value = match.Groups[1].Value;
                    var item  = new LinkItem();

                    var hrefMatch = Regex.Match(value, @"href=\""(.*?)\""", RegexOptions.IgnoreCase);

                    if (hrefMatch.Success)
                    {
                        item.Href = hrefMatch.Groups[1].Value;
                    }

                    var thumbNailMatch = Regex.Match(value, @"src=\""(.*?)\""", RegexOptions.IgnoreCase);

                    if (!thumbNailMatch.Success)
                    {
                        continue;
                    }

                    item.Text = thumbNailMatch.Groups[1].Value;

                    linkList.Add(item);
                }
            }

            return(linkList);
        }
示例#5
0
        /// <summary>
        /// Gets the forum page as string.
        /// </summary>
        /// <param name="url">The URL.</param>
        /// <returns>
        /// The Page Content
        /// </returns>
        public static string GetForumPageAsString(string url)
        {
            string pageContent;

            try
            {
                var webClient = new WebClient();

                if (!CacheController.Instance().UserSettings.GuestMode)
                {
                    webClient.Headers.Add($"Cookie: {CookieManager.GetInstance().GetCookieString()}");
                }

                pageContent = webClient.DownloadString(url);

                webClient.Dispose();
            }
            catch (Exception)
            {
                pageContent = string.Empty;
            }

            return(pageContent);
        }