12
12
// Copyright (C) 2005, 2007 Brian Nickel
13
13
// Copyright (C) 2006 Novell, Inc.
14
14
// Copyright (C) 2002,2003 Scott Wheeler (Original Implementation)
15
- //
15
+ //
16
16
// This library is free software; you can redistribute it and/or modify
17
17
// it under the terms of the GNU Lesser General Public License version
18
18
// 2.1 as published by the Free Software Foundation.
28
28
// USA
29
29
//
30
30
31
- using System ;
32
- using System . Collections . Generic ;
33
31
using System . Globalization ;
34
- using System . IO ;
35
- using System . Runtime . Serialization ;
32
+ using System . Runtime . ExceptionServices ;
36
33
37
34
namespace TagLib
38
35
{
@@ -56,10 +53,10 @@ public enum ReadStyle
56
53
Average = 2 ,
57
54
58
55
/// <summary>
59
- /// Use the <see cref="PictureLazy"/> class in the
60
- /// the property <see cref="Tag.Pictures"/>.
56
+ /// Use the <see cref="PictureLazy"/> class in the
57
+ /// the property <see cref="Tag.Pictures"/>.
61
58
/// This will avoid loading picture content when reading the Tag.
62
- /// Picture will be read lazily, when the picture content is
59
+ /// Picture will be read lazily, when the picture content is
63
60
/// accessed.
64
61
/// </summary>
65
62
PictureLazy = 4
@@ -148,7 +145,7 @@ public enum AccessMode
148
145
/// methods.</para>
149
146
/// <para>If the resolver returns a new <see cref="File" />,
150
147
/// it will instantly be returned, by <see
151
- /// cref="Create(string)" />. If it returns <see
148
+ /// cref="Create(string)" />. If it returns <see
152
149
/// langword="null" />, <see cref="Create(string)" /> will
153
150
/// continue to process. If the resolver throws an exception
154
151
/// it will be uncaught.</para>
@@ -526,15 +523,15 @@ public void Dispose ()
526
523
/// TagLib.Id3v2.Tag id3 = file.GetTag (TagLib.TagTypes.Id3v2, true);
527
524
/// if (id3 != null)
528
525
/// id3.SetTextFrame ("TMOO", moods);
529
- ///
526
+ ///
530
527
/// TagLib.Asf.Tag asf = file.GetTag (TagLib.TagTypes.Asf, true);
531
528
/// if (asf != null)
532
529
/// asf.SetDescriptorStrings (moods, "WM/Mood", "Mood");
533
- ///
530
+ ///
534
531
/// TagLib.Ape.Tag ape = file.GetTag (TagLib.TagTypes.Ape);
535
532
/// if (ape != null)
536
533
/// ape.SetValue ("MOOD", moods);
537
- ///
534
+ ///
538
535
/// // Whatever tag types you want...
539
536
///}</code>
540
537
/// </example>
@@ -572,23 +569,23 @@ public void Dispose ()
572
569
/// if (f != null)
573
570
/// return f.FieldList.ToArray ();
574
571
/// }
575
- ///
572
+ ///
576
573
/// TagLib.Asf.Tag asf = file.GetTag (TagLib.TagTypes.Asf);
577
574
/// if (asf != null) {
578
575
/// string [] value = asf.GetDescriptorStrings ("WM/Mood", "Mood");
579
576
/// if (value.Length > 0)
580
577
/// return value;
581
578
/// }
582
- ///
579
+ ///
583
580
/// TagLib.Ape.Tag ape = file.GetTag (TagLib.TagTypes.Ape);
584
581
/// if (ape != null) {
585
582
/// Item item = ape.GetItem ("MOOD");
586
583
/// if (item != null)
587
584
/// return item.ToStringArray ();
588
585
/// }
589
- ///
586
+ ///
590
587
/// // Whatever tag types you want...
591
- ///
588
+ ///
592
589
/// return new string [] {};
593
590
///}</code>
594
591
/// </example>
@@ -831,7 +828,7 @@ long RFind (ByteVector pattern, long startPosition, ByteVector after)
831
828
*/
832
829
833
830
// Save the location of the current read pointer. We
834
- // will restore the position using Seek() before all
831
+ // will restore the position using Seek() before all
835
832
// returns.
836
833
837
834
long original_position = file_stream . Position ;
@@ -985,7 +982,7 @@ public void Insert (ByteVector data, long start)
985
982
/// <summary>
986
983
/// Inserts a specified block-size into the file repesented
987
984
/// by the current instance at a specified location. Former
988
- /// data at this location is not overwriten and may then
985
+ /// data at this location is not overwriten and may then
989
986
/// contain random content.
990
987
/// </summary>
991
988
/// <param name="size">
@@ -999,8 +996,8 @@ public void Insert (ByteVector data, long start)
999
996
/// <remarks>
1000
997
/// This method is usefull to reserve some space in the file.
1001
998
/// To insert or replace defined data blocks, use <see
1002
- /// cref="Insert(ByteVector,long)" /> or
1003
- /// <see cref="Insert(ByteVector,long,long)"/>
999
+ /// cref="Insert(ByteVector,long)" /> or
1000
+ /// <see cref="Insert(ByteVector,long,long)"/>
1004
1001
/// </remarks>
1005
1002
public void Insert ( long size , long start )
1006
1003
{
@@ -1321,8 +1318,15 @@ public static File Create (IFileAbstraction abstraction, string mimetype, ReadSt
1321
1318
file . MimeType = mimetype ;
1322
1319
return file ;
1323
1320
} catch ( System . Reflection . TargetInvocationException e ) {
1324
- PrepareExceptionForRethrow ( e . InnerException ) ;
1321
+ #if NETSTANDARD2_0
1322
+ // .NET Standard 2.0: Stack trace will be lost when rethrowing inner exception.
1323
+ // This is a limitation of .NET Standard 2.0.
1325
1324
throw e . InnerException ;
1325
+ #else
1326
+ // Modern .NET: preserve stack trace
1327
+ ExceptionDispatchInfo . Capture ( e . InnerException ) . Throw ( ) ;
1328
+ throw ; // Unreachable, but required for compiler
1329
+ #endif
1326
1330
}
1327
1331
}
1328
1332
@@ -1335,7 +1339,7 @@ public static File Create (IFileAbstraction abstraction, string mimetype, ReadSt
1335
1339
/// file type recognition stack.
1336
1340
/// </param>
1337
1341
/// <remarks>
1338
- /// A <see cref="FileTypeResolver" /> adds support for
1342
+ /// A <see cref="FileTypeResolver" /> adds support for
1339
1343
/// recognizing a file type outside of the standard mime-type
1340
1344
/// methods.
1341
1345
/// </remarks>
@@ -1352,7 +1356,7 @@ public static void AddFileTypeResolver (FileTypeResolver resolver)
1352
1356
#region Private/Protected Methods
1353
1357
1354
1358
/// <summary>
1355
- /// Prepare to Save the file. Thismust be called at the begining
1359
+ /// Prepare to Save the file. Thismust be called at the begining
1356
1360
/// of every File.Save() method.
1357
1361
/// </summary>
1358
1362
protected void PreSave ( )
@@ -1383,7 +1387,7 @@ protected void PreSave ()
1383
1387
/// <param name="data">
1384
1388
/// A <see cref="ByteVector" /> object containing the data to
1385
1389
/// insert into the file. if null, no data is writen to the
1386
- /// file and the block is just inserted without overwriting the
1390
+ /// file and the block is just inserted without overwriting the
1387
1391
/// former data at the given location.
1388
1392
/// </param>
1389
1393
/// <param name="size">
@@ -1451,8 +1455,8 @@ void Insert (ByteVector data, long size, long start, long replace)
1451
1455
byte [ ] buffer ;
1452
1456
byte [ ] about_to_overwrite ;
1453
1457
1454
- // This is basically a special case of the loop below.
1455
- // Here we're just doing the same steps as below, but
1458
+ // This is basically a special case of the loop below.
1459
+ // Here we're just doing the same steps as below, but
1456
1460
// since we aren't using the same buffer size -- instead
1457
1461
// we're using the tag size -- this has to be handled as
1458
1462
// a special case. We're also using File::writeBlock()
@@ -1476,12 +1480,12 @@ void Insert (ByteVector data, long size, long start, long replace)
1476
1480
about_to_overwrite . Length ) ;
1477
1481
1478
1482
// Ok, here's the main loop. We want to loop until the
1479
- // read fails, which means that we hit the end of the
1483
+ // read fails, which means that we hit the end of the
1480
1484
// file.
1481
1485
1482
1486
while ( buffer_length != 0 ) {
1483
1487
// Seek to the current read position and read
1484
- // the data that we're about to overwrite.
1488
+ // the data that we're about to overwrite.
1485
1489
// Appropriately increment the readPosition.
1486
1490
1487
1491
file_stream . Position = read_position ;
@@ -1527,25 +1531,8 @@ protected void Truncate (long length)
1527
1531
Mode = old_mode ;
1528
1532
}
1529
1533
1530
- /// <summary>
1531
- /// Causes the original strack trace of the exception to be preserved when it is rethrown
1532
- /// </summary>
1533
- /// <param name="ex"></param>
1534
- static void PrepareExceptionForRethrow ( Exception ex )
1535
- {
1536
- var ctx = new StreamingContext ( StreamingContextStates . CrossAppDomain ) ;
1537
- var mgr = new ObjectManager ( null , ctx ) ;
1538
- var si = new SerializationInfo ( ex . GetType ( ) , new FormatterConverter ( ) ) ;
1539
-
1540
- ex . GetObjectData ( si , ctx ) ;
1541
- mgr . RegisterObject ( ex , 1 , si ) ; // prepare for SetObjectData
1542
- mgr . DoFixups ( ) ; // ObjectManager calls SetObjectData
1543
- }
1544
-
1545
1534
#endregion
1546
1535
1547
-
1548
-
1549
1536
#region Classes
1550
1537
1551
1538
/// <summary>
@@ -1669,7 +1656,7 @@ public void CloseStream (Stream stream)
1669
1656
/// return;
1670
1657
///
1671
1658
/// Gnome.Vfs.Vfs.Initialize ();
1672
- ///
1659
+ ///
1673
1660
/// try {
1674
1661
/// TagLib.File file = TagLib.File.Create (
1675
1662
/// new VfsFileAbstraction (args [0]));
@@ -1710,24 +1697,24 @@ public void CloseStream (Stream stream)
1710
1697
///import Gnome.Vfs from "gnome-vfs-sharp"
1711
1698
///
1712
1699
///class VfsFileAbstraction (TagLib.File.IFileAbstraction):
1713
- ///
1700
+ ///
1714
1701
/// _name as string
1715
- ///
1702
+ ///
1716
1703
/// def constructor(file as string):
1717
1704
/// _name = file
1718
- ///
1705
+ ///
1719
1706
/// Name:
1720
1707
/// get:
1721
1708
/// return _name
1722
- ///
1709
+ ///
1723
1710
/// ReadStream:
1724
1711
/// get:
1725
1712
/// return VfsStream(_name, FileMode.Open)
1726
- ///
1713
+ ///
1727
1714
/// WriteStream:
1728
1715
/// get:
1729
1716
/// return VfsStream(_name, FileMode.Open)
1730
- ///
1717
+ ///
1731
1718
///if len(argv) == 1:
1732
1719
/// Vfs.Initialize()
1733
1720
///
@@ -1744,7 +1731,7 @@ public interface IFileAbstraction
1744
1731
/// implementation.
1745
1732
/// </summary>
1746
1733
/// <value>
1747
- /// A <see cref="string" /> object containing the
1734
+ /// A <see cref="string" /> object containing the
1748
1735
/// name or identifier used by the implementation.
1749
1736
/// </value>
1750
1737
/// <remarks>
0 commit comments