/// <summary> /// Saves to file. /// </summary> /// <param name="FileName">Name of the file.</param> /// <param name="xInfo">The x information.</param> /// <returns><c>true</c> if XXXX, <c>false</c> otherwise.</returns> public static bool SaveToFile(string FileName, ID3v1 xInfo) { ID3v1 xTemp = ID3v1.LoadFromFile(FileName); xInfo.FileName = FileName; if (xTemp == null) { xInfo.FileHasTag = false; } else { xInfo.FileHasTag = true; } return(xInfo.UpdateFile()); }
/// <summary> /// Loads from file. /// </summary> /// <param name="FileName">Name of the file.</param> /// <returns>ID3v1.</returns> public static ID3v1 LoadFromFile(string FileName) { byte[] Buffer = new byte[128]; FileStream xStream; try { xStream = new FileStream(FileName, FileMode.Open); xStream.Seek(-128, SeekOrigin.End); xStream.Read(Buffer, 0, 128); xStream.Close(); } catch (FileNotFoundException EX) { return(null); } // Convert the Byte Array to a String // Encoding xASCII = new ASCIIEncoding(); // NB: Encoding is an Abstract class Encoding xASCII = Encoding.Default; string ID3TagString = xASCII.GetString(Buffer); // If there is an attched ID3 v1.x TAG then read it if (ID3TagString.Substring(0, 3) == "TAG") { ID3v1 xInfo = new ID3v1(); xInfo.FileName = FileName; xInfo.Title = ID3TagString.Substring(3, 30).Trim(ID3v1.TrimChars); xInfo.Artist = ID3TagString.Substring(33, 30).Trim(ID3v1.TrimChars); xInfo.Album = ID3TagString.Substring(63, 30).Trim(ID3v1.TrimChars); xInfo.Year = ID3TagString.Substring(93, 4).Trim(ID3v1.TrimChars); xInfo.Comment = ID3TagString.Substring(97, 28).Trim(ID3v1.TrimChars); // Get the track number if TAG conforms to ID3 v1.1 if (ID3TagString[125] == 0) { xInfo.Track = Buffer[126]; } else { xInfo.Track = 0; } xInfo.GenreID = Buffer[127]; xInfo.FileHasTag = true; return(xInfo); } return(null); }