Author: bnickel
Date: 2007-12-25 07:12:52 -0500 (Tue, 25 Dec 2007)
New Revision: 91875
Modified:
trunk/taglib-sharp/ChangeLog
trunk/taglib-sharp/src/TagLib/Asf/File.cs
trunk/taglib-sharp/src/TagLib/Flac/File.cs
trunk/taglib-sharp/src/TagLib/Mpeg4/File.cs
trunk/taglib-sharp/src/TagLib/NonContainer/File.cs
trunk/taglib-sharp/src/TagLib/Ogg/File.cs
trunk/taglib-sharp/src/TagLib/Riff/File.cs
Log:
2007-12-25 Brian Nickel <[EMAIL PROTECTED]>
* src/TagLib/Riff/File.cs:
* src/TagLib/Flac/File.cs:
* src/TagLib/Mpeg4/File.cs:
* src/TagLib/NonContainer/File.cs:
* src/TagLib/Asf/File.cs:
* src/TagLib/Ogg/File.cs: Wrap constructors and save operations in
try/finally to ensure the streams get closed. (Thanks to oliphant for
the bug report.)
Modified: trunk/taglib-sharp/ChangeLog
===================================================================
--- trunk/taglib-sharp/ChangeLog 2007-12-25 11:02:14 UTC (rev 91874)
+++ trunk/taglib-sharp/ChangeLog 2007-12-25 12:12:52 UTC (rev 91875)
@@ -1,5 +1,16 @@
2007-12-25 Brian Nickel <[EMAIL PROTECTED]>
+ * src/TagLib/Riff/File.cs:
+ * src/TagLib/Flac/File.cs:
+ * src/TagLib/Mpeg4/File.cs:
+ * src/TagLib/NonContainer/File.cs:
+ * src/TagLib/Asf/File.cs:
+ * src/TagLib/Ogg/File.cs: Wrap constructors and save operations in
+ try/finally to ensure the streams get closed. (Thanks to oliphant for
+ the bug report.)
+
+2007-12-25 Brian Nickel <[EMAIL PROTECTED]>
+
* src/TagLib/Id3v1/Tag.cs: Added constructor to create from data. Added
documentation. Fixed properties to produce correct output when empty.
Removed broken IsEmpty property.
Modified: trunk/taglib-sharp/src/TagLib/Asf/File.cs
===================================================================
--- trunk/taglib-sharp/src/TagLib/Asf/File.cs 2007-12-25 11:02:14 UTC (rev
91874)
+++ trunk/taglib-sharp/src/TagLib/Asf/File.cs 2007-12-25 12:12:52 UTC (rev
91875)
@@ -179,30 +179,31 @@
public override void Save ()
{
Mode = AccessMode.Write;
-
- HeaderObject header = new HeaderObject (this, 0);
-
- if (asf_tag == null) {
- header.RemoveContentDescriptors ();
- TagTypesOnDisk &= ~ TagTypes.Asf;
- } else {
- TagTypesOnDisk |= TagTypes.Asf;
- header.AddUniqueObject (
- asf_tag.ContentDescriptionObject);
- header.AddUniqueObject (
-
asf_tag.ExtendedContentDescriptionObject);
- header.Extension.AddUniqueObject (
- asf_tag.MetadataLibraryObject);
+ try {
+ HeaderObject header = new HeaderObject (this,
0);
+
+ if (asf_tag == null) {
+ header.RemoveContentDescriptors ();
+ TagTypesOnDisk &= ~ TagTypes.Asf;
+ } else {
+ TagTypesOnDisk |= TagTypes.Asf;
+ header.AddUniqueObject (
+
asf_tag.ContentDescriptionObject);
+ header.AddUniqueObject (
+
asf_tag.ExtendedContentDescriptionObject);
+ header.Extension.AddUniqueObject (
+ asf_tag.MetadataLibraryObject);
+ }
+
+ ByteVector output = header.Render ();
+ long diff = output.Count - (long)
header.OriginalSize;
+ Insert (output, 0, (long) header.OriginalSize);
+
+ InvariantStartPosition += diff;
+ InvariantEndPosition += diff;
+ } finally {
+ Mode = AccessMode.Closed;
}
-
- ByteVector output = header.Render ();
- long diff = output.Count - (long) header.OriginalSize;
- Insert (output, 0, (long) header.OriginalSize);
-
- InvariantStartPosition += diff;
- InvariantEndPosition += diff;
-
- Mode = AccessMode.Closed;
}
/// <summary>
@@ -406,21 +407,22 @@
private void Read (ReadStyle propertiesStyle)
{
Mode = AccessMode.Read;
-
- HeaderObject header = new HeaderObject (this, 0);
-
- if (header.HasContentDescriptors)
- TagTypesOnDisk |= TagTypes.Asf;
-
- asf_tag = new Asf.Tag (header);
-
- InvariantStartPosition = (long) header.OriginalSize;
- InvariantEndPosition = Length;
-
- if (propertiesStyle != ReadStyle.None)
- properties = header.Properties;
-
- Mode = AccessMode.Closed;
+ try {
+ HeaderObject header = new HeaderObject (this,
0);
+
+ if (header.HasContentDescriptors)
+ TagTypesOnDisk |= TagTypes.Asf;
+
+ asf_tag = new Asf.Tag (header);
+
+ InvariantStartPosition = (long)
header.OriginalSize;
+ InvariantEndPosition = Length;
+
+ if (propertiesStyle != ReadStyle.None)
+ properties = header.Properties;
+ } finally {
+ Mode = AccessMode.Closed;
+ }
}
#endregion
Modified: trunk/taglib-sharp/src/TagLib/Flac/File.cs
===================================================================
--- trunk/taglib-sharp/src/TagLib/Flac/File.cs 2007-12-25 11:02:14 UTC (rev
91874)
+++ trunk/taglib-sharp/src/TagLib/Flac/File.cs 2007-12-25 12:12:52 UTC (rev
91875)
@@ -187,75 +187,78 @@
public override void Save ()
{
Mode = AccessMode.Write;
-
- // Update the tags at the beginning of the file.
- long metadata_start = StartTag.Write ();
- long metadata_end;
-
- // Get all the blocks, but don't read the data for ones
- // we're filling with stored data.
- IList<Block> old_blocks = ReadBlocks (ref
metadata_start,
- out metadata_end, BlockMode.Blacklist,
- BlockType.XiphComment, BlockType.Picture);
-
- // Create new vorbis comments is they don't exist.
- GetTag (TagTypes.Xiph, true);
-
- // Create new blocks and add the basics.
- List<Block> new_blocks = new List<Block> ();
- new_blocks.Add (old_blocks [0]);
-
- // Add blocks we don't deal with from the file.
- foreach (Block block in old_blocks)
- if (block.Type != BlockType.StreamInfo &&
- block.Type != BlockType.XiphComment &&
- block.Type != BlockType.Picture &&
- block.Type != BlockType.Padding)
- new_blocks.Add (block);
-
- new_blocks.Add (new Block (BlockType.XiphComment,
- (GetTag (TagTypes.Xiph, true) as
- Ogg.XiphComment).Render (false)));
-
- foreach (IPicture picture in metadata.Pictures) {
- if (picture == null)
- continue;
+ try {
+ // Update the tags at the beginning of the file.
+ long metadata_start = StartTag.Write ();
+ long metadata_end;
- new_blocks.Add (new Block (BlockType.Picture,
- new Picture (picture).Render ()));
+ // Get all the blocks, but don't read the data
for ones
+ // we're filling with stored data.
+ IList<Block> old_blocks = ReadBlocks (ref
metadata_start,
+ out metadata_end, BlockMode.Blacklist,
+ BlockType.XiphComment,
BlockType.Picture);
+
+ // Create new vorbis comments is they don't
exist.
+ GetTag (TagTypes.Xiph, true);
+
+ // Create new blocks and add the basics.
+ List<Block> new_blocks = new List<Block> ();
+ new_blocks.Add (old_blocks [0]);
+
+ // Add blocks we don't deal with from the file.
+ foreach (Block block in old_blocks)
+ if (block.Type != BlockType.StreamInfo
&&
+ block.Type !=
BlockType.XiphComment &&
+ block.Type != BlockType.Picture
&&
+ block.Type != BlockType.Padding)
+ new_blocks.Add (block);
+
+ new_blocks.Add (new Block
(BlockType.XiphComment,
+ (GetTag (TagTypes.Xiph, true) as
+ Ogg.XiphComment).Render
(false)));
+
+ foreach (IPicture picture in metadata.Pictures)
{
+ if (picture == null)
+ continue;
+
+ new_blocks.Add (new Block
(BlockType.Picture,
+ new Picture (picture).Render
()));
+ }
+
+ // Get the length of the blocks.
+ long length = 0;
+ foreach (Block block in new_blocks)
+ length += block.TotalSize;
+
+ // Find the padding size to avoid trouble. If
that fails
+ // make some.
+ long padding_size = metadata_end -
metadata_start -
+ BlockHeader.Size - length;
+ if (padding_size < 0)
+ padding_size = 1024 * 4;
+
+ // Add a padding block.
+ if (padding_size != 0)
+ new_blocks.Add (new Block
(BlockType.Padding,
+ new ByteVector ((int)
padding_size)));
+
+ // Render the blocks.
+ ByteVector block_data = new ByteVector ();
+ for (int i = 0; i < new_blocks.Count; i ++)
+ block_data.Add (new_blocks [i].Render (
+ i == new_blocks.Count - 1));
+
+ // Update the blocks.
+ Insert (block_data, metadata_start,
metadata_end -
+ metadata_start);
+
+ // Update the tags at the end of the file.
+ EndTag.Write ();
+
+ TagTypesOnDisk = TagTypes;
+ } finally {
+ Mode = AccessMode.Closed;
}
-
- // Get the length of the blocks.
- long length = 0;
- foreach (Block block in new_blocks)
- length += block.TotalSize;
-
- // Find the padding size to avoid trouble. If that fails
- // make some.
- long padding_size = metadata_end - metadata_start -
- BlockHeader.Size - length;
- if (padding_size < 0)
- padding_size = 1024 * 4;
-
- // Add a padding block.
- if (padding_size != 0)
- new_blocks.Add (new Block (BlockType.Padding,
- new ByteVector ((int) padding_size)));
-
- // Render the blocks.
- ByteVector block_data = new ByteVector ();
- for (int i = 0; i < new_blocks.Count; i ++)
- block_data.Add (new_blocks [i].Render (
- i == new_blocks.Count - 1));
-
- // Update the blocks.
- Insert (block_data, metadata_start, metadata_end -
- metadata_start);
-
- // Update the tags at the end of the file.
- EndTag.Write ();
- Mode = AccessMode.Closed;
- TagTypesOnDisk = TagTypes;
}
/// <summary>
Modified: trunk/taglib-sharp/src/TagLib/Mpeg4/File.cs
===================================================================
--- trunk/taglib-sharp/src/TagLib/Mpeg4/File.cs 2007-12-25 11:02:14 UTC (rev
91874)
+++ trunk/taglib-sharp/src/TagLib/Mpeg4/File.cs 2007-12-25 12:12:52 UTC (rev
91875)
@@ -199,88 +199,90 @@
// Try to get into write mode.
Mode = File.AccessMode.Write;
-
- FileParser parser = new FileParser (this);
- parser.ParseBoxHeaders ();
-
- InvariantStartPosition = parser.MdatStartPosition;
- InvariantEndPosition = parser.MdatEndPosition;
-
- long size_change = 0;
- long write_position = 0;
-
- ByteVector tag_data = udta_box.Render ();
-
- // If we don't have a "udta" box to overwrite...
- if (parser.UdtaTree == null ||
- parser.UdtaTree.Length == 0 ||
- parser.UdtaTree [parser.UdtaTree.Length - 1
- ].BoxType != BoxType.Udta) {
+ try {
+ FileParser parser = new FileParser (this);
+ parser.ParseBoxHeaders ();
- // Stick the box at the end of the moov box.
- BoxHeader moov_header = parser.MoovTree [
- parser.MoovTree.Length - 1];
- size_change = tag_data.Count;
- write_position = moov_header.Position +
- moov_header.TotalBoxSize;
- Insert (tag_data, write_position, 0);
-
- // Overwrite the parent box sizes.
- for (int i = parser.MoovTree.Length - 1; i >= 0;
- i --)
- size_change = parser.MoovTree [i
- ].Overwrite (this, size_change);
- } else {
- // Overwrite the old box.
- BoxHeader udta_header = parser.UdtaTree [
- parser.UdtaTree.Length - 1];
- size_change = tag_data.Count -
- udta_header.TotalBoxSize;
- write_position = udta_header.Position;
- Insert (tag_data, write_position,
- udta_header.TotalBoxSize);
-
- // Overwrite the parent box sizes.
- for (int i = parser.UdtaTree.Length - 2; i >= 0;
- i --)
- size_change = parser.UdtaTree [i
- ].Overwrite (this, size_change);
- }
-
- // If we've had a size change, we may need to adjust
- // chunk offsets.
- if (size_change != 0) {
- // We may have moved the offset boxes, so we
- // need to reread.
- parser.ParseChunkOffsets ();
InvariantStartPosition =
parser.MdatStartPosition;
InvariantEndPosition = parser.MdatEndPosition;
- foreach (Box box in parser.ChunkOffsetBoxes) {
- IsoChunkLargeOffsetBox co64 =
- box as IsoChunkLargeOffsetBox;
+ long size_change = 0;
+ long write_position = 0;
+
+ ByteVector tag_data = udta_box.Render ();
+
+ // If we don't have a "udta" box to overwrite...
+ if (parser.UdtaTree == null ||
+ parser.UdtaTree.Length == 0 ||
+ parser.UdtaTree [parser.UdtaTree.Length
- 1
+ ].BoxType != BoxType.Udta) {
- if (co64 != null) {
- co64.Overwrite (this,
- size_change,
- write_position);
- continue;
- }
+ // Stick the box at the end of the moov
box.
+ BoxHeader moov_header = parser.MoovTree
[
+ parser.MoovTree.Length - 1];
+ size_change = tag_data.Count;
+ write_position = moov_header.Position +
+ moov_header.TotalBoxSize;
+ Insert (tag_data, write_position, 0);
- IsoChunkOffsetBox stco =
- box as IsoChunkOffsetBox;
+ // Overwrite the parent box sizes.
+ for (int i = parser.MoovTree.Length -
1; i >= 0;
+ i --)
+ size_change = parser.MoovTree [i
+ ].Overwrite (this,
size_change);
+ } else {
+ // Overwrite the old box.
+ BoxHeader udta_header = parser.UdtaTree
[
+ parser.UdtaTree.Length - 1];
+ size_change = tag_data.Count -
+ udta_header.TotalBoxSize;
+ write_position = udta_header.Position;
+ Insert (tag_data, write_position,
+ udta_header.TotalBoxSize);
- if (stco != null) {
- stco.Overwrite (this,
- size_change,
- write_position);
- continue;
+ // Overwrite the parent box sizes.
+ for (int i = parser.UdtaTree.Length -
2; i >= 0;
+ i --)
+ size_change = parser.UdtaTree [i
+ ].Overwrite (this,
size_change);
+ }
+
+ // If we've had a size change, we may need to
adjust
+ // chunk offsets.
+ if (size_change != 0) {
+ // We may have moved the offset boxes,
so we
+ // need to reread.
+ parser.ParseChunkOffsets ();
+ InvariantStartPosition =
parser.MdatStartPosition;
+ InvariantEndPosition =
parser.MdatEndPosition;
+
+ foreach (Box box in
parser.ChunkOffsetBoxes) {
+ IsoChunkLargeOffsetBox co64 =
+ box as
IsoChunkLargeOffsetBox;
+
+ if (co64 != null) {
+ co64.Overwrite (this,
+ size_change,
+ write_position);
+ continue;
+ }
+
+ IsoChunkOffsetBox stco =
+ box as
IsoChunkOffsetBox;
+
+ if (stco != null) {
+ stco.Overwrite (this,
+ size_change,
+ write_position);
+ continue;
+ }
}
}
+
+ TagTypesOnDisk = TagTypes;
+ } finally {
+ Mode = File.AccessMode.Closed;
}
-
- Mode = File.AccessMode.Closed;
- TagTypesOnDisk = TagTypes;
}
/// <summary>
@@ -360,53 +362,55 @@
// TODO: Support Id3v2 boxes!!!
tag = new CombinedTag ();
Mode = AccessMode.Read;
-
- FileParser parser = new FileParser (this);
-
- if (propertiesStyle == ReadStyle.None)
- parser.ParseTag ();
- else
- parser.ParseTagAndProperties ();
-
- InvariantStartPosition = parser.MdatStartPosition;
- InvariantEndPosition = parser.MdatEndPosition;
-
- udta_box = parser.UserDataBox;
-
- if (udta_box != null && udta_box.GetChild (BoxType.Meta)
- != null && udta_box.GetChild (BoxType.Meta
- ).GetChild (BoxType.Ilst) != null)
- TagTypesOnDisk |= TagTypes.Apple;
-
- if (udta_box == null)
- udta_box = new IsoUserDataBox ();
-
- apple_tag = new AppleTag (udta_box);
- tag.SetTags (apple_tag);
-
- // If we're not reading properties, we're done.
- if (propertiesStyle == ReadStyle.None) {
+ try {
+ FileParser parser = new FileParser (this);
+
+ if (propertiesStyle == ReadStyle.None)
+ parser.ParseTag ();
+ else
+ parser.ParseTagAndProperties ();
+
+ InvariantStartPosition =
parser.MdatStartPosition;
+ InvariantEndPosition = parser.MdatEndPosition;
+
+ udta_box = parser.UserDataBox;
+
+ if (udta_box != null && udta_box.GetChild
(BoxType.Meta)
+ != null && udta_box.GetChild
(BoxType.Meta
+ ).GetChild (BoxType.Ilst) != null)
+ TagTypesOnDisk |= TagTypes.Apple;
+
+ if (udta_box == null)
+ udta_box = new IsoUserDataBox ();
+
+ apple_tag = new AppleTag (udta_box);
+ tag.SetTags (apple_tag);
+
+ // If we're not reading properties, we're done.
+ if (propertiesStyle == ReadStyle.None) {
+ Mode = AccessMode.Closed;
+ return;
+ }
+
+ // Get the movie header box.
+ IsoMovieHeaderBox mvhd_box =
parser.MovieHeaderBox;
+ if(mvhd_box == null) {
+ Mode = AccessMode.Closed;
+ throw new CorruptFileException (
+ "mvhd box not found.");
+ }
+
+ IsoAudioSampleEntry audio_sample_entry =
+ parser.AudioSampleEntry;
+ IsoVisualSampleEntry visual_sample_entry =
+ parser.VisualSampleEntry;
+
+ // Read the properties.
+ properties = new Properties (mvhd_box.Duration,
+ audio_sample_entry,
visual_sample_entry);
+ } finally {
Mode = AccessMode.Closed;
- return;
}
-
- // Get the movie header box.
- IsoMovieHeaderBox mvhd_box = parser.MovieHeaderBox;
- if(mvhd_box == null) {
- Mode = AccessMode.Closed;
- throw new CorruptFileException (
- "mvhd box not found.");
- }
-
- IsoAudioSampleEntry audio_sample_entry =
- parser.AudioSampleEntry;
- IsoVisualSampleEntry visual_sample_entry =
- parser.VisualSampleEntry;
-
- // Read the properties.
- properties = new Properties (mvhd_box.Duration,
- audio_sample_entry, visual_sample_entry);
- Mode = AccessMode.Closed;
}
#endregion
Modified: trunk/taglib-sharp/src/TagLib/NonContainer/File.cs
===================================================================
--- trunk/taglib-sharp/src/TagLib/NonContainer/File.cs 2007-12-25 11:02:14 UTC
(rev 91874)
+++ trunk/taglib-sharp/src/TagLib/NonContainer/File.cs 2007-12-25 12:12:52 UTC
(rev 91875)
@@ -203,11 +203,14 @@
{
long start, end;
Mode = AccessMode.Write;
- tag.Write (out start, out end);
- InvariantStartPosition = start;
- InvariantEndPosition = end;
- Mode = AccessMode.Closed;
- TagTypesOnDisk = TagTypes;
+ try {
+ tag.Write (out start, out end);
+ InvariantStartPosition = start;
+ InvariantEndPosition = end;
+ TagTypesOnDisk = TagTypes;
+ } finally {
+ Mode = AccessMode.Closed;
+ }
}
/// <summary>
@@ -366,27 +369,29 @@
private void Read (ReadStyle propertiesStyle)
{
Mode = AccessMode.Read;
- tag = new Tag (this);
-
- // Read the tags and property data at the beginning of
- // the file.
- InvariantStartPosition = tag.ReadStart ();
- TagTypesOnDisk |= StartTag.TagTypes;
- ReadStart (InvariantStartPosition, propertiesStyle);
-
- // Read the tags and property data at the end of the
- // file.
- InvariantEndPosition = tag.ReadEnd ();
- TagTypesOnDisk |= EndTag.TagTypes;
- ReadEnd (InvariantEndPosition, propertiesStyle);
-
- // Read the audio properties.
- properties = (propertiesStyle != ReadStyle.None) ?
- ReadProperties (InvariantStartPosition,
- InvariantEndPosition, propertiesStyle) :
- null;
-
- Mode = AccessMode.Closed;
+ try {
+ tag = new Tag (this);
+
+ // Read the tags and property data at the
beginning of
+ // the file.
+ InvariantStartPosition = tag.ReadStart ();
+ TagTypesOnDisk |= StartTag.TagTypes;
+ ReadStart (InvariantStartPosition,
propertiesStyle);
+
+ // Read the tags and property data at the end
of the
+ // file.
+ InvariantEndPosition = tag.ReadEnd ();
+ TagTypesOnDisk |= EndTag.TagTypes;
+ ReadEnd (InvariantEndPosition, propertiesStyle);
+
+ // Read the audio properties.
+ properties = (propertiesStyle !=
ReadStyle.None) ?
+ ReadProperties (InvariantStartPosition,
+ InvariantEndPosition,
propertiesStyle) :
+ null;
+ } finally {
+ Mode = AccessMode.Closed;
+ }
}
#endregion
Modified: trunk/taglib-sharp/src/TagLib/Ogg/File.cs
===================================================================
--- trunk/taglib-sharp/src/TagLib/Ogg/File.cs 2007-12-25 11:02:14 UTC (rev
91874)
+++ trunk/taglib-sharp/src/TagLib/Ogg/File.cs 2007-12-25 12:12:52 UTC (rev
91875)
@@ -53,14 +53,18 @@
public File (string path) : this (path, ReadStyle.Average)
{}
- public File (File.IFileAbstraction abstraction, ReadStyle
propertiesStyle) : base (abstraction)
- {
- Mode = AccessMode.Read;
- tag = new GroupedComment ();
- Read (propertiesStyle);
- Mode = AccessMode.Closed;
- TagTypesOnDisk = TagTypes;
- }
+ public File (File.IFileAbstraction abstraction,
+ ReadStyle propertiesStyle) : base (abstraction)
+ {
+ Mode = AccessMode.Read;
+ try {
+ tag = new GroupedComment ();
+ Read (propertiesStyle);
+ TagTypesOnDisk = TagTypes;
+ } finally {
+ Mode = AccessMode.Closed;
+ }
+ }
public File (File.IFileAbstraction abstraction) : this (abstraction,
ReadStyle.Average)
{}
@@ -105,56 +109,61 @@
tag.Clear ();
}
- public override void Save ()
- {
- Mode = AccessMode.Write;
-
- long end;
- List<Page> pages = new List<Page> ();
- Dictionary<uint, Bitstream> streams = ReadStreams (pages, out end);
- Dictionary<uint, Paginator> paginators = new Dictionary<uint,
Paginator> ();
- List<List<Page>> new_pages = new List<List<Page>> ();
-
- foreach (Page page in pages)
- {
- uint id = page.Header.StreamSerialNumber;
- if (!paginators.ContainsKey (id))
- paginators.Add (id, new Paginator (streams [id].Codec));
-
- paginators [id].AddPage (page);
- }
-
- foreach (uint id in paginators.Keys)
- {
- paginators [id].SetComment (tag.GetComment (id));
- new_pages.Add (new List<Page> (paginators [id].Paginate ()));
- }
-
- ByteVector output = new ByteVector ();
- bool empty;
- do
- {
- empty = true;
- foreach (List<Page> stream_pages in new_pages)
- {
- if (stream_pages.Count == 0)
- continue;
-
- output.Add (stream_pages [0].Render ());
- stream_pages.RemoveAt (0);
-
- if (stream_pages.Count != 0)
- empty = false;
- }
- } while (!empty);
-
- Insert (output, 0, end);
- InvariantStartPosition = output.Count;
- InvariantEndPosition = Length;
-
- Mode = AccessMode.Closed;
- TagTypesOnDisk = TagTypes;
- }
+ public override void Save ()
+ {
+ Mode = AccessMode.Write;
+ try {
+ long end;
+ List<Page> pages = new List<Page> ();
+ Dictionary<uint, Bitstream> streams =
+ ReadStreams (pages, out end);
+ Dictionary<uint, Paginator> paginators =
+ new Dictionary<uint, Paginator> ();
+ List<List<Page>> new_pages =
+ new List<List<Page>> ();
+
+ foreach (Page page in pages) {
+ uint id =
page.Header.StreamSerialNumber;
+ if (!paginators.ContainsKey (id))
+ paginators.Add (id, new Paginator (
+ streams [id].Codec));
+
+ paginators [id].AddPage (page);
+ }
+
+ foreach (uint id in paginators.Keys) {
+ paginators [id].SetComment (
+ tag.GetComment (id));
+ new_pages.Add (new List<Page> (
+ paginators [id].Paginate ()));
+ }
+
+ ByteVector output = new ByteVector ();
+ bool empty;
+ do {
+ empty = true;
+ foreach (List<Page> stream_pages in
new_pages) {
+ if (stream_pages.Count == 0)
+ continue;
+
+ output.Add (stream_pages [0]
+ .Render ());
+ stream_pages.RemoveAt (0);
+
+ if (stream_pages.Count != 0)
+ empty = false;
+ }
+ } while (!empty);
+
+ Insert (output, 0, end);
+ InvariantStartPosition = output.Count;
+ InvariantEndPosition = Length;
+
+ TagTypesOnDisk = TagTypes;
+ } finally {
+ Mode = AccessMode.Closed;
+ }
+ }
private Dictionary<uint, Bitstream> ReadStreams (List<Page> pages, out
long end)
{
Modified: trunk/taglib-sharp/src/TagLib/Riff/File.cs
===================================================================
--- trunk/taglib-sharp/src/TagLib/Riff/File.cs 2007-12-25 11:02:14 UTC (rev
91874)
+++ trunk/taglib-sharp/src/TagLib/Riff/File.cs 2007-12-25 12:12:52 UTC (rev
91875)
@@ -58,22 +58,27 @@
public File (string path) : this (path, ReadStyle.Average)
{}
- public File (File.IFileAbstraction abstraction, ReadStyle
propertiesStyle) : base (abstraction)
- {
- uint riff_size;
- long tag_start, tag_end;
-
- Mode = AccessMode.Read;
- Read (true, propertiesStyle, out riff_size, out tag_start, out
tag_end);
- Mode = AccessMode.Closed;
-
- TagTypesOnDisk = TagTypes;
-
- GetTag (TagTypes.Id3v2, true);
- GetTag (TagTypes.RiffInfo, true);
- GetTag (TagTypes.MovieId, true);
- GetTag (TagTypes.DivX, true);
- }
+ public File (File.IFileAbstraction abstraction,
+ ReadStyle propertiesStyle) : base (abstraction)
+ {
+ uint riff_size;
+ long tag_start, tag_end;
+
+ Mode = AccessMode.Read;
+ try {
+ Read (true, propertiesStyle, out riff_size,
+ out tag_start, out tag_end);
+ } finally {
+ Mode = AccessMode.Closed;
+ }
+
+ TagTypesOnDisk = TagTypes;
+
+ GetTag (TagTypes.Id3v2, true);
+ GetTag (TagTypes.RiffInfo, true);
+ GetTag (TagTypes.MovieId, true);
+ GetTag (TagTypes.DivX, true);
+ }
public File (File.IFileAbstraction abstraction) : this (abstraction,
ReadStyle.Average)
{}
@@ -258,63 +263,69 @@
tag.SetTags (id32_tag, info_tag, mid_tag, divx_tag);
}
- public override void Save ()
- {
- Mode = AccessMode.Write;
-
- ByteVector data = new ByteVector ();
-
- if (id32_tag != null)
- {
- ByteVector tag_data = id32_tag.Render ();
- if (tag_data.Count > 10)
- {
- if (tag_data.Count % 2 == 1)
- tag_data.Add (0);
- data.Add ("ID32");
- data.Add (ByteVector.FromUInt ((uint) tag_data.Count, false));
- data.Add (tag_data);
- }
- }
-
- if (info_tag != null)
- data.Add (info_tag.RenderEnclosed ());
-
- if (mid_tag != null)
- data.Add (mid_tag.RenderEnclosed ());
-
- if (divx_tag != null && !divx_tag.IsEmpty)
- {
- ByteVector tag_data = divx_tag.Render ();
- data.Add ("IDVX");
- data.Add (ByteVector.FromUInt ((uint) tag_data.Count, false));
- data.Add (tag_data);
- }
-
- uint riff_size;
- long tag_start, tag_end;
- Read (false, ReadStyle.None, out riff_size, out tag_start, out
tag_end);
-
- if (tag_start < 12 || tag_end < tag_start)
- tag_start = tag_end = Length;
-
- int length = (int)(tag_end - tag_start);
- int padding_size = length - data.Count - 8;
- if (padding_size < 0)
- padding_size = 1024;
-
- data.Add ("JUNK");
- data.Add (ByteVector.FromUInt ((uint)padding_size, false));
- data.Add (new ByteVector (padding_size));
-
- Insert (data, tag_start, length);
-
- if (data.Count - length != 0 && tag_start <= riff_size)
- Insert (ByteVector.FromUInt ((uint)(riff_size + data.Count -
length), false), 4, 4);
-
- Mode = AccessMode.Closed;
-
- TagTypesOnDisk = TagTypes;
- }
- }
+ public override void Save ()
+ {
+ Mode = AccessMode.Write;
+ try {
+ ByteVector data = new ByteVector ();
+
+ if (id32_tag != null) {
+ ByteVector tag_data = id32_tag.Render
();
+ if (tag_data.Count > 10) {
+ if (tag_data.Count % 2 == 1)
+ tag_data.Add (0);
+ data.Add ("ID32");
+ data.Add (ByteVector.FromUInt (
+ (uint) tag_data.Count,
+ false));
+ data.Add (tag_data);
+ }
+ }
+
+ if (info_tag != null)
+ data.Add (info_tag.RenderEnclosed ());
+
+ if (mid_tag != null)
+ data.Add (mid_tag.RenderEnclosed ());
+
+ if (divx_tag != null && !divx_tag.IsEmpty) {
+ ByteVector tag_data = divx_tag.Render
();
+ data.Add ("IDVX");
+ data.Add (ByteVector.FromUInt (
+ (uint) tag_data.Count, false));
+ data.Add (tag_data);
+ }
+
+ uint riff_size;
+ long tag_start, tag_end;
+ Read (false, ReadStyle.None, out riff_size,
+ out tag_start, out tag_end);
+
+ if (tag_start < 12 || tag_end < tag_start)
+ tag_start = tag_end = Length;
+
+ int length = (int)(tag_end - tag_start);
+ int padding_size = length - data.Count - 8;
+ if (padding_size < 0)
+ padding_size = 1024;
+
+ data.Add ("JUNK");
+ data.Add (ByteVector.FromUInt (
+ (uint)padding_size, false));
+ data.Add (new ByteVector (padding_size));
+
+ Insert (data, tag_start, length);
+
+ if (data.Count - length != 0 &&
+ tag_start <= riff_size)
+ Insert (ByteVector.FromUInt ((uint)
+ (riff_size + data.Count -
length),
+ false), 4, 4);
+
+ TagTypesOnDisk = TagTypes;
+ } finally {
+ Mode = AccessMode.Closed;
+ }
+ }
+ }
}
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches