/// <summary> /// Initializes a new instance of the <see cref="EpisodeInfo" /> class with the values /// contained in the specified Episode object. /// </summary> /// <param name="epInfo">Episode object specifying initial values.</param> internal EpisodeInfo(Model.Episode epInfo) : this() { this.Name = epInfo.Name; this.Description = epInfo.Description; this.Date = epInfo.Date; this.Duration = epInfo.Duration; }
private void ProgressBtnClick(object sender, RoutedEventArgs e) { Model.Episode item = (Model.Episode)(sender as FrameworkElement).DataContext; Model.SubjectLarge subject = (Model.SubjectLarge)DataContext; int offset = subject.eps_offset; int index = (item.sort == "…") ? 0 : Convert.ToInt16(item.sort); SubjectContentCtrl.Content = subject_episodes; subject_episodes.EpisodeList.ScrollToVerticalOffset((index - offset) * 40); }
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()); }
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); }