public static bool Add(int progid) { Model.Programme progInfo = new Model.Programme(progid); if (progInfo.SingleEpisode) { using (SQLiteCommand command = new SQLiteCommand("select downloads.epid from downloads, episodes where downloads.epid=episodes.epid and progid=@progid", FetchDbConn())) { command.Parameters.Add(new SQLiteParameter("progid", progid)); using (SQLiteMonDataReader reader = new SQLiteMonDataReader(command.ExecuteReader())) { if (reader.Read()) { // The one download for this programme is already in the downloads list return(false); } } } } ThreadPool.QueueUserWorkItem(delegate { AddAsync(progid); }); return(true); }
public static bool Add(int progid) { Model.Programme progInfo = new Model.Programme(progid); if (progInfo.SingleEpisode) { using (SQLiteCommand command = new SQLiteCommand("select downloads.epid from downloads, episodes where downloads.epid=episodes.epid and progid=@progid", FetchDbConn())) { command.Parameters.Add(new SQLiteParameter("progid", progid)); using (SQLiteMonDataReader reader = new SQLiteMonDataReader(command.ExecuteReader())) { if (reader.Read()) { // The one download for this programme is already in the downloads list return false; } } } } ThreadPool.QueueUserWorkItem(delegate { AddAsync(progid); }); return true; }
public static string FindFreeSaveFileName(string formatString, Model.Programme progInfo, Model.Episode epInfo, string baseSavePath) { string rootName = Path.Combine(baseSavePath, CreateSaveFileName(formatString, progInfo, epInfo)); string savePath = rootName; // Make sure the save folder exists (to support subfolders in the save file name template) string saveDir = Path.GetDirectoryName(savePath); Directory.CreateDirectory(saveDir); string currentFileName = null; // If the passed episode info is actually a download, get it's current path if (typeof(Download) == epInfo.GetType()) { currentFileName = ((Download)epInfo).DownloadPath; // Remove the extension from the current name if applicable if (currentFileName != null) { int extensionPos = currentFileName.LastIndexOf('.'); if (extensionPos > -1) { currentFileName = currentFileName.Substring(0, extensionPos); } } } int diffNum = 1; // Check for a pre-existing file with the same name (ignoring the current name for this file) while (Directory.GetFiles(saveDir, Path.GetFileName(savePath) + ".*").Length > 0 && savePath != currentFileName) { savePath = rootName + " (" + Convert.ToString(diffNum, CultureInfo.CurrentCulture) + ")"; diffNum += 1; } return(savePath); }
public static string CreateSaveFileName(string formatString, Model.Programme progInfo, Model.Episode epInfo) { if (string.IsNullOrEmpty(formatString)) { // The format string is an empty string, so the output must be an empty string return(string.Empty); } string fileName = formatString; // Convert %title% -> %epname% for backwards compatability fileName = fileName.Replace("%title%", "%epname%"); // Make variable substitutions fileName = fileName.Replace("%progname%", progInfo.Name); fileName = fileName.Replace("%epname%", epInfo.Name); fileName = fileName.Replace("%hour%", epInfo.Date.ToString("HH", CultureInfo.CurrentCulture)); fileName = fileName.Replace("%minute%", epInfo.Date.ToString("mm", CultureInfo.CurrentCulture)); fileName = fileName.Replace("%day%", epInfo.Date.ToString("dd", CultureInfo.CurrentCulture)); fileName = fileName.Replace("%month%", epInfo.Date.ToString("MM", CultureInfo.CurrentCulture)); fileName = fileName.Replace("%shortmonthname%", epInfo.Date.ToString("MMM", CultureInfo.CurrentCulture)); fileName = fileName.Replace("%monthname%", epInfo.Date.ToString("MMMM", CultureInfo.CurrentCulture)); fileName = fileName.Replace("%year%", epInfo.Date.ToString("yy", CultureInfo.CurrentCulture)); fileName = fileName.Replace("%longyear%", epInfo.Date.ToString("yyyy", CultureInfo.CurrentCulture)); // Replace invalid file name characters with spaces (except for directory separators // as this then allows the flexibility of storing the downloads in subdirectories) foreach (char removeChar in Path.GetInvalidFileNameChars()) { if (removeChar != Path.DirectorySeparatorChar) { fileName = fileName.Replace(removeChar, ' '); } } // Replace runs of spaces with a single space fileName = Regex.Replace(fileName, " {2,}", " "); return(fileName.Trim()); }
/// <summary> /// Initializes a new instance of the <see cref="ProgrammeInfo" /> class with the values /// contained in the specified Programme object. /// </summary> /// <param name="progInfo">Programme object specifying initial values.</param> internal ProgrammeInfo(Model.Programme progInfo) { this.Name = progInfo.Name; this.Description = progInfo.Description; this.SingleEpisode = progInfo.SingleEpisode; }