void addFolder(string recTVFolder) { DirectoryInfo di = new DirectoryInfo(recTVFolder); ArrayList files = new ArrayList(); files.AddRange(di.GetFiles("*.wtv")); files.AddRange(di.GetFiles("*.dvr-ms")); IComparer dateComparer = new DateComparer(); files.Sort(dateComparer); foreach (FileInfo fi in files) { try { // If file is not in use, add it, otherwise postpone it AddTVProgrammeResults ATVresult = AddTVProgrammeIfPossible(fi); if (ATVresult != AddTVProgrammeResults.Success) { DebugNormal("Cannot add " + fi.Name + " yet, file in use - postponing."); if (!PostponedFiles.Contains(fi.FullName)) { PostponedFiles.Add(fi.FullName); } } else { DebugNormal("Added " + fi.Name); } } catch (Exception ex) { DebugError(ex); } } if (Settings.Default.RecurseRecTVSubfolders) { foreach (DirectoryInfo diDir in di.GetDirectories()) { FileAttributes att = diDir.Attributes; if ((att & FileAttributes.Hidden) == FileAttributes.Hidden) { continue; } if ((att & FileAttributes.System) == FileAttributes.System) { continue; } addFolder(diDir.FullName); } } }
private void CheckPostponedFiles() { Monitor.Enter(checkPostponedFiles); DebugNormal("Checking if we postponed any files in use..."); if (PostponedFiles.Count < 1) { Monitor.Exit(checkPostponedFiles); return; // no files } DebugNormal("Found " + PostponedFiles.Count.ToString() + " postponed files to re-check..."); List <string> FilesToDelete = new List <string>(); // Enumerate in reverse order in case of removals foreach (string f in PostponedFiles) { FileInfo fi = new FileInfo(f); DebugNormal("Checking " + fi.Name); AddTVProgrammeResults ATVresult = AddTVProgrammeIfPossible(fi); if (ATVresult == AddTVProgrammeResults.Success) { // It wasn't in use, it's been added - so let's remove it FilesToDelete.Add(f); DebugNormal("Added file " + fi.Name + " and removed from postpone list."); } else { DebugNormal("File " + fi.Name + " could not be added yet: " + ATVresult.ToString()); // Is it waaaay old? Remove if so if (MinutesSinceFileWasCreated(fi) > IGNORE_FILES_IN_USE_MORE_THAN_THIS_MINUTES_OLD) { FilesToDelete.Add(f); DebugNormal("File " + fi.Name + " is older than " + IGNORE_FILES_IN_USE_MORE_THAN_THIS_MINUTES_OLD.ToString() + " minutes and still in use, abandoning attempts to add it to recorded TV list."); } } } // Delete the files we've added foreach (string f in FilesToDelete) { PostponedFiles.Remove(f); } Monitor.Exit(checkPostponedFiles); }
void fw_Created(object sender, FileSystemEventArgs e) { if (!fileIsRecordedTVFile(e.FullPath)) { return; } DebugNormal("Watcher: File created - " + e.FullPath); // If file is not in use, add it, otherwise postpone it FileInfo fi = new FileInfo(e.FullPath); AddTVProgrammeResults ATVresult = AddTVProgrammeIfPossible(fi); if (ATVresult != AddTVProgrammeResults.Success) { DebugNormal("Cannot add " + fi.Name + " yet:" + ATVresult.ToString() + " - postponing."); if (!PostponedFiles.Contains(fi.FullName)) { PostponedFiles.Add(fi.FullName); } } }