public static LibraryFile CreateLibraryEntry(ObservableCollection<Song> libSourceToUse, string tempMusicLibraryFile) { var tempPathList = libSourceToUse.Select(x => x.FileLocation).ToList(); var MatchingChars = from len in Enumerable.Range(0, tempPathList.Min(s => s.Length)).Reverse() let possibleMatch = tempPathList.First().Substring(0, len) where tempPathList.All(f => f.StartsWith(possibleMatch)) select possibleMatch; string tempSource = Path.GetDirectoryName(MatchingChars.First()); string tempLibName = System.IO.Path.GetFileNameWithoutExtension(tempMusicLibraryFile); string tempFileLoc = tempMusicLibraryFile; LibraryFile tempLibFile = new LibraryFile(tempFileLoc, tempLibName, tempSource); return tempLibFile; }
public static LibraryFile CreateLibraryEntry(ObservableCollection <Song> libSourceToUse, string tempMusicLibraryFile) { var tempPathList = libSourceToUse.Select(x => x.FileLocation).ToList(); var MatchingChars = from len in Enumerable.Range(0, tempPathList.Min(s => s.Length)).Reverse() let possibleMatch = tempPathList.First().Substring(0, len) where tempPathList.All(f => f.StartsWith(possibleMatch)) select possibleMatch; string tempSource = Path.GetDirectoryName(MatchingChars.First()); string tempLibName = System.IO.Path.GetFileNameWithoutExtension(tempMusicLibraryFile); string tempFileLoc = tempMusicLibraryFile; LibraryFile tempLibFile = new LibraryFile(tempFileLoc, tempLibName, tempSource); return(tempLibFile); }
// Generate a new library file using the selected directory. private async Task<LibraryFile> DoGenerateLibrary(string selectedFolder, string libraryName) { LibraryFile tempLibraryFile = new LibraryFile(); await Task.Run(() => { ObservableCollection<Song> tempLibrary = GenerateLibrary.Create(selectedFolder); // Adds the songs contained within this new library to the library window. MusickLibrary.SongList.Union(tempLibrary).ToList(); // Create library entry for the application to use and see. tempLibraryFile = GenerateLibrary.CreateLibraryEntry(tempLibrary, libraryName); // Serialize Library. JSON.SerializeLibrary(libraryName, tempLibrary); return tempLibraryFile; } ); return tempLibraryFile; }