public SharedFile(string filePath, byte[] fileHash, RIndexedHashtable <string, string> metaData, string comment, byte rating, DateTime?lastRequest) { if (filePath == null) { throw new ArgumentNullException("filePath"); } if (fileHash == null) { throw new ArgumentNullException("fileHash"); } if (fileHash.Length != 64) { throw new ArgumentException(); } if (rating > 3) { throw new ArgumentOutOfRangeException("rating"); } if (comment == null) { throw new ArgumentNullException("comment"); } m_FilePath = filePath; m_DirectoryPath = Path.GetDirectoryName(m_FilePath); m_FileName = Path.GetFileName(m_FilePath); m_FileHash = fileHash; m_FileHashString = Core.ByteArrayToString(m_FileHash); m_OnceHashedFileHash = ComputeHashes.SHA512Compute(m_FileHash); m_OnceHashedFileHashString = Core.ByteArrayToString(m_OnceHashedFileHash); m_TwiceHashedFileHash = ComputeHashes.SHA512Compute(m_OnceHashedFileHash); m_TwiceHashedFileHashString = Core.ByteArrayToString(m_TwiceHashedFileHash); m_ThriceHashedFileHash = ComputeHashes.SHA512Compute(m_TwiceHashedFileHash); m_ThriceHashedFileHashString = Core.ByteArrayToString(m_ThriceHashedFileHash); m_FileSize = new FileInfo(m_FilePath).Length; m_FileSizeString = Core.LengthToString(m_FileSize); m_Sectors = m_FileSize / 32768; if (metaData.IsEmpty) { try { switch (Path.GetExtension(m_FilePath)) { case ".mp3": FileStream fileStream = new FileStream(m_FilePath, FileMode.Open, FileAccess.Read, FileShare.Read); ID3v1TagReader id3v1 = new ID3v1TagReader(fileStream); if (id3v1.HasTag) { if (id3v1.HasAlbum && id3v1.Album.Trim() != string.Empty) { m_MetaData.Add("Album", id3v1.Album.Trim()); } if (id3v1.HasArtist && id3v1.Artist.Trim() != string.Empty) { m_MetaData.Add("Artist", id3v1.Artist.Trim()); } if (id3v1.HasTitle && id3v1.Title.Trim() != string.Empty) { m_MetaData.Add("Title", id3v1.Title.Trim()); } } ID3v2TagTextFrameReader id3v2 = new ID3v2TagTextFrameReader(fileStream); if (id3v2.HasTag) { if (id3v2.Frames.ContainsKey("TALB") && id3v2.Frames["TALB"].Trim() != string.Empty) { m_MetaData.Add("TALB", id3v2.Frames["TALB"].Trim()); } if (id3v2.Frames.ContainsKey("TPE1") && id3v2.Frames["TPE1"].Trim() != string.Empty) { m_MetaData.Add("TPE1", id3v2.Frames["TPE1"].Trim()); } if (id3v2.Frames.ContainsKey("TIT2") && id3v2.Frames["TIT2"].Trim() != string.Empty) { m_MetaData.Add("TIT2", id3v2.Frames["TIT2"].Trim()); } } fileStream.Close(); break; default: FileVersionInfo fileVersionInfo = FileVersionInfo.GetVersionInfo(m_FilePath); if (fileVersionInfo.CompanyName != null && fileVersionInfo.CompanyName.Trim() != string.Empty) { m_MetaData.Add("CompanyName", fileVersionInfo.CompanyName.Trim()); } if (fileVersionInfo.ProductName != null && fileVersionInfo.ProductName.Trim() != string.Empty) { m_MetaData.Add("ProductName", fileVersionInfo.ProductName.Trim()); } break; } } catch (Exception ex) { m_Logger.Log(ex, "An Exception was thrown while gathering meta data!"); } } else { m_MetaData = metaData; } Core.ParseMetaData(m_MetaData, out m_Album, out m_Artist, out m_Title); m_Rating = rating; m_Comment = comment; m_LastRequest = lastRequest; m_LastWriteTime = File.GetLastWriteTime(m_FilePath); }
public SharedFile(string filePath, byte[] fileHash, RIndexedHashtable<string, string> metaData, string comment, byte rating, DateTime? lastRequest) { if (filePath == null) throw new ArgumentNullException("filePath"); if (fileHash == null) throw new ArgumentNullException("fileHash"); if (fileHash.Length != 64) throw new ArgumentException(); if (rating > 3) throw new ArgumentOutOfRangeException("rating"); if (comment == null) throw new ArgumentNullException("comment"); m_FilePath = filePath; m_DirectoryPath = Path.GetDirectoryName(m_FilePath); m_FileName = Path.GetFileName(m_FilePath); m_FileHash = fileHash; m_FileHashString = Core.ByteArrayToString(m_FileHash); m_OnceHashedFileHash = ComputeHashes.SHA512Compute(m_FileHash); m_OnceHashedFileHashString = Core.ByteArrayToString(m_OnceHashedFileHash); m_TwiceHashedFileHash = ComputeHashes.SHA512Compute(m_OnceHashedFileHash); m_TwiceHashedFileHashString = Core.ByteArrayToString(m_TwiceHashedFileHash); m_ThriceHashedFileHash = ComputeHashes.SHA512Compute(m_TwiceHashedFileHash); m_ThriceHashedFileHashString = Core.ByteArrayToString(m_ThriceHashedFileHash); m_FileSize = new FileInfo(m_FilePath).Length; m_FileSizeString = Core.LengthToString(m_FileSize); m_Sectors = m_FileSize / 32768; if (metaData.IsEmpty) try { switch (Path.GetExtension(m_FilePath)) { case ".mp3": FileStream fileStream = new FileStream(m_FilePath, FileMode.Open, FileAccess.Read, FileShare.Read); ID3v1TagReader id3v1 = new ID3v1TagReader(fileStream); if (id3v1.HasTag) { if (id3v1.HasAlbum && id3v1.Album.Trim() != string.Empty) m_MetaData.Add("Album", id3v1.Album.Trim()); if (id3v1.HasArtist && id3v1.Artist.Trim() != string.Empty) m_MetaData.Add("Artist", id3v1.Artist.Trim()); if (id3v1.HasTitle && id3v1.Title.Trim() != string.Empty) m_MetaData.Add("Title", id3v1.Title.Trim()); } ID3v2TagTextFrameReader id3v2 = new ID3v2TagTextFrameReader(fileStream); if (id3v2.HasTag) { if (id3v2.Frames.ContainsKey("TALB") && id3v2.Frames["TALB"].Trim() != string.Empty) m_MetaData.Add("TALB", id3v2.Frames["TALB"].Trim()); if (id3v2.Frames.ContainsKey("TPE1") && id3v2.Frames["TPE1"].Trim() != string.Empty) m_MetaData.Add("TPE1", id3v2.Frames["TPE1"].Trim()); if (id3v2.Frames.ContainsKey("TIT2") && id3v2.Frames["TIT2"].Trim() != string.Empty) m_MetaData.Add("TIT2", id3v2.Frames["TIT2"].Trim()); } fileStream.Close(); break; default: FileVersionInfo fileVersionInfo = FileVersionInfo.GetVersionInfo(m_FilePath); if (fileVersionInfo.CompanyName != null && fileVersionInfo.CompanyName.Trim() != string.Empty) m_MetaData.Add("CompanyName", fileVersionInfo.CompanyName.Trim()); if (fileVersionInfo.ProductName != null && fileVersionInfo.ProductName.Trim() != string.Empty) m_MetaData.Add("ProductName", fileVersionInfo.ProductName.Trim()); break; } } catch (Exception ex) { m_Logger.Log(ex, "An Exception was thrown while gathering meta data!"); } else m_MetaData = metaData; Core.ParseMetaData(m_MetaData, out m_Album, out m_Artist, out m_Title); m_Rating = rating; m_Comment = comment; m_LastRequest = lastRequest; m_LastWriteTime = File.GetLastWriteTime(m_FilePath); }