public static bool RemoveTag(string fileName)
{
FileStream stream=File.Open(fileName,FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite);
try
{
TagHeader header=TagHeader.FromStream(stream);
if(header==null)
{
return false;
}
// An intermediate file needs to be used.
string intermediateFile=GetTempIntermediateFileName(fileName);
FileStream intermedStream=File.Create(intermediateFile);
stream.Seek(header.TagSize+10, SeekOrigin.Begin);
//Copy the data after the tag to the intermediate file.
CopyFromStreamToStream(stream, intermedStream);
intermedStream.Close();
stream.Close();
// If control reaches this point, then everything went file, so
// should normally delete the original file and rename the intermediate file.
// But as a safety measure, for pre-release, alpha, and beta version,
// instead of removing the file, I decided to rename the old file to
// fileName+".old."+revisionNumber instead. The user can manually delete
// the these files after ensuring the integrity of the new files.
#if ACHAMENES_ID3_BACKUP
File.Move(fileName, GetBackupFileName(fileName));
#else
File.Delete(fileName);
#endif
File.Move(intermediateFile, fileName);
return true;
}
finally
{
if(stream!=null)
{
stream.Close();
}
}
}
}