public static void AddMusicFile(SupportedFileExtension ext, string path) { if (path == null) { throw new ArgumentNullException(nameof(path), $"Cannot add new music file, since path is null."); } if (path.Length < 8) // "C:\x.abc" is 8 characters long { throw new ArgumentException("Cannot add new music file, path is too short.", nameof(path)); } try { ITaggingService taggingService = DependencyInjector.GetService <ITaggingService>(); Dictionary <string, object> tagData = taggingService.Read(path, new List <string>() { ext.ToString() }); MetaData trackData = UtilityHelper.FormatMetaData(tagData); TrackLocal track = new TrackLocal(new MusicFileProperties(path), trackData); TracklistTracks.Add(track); } catch (Exception) // TODO: more polished exception handling { UtilityHelper.ShowExceptionDialog( "File reading error", "File reading error happened while trying to parse a music file from local directory. This file will be omitted from Tracklist!", $"File location: {path}"); } }
private Dictionary <string, SupportedFileExtension> filePaths; // The found paths (each path is unique) public LocalMediaPack(string rootPath, bool isResultOfDriveSearch, SupportedFileExtension baseExtension = SupportedFileExtension.Unknown) { filePaths = new Dictionary <string, SupportedFileExtension>(); RootPath = rootPath; BaseExtension = baseExtension; // Will not be used if IsResultOfDriveSearch = false IsResultOfDriveSearch = isResultOfDriveSearch; }
private bool IsSupported(ProjectFile projectFile) { var extensions = SupportedFileExtension.Split(';'); return(extensions?.Length > 1 ? extensions.Any(ext => IsSupported1(projectFile, ext)) : IsSupported1(projectFile, SupportedFileExtension)); }
public static SupportedMediaPlayers GetOfflinePlayersWhichSupportFormat(SupportedFileExtension ext) { switch (ext) { case SupportedFileExtension.MP3: case SupportedFileExtension.FLAC: case SupportedFileExtension.All: return(SupportedMediaPlayers.Foobar2000); } return(SupportedMediaPlayers.Foobar2000); // Default offline player }
public bool AddFilePath(string path, SupportedFileExtension type) // Adds a new path of a file inside the LMP's root directory { if (path == null) { throw new ArgumentNullException(nameof(path), $"Cannot add file path, since it is null."); } if (path.Length < 8) { throw new ArgumentException($"Cannot add file path ({path}), it is too short.", nameof(path)); // "C:\x.abc" is 8 characters long } if (filePaths.ContainsKey(path)) { return(false); // Cannot add, already added, use ModifyFilePath() instead } else { filePaths.Add(path, type); return(true); // Added successfully } }
public bool ModifyFilePath(string oldPath, string newPath, SupportedFileExtension newType) // Changes an already existing file path { if (oldPath == null || newPath == null) { throw new ArgumentNullException($"Cannot add file path, since one or both of the parameters ({oldPath}, {newPath}) are null."); } if (oldPath.Length < 8 || newPath.Length < 8) { throw new ArgumentException($"Cannot add file path, one or both of the paramteres is too short ({oldPath}, {newPath})."); // "C:\x.abc" is 8 characters long } if (!filePaths.ContainsKey(oldPath)) { return(false); // Cannot modify non existent entry, use AddFilePath() instead } else { filePaths.Remove(oldPath); filePaths.Add(newPath, newType); return(true); // Added successfully } }
private static void LoadPersistence(IDatabaseService dbService, IFileService fileService) // Loads all data from an already existing database file { List <string[]> lmpRows = dbService.GetAllRows("LocalMediaPacks"); // Getting LocalMediaPack objects if (lmpRows.Count > 0) { foreach (string[] row in lmpRows) { string rootPath = row[0]; SupportedFileExtension baseExtension = (row[1].Length > 0) ? (SupportedFileExtension)Enum.Parse(typeof(SupportedFileExtension), row[1]) : SupportedFileExtension.MP3; // Default type is MP3 if cell is null bool isResultOfDriveSearch = Int32.Parse(row[2]) == 1; string filePaths = row[3]; // Array of strings, divided by "|" LocalMediaPack lmp = new LocalMediaPack(rootPath, isResultOfDriveSearch, baseExtension); foreach (string path in filePaths.Split('|')) { SupportedFileExtension type = (SupportedFileExtension)Enum.Parse(typeof(SupportedFileExtension), fileService.GetExtensionFromFilePath(path).ToUpper()); // Eg. "MP3" or "FLAC" lmp.AddFilePath(path, type); } LMPContext.StoredLocalMediaPacks.Add(lmp); // Adding to current container } } }
public bool GetFileSupportedFileExtension(string path, out SupportedFileExtension type) // Returns an already existing path's extension type { // We don't have to re-write "get value" logic, since Dictionary already provides it, // however, we still want to hide the internal data structure return(filePaths.TryGetValue(path, out type)); }