/// <summary> /// Updates the 'Discovered Files' count on the main form. Ideally used when updating the form /// while an upload process is taking place /// </summary> public void RecountLibraryFiles() { try { int count = 0; foreach (var watchFolder in MainForm.WatchFolders) { foreach (var file in FastDirectoryEnumerator.EnumerateFiles(watchFolder.Path, "*.*", SearchOption.AllDirectories)) { if (Path.GetExtension(file.Name.ToLower()).In(Global.SupportedMusicFiles)) { count++; } } } MainForm.SetDiscoveredFilesLabel(count.ToString()); } catch (Exception e) { Logger.Log(e, "RecountLibraryFiles", Log.LogTypeEnum.Warning); } }
public static void DeleteAllCharts() { foreach (FileData file in FastDirectoryEnumerator.EnumerateFiles(GlobalVars.CacheFolder, "*.png")) { File.Delete(file.Path); } }
public async Task <Stream> Load(string source) { var fileName = source.Substring(source.LastIndexOf("/images/", StringComparison.InvariantCulture) + 1); fileName = fileName.Replace('/', '_'); if (!Directory.Exists(Constants.Constants.Assets)) { Directory.CreateDirectory(Constants.Constants.Assets); } var files = FastDirectoryEnumerator.EnumerateFiles(Constants.Constants.Assets); var file = files.FirstOrDefault(a => a.Name.Contains(fileName)); if (file != null) { return(File.OpenRead(file.Path)); } using (var client = new HttpClient()) { var data = await client.GetByteArrayAsync(source); { if (data == null || data.Length == 0) { return(null); } File.WriteAllBytes(Constants.Constants.Assets + fileName, data); return(new MemoryStream(data)); } } }
private static List <string> GetUnityInstallations(string root, bool useFastFileEnumerator) { if (useFastFileEnumerator) { return(FastDirectoryEnumerator.EnumerateFiles(root, "Unity.exe", SearchOption.AllDirectories) .AsParallel() .Tap(file => Console.WriteLine("Found {0}", file.Path)) .Select(file => file.Path) .ToList()); } var folders = new List <string>(); var unity = Path.Combine(root, "Unity.exe"); if (File.Exists(unity)) { Console.WriteLine("Found {0}", unity); folders.Add(unity); return(folders); } foreach (var directory in Directory.EnumerateDirectories(root)) { folders.AddRange(GetUnityInstallations(directory, useFastFileEnumerator)); } return(folders); }
/// <summary> /// Convert a path image to a bitmap-cached image /// </summary> /// <param name="value">The value produced by the binding source.</param> /// <param name="targetType">The type of the binding target property.</param> /// <param name="parameter">The converter parameter to use.</param> /// <param name="culture">The culture to use in the converter.</param> /// <returns>Cached image</returns> public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { if (string.IsNullOrEmpty(value?.ToString())) { return(null); } var path = value.ToString(); var fileName = path.Substring(path.LastIndexOf("/images/", StringComparison.InvariantCulture) + 1); fileName = fileName.Replace('/', '_'); var files = FastDirectoryEnumerator.EnumerateFiles(Utils.Constants.Assets); var file = files.FirstOrDefault(a => a.Name.Contains(fileName)); if (file != null) { return(new Uri(file.Path, UriKind.Absolute)); } Task.Run(async() => { using (var client = new HttpClient()) { var data = await client.GetByteArrayAsync(path); { if (data == null || data.Length == 0) { return; } File.WriteAllBytes(Utils.Constants.Assets + fileName, data); } } }); return(new Uri(path, UriKind.Absolute)); }
/// <summary> /// Gets <see cref="FileData"/> for all the files in a directory that match a /// specific filter. /// </summary> /// <param name="path">The path to search.</param> /// <param name="searchPattern">The search string to match against files in the path.</param> /// <returns>An object that implements <see cref="IEnumerable{FileData}"/> and /// allows you to enumerate the files in the given directory.</returns> /// <exception cref="ArgumentNullException"> /// <paramref name="path"/> is a null reference (Nothing in VB) /// </exception> /// <exception cref="ArgumentNullException"> /// <paramref name="filter"/> is a null reference (Nothing in VB) /// </exception> public static FileData[] GetFiles(string path, string searchPattern, SearchOption searchOption) { IEnumerable <FileData> e = FastDirectoryEnumerator.EnumerateFiles(path, searchPattern, searchOption); List <FileData> list = new List <FileData>(e); FileData[] retval = new FileData[list.Count]; list.CopyTo(retval); return(retval); }
public void Start() { EnableRaisingEvents = true; FileData = FastDirectoryEnumerator.EnumerateFiles( Path, Filter, this.IncludeSubdirectories ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly).ToArray(); Timer.Start(); }
private void CollectFilesInfo(string path) { try { allFiles = FastDirectoryEnumerator.EnumerateFiles(path, "*", SearchOption.AllDirectories); allFilesCount = allFiles.Count(); maxValueProgressBar += allFilesCount; } catch (Exception ex) { logger.Log(ex.Message); return; } }
private int CalculateMaxProjectFileNumber(string dirPath) { int maxOrdNum = 0; foreach (FileData fd in FastDirectoryEnumerator.EnumerateFiles(dirPath, "*" + Project.ProjectFileExtension, SearchOption.TopDirectoryOnly)) { int ordNum; string tail = fd.Name.TrimStart(resourceManager.GetString("ProjectFileNameDefault").ToCharArray()) .TrimEnd(Project.ProjectFileExtension.ToCharArray()); if (int.TryParse(tail, out ordNum) && ordNum > maxOrdNum) { maxOrdNum = ordNum; } } return(maxOrdNum); }
private void OnTimedEvent(object source, ElapsedEventArgs e) { var compareData = FastDirectoryEnumerator.EnumerateFiles( Path, Filter, this.IncludeSubdirectories ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly).ToArray(); bool equal = FileData.Count() == compareData.Count() && !FileData.Except(compareData, new FileDataComparer()).Any() && !compareData.Except(FileData, new FileDataComparer()).Any(); if (!equal) { var ags = new PollDiscoveredChangeArgs("File structure changed"); OnPollDiscoveredChange(this, ags); } }
public string GetFullPath(string filename, string extension = ".3ds") { if (string.IsNullOrWhiteSpace(filename)) { return null; } else { var fullPath = Path.Combine(_watchedDirectoryLocation, filename); if (File.Exists(fullPath)) { return fullPath; } else { return FastDirectoryEnumerator.EnumerateFiles(_watchedDirectoryLocation, Path.GetFileNameWithoutExtension(filename) + extension, SearchOption.AllDirectories).Select(fd => fd.Path).FirstOrDefault(); } } }
/// <summary> /// Finds the files in path. /// </summary> /// <param name="path">The files path.</param> /// <param name="type">The SearchOption type.</param> /// <returns> /// A collection of files and FileInfo collections /// </returns> public static Dictionary <string, Section> FindFilesInPath(string path, SearchOption type) { var fileCollection = new List <string>(); foreach (string ext in Get.InOutCollection.VideoExtentions) { IEnumerable <FileData> files = FastDirectoryEnumerator.EnumerateFiles( path, "*." + ext.ToLower().ToList(), SearchOption.AllDirectories); fileCollection.AddRange((from f in files select f.Path).ToList()); } return(fileCollection.ToDictionary( file => file, file => Regex.IsMatch( file, "(?<![0-9])s{0,1}([0-9]{1,2})((?:(?:e[0-9]+)+)|(?:(?:x[0-9]+)+))", RegexOptions.IgnoreCase) ? Section.Tv : Section.Movies)); }
private List <FileData> GetAssemblyFilesFromDirectories(List <string> directories) { ConcurrentDictionary <string, FileData> allAssemblies = new ConcurrentDictionary <string, FileData>(); ParallelOptions parallelOptions = new ParallelOptions(); if (Directories.Count == 1) { parallelOptions.MaxDegreeOfParallelism = 1; } Parallel.ForEach(directories, directory => { foreach (FileData assembly in FastDirectoryEnumerator.EnumerateFiles(directory, "*.dll", System.IO.SearchOption.AllDirectories)) { allAssemblies.TryAdd(assembly.Path, assembly); } }); return(allAssemblies.Values.ToList()); }
/// <summary> /// Gets <see cref="FileData"/> for all the files in a directory that match a /// specific filter. /// </summary> /// <param name="path">The path to search.</param> /// <param name="searchPattern">The search string to match against files in the path.</param> /// <returns>An object that implements <see cref="IEnumerable{FileData}"/> and /// allows you to enumerate the files in the given directory.</returns> /// <exception cref="ArgumentNullException"> /// <paramref name="path"/> is a null reference (Nothing in VB) /// </exception> /// <exception cref="ArgumentNullException"> /// <paramref name="filter"/> is a null reference (Nothing in VB) /// </exception> public static IEnumerable <FileData> EnumerateFiles(string path, string searchPattern) { return(FastDirectoryEnumerator.EnumerateFiles(path, searchPattern, SearchOption.TopDirectoryOnly)); }
/// <summary> /// Gets <see cref="FileData"/> for all the files in a directory. /// </summary> /// <param name="path">The path to search.</param> /// <returns>An object that implements <see cref="IEnumerable{FileData}"/> and /// allows you to enumerate the files in the given directory.</returns> /// <exception cref="ArgumentNullException"> /// <paramref name="path"/> is a null reference (Nothing in VB) /// </exception> public static IEnumerable <FileData> EnumerateFiles(string path) { return(FastDirectoryEnumerator.EnumerateFiles(path, "*")); }
/// <summary> /// Executes the scan /// </summary> public void Process() { SetStatus(); CurrentMusicFiles = MainForm.MusicFileRepo.LoadAll().Result; foreach (var musicFile in CurrentMusicFiles) { CurrentMusicFilesHash.Add(musicFile.Path); } if (MainForm.WatchFolders.Count == 0) { MainForm.MusicFileRepo.DeleteAll().Wait(); } // // Get files to add - Cross reference with the DB // foreach (var watchFolder in MainForm.WatchFolders) { if (MainForm.Aborting) { SetStatus("Idle", "Idle"); return; } foreach (var file in FastDirectoryEnumerator.EnumerateFiles(watchFolder.Path, "*.*", SearchOption.AllDirectories)) { if (MainForm.Aborting) { SetStatus("Idle", "Idle"); return; } if (!CurrentMusicFilesHash.Contains(file.Path)) { if (Path.GetExtension(file.Name.ToLower()).In(Global.SupportedFiles)) { NewFiles.Add(file); NewFilesHash.Add(file.Path); } } if (Path.GetExtension(file.Name.ToLower()).In(Global.SupportedFiles)) { DiscoveredFilesHash.Add(file.Path); } } } // // Get files to delete - Cross reference with the DB // foreach (var musicFile in CurrentMusicFiles) { if (MainForm.Aborting) { SetStatus("Idle", "Idle"); return; } if (!DiscoveredFilesHash.Contains(musicFile.Path)) { MusicFilesToDelete.Add(musicFile); } } using (var conn = new SQLiteConnection("Data Source=" + Global.DbLocation)) { SetStatus(); conn.Open(); int count = 0; foreach (var file in NewFiles) { if (MainForm.Aborting) { MainForm.SetStatusMessage("Idle", "Idle"); return; } count++; if (count > MainForm.InitialFilesCount) { if (count % 100 == 0) { MainForm.SetDiscoveredFilesLabel(count.ToString()); } } SetStatus(); AddToDB(conn, new MusicFile(file.Path)); } if (MainForm.Aborting) { SetStatus("Idle", "Idle"); return; } count = 0; foreach (var musicFile in MusicFilesToDelete) { if (MainForm.Aborting) { MainForm.SetStatusMessage("Idle", "Idle"); return; } count++; RemoveFromDB(conn, musicFile.Path); } ; MainForm.SetDiscoveredFilesLabel(MainForm.MusicFileRepo.CountAll().Result.ToString()); } SetStatus(MainForm.ConnectedToYTMusic ? "Ready" : "Waiting for YouTube Music connection", "Waiting for YouTube Music connection"); }
/// <summary> /// Converts the media path import database into a MovieModel DB. /// </summary> public static void ConvertMediaPathImportToDB() { var db = MediaPathDBFactory.GetMediaPathMoviesUnsorted(); var count = 0; MovieDBFactory.ImportProgressMaximum = db.Count; ImportDatabase.Clear(); var getFiles = new string[1]; var currentGetPathFiles = string.Empty; foreach (var file in db) { MovieDBFactory.ImportProgressCurrent = count; MovieDBFactory.ImportProgressStatus = string.Format("Processing: " + file.PathAndFileName); if (file.Path != currentGetPathFiles) { var files = FastDirectoryEnumerator.EnumerateFiles(file.Path, "*.*", SearchOption.TopDirectoryOnly); getFiles = (from f in files select f.Path).ToArray(); currentGetPathFiles = file.Path; } var movieModel = new MovieModel { Title = Tools.Importing.MovieNaming.GetMovieName(file.PathAndFileName, file.MediaPathType), Year = Tools.Importing.MovieNaming.GetMovieYear(file.PathAndFileName), ScraperGroup = file.ScraperGroup, VideoSource = file.DefaultVideoSource, NfoPathOnDisk = FindNFO(file.FilenameWithOutExt, file.Path, getFiles), PosterPathOnDisk = FindPoster(file.FilenameWithOutExt, file.Path, getFiles), FanartPathOnDisk = FindFanart(file.FilenameWithOutExt, file.Path, getFiles) }; var result = (from m in ImportDatabase where m.Title == movieModel.Title select m).ToList(); if (result.Count == 0) { if (!string.IsNullOrEmpty(movieModel.NfoPathOnDisk)) { InOut.OutFactory.LoadMovie(movieModel); movieModel.ChangedText = false; } if (!string.IsNullOrEmpty(movieModel.PosterPathOnDisk)) { movieModel.GenerateSmallPoster(movieModel.PosterPathOnDisk); movieModel.ChangedPoster = false; } if (!string.IsNullOrEmpty(movieModel.FanartPathOnDisk)) { movieModel.GenerateSmallFanart(movieModel.FanartPathOnDisk); movieModel.ChangedFanart = false; } movieModel.AssociatedFiles.AddToMediaCollection(file); ImportDatabase.Add(movieModel); } else { // result[0].AssociatedFiles.GetMediaCollection().Clear(); result[0].AssociatedFiles.AddToMediaCollection(file); } count++; } }
private static int Main(params string[] args) { return(Parser.Default.ParseArguments <RestoreOptions, LinkOptions, EnumerateOptions, HashOptions>(args) .MapResult( (RestoreOptions opts) => { return 0; }, (LinkOptions opts) => { return 0; }, (EnumerateOptions opts) => { return 0; }, (HashOptions opts) => { return 0; }, errs => 1)); var obj = new object(); var files = ReadFromLog(); var totalToLink = files.Count; var deleted = 0; var fails = 0; var processed = 0; var linked = 0; var copied = 0; if (false) { files .AsParallel() .Tap(kvp => { var source = Path.Combine(TARGET_PATH, kvp.Value); lock (obj) processed++; if (File.Exists(kvp.Key)) { File.Delete(kvp.Key); lock (obj) deleted++; } if (CreateSymbolicLink(kvp.Key, source, SymbolicLink.File)) { lock (obj) linked++; } else { File.Copy(source, kvp.Key); // Restore the file if there's an error lock (obj) fails++; } lock (obj) if (processed % 1000 == 0) { Console.WriteLine("Processed {0} of {1} ({2:0.00%}) Symlinked: {3}, Errored: {4}, Deleted: {5}", processed, totalToLink, (float)processed / totalToLink, linked, fails, deleted); } }) .ToArray(); } files .AsParallel() .Tap(kvp => { var source = Path.Combine(TARGET_PATH, kvp.Value); if (File.Exists(kvp.Key)) { File.Delete(kvp.Key); } File.Copy(source, kvp.Key); lock (obj) copied++; lock (obj) if (copied % 100 == 0) { Console.WriteLine("Copied {0} of {1} ({2:0.00%})", copied, totalToLink, (float)copied / totalToLink); } }) .ToArray(); while (true) { Console.ReadKey(true); } return(0); if (!Directory.Exists(TARGET_PATH)) { Directory.CreateDirectory(TARGET_PATH); } files .AsParallel() .GroupBy(kvp => kvp.Value) .Select(group => group.First()) .Select(kvp => new { hash = kvp.Value, file = new FileInfo(kvp.Key) }) .Tap(fileAndHash => { var from = fileAndHash.file.FullName; var to = Path.Combine(TARGET_PATH, fileAndHash.hash); File.Copy(from, to, false); Console.WriteLine("Copied {0}", fileAndHash.file.Name); }) .ToArray(); while (true) { Console.ReadKey(true); } return(0); if (File.Exists(@"C:\Users\samue\Desktop\minifier-log-exec.txt")) { File.Delete(@"C:\Users\samue\Desktop\minifier-log-exec.txt"); } var oldOut = Console.Out; var ostrm = new FileStream(@"C:\Users\samue\Desktop\minifier-log-exec.txt", FileMode.OpenOrCreate, FileAccess.Write); var writer = new StreamWriter(ostrm); writer.AutoFlush = true; Console.SetOut(writer); Console.Title = "Link Twins"; var totalBytes = 0L; var totalFiles = 0L; var filesToHash = 0L; var bytesToHash = 0L; var hashedFiles = 0L; var hashedBytes = 0L; var equalFiles = FastDirectoryEnumerator.EnumerateFiles(@"C:\Unity\", "*.*", SearchOption.AllDirectories) .AsParallel() .Tap(file => { lock (obj) { totalFiles++; totalBytes += file.Size; } if (totalFiles % 1000 == 0) { Console.WriteLine("Found {0} files ({1})", totalFiles, FormatBytes(totalBytes)); } }) .AsParallel() //.Select(filePath => new FileInfo(filePath)) .GroupBy(file => file.Size) .Where(group => group.Count() > 1) //.Tap(group => Console.WriteLine("{0} files named {1}", group.Count(), group.Key)) .Tap(group => { lock (obj) { filesToHash += group.Count(); bytesToHash += group.Sum(file => file.Size); } }) .SelectMany(group => group) .ToArray() .AsParallel() //.GroupBy(file => file.Length) //.Where(group => group.Count() > 1) //.Tap(group => Console.WriteLine("Metadata: {0} with {1} files", group.Key, group.Count())) //.SelectMany(group => group) .Select(file => new { file, hash = GetChecksumBuffered(File.OpenRead(file.Path)) }) .Tap(fileAndHash => { lock (obj) { hashedFiles++; hashedBytes += fileAndHash.file.Size; } if (hashedFiles % 1000 == 0) { Console.WriteLine("{0} of {1} ({2:0.00%}) hashed files, {3} of {4} ({5:0.00%}) hashed data", hashedFiles, filesToHash, (float)hashedFiles / filesToHash, FormatBytes(hashedBytes), FormatBytes(bytesToHash), (float)hashedBytes / bytesToHash); } }) .GroupBy(file => file.hash) .Where(group => group.Count() > 1) //.Tap(group => Console.WriteLine("{0} files equal to {1}", group.Count(), group.First().file.Path)) .ToDictionary(group => group.Key, group => group.Select(g => g.file).ToList()); if (File.Exists(LOG_PATH)) { File.Delete(LOG_PATH); } using (var log = File.CreateText(LOG_PATH)) { foreach (var kvp in equalFiles) { log.WriteLine(kvp.Key); foreach (var file in kvp.Value) { log.WriteLine("\t{0}", file.Path); } log.WriteLine(string.Empty); } } Console.WriteLine("Final calculations..."); var finalBytes = equalFiles .AsParallel() .Select(kvp => kvp.Value.First()) .Sum(file => file.Size); var saveableBytes = equalFiles .AsParallel() .SelectMany(kvp => kvp.Value) .Sum(file => file.Size) - finalBytes; Console.WriteLine("{0} of {1} ({2:00.00%}) files can be linked", equalFiles.Count, totalFiles, (float)equalFiles.Count / totalFiles); Console.WriteLine("{0} of {1} ({2:00.00%}) could be saved", FormatBytes(saveableBytes), FormatBytes(totalBytes), (float)saveableBytes / totalBytes); Console.WriteLine("The final source files would have {0}", FormatBytes(finalBytes)); //foreach (var f in files) // Console.WriteLine(string.Format("{0} at {1}", f.Key, f.Value.Aggregate("", (a, b) => a + " " + b))); }
public void SavePicturesToDB() { mVehicleTaskList = VehicleMongoDAL.GetInstance().GetAllVehicleTask(); if (null != mVehicleTaskList) { if (mVehicleTaskList.Count > 0) { for (int i = 0; i < mVehicleTaskList.Count; i++) { if (mVehicleTaskList[i].TaskState == "0") { currentIndex = i; break; } else { currentIndex = -1; } } if (currentIndex >= 0) { foreach (FileData f in FastDirectoryEnumerator.EnumerateFiles(mVehicleTaskList[currentIndex].TaskPath, "*", System.IO.SearchOption.AllDirectories)) { string filename = f.Path.ToLower(); string FileFullName = f.Path; if ((filename.Contains(".jpg") || filename.Contains(".bmp") || filename.Contains(".jpeg"))) { m_listFilePath.Add(f.Path); //InsertIntoMongo(filename); mVehicleTaskList[currentIndex].TaskCount = mTaskCount++.ToString(); } if (m_listFilePath.Count >= 100) { ZmqVehicleSink.GetInstance().SendVehicles(m_listFilePath); try { mVehicleTaskList[currentIndex].TaskCount = (Convert.ToInt32(mVehicleTaskList[currentIndex].TaskCount) + m_listFilePath.Count).ToString(); VehicleMongoDAL.GetInstance().UpdateVehicleTask(mVehicleTaskList[currentIndex]); this.Invoke(new DelegateBindHandler(BindDataSource)); } catch { } m_listFilePath.Clear(); } } if (m_listFilePath.Count > 0) { ZmqVehicleSink.GetInstance().SendVehicles(m_listFilePath); try { mVehicleTaskList[currentIndex].TaskCount = (Convert.ToInt32(mVehicleTaskList[currentIndex].TaskCount) + m_listFilePath.Count).ToString(); VehicleMongoDAL.GetInstance().UpdateVehicleTask(mVehicleTaskList[currentIndex]); this.Invoke(new DelegateBindHandler(BindDataSource)); } catch { } m_listFilePath.Clear(); } mVehicleTaskList[currentIndex].TaskState = "1"; VehicleMongoDAL.GetInstance().UpdateVehicleTask(mVehicleTaskList[currentIndex]); loadTaskData(); } } } try { Thread.Sleep(1000); this.Invoke(new DelegateRestartTime(RestartTime)); } catch { } }
/// <summary> /// Executes the scan /// </summary> public void Process() { Stopped = false; SetStatus(); if (MainForm.WatchFolders.Count == 0) { MainForm.MusicFileRepo.DeleteAll().Wait(); MainForm.PlaylistFileRepo.DeleteAll().Wait(); MainForm.SetDiscoveredFilesLabel("0"); MainForm.SetIssuesLabel("0"); MainForm.SetUploadedLabel("0"); } CurrentMusicFiles = MainForm.MusicFileRepo.LoadAll().Result; foreach (var musicFile in CurrentMusicFiles) { CurrentProcessingFilesHash.Add(musicFile.Path); } CurrentPlaylistFiles = MainForm.PlaylistFileRepo.LoadAll().Result; foreach (var playlistFile in CurrentPlaylistFiles) { CurrentProcessingFilesHash.Add(playlistFile.Path); } // // Get files to add - Cross reference with the DB // foreach (var watchFolder in MainForm.WatchFolders) { if (MainFormAborting()) { return; } if (Directory.Exists(watchFolder.Path)) { foreach (var file in FastDirectoryEnumerator.EnumerateFiles(watchFolder.Path, "*.*", SearchOption.AllDirectories)) { try { if (MainFormAborting()) { return; } if (!CurrentProcessingFilesHash.Contains(file.Path)) { if (Path.GetExtension(file.Name.ToLower()).In(Global.SupportedMusicFiles) || Path.GetExtension(file.Name.ToLower()).In(Global.SupportedPlaylistFiles)) { NewFiles.Add(file); NewFilesHash.Add(file.Path); } } if (MainFormAborting()) { return; } if (Path.GetExtension(file.Name.ToLower()).In(Global.SupportedMusicFiles) || Path.GetExtension(file.Name.ToLower()).In(Global.SupportedPlaylistFiles)) { DiscoveredFilesHash.Add(file.Path); } } catch (Exception e) { Logger.Log( e, "FileScanner.Process - Error reading file (possibly removed): " + file.Path, Log.LogTypeEnum.Error, false); } } } else { if (MainFormAborting()) { return; } SetStatus("Error: Watch folder directory does not exists: " + watchFolder.Path.EllipsisPath(100), "Directory "); ThreadHelper.SafeSleep(5000); } } // // Get files to delete - Cross reference with the DB // foreach (var musicFile in CurrentMusicFiles) { if (MainFormAborting()) { return; } if (!DiscoveredFilesHash.Contains(musicFile.Path)) { MusicFilesToDelete.Add(musicFile); } } foreach (var playlistFile in CurrentPlaylistFiles) { if (MainFormAborting()) { return; } if (!DiscoveredFilesHash.Contains(playlistFile.Path)) { PlaylistFilesToDelete.Add(playlistFile); } } using (var conn = new SQLiteConnection("Data Source=" + Global.DbLocation + ";cache=shared")) { SetStatus(); conn.Open(); try { int count = 0; foreach (var file in NewFiles) { if (MainFormAborting(conn)) { return; } count++; if (count % 100 == 0) { MainForm.SetDiscoveredFilesLabel(count.ToString()); } SetStatus(); if (Path.GetExtension(file.Path).ToLower().In(Global.SupportedMusicFiles)) { AddMusiFileToDB(conn, new MusicFile(file.Path)); } else if (Path.GetExtension(file.Path).ToLower().In(Global.SupportedPlaylistFiles)) { AddPlaylistFileToDB(conn, new PlaylistFile(file.Path, file.LastWriteTime)); } } if (MainFormAborting(conn)) { return; } foreach (var musicFile in MusicFilesToDelete) { if (MainFormAborting(conn)) { return; } RemoveMusicFileFromDB(conn, musicFile.Path); } ; if (MainFormAborting(conn)) { return; } foreach (var playlistFile in PlaylistFilesToDelete) { if (MainFormAborting(conn)) { return; } RemovePlaylistFileFromDb(conn, playlistFile.Path); } ; MainForm.SetDiscoveredFilesLabel(MainForm.MusicFileRepo.CountAll().Result.ToString()); } catch { } conn.Close(); } SetStatus(MainForm.ConnectedToYTMusic ? "Ready" : "Waiting for YouTube Music connection", "Waiting for YouTube Music connection"); Stopped = true; }