@@ -1235,6 +1235,37 @@ public static File Create (string path, string mimetype, ReadStyle propertiesSty
1235
1235
return Create ( new LocalFileAbstraction ( path ) , mimetype , propertiesStyle ) ;
1236
1236
}
1237
1237
1238
+ /// <summary>
1239
+ /// Returns true if the file is supported
1240
+ /// </summary>
1241
+ /// <param name="path">The file path</param>
1242
+ /// <returns>True if supported, false otherwise</returns>
1243
+ public static bool IsSupportedFile ( string path )
1244
+ {
1245
+ var abstraction = new LocalFileAbstraction ( path ) ;
1246
+
1247
+ return IsSupportedFile ( abstraction ) ;
1248
+ }
1249
+
1250
+ private static bool IsSupportedFile ( IFileAbstraction abstraction )
1251
+ {
1252
+ string mimetype = GetMimeType ( abstraction ) ;
1253
+
1254
+ return FileTypes . AvailableTypes . ContainsKey ( mimetype ) ;
1255
+ }
1256
+
1257
+ private static string GetMimeType ( IFileAbstraction abstraction )
1258
+ {
1259
+ string ext = string . Empty ;
1260
+
1261
+ int index = abstraction . Name . LastIndexOf ( "." ) + 1 ;
1262
+
1263
+ if ( index >= 1 && index < abstraction . Name . Length )
1264
+ ext = abstraction . Name . Substring ( index , abstraction . Name . Length - index ) ;
1265
+
1266
+ return $ "taglib/{ ext . ToLower ( CultureInfo . InvariantCulture ) } ";
1267
+ }
1268
+
1238
1269
/// <summary>
1239
1270
/// Creates a new instance of a <see cref="File" /> subclass
1240
1271
/// for a specified file abstraction, mime-type, and read
@@ -1269,16 +1300,7 @@ public static File Create (string path, string mimetype, ReadStyle propertiesSty
1269
1300
/// </exception>
1270
1301
public static File Create ( IFileAbstraction abstraction , string mimetype , ReadStyle propertiesStyle )
1271
1302
{
1272
- if ( mimetype == null ) {
1273
- string ext = string . Empty ;
1274
-
1275
- int index = abstraction . Name . LastIndexOf ( "." ) + 1 ;
1276
-
1277
- if ( index >= 1 && index < abstraction . Name . Length )
1278
- ext = abstraction . Name . Substring ( index , abstraction . Name . Length - index ) ;
1279
-
1280
- mimetype = "taglib/" + ext . ToLower ( CultureInfo . InvariantCulture ) ;
1281
- }
1303
+ mimetype ??= GetMimeType ( abstraction ) ;
1282
1304
1283
1305
foreach ( var resolver in file_type_resolvers ) {
1284
1306
var file = resolver ( abstraction , mimetype , propertiesStyle ) ;
@@ -1287,7 +1309,7 @@ public static File Create (IFileAbstraction abstraction, string mimetype, ReadSt
1287
1309
return file ;
1288
1310
}
1289
1311
1290
- if ( ! FileTypes . AvailableTypes . ContainsKey ( mimetype ) )
1312
+ if ( ! IsSupportedFile ( abstraction ) )
1291
1313
throw new UnsupportedFormatException (
1292
1314
string . Format ( CultureInfo . InvariantCulture , "{0} ({1})" , abstraction . Name , mimetype ) ) ;
1293
1315
0 commit comments