Author: abock
Date: 2006-11-14 00:04:04 -0500 (Tue, 14 Nov 2006)
New Revision: 67813
Added:
trunk/taglib-sharp/src/TagLib/FileTypes.cs
Modified:
trunk/taglib-sharp/ChangeLog
trunk/taglib-sharp/src/Makefile.am
trunk/taglib-sharp/src/TagLib/File.cs
trunk/taglib-sharp/src/TagLib/SupportedMimeType.cs
Log:
2006-11-13 Aaron Bockover <[EMAIL PROTECTED]>
* src/TagLib/SupportedMimeType.cs: Load mime types in static constructor
* src/TagLib/FileTypes.cs: File type loader that initializes the
SupportedMimeType support
* src/TagLib/File.cs: Use FileTypes.AvailableTypes
* src/Makefile.am: Added src/TagLib/FileTypes.cs
Modified: trunk/taglib-sharp/ChangeLog
===================================================================
--- trunk/taglib-sharp/ChangeLog 2006-11-14 04:42:13 UTC (rev 67812)
+++ trunk/taglib-sharp/ChangeLog 2006-11-14 05:04:04 UTC (rev 67813)
@@ -1,3 +1,14 @@
+2006-11-13 Aaron Bockover <[EMAIL PROTECTED]>
+
+ * src/TagLib/SupportedMimeType.cs: Load mime types in static constructor
+
+ * src/TagLib/FileTypes.cs: File type loader that initializes the
+ SupportedMimeType support
+
+ * src/TagLib/File.cs: Use FileTypes.AvailableTypes
+
+ * src/Makefile.am: Added src/TagLib/FileTypes.cs
+
2006-11-06 Brian Nickel <[EMAIL PROTECTED]>
* src/TagLib/Id3v2/Tag.cs:
Modified: trunk/taglib-sharp/src/Makefile.am
===================================================================
--- trunk/taglib-sharp/src/Makefile.am 2006-11-14 04:42:13 UTC (rev 67812)
+++ trunk/taglib-sharp/src/Makefile.am 2006-11-14 05:04:04 UTC (rev 67813)
@@ -96,7 +96,8 @@
$(srcdir)/TagLib/UnsupportedFormatException.cs \
$(srcdir)/TagLib/ReadOnlyException.cs \
$(srcdir)/TagLib/Picture.cs \
- $(srcdir)/TagLib/ListBase.cs
+ $(srcdir)/TagLib/ListBase.cs \
+ $(srcdir)/TagLib/FileTypes.cs
taglib-sharp.snk: $(top_srcdir)/taglib-sharp.snk
cp $(top_srcdir)/taglib-sharp.snk .
Modified: trunk/taglib-sharp/src/TagLib/File.cs
===================================================================
--- trunk/taglib-sharp/src/TagLib/File.cs 2006-11-14 04:42:13 UTC (rev
67812)
+++ trunk/taglib-sharp/src/TagLib/File.cs 2006-11-14 05:04:04 UTC (rev
67813)
@@ -43,51 +43,10 @@
}
public abstract class File
- {
- private static Hashtable file_types = new Hashtable();
-
+ {
public delegate IFileAbstraction FileAbstractionCreator (string path);
public delegate File FileTypeResolver (string path,
AudioProperties.ReadStyle style);
-
- // A static Type array is used instead of getting types by
- // reflecting the executing assembly as Assembly.GetTypes is very
- // inefficient and leaks every type instance under Mono.
- // Not reflecting taglib-sharp.dll saves about 120KB of heap
- private static Type [] static_file_types = new Type [] {
- typeof(TagLib.Asf.File),
- typeof(TagLib.Flac.File),
- typeof(TagLib.Mpc.File),
- typeof(TagLib.Mpeg4.File),
- typeof(TagLib.Mpeg.File),
- typeof(TagLib.Ogg.File),
- typeof(TagLib.WavPack.File),
- typeof(TagLib.Ogg.Flac.File),
- typeof(TagLib.Ogg.Vorbis.File)
- };
-
- static File()
- {
- /* See above message about Assembly.GetTypes */
- /*System.Reflection.Assembly assembly =
System.Reflection.Assembly.GetExecutingAssembly();
-
- foreach(Type type in assembly.GetTypes()) {
- if(!type.IsSubclassOf(typeof(File))) {
- continue;
- }
- */
-
- foreach(Type type in static_file_types) {
- Attribute [] attrs = Attribute.GetCustomAttributes(type,
typeof(SupportedMimeType));
- if(attrs == null || attrs.Length == 0) {
- continue;
- }
-
- foreach(SupportedMimeType attr in attrs) {
- file_types.Add(attr.MimeType, type);
- }
- }
- }
-
+
public enum AccessMode
{
Read,
@@ -583,12 +542,12 @@
mimetype = "taglib/" + ext.ToLower();
}
- Type file_type = file_types[mimetype] as Type;
- if(file_type == null)
- {
+ if(!FileTypes.AvailableTypes.ContainsKey(mimetype)) {
throw new UnsupportedFormatException(String.Format("{0} ({1})",
path, mimetype));
}
+ Type file_type = FileTypes.AvailableTypes[mimetype];
+
try {
File file = (File)Activator.CreateInstance(file_type, new object
[] { path, style });
file.MimeType = mimetype;
Added: trunk/taglib-sharp/src/TagLib/FileTypes.cs
===================================================================
--- trunk/taglib-sharp/src/TagLib/FileTypes.cs 2006-11-14 04:42:13 UTC (rev
67812)
+++ trunk/taglib-sharp/src/TagLib/FileTypes.cs 2006-11-14 05:04:04 UTC (rev
67813)
@@ -0,0 +1,77 @@
+/***************************************************************************
+ copyright : (C) 2006 Novell, Inc.
+ email : [EMAIL PROTECTED]
+ ***************************************************************************/
+
+/***************************************************************************
+ * This library is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU Lesser General Public License version *
+ * 2.1 as published by the Free Software Foundation. *
+ * *
+ * This library is distributed in the hope that it will be useful, but *
+ * WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this library; if not, write to the Free Software *
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 *
+ * USA *
+ ***************************************************************************/
+
+using System;
+using System.Collections.Generic;
+
+namespace TagLib
+{
+ public static class FileTypes
+ {
+ private static Dictionary<string, Type> file_types;
+
+ // A static Type array is used instead of getting types by
+ // reflecting the executing assembly as Assembly.GetTypes is very
+ // inefficient and leaks every type instance under Mono.
+ // Not reflecting taglib-sharp.dll saves about 120KB of heap
+ private static Type [] static_file_types = new Type [] {
+ typeof(TagLib.Asf.File),
+ typeof(TagLib.Flac.File),
+ typeof(TagLib.Mpc.File),
+ typeof(TagLib.Mpeg4.File),
+ typeof(TagLib.Mpeg.File),
+ typeof(TagLib.Ogg.File),
+ typeof(TagLib.WavPack.File),
+ typeof(TagLib.Ogg.Flac.File),
+ typeof(TagLib.Ogg.Vorbis.File)
+ };
+
+ static FileTypes()
+ {
+ Init();
+ }
+
+ internal static void Init()
+ {
+ if(file_types != null) {
+ return;
+ }
+
+ file_types = new Dictionary<string, Type>();
+
+ foreach(Type type in static_file_types) {
+ Attribute [] attrs = Attribute.GetCustomAttributes(type,
typeof(SupportedMimeType));
+ if(attrs == null || attrs.Length == 0) {
+ continue;
+ }
+
+ foreach(SupportedMimeType attr in attrs) {
+ file_types.Add(attr.MimeType, type);
+ }
+ }
+ }
+
+ public static IDictionary<string, Type> AvailableTypes {
+ get { return file_types; }
+ }
+ }
+}
+
Modified: trunk/taglib-sharp/src/TagLib/SupportedMimeType.cs
===================================================================
--- trunk/taglib-sharp/src/TagLib/SupportedMimeType.cs 2006-11-14 04:42:13 UTC
(rev 67812)
+++ trunk/taglib-sharp/src/TagLib/SupportedMimeType.cs 2006-11-14 05:04:04 UTC
(rev 67813)
@@ -21,24 +21,21 @@
***************************************************************************/
using System;
-using System.Collections;
+using System.Collections.Generic;
namespace TagLib
{
[AttributeUsage(AttributeTargets.Class, AllowMultiple=true)]
public class SupportedMimeType : Attribute
{
- private static ArrayList mime_types = new ArrayList();
+ private static List<SupportedMimeType> mime_types = new
List<SupportedMimeType>();
private string mime_type;
private string extension;
-
- public string MimeType {
- get { return mime_type; }
- }
- public string Extension {
- get { return extension; }
+ static SupportedMimeType()
+ {
+ FileTypes.Init();
}
public SupportedMimeType(string mime_type)
@@ -51,8 +48,16 @@
{
this.extension = extension;
}
+
+ public string MimeType {
+ get { return mime_type; }
+ }
- public static IEnumerable AllMimeTypes {
+ public string Extension {
+ get { return extension; }
+ }
+
+ public static IEnumerable<string> AllMimeTypes {
get {
foreach(SupportedMimeType type in mime_types) {
yield return type.MimeType;
@@ -60,7 +65,7 @@
}
}
- public static IEnumerable AllExtensions {
+ public static IEnumerable<string> AllExtensions {
get {
foreach(SupportedMimeType type in mime_types) {
if(type.Extension != null) {
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches