private void CatchUpOne() { Cursor.Current = Cursors.WaitCursor; try { Rss.RssFeed rssFeed = Utils.GetFeed(feedItem); if (rssFeed != null) { progressBar1.Maximum = rssFeed.Channels[0].Items.Count; progressBar1.Minimum = 0; int Start = Convert.ToInt32(numericValue.Value); for (int q = Start; q < rssFeed.Channels[0].Items.Count; q++) { progressBar1.Value = q; Rss.RssItem rssItem = rssFeed.Channels[0].Items[q]; if (Settings.Default.History[rssItem.GetHashCode().ToString()] == null) { HistoryItem historyItem = new HistoryItem(); historyItem.FeedGUID = feedItem.GUID; historyItem.Hashcode = rssItem.GetHashCode(); historyItem.Title = rssItem.Title; historyItem.ItemDate = rssItem.PubDate.ToString(); historyItem.FeedUrl = feedItem.Url; Settings.Default.History.Add(historyItem); } } } Cursor.Current = Cursors.Default; } catch (Exception ex) { log.Error("Error during catch-up", ex); Cursor.Current = Cursors.Default; MessageBox.Show(ex.Message, languages.FormStrings.ErrorDuringCatchUp, MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1); } }
/// <summary> /// Removes the specified item. /// </summary> /// <param name="item">The item.</param> public void Remove(HistoryItem item) { List.Remove(item); }
/// <summary> /// Adds an history item to the history list /// </summary> /// <param name="historyItem"></param> public void Add(HistoryItem historyItem) { List.Add(historyItem); // Settings.Default.Save(); }
/// <summary> /// Sets the item. /// </summary> /// <param name="Index">The index.</param> /// <param name="Item">The item.</param> private void setItem(int Index, HistoryItem Item) { List[Index] = Item; }
private DownloadPackage GetDownloadPackage(Rss.RssItem rssItem, FeedItem feedItem, string strDownloadlocation) { bool boolAcceptableFile = false; bool byteRanging = true; string strFilenameWithoutExt = null; string strFilenameExt = null; string strPath = null; DirectoryInfo dirInfo = null; FileInfo[] fileInfo = null; long longReturn = 0; //bool boolGuid = false; string strFilename = null; // new WebResponse response = null; // first try a HEAD call (less intrusive) if (feedItem.Authenticate == true) { string strPassword = EncDec.Decrypt(feedItem.Password, feedItem.Username); response = GetWebResponseObjectHEAD(rssItem.Enclosure.Url, feedItem.Username, strPassword); } else { response = GetWebResponseObjectHEAD(rssItem.Enclosure.Url, "", ""); } // the HEAD call didn't seem to work. We'll use a GET now if (response == null) { if (feedItem.Authenticate == true) { string strPassword = EncDec.Decrypt(feedItem.Password, feedItem.Username); response = GetWebResponseObjectGET(rssItem.Enclosure.Url, feedItem.Username, strPassword); } else { response = GetWebResponseObjectGET(rssItem.Enclosure.Url, "", ""); } } if (response != null) { long longDownloadsize = response.ContentLength; if (longDownloadsize == -1) { longDownloadsize = 1; } WebHeaderCollection responseHeaders = response.Headers; string[] strAcceptRange = responseHeaders.GetValues("Accept-Ranges"); if (strAcceptRange != null && strAcceptRange[0] == "none") { // no byte ranging byteRanging = false; } // check if there is content-disposition header string[] strContDisp = responseHeaders.GetValues("content-disposition"); string strAttachment = ""; string strHeader = ""; if (strContDisp != null && strContDisp.Length > 0) { for (int l = 0; l < strContDisp.Length; l++) { strHeader = strContDisp[l]; if (strHeader.ToLower().StartsWith("attachment")) { // attachment header strAttachment = strHeader.Substring(strHeader.ToLower().IndexOf("filename=") + 9); } } } if (strAttachment != "") { if (feedItem.UseTitleForFiles) { FileInfo f = new FileInfo(strAttachment); strPath = Utils.GetValidFileName(rssItem.Title + f.Extension); } else { strPath = strAttachment; strPath = Utils.GetValidFileName(strPath); } strFilename = strDownloadlocation + "\\" + strPath; if (strFilename.IndexOf(".") > 0) { FileInfo f = new FileInfo(strFilename); strFilenameWithoutExt = f.FullName.Substring(0, f.FullName.Length - f.Extension.Length); //strFilenameWithoutExt = strFilename.Substring(0, strFilename.LastIndexOf(".")); strFilenameExt = f.Extension.Substring(1); //strFilenameExt = strFilename.Substring(strFilename.LastIndexOf(".") + 1); } else { strFilenameWithoutExt = strFilename; strFilenameExt = ""; } } else { try { Uri uriEnclosure = new Uri(rssItem.Enclosure.Url); string strEnclosureUrl = uriEnclosure.GetLeftPart(UriPartial.Path); if (feedItem.UseTitleForFiles) { strPath = strEnclosureUrl.Substring(strEnclosureUrl.LastIndexOf("/") + 1); FileInfo f = new FileInfo(strPath); strPath = Utils.GetValidFileName(rssItem.Title + f.Extension); } else { strPath = strEnclosureUrl.Substring(strEnclosureUrl.LastIndexOf("/") + 1); } if (strPath == "") { // check the query strEnclosureUrl = uriEnclosure.GetLeftPart(UriPartial.Query); if (feedItem.UseTitleForFiles) { strPath = strEnclosureUrl.Substring(strEnclosureUrl.LastIndexOf("/") + 1); FileInfo f = new FileInfo(strPath); strPath = Utils.GetValidFileName(rssItem.Title + f.Extension); } else { strPath = strEnclosureUrl.Substring(strEnclosureUrl.LastIndexOf("/") + 1); } } // empty path? not good. Generate one //strPath = System.Web.HttpUtility.UrlDecode(strPath); strFilename = strDownloadlocation + "\\" + strPath; FileInfo fileInfo1 = new FileInfo(strFilename); strFilenameWithoutExt = fileInfo1.FullName.Substring(0, fileInfo1.FullName.Length - fileInfo1.Extension.Length); //strFilenameWithoutExt = strFilename.Substring(0, strFilename.LastIndexOf(".")); strFilenameExt = fileInfo1.Extension.Substring(1); //strFilenameExt = strFilename.Substring(strFilename.LastIndexOf(".") + 1); //strFilenameWithoutExt = strFilename.Substring(0, strFilename.LastIndexOf(".")); //strFilenameExt = strFilename.Substring(strFilename.LastIndexOf(".") + 1); } catch { strFilename = ""; strFilenameExt = ""; strFilenameWithoutExt = ""; boolAcceptableFile = false; } } if (Settings.Default.DefaultMediaAction == 0) { boolAcceptableFile = true; } else { foreach (string extension in Utils.AudioExtensions) { if (extension.ToUpper() == strFilenameExt.ToUpper()) { boolAcceptableFile = true; break; } } if (!boolAcceptableFile) { // check if it is a video file foreach (string extension in Utils.VideoExtensions) { if (extension.ToUpper() == strFilenameExt.ToUpper()) { boolAcceptableFile = true; break; } } } } if (boolAcceptableFile) { try { dirInfo = new System.IO.DirectoryInfo(strDownloadlocation); fileInfo = dirInfo.GetFiles(strPath); } catch (Exception fex) { if (Settings.Default.LogLevel > 0) { log.Error("Retriever", fex); } strFilenameExt = ""; } // check if the file is available on the filesystem bool boolContinue = true; if (fileInfo.Length > 0) { if ((fileInfo.Length > 0 && fileInfo[0].Length != longDownloadsize)) { // there is a file with the same name switch (Settings.Default.DuplicateAction) { case 1: strFilename = strFilenameWithoutExt + DateTime.Now.ToString("yyyyMMddTHHMMss") + "." + strFilenameExt; boolContinue = true; break; default: boolContinue = false; break; } } else if (fileInfo.Length > 0) { // add the item to the history HistoryItem historyItem = new HistoryItem(); historyItem.FeedGUID = feedItem.GUID; historyItem.FeedUrl = feedItem.Url; historyItem.Title = rssItem.Title; historyItem.Hashcode = rssItem.GetHashCode(); //historyItem.LocalFilename = fileInfo[0].FullName; historyItem.ItemDate = fileInfo[0].CreationTime.ToString("yyyy-MM-dd HH:MM:ss"); historyItem.FileName = fileInfo[0].Name; //historyItem.URL = enc.EnclosureURL; Settings.Default.History.Add(historyItem); boolContinue = false; } else { boolContinue = false; } } if (boolContinue) { // did the user specify a text filter on the item? if (feedItem.Textfilter != null && feedItem.Textfilter != "") { System.Text.RegularExpressions.Regex regEx = new System.Text.RegularExpressions.Regex(feedItem.Textfilter); if (regEx.Match(rssItem.Description).Success || regEx.Match(rssItem.Title).Success) { // if(rssItem.Description.ToUpper().IndexOf(feedItem.textFilter.ToUpper()) >= 0 || rssItem.Title.ToUpper().IndexOf(feedItem.textFilter.ToUpper()) >= 0) // { longReturn = longDownloadsize; } else if (rssItem.Description.ToUpper().IndexOf(feedItem.Textfilter.ToUpper()) >= 0 || rssItem.Title.ToUpper().IndexOf(feedItem.Textfilter.ToUpper()) >= 0) { longReturn = longDownloadsize; } } else { longReturn = longDownloadsize; } } } } DownloadPackage downloadPackage = new DownloadPackage(); downloadPackage.ByteRanging = byteRanging; downloadPackage.DownloadSize = longReturn; downloadPackage.strFilename = strFilename; return(downloadPackage); }