private int ScanSongs() { int changesMade = 0; Config.ConfigFile config = SongPlayerFactory.GetConfigFile(); string[] directories = config.GetValue("library.path").Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries); string[] extensions = config.GetValue("library.extensions").Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries); if (extensions.Length == 0) { extensions = new string[] { "mp3" } } ; List <string> files = new List <string>(); foreach (string directory in directories) { if (Directory.Exists(directory)) { foreach (string extension in extensions) { files.AddRange(Directory.GetFiles(directory, "*." + extension, SearchOption.AllDirectories).AsEnumerable <string>()); } } } //Find removed songs lock (lockObject) { if (_songs.RemoveAll(s => !files.Any(f => f == s.FileName)) > 0) { changesMade++; } } //Find added songs foreach (string fileName in files) { lock (lockObject) { if (_songs.Any(s => s.FileName == fileName)) { continue; } } Song song = new Song(); song.FileName = fileName; FileInfo fileInfo = new FileInfo(fileName); song.Name = Regex.Replace(fileInfo.Name, @"\" + fileInfo.Extension + "$", string.Empty, RegexOptions.IgnoreCase); AddSong(song); changesMade++; } return(changesMade); }
public static ConfigFile GetConfigFile() { if (!System.IO.File.Exists("songrequest.config")) { ConfigFile configFile = new ConfigFile("songrequest.config"); configFile.SetValue("server.port", "8765"); configFile.SetValue("server.clients", "all"); configFile.SetValue("library.path", "c:\\music"); configFile.SetValue("library.minutesbetweenscans", "1"); configFile.SetValue("library.extensions", "mp3"); configFile.SetValue("player.minimalsonginqueue", "0"); configFile.SetValue("player.maximalsonginqueue", "500"); configFile.Save(); } return new ConfigFile("songrequest.config"); }
public static ConfigFile GetConfigFile() { if (!System.IO.File.Exists("songrequest.config")) { ConfigFile configFile = new ConfigFile("songrequest.config"); configFile.SetValue("server.host", "*"); configFile.SetValue("server.port", "8765"); configFile.SetValue("server.clients", "all"); if (Settings.IsRunningOnWindows()) configFile.SetValue("library.path", "c:\\music"); else configFile.SetValue("library.path", "~/Music"); configFile.SetValue("library.minutesbetweenscans", "1"); configFile.SetValue("library.extensions", "mp3"); configFile.SetValue("player.minimalsonginqueue", "0"); configFile.SetValue("player.maximalsonginqueue", "500"); configFile.SetValue("player.startupvolume", "50"); configFile.Save(); } return new ConfigFile("songrequest.config"); }