public void Clone(OrgFolder folder) { if (this.FolderPath != folder.FolderPath) { this.FolderPath = folder.FolderPath; } if (this.CopyFrom != folder.CopyFrom) { this.CopyFrom = folder.CopyFrom; } if (this.Recursive != folder.Recursive) { this.Recursive = folder.Recursive; } if (this.AllowDeleting != folder.AllowDeleting) { this.AllowDeleting = folder.AllowDeleting; } this.AutomaticallyDeleteEmptyFolders = folder.AutomaticallyDeleteEmptyFolders; this.ignoreFiles.Clear(); foreach (string ignrFile in folder.ignoreFiles) { this.ignoreFiles.Add(ignrFile); } if (this.Id != folder.Id) { this.Id = folder.Id; } }
public bool BuildFolderMoveItem(string folderPath, OrgFolder scanDir, out OrgItem item) { item = new OrgItem(folderPath, this, scanDir, true); if (!this.MoveFolder) { return(false); } string[] fileList = Directory.GetFiles(folderPath); foreach (string file in fileList) { OrgItem fileItem; if (this.BuildFileMoveItem(file, scanDir, out fileItem)) { return(true); } } string[] subDirs = Directory.GetDirectories(folderPath); foreach (string subDir in subDirs) { OrgItem subItem; if (this.BuildFolderMoveItem(subDir, scanDir, out subItem)) { return(true); } } return(false); }
/// <summary> /// Constructor for file from scan folder /// </summary> /// <param name="path">file's path</param> /// <param name="copy">whether file is allowed to be copied</param> /// <param name="allowDelete">whether file is allowed to be deleted</param> /// <param name="folder">scan folder file belongs to</param> public OrgPath(string path, bool copy, bool allowDelete, OrgFolder folder) { this.Path = path; this.Copy = copy; this.AllowDelete = allowDelete; this.OrgFolder = folder; this.SimilarTo = -1; }
/// <summary> /// Constructor for file from scan folder /// </summary> /// <param name="path">file's path</param> /// <param name="copy">whether file is allowed to be copied</param> /// <param name="allowDelete">whether file is allowed to be deleted</param> /// <param name="folder">scan folder file belongs to</param> public OrgPath(string path, bool copy, bool allowDelete, OrgFolder folder) { this.Path = path; this.Copy = copy; this.AllowDelete = allowDelete; this.OrgFolder = folder; this.SimilarTo = -1; }
/// <summary> /// Run through all TV shows all looks for episodes that may need to be renamed and for missing episodes. /// For missing episodes it attempts to match them to files from the search directories. /// </summary> /// <param name="shows">Shows to scan</param> /// <param name="queuedItems">Items currently in queue (to be skipped)</param> /// <returns></returns> public List <OrgItem> RunScan(List <ContentRootFolder> folders, List <OrgItem> queuedItems, bool fast) { // Set running flag scanRunning = true; cancelRequested = false; // Convert all TV folder to scan folders so we can do a scan of them List <OrgFolder> tvFoldersAsOrgFolders = new List <OrgFolder>(); foreach (ContentRootFolder tvFolder in folders) { OrgFolder orgFolder = new OrgFolder(tvFolder.FullPath, false, false, false, false); tvFoldersAsOrgFolders.Add(orgFolder); } // Do directory scan on all TV folders DirectoryScan dirScan = new DirectoryScan(false); dirScan.ProgressChange += dirScan_ProgressChange; dirScan.RunScan(tvFoldersAsOrgFolders, queuedItems, 90, true, false, fast, true); List <OrgItem> results = dirScan.Items; // Check if show folder needs to be renamed! int number = results.Count; foreach (ContentRootFolder tvFolder in folders) { for (int i = 0; i < Organization.Shows.Count; i++) { TvShow show = (TvShow)Organization.Shows[i]; if (show.Id <= 0 || show.RootFolder != tvFolder.FullPath) { continue; } string builtFolder = Path.Combine(show.RootFolder, FileHelper.GetSafeFileName(show.DatabaseName)); if (show.Path != builtFolder) { OrgItem newItem = new OrgItem(OrgStatus.Organization, OrgAction.Rename, show.Path, builtFolder, new TvEpisode("", show, -1, -1, "", ""), null, FileCategory.Folder, null); newItem.Enable = true; newItem.Number = number++; results.Add(newItem); } } } // Update progress OnProgressChange(ScanProcess.TvFolder, string.Empty, 100); // Clear flags scanRunning = false; // Return results return(results); }
/// <summary> /// Builds list of file contained in a set of organization folders. /// File search is done recursively on sub-folders if folder recursive /// property is checked. /// </summary> /// <param name="folder">Organization folder to get files from</param> /// <param name="files">List of file being built</param> private void GetFolderFiles(OrgFolder baseFolder, string folderPath, List <OrgPath> files, List <OrgItem> autoMoves) { // Get each file from the folder (try/catch here so that if user specifies as directory that needs special permission it doesn't crash) try { // Get all files from current path, convert to OrgPath and add to list string[] fileList = Directory.GetFiles(folderPath); foreach (string file in fileList) { bool autoMoving = false; foreach (AutoMoveFileSetup autoSetup in Settings.AutoMoveSetups) { OrgItem item; if (autoSetup.BuildFileMoveItem(file, baseFolder, out item)) { autoMoves.Add(item); autoMoving = true; break; } } if (!autoMoving) { files.Add(new OrgPath(file, baseFolder.CopyFrom, baseFolder.AllowDeleting, baseFolder)); } } // Recursively seach sub-folders if recursive folder if (baseFolder.Recursive) { string[] subDirs = Directory.GetDirectories(folderPath); foreach (string subDir in subDirs) { bool autoMoving = false; foreach (AutoMoveFileSetup autoSetup in Settings.AutoMoveSetups) { OrgItem item; if (autoSetup.BuildFolderMoveItem(subDir, baseFolder, out item)) { autoMoves.Add(item); autoMoving = true; break; } } if (!autoMoving) { GetFolderFiles(baseFolder, subDir, files, autoMoves); } } } } catch { } }
/// <summary> /// Run through all TV shows all looks for episodes that may need to be renamed and for missing episodes. /// For missing episodes it attempts to match them to files from the search directories. /// </summary> /// <param name="shows">Shows to scan</param> /// <param name="queuedItems">Items currently in queue (to be skipped)</param> /// <returns></returns> public List<OrgItem> RunScan(List<ContentRootFolder> folders, List<OrgItem> queuedItems, bool fast) { // Set running flag scanRunning = true; cancelRequested = false; // Convert all TV folder to scan folders so we can do a scan of them List<OrgFolder> tvFoldersAsOrgFolders = new List<OrgFolder>(); foreach (ContentRootFolder tvFolder in folders) { OrgFolder orgFolder = new OrgFolder(tvFolder.FullPath, false, false, false, false); tvFoldersAsOrgFolders.Add(orgFolder); } // Do directory scan on all TV folders DirectoryScan dirScan = new DirectoryScan(false); dirScan.ProgressChange += dirScan_ProgressChange; dirScan.RunScan(tvFoldersAsOrgFolders, queuedItems, 90, true, false, fast, true); List<OrgItem> results = dirScan.Items; // Check if show folder needs to be renamed! int number = results.Count; foreach (ContentRootFolder tvFolder in folders) for (int i = 0; i < Organization.Shows.Count; i++) { TvShow show = (TvShow)Organization.Shows[i]; if (show.Id <= 0 || show.RootFolder != tvFolder.FullPath) continue; string builtFolder = Path.Combine(show.RootFolder, FileHelper.GetSafeFileName(show.DatabaseName)); if (show.Path != builtFolder) { OrgItem newItem = new OrgItem(OrgStatus.Organization, OrgAction.Rename, show.Path, builtFolder, new TvEpisode("", show, -1, -1, "", ""), null, FileCategory.Folder, null); newItem.Enable = true; newItem.Number = number++; results.Add(newItem); } } // Update progress OnProgressChange(ScanProcess.TvFolder, string.Empty, 100); // Clear flags scanRunning = false; // Return results return results; }
public bool BuildFileMoveItem(string filePath, OrgFolder scanDir, out OrgItem item) { item = null; foreach (string fileType in this.FileTypes) { if (FileHelper.FileTypeMatch(fileType, filePath)) { item = new OrgItem(filePath, this, scanDir, false); if (File.Exists(item.DestinationPath)) { item.Action = OrgAction.AlreadyExists; item.Enable = false; } return(true); } } return(false); }
/// <summary> /// Constructor for TV rename/missing check where file was found. /// </summary> /// <param name="status">Status of rename/missing</param> /// <param name="action">action to be performed</param> /// <param name="file">source path</param> /// <param name="destination">destination path</param> /// <param name="episode">TV episode for file</param> /// <param name="episode2">2nd Tv epsidoe for file</param> /// <param name="category">file category</param> public OrgItem(OrgStatus status, OrgAction action, string file, string destination, TvEpisode episode, TvEpisode episode2, FileCategory category, OrgFolder scanDir) : this(action, file, destination, episode, episode2, category, scanDir) { this.Status = status; this.Progress = 0; }
/// <summary> /// Run through all TV shows all looks for episodes that may need to be renamed and for missing episodes. /// For missing episodes it attempts to match them to files from the search directories. /// </summary> /// <param name="shows">Shows to scan</param> /// <param name="queuedItems">Items currently in queue (to be skipped)</param> /// <returns></returns> public List <OrgItem> RunScan(List <Content> shows, List <OrgItem> queuedItems) { // Set running flag scanRunning = true; // Initialiaze scan items List <OrgItem> missingCheckItem = new List <OrgItem>(); // Initialize item numbers int number = 0; // Go through each show for (int i = 0; i < shows.Count; i++) { TvShow show = (TvShow)shows[i]; if (cancelRequested) { break; } OnProgressChange(ScanProcess.TvRename, shows[i].DatabaseName, (int)Math.Round((double)i / (shows.Count) * 30) + 70); // Go each show foreach (TvEpisode ep in show.Episodes) { // Check for cancellation if (cancelRequested) { break; } // Skipped ignored episodes if (ep.Ignored) { continue; } // Init found flag bool found = false; // Rename check if (ep.Missing == MissingStatus.Located) { if (shows[i].DoRenaming) { found = true; TvEpisode ep2 = null; if (ep.File.MultiPart) { if (ep.File.Part == 1) { foreach (TvEpisode epEnumerated in show.Episodes) { if (epEnumerated.Season == ep.Season && epEnumerated.DisplayNumber == ep.DisplayNumber + 1) { ep2 = epEnumerated; break; } } } else { continue; } } // Build desired path string builtPath = show.BuildFilePath(ep, ep2, Path.GetExtension(ep.File.FilePath)); // Check if rename needed (or move within folder) if (ep.File.FilePath != builtPath) { OrgItem newItem = new OrgItem(OrgStatus.Organization, OrgAction.Rename, ep.File.FilePath, builtPath, ep, ep2, FileCategory.TvVideo, null); newItem.Enable = true; if (!show.DoRenaming) { newItem.Category = FileCategory.Ignored; } newItem.Number = number++; missingCheckItem.Add(newItem); } } else { continue; } } else { continue; } // Add empty item for missing if (!found && ep.Aired && show.DoMissingCheck) { OrgItem newItem = new OrgItem(OrgStatus.Missing, OrgAction.None, ep, null, FileCategory.TvVideo, null); if (!show.DoRenaming) { newItem.Category = FileCategory.Ignored; } newItem.Number = number++; missingCheckItem.Add(newItem); } } } // Convert all TV folders to org folders List <OrgFolder> tvFoldersAsOrgFolders = new List <OrgFolder>(); foreach (ContentRootFolder tvFolder in Settings.TvFolders) { OrgFolder orgFolder = new OrgFolder(tvFolder.FullPath, false, false, false, false); tvFoldersAsOrgFolders.Add(orgFolder); } // Update progress OnProgressChange(ScanProcess.TvRename, string.Empty, 100); // Clear flags scanRunning = false; cancelRequested = false; // Return results return(missingCheckItem); }
/// <summary> /// Loads settings from XML. /// </summary> public static void Load() { string basePath = Organization.GetBasePath(false); if (!Directory.Exists(basePath)) return; // Initialize file types to defautls VideoFileTypes = new ObservableCollection<string>(); foreach (string type in DefaultVideoFileTypes) VideoFileTypes.Add(type); DeleteFileTypes = new ObservableCollection<string>(); foreach (string type in DefaultDeleteFileTypes) DeleteFileTypes.Add(type); IgnoreFileTypes = new ObservableCollection<string>(); foreach (string type in DefaultIgnoreFileTypes) IgnoreFileTypes.Add(type); // Load settings XML string path = Path.Combine(basePath, ROOT_XML + ".xml"); if (File.Exists(path)) { // Load XML XmlTextReader reader = new XmlTextReader(path); XmlDocument xmlDoc = new XmlDocument(); xmlDoc.Load(reader); foreach (XmlNode propNode in xmlDoc.DocumentElement.ChildNodes) { XmlElements element; if (!Enum.TryParse<XmlElements>(propNode.Name, out element)) continue; string value = propNode.InnerText; switch (element) { case XmlElements.ScanDirectories: ScanDirectories = new ObservableCollection<OrgFolder>(); foreach (XmlNode scanDirNode in propNode.ChildNodes) { OrgFolder folder = new OrgFolder(); folder.Load(scanDirNode); ScanDirectories.Add(folder); } break; case XmlElements.TvFileFormat: TvFileFormat.Load(propNode); break; case XmlElements.MovieFileFormat: MovieFileFormat.Load(propNode); break; case XmlElements.MovieFolderColletion: MovieFolders.Load(propNode); break; case XmlElements.TvFolderCollection: TvFolders.Load(propNode); break; case XmlElements.VideoFileTypes: VideoFileTypes = new ObservableCollection<string>(); foreach (XmlNode fileTypeNode in propNode.ChildNodes) { string videoType = fileTypeNode.InnerText; if (videoType.StartsWith(".")) videoType = videoType.Substring(1, videoType.Length - 1); VideoFileTypes.Add(videoType); } break; case XmlElements.DeleteFileTypes: DeleteFileTypes = new ObservableCollection<string>(); foreach (XmlNode fileTypeNode in propNode.ChildNodes) { string delType = fileTypeNode.InnerText; if (delType.StartsWith(".")) delType = delType.Substring(1, delType.Length - 1); DeleteFileTypes.Add(delType); } break; case XmlElements.IgnoreFileTypes: IgnoreFileTypes = new ObservableCollection<string>(); foreach (XmlNode fileTypeNode in propNode.ChildNodes) { string ignoreType = fileTypeNode.InnerText; if (ignoreType.StartsWith(".")) ignoreType = ignoreType.Substring(1, ignoreType.Length - 1); IgnoreFileTypes.Add(ignoreType); } break; case XmlElements.AutoMoveSetups: AutoMoveSetups = new ObservableCollection<AutoMoveFileSetup>(); foreach (XmlNode setupNode in propNode.ChildNodes) { AutoMoveFileSetup setup = new AutoMoveFileSetup(); setup.Load(setupNode); AutoMoveSetups.Add(setup); } break; case XmlElements.Gui: GuiControl.Load(propNode); break; case XmlElements.General: General.Load(propNode); break; case XmlElements.MovieFolders: MovieFolders.Clear(); foreach (XmlNode movieFolderNode in propNode.ChildNodes) { ContentRootFolder folder = new ContentRootFolder(ContentType.Movie); folder.Load(movieFolderNode); MovieFolders.Add(folder); } break; case XmlElements.TvFolders: TvFolders.Clear(); foreach (XmlNode tvFolderNode in propNode.ChildNodes) { ContentRootFolder folder = new ContentRootFolder(ContentType.TvShow); folder.Load(tvFolderNode); TvFolders.Add(folder); } break; } } } OnSettingsModified(true); }
public void Clone(OrgFolder folder) { if (this.FolderPath != folder.FolderPath) this.FolderPath = folder.FolderPath; if (this.CopyFrom != folder.CopyFrom) this.CopyFrom = folder.CopyFrom; if (this.Recursive != folder.Recursive) this.Recursive = folder.Recursive; if (this.AllowDeleting != folder.AllowDeleting) this.AllowDeleting = folder.AllowDeleting; this.AutomaticallyDeleteEmptyFolders = folder.AutomaticallyDeleteEmptyFolders; this.ignoreFiles.Clear(); foreach (string ignrFile in folder.ignoreFiles) this.ignoreFiles.Add(ignrFile); if (this.Id != folder.Id) this.Id = folder.Id; }
/// <summary> /// Constructor for directory scan for file matched to TV episode. /// </summary> /// <param name="action">action to be performed</param> /// <param name="file">source path</param> /// <param name="destination">destination path</param> /// <param name="episode">TV episode for file</param> /// <param name="episode2">2nd Tv epsidoe for file</param> /// <param name="category">file category</param> public OrgItem(OrgAction action, string file, string destination, TvEpisode episode, TvEpisode episode2, FileCategory category, OrgFolder scanDir) : this() { this.Action = action; this.SourcePath = file; this.DestinationPath = destination; this.TvEpisode = new TvEpisode(episode); this.Category = category; if (episode2 != null) this.TvEpisode2 = new TvEpisode(episode2); this.Enable = false; this.ScanDirectory = scanDir; this.Number = 0; }
/// <summary> /// Constructor for movie item. /// </summary> /// <param name="action">action to be performed</param> /// <param name="sourceFile">the source path</param> /// <param name="category">file's category</param> /// <param name="movie">Movie object related to file</param> /// <param name="destination">destination path</param> /// <param name="scanDir">path to content folder of movie</param> public OrgItem(OrgAction action, string sourceFile, FileCategory category, Movie movie, string destination, OrgFolder scanDir) : this() { this.Progress = 0; this.Action = action; this.SourcePath = sourceFile; this.Movie = movie; this.ScanDirectory = scanDir; this.DestinationPath = destination; this.Category = category; this.Enable = false; this.Number = 0; }
/// <summary> /// Constructor for directory scan for file that is unknown. /// </summary> /// <param name="action">action to be performed</param> /// <param name="file">source path</param> /// <param name="category">file category</param> public OrgItem(string file, AutoMoveFileSetup autoMoveSetup, OrgFolder scanDir, bool folder) : this() { this.Progress = 0; this.Action = scanDir.CopyFrom ? OrgAction.Copy : OrgAction.Move; this.AutoMoveSetup = autoMoveSetup; this.SourcePath = file; this.Category = FileCategory.AutoMove; if (folder) this.Category |= FileCategory.Folder; this.Enable = true; this.ScanDirectory = scanDir; this.Number = 0; this.BuildDestination(); }
/// <summary> /// Constructor for directory scan for file that is unknown. /// </summary> /// <param name="action">action to be performed</param> /// <param name="file">source path</param> /// <param name="category">file category</param> public OrgItem(OrgAction action, string file, FileCategory category, OrgFolder scanDir) : this() { this.Progress = 0; this.Action = action; this.SourcePath = file; if (action == OrgAction.Delete) this.DestinationPath = FileHelper.DELETE_DIRECTORY; else this.DestinationPath = string.Empty; this.Category = category; this.Enable = false; this.ScanDirectory = scanDir; this.Number = 0; }
/// <summary> /// Constructor for TV rename/missing check where file was not found. /// </summary> /// <param name="status">Status of rename/missing</param> /// <param name="action">action to be performed</param> /// <param name="episode">TV episode for file</param> /// <param name="episode2">2nd Tv epsidoe for file</param> /// <param name="category">file category</param> public OrgItem(OrgStatus status, OrgAction action, TvEpisode episode, TvEpisode episode2, FileCategory category, OrgFolder scanDir, TvEpisodeTorrent torrentEp) : this() { this.Status = status; this.Progress = 0; this.Action = action; this.SourcePath = string.Empty; if (action == OrgAction.Delete) this.DestinationPath = FileHelper.DELETE_DIRECTORY; else this.DestinationPath = string.Empty; this.TvEpisode = new TvEpisode(episode); if (episode2 != null) this.TvEpisode2 = new TvEpisode(episode2); this.TorrentTvEpisode = torrentEp; this.Category = category; this.Enable = action == OrgAction.Torrent; this.ScanDirectory = scanDir; this.Number = 0; }
/// <summary> /// Constructor for copying instance. /// </summary> public OrgFolder(OrgFolder folder) { Clone(folder); }
public bool BuildFolderMoveItem(string folderPath, OrgFolder scanDir, out OrgItem item) { item = new OrgItem(folderPath, this, scanDir, true); if (!this.MoveFolder) return false; string[] fileList = Directory.GetFiles(folderPath); foreach (string file in fileList) { OrgItem fileItem; if (this.BuildFileMoveItem(file, scanDir, out fileItem)) return true; } string[] subDirs = Directory.GetDirectories(folderPath); foreach (string subDir in subDirs) { OrgItem subItem; if (this.BuildFolderMoveItem(subDir, scanDir, out subItem)) return true; } return false; }
public bool BuildFileMoveItem(string filePath, OrgFolder scanDir, out OrgItem item) { item = null; foreach (string fileType in this.FileTypes) if (FileHelper.FileTypeMatch(fileType, filePath)) { item = new OrgItem(filePath, this, scanDir, false); if (File.Exists(item.DestinationPath)) { item.Action = OrgAction.AlreadyExists; item.Enable = false; } return true; } return false; }
/// <summary> /// Loads settings from XML. /// </summary> public static void Load() { string basePath = Organization.GetBasePath(false); if (!Directory.Exists(basePath)) { return; } // Initialize file types to defautls VideoFileTypes = new ObservableCollection <string>(); foreach (string type in DefaultVideoFileTypes) { VideoFileTypes.Add(type); } DeleteFileTypes = new ObservableCollection <string>(); foreach (string type in DefaultDeleteFileTypes) { DeleteFileTypes.Add(type); } IgnoreFileTypes = new ObservableCollection <string>(); foreach (string type in DefaultIgnoreFileTypes) { IgnoreFileTypes.Add(type); } // Load settings XML string path = Path.Combine(basePath, ROOT_XML + ".xml"); if (File.Exists(path)) { // Load XML XmlTextReader reader = new XmlTextReader(path); XmlDocument xmlDoc = new XmlDocument(); xmlDoc.Load(reader); foreach (XmlNode propNode in xmlDoc.DocumentElement.ChildNodes) { XmlElements element; if (!Enum.TryParse <XmlElements>(propNode.Name, out element)) { continue; } string value = propNode.InnerText; switch (element) { case XmlElements.ScanDirectories: ScanDirectories = new ObservableCollection <OrgFolder>(); foreach (XmlNode scanDirNode in propNode.ChildNodes) { OrgFolder folder = new OrgFolder(); folder.Load(scanDirNode); ScanDirectories.Add(folder); } break; case XmlElements.TvFileFormat: TvFileFormat.Load(propNode); break; case XmlElements.MovieFileFormat: MovieFileFormat.Load(propNode); break; case XmlElements.MovieFolderColletion: MovieFolders.Load(propNode); break; case XmlElements.TvFolderCollection: TvFolders.Load(propNode); break; case XmlElements.VideoFileTypes: VideoFileTypes = new ObservableCollection <string>(); foreach (XmlNode fileTypeNode in propNode.ChildNodes) { string videoType = fileTypeNode.InnerText; if (videoType.StartsWith(".")) { videoType = videoType.Substring(1, videoType.Length - 1); } VideoFileTypes.Add(videoType); } break; case XmlElements.DeleteFileTypes: DeleteFileTypes = new ObservableCollection <string>(); foreach (XmlNode fileTypeNode in propNode.ChildNodes) { string delType = fileTypeNode.InnerText; if (delType.StartsWith(".")) { delType = delType.Substring(1, delType.Length - 1); } DeleteFileTypes.Add(delType); } break; case XmlElements.IgnoreFileTypes: IgnoreFileTypes = new ObservableCollection <string>(); foreach (XmlNode fileTypeNode in propNode.ChildNodes) { string ignoreType = fileTypeNode.InnerText; if (ignoreType.StartsWith(".")) { ignoreType = ignoreType.Substring(1, ignoreType.Length - 1); } IgnoreFileTypes.Add(ignoreType); } break; case XmlElements.AutoMoveSetups: AutoMoveSetups = new ObservableCollection <AutoMoveFileSetup>(); foreach (XmlNode setupNode in propNode.ChildNodes) { AutoMoveFileSetup setup = new AutoMoveFileSetup(); setup.Load(setupNode); AutoMoveSetups.Add(setup); } break; case XmlElements.Gui: GuiControl.Load(propNode); break; case XmlElements.General: General.Load(propNode); break; case XmlElements.MovieFolders: MovieFolders.Clear(); foreach (XmlNode movieFolderNode in propNode.ChildNodes) { ContentRootFolder folder = new ContentRootFolder(ContentType.Movie); folder.Load(movieFolderNode); MovieFolders.Add(folder); } break; case XmlElements.TvFolders: TvFolders.Clear(); foreach (XmlNode tvFolderNode in propNode.ChildNodes) { ContentRootFolder folder = new ContentRootFolder(ContentType.TvShow); folder.Load(tvFolderNode); TvFolders.Add(folder); } break; } } } OnSettingsModified(true); }
/// <summary> /// Run through all TV shows all looks for episodes that may need to be renamed and for missing episodes. /// For missing episodes it attempts to match them to files from the search directories. /// </summary> /// <param name="shows">Shows to scan</param> /// <param name="queuedItems">Items currently in queue (to be skipped)</param> /// <returns></returns> public List<OrgItem> RunScan(List<Content> shows, List<OrgItem> queuedItems) { // Set running flag scanRunning = true; // Initialiaze scan items List<OrgItem> missingCheckItem = new List<OrgItem>(); // Initialize item numbers int number = 0; // Go through each show for (int i = 0; i < shows.Count; i++) { TvShow show = (TvShow)shows[i]; if (cancelRequested) break; OnProgressChange(ScanProcess.TvRename, shows[i].DatabaseName, (int)Math.Round((double)i / (shows.Count) * 30) + 70); // Go each show foreach (TvEpisode ep in show.Episodes) { // Check for cancellation if (cancelRequested) break; // Skipped ignored episodes if (ep.Ignored) continue; // Init found flag bool found = false; // Rename check if (ep.Missing == MissingStatus.Located) { if (shows[i].DoRenaming) { found = true; TvEpisode ep2 = null; if (ep.File.MultiPart) { if (ep.File.Part == 1) { foreach (TvEpisode epEnumerated in show.Episodes) if (epEnumerated.Season == ep.Season && epEnumerated.DisplayNumber == ep.DisplayNumber + 1) { ep2 = epEnumerated; break; } } else continue; } // Build desired path string builtPath = show.BuildFilePath(ep, ep2, Path.GetExtension(ep.File.FilePath)); // Check if rename needed (or move within folder) if (ep.File.FilePath != builtPath) { OrgItem newItem = new OrgItem(OrgStatus.Organization, OrgAction.Rename, ep.File.FilePath, builtPath, ep, ep2, FileCategory.TvVideo, null); newItem.Enable = true; if (!show.DoRenaming) newItem.Category = FileCategory.Ignored; newItem.Number = number++; missingCheckItem.Add(newItem); } } else continue; } else continue; // Add empty item for missing if (!found && ep.Aired && show.DoMissingCheck) { OrgItem newItem = new OrgItem(OrgStatus.Missing, OrgAction.None, ep, null, FileCategory.TvVideo, null, null); if (!show.DoRenaming) newItem.Category = FileCategory.Ignored; newItem.Number = number++; missingCheckItem.Add(newItem); } } } // Convert all TV folders to org folders List<OrgFolder> tvFoldersAsOrgFolders = new List<OrgFolder>(); foreach (ContentRootFolder tvFolder in Settings.TvFolders) { OrgFolder orgFolder = new OrgFolder(tvFolder.FullPath, false, false, false, false); tvFoldersAsOrgFolders.Add(orgFolder); } // Update progress OnProgressChange(ScanProcess.TvRename, string.Empty, 100); // Clear flags scanRunning = false; cancelRequested = false; // Return results return missingCheckItem; }
/// <summary> /// Builds list of file contained in a set of organization folders. /// File search is done recursively on sub-folders if folder recursive /// property is checked. /// </summary> /// <param name="folder">Organization folder to get files from</param> /// <param name="files">List of file being built</param> private void GetFolderFiles(OrgFolder baseFolder, string folderPath, List<OrgPath> files, List<OrgItem> autoMoves) { // Get each file from the folder (try/catch here so that if user specifies as directory that needs special permission it doesn't crash) try { // Get all files from current path, convert to OrgPath and add to list string[] fileList = Directory.GetFiles(folderPath); foreach (string file in fileList) { bool autoMoving = false; foreach (AutoMoveFileSetup autoSetup in Settings.AutoMoveSetups) { OrgItem item; if(autoSetup.BuildFileMoveItem(file, baseFolder, out item)) { autoMoves.Add(item); autoMoving = true; break; } } if (!autoMoving) files.Add(new OrgPath(file, baseFolder.CopyFrom, baseFolder.AllowDeleting, baseFolder)); } // Recursively seach sub-folders if recursive folder if (baseFolder.Recursive) { string[] subDirs = Directory.GetDirectories(folderPath); foreach (string subDir in subDirs) { bool autoMoving = false; foreach (AutoMoveFileSetup autoSetup in Settings.AutoMoveSetups) { OrgItem item; if (autoSetup.BuildFolderMoveItem(subDir, baseFolder, out item)) { autoMoves.Add(item); autoMoving = true; break; } } if (!autoMoving) GetFolderFiles(baseFolder, subDir, files, autoMoves); } } } catch { } }
/// <summary> /// Constructor for copying instance. /// </summary> public OrgFolder(OrgFolder folder) { Clone(folder); }