Remove initialization on MIMETypeUtil

pull/1/head
Frederic Jacobs 10 years ago
parent 1f61291e0c
commit 7a5f9f1413

@ -20,9 +20,6 @@
#import "VersionMigrations.h" #import "VersionMigrations.h"
#import "UIColor+OWS.h" #import "UIColor+OWS.h"
#import "CodeVerificationViewController.h" #import "CodeVerificationViewController.h"
#import "MIMETypeUtil.h"
#import "TSDatabaseView.h"
#import <PastelogKit/Pastelog.h>
#ifdef __APPLE__ #ifdef __APPLE__
#include "TargetConditionals.h" #include "TargetConditionals.h"
@ -138,7 +135,7 @@ static NSString* const kCallSegue = @"2.0_6.0_Call_Segue";
[self refreshContacts]; [self refreshContacts];
[TSPreKeyManager refreshPreKeys]; [TSPreKeyManager refreshPreKeys];
} }
[MIMETypeUtil initialize];
return YES; return YES;
} }
@ -284,7 +281,11 @@ static NSString* const kCallSegue = @"2.0_6.0_Call_Segue";
window.windowLevel = CGFLOAT_MAX; window.windowLevel = CGFLOAT_MAX;
// There appears to be no more reliable way to get the launchscreen image from an asset bundle // There appears to be no more reliable way to get the launchscreen image from an asset bundle
NSDictionary *dict = @{@"320x480" : @"LaunchImage-700", @"320x568" : @"LaunchImage-700-568h", @"375x667" : @"LaunchImage-800-667h", @"414x736" : @"LaunchImage-800-Portrait-736h"}; NSDictionary *dict = @{@"320x480" : @"LaunchImage-700",
@"320x568" : @"LaunchImage-700-568h",
@"375x667" : @"LaunchImage-800-667h",
@"414x736" : @"LaunchImage-800-Portrait-736h"};
NSString *key = [NSString stringWithFormat:@"%dx%d", (int)[UIScreen mainScreen].bounds.size.width, (int)[UIScreen mainScreen].bounds.size.height]; NSString *key = [NSString stringWithFormat:@"%dx%d", (int)[UIScreen mainScreen].bounds.size.width, (int)[UIScreen mainScreen].bounds.size.height];
UIImage *launchImage = [UIImage imageNamed:dict[key]]; UIImage *launchImage = [UIImage imageNamed:dict[key]];
UIImageView *imgView = [[UIImageView alloc] initWithImage:launchImage]; UIImageView *imgView = [[UIImageView alloc] initWithImage:launchImage];

@ -2,8 +2,6 @@
@interface MIMETypeUtil : NSObject @interface MIMETypeUtil : NSObject
+(void) initialize;
+(BOOL)isSupportedMIMEType:(NSString*)contentType; +(BOOL)isSupportedMIMEType:(NSString*)contentType;
+(BOOL)isSupportedVideoMIMEType:(NSString*)contentType; +(BOOL)isSupportedVideoMIMEType:(NSString*)contentType;
+(BOOL)isSupportedAudioMIMEType:(NSString*)contentType; +(BOOL)isSupportedAudioMIMEType:(NSString*)contentType;

@ -3,110 +3,108 @@
@implementation MIMETypeUtil @implementation MIMETypeUtil
static NSDictionary *supportedVideoMIMETypesToExtensionTypes; + (NSDictionary*)supportedVideoMIMETypesToExtensionTypes{
static NSDictionary *supportedAudioMIMETypesToExtensionTypes; return @{@"video/3gpp":@"3gp",
static NSDictionary *supportedImageMIMETypesToExtensionTypes; @"video/3gpp2":@"3g2",
static NSDictionary *supportedVideoExtensionTypesToMIMETypes; @"video/mp4":@"mp4",
static NSDictionary *supportedAudioExtensionTypesToMIMETypes; @"video/quicktime":@"mov",
static NSDictionary *supportedImageExtensionTypesToMIMETypes; @"video/x-m4v":@"m4v"
};
#pragma mark uses file extensions or MIME types only }
+(void) initialize {
// Initialize must be called before this class is used. Could later be in e.g. a .plist + (NSDictionary*)supportedAudioMIMETypesToExtensionTypes{
supportedVideoMIMETypesToExtensionTypes =@{@"video/3gpp":@"3gp", return @{@"audio/x-m4p":@"m4p",
@"video/3gpp2":@"3g2", @"audio/x-m4b":@"m4b",
@"video/mp4":@"mp4", @"audio/x-m4a":@"m4a",
@"video/quicktime":@"mov", @"audio/wav":@"wav",
@"video/x-m4v":@"m4v" @"audio/x-wav":@"wav",
}; @"audio/x-mpeg":@"mp3",
@"audio/mpeg":@"mp3",
supportedAudioMIMETypesToExtensionTypes = @{@"audio/x-m4p":@"m4p", @"audio/mp4":@"mp4",
@"audio/x-m4b":@"m4b", @"audio/mp3":@"mp3",
@"audio/x-m4a":@"m4a", @"audio/mpeg3":@"mp3",
@"audio/wav":@"wav", @"audio/x-mp3":@"mp3",
@"audio/x-wav":@"wav", @"audio/x-mpeg3":@"mp3",
@"audio/x-mpeg":@"mp3", @"audio/amr":@"amr",
@"audio/mpeg":@"mp3", @"audio/aiff":@"aiff",
@"audio/mp4":@"mp4", @"audio/x-aiff":@"aiff",
@"audio/mp3":@"mp3", @"audio/3gpp2":@"3g2",
@"audio/mpeg3":@"mp3", @"audio/3gpp":@"3gp"
@"audio/x-mp3":@"mp3", };
@"audio/x-mpeg3":@"mp3", }
@"audio/amr":@"amr",
@"audio/aiff":@"aiff", + (NSDictionary*)supportedImageMIMETypesToExtensionTypes{
@"audio/x-aiff":@"aiff", return @{@"image/jpeg":@"jpeg",
@"audio/3gpp2":@"3g2", @"image/pjpeg":@"jpeg",
@"audio/3gpp":@"3gp" @"image/png":@"png",
}; @"image/gif":@"gif",
@"image/tiff":@"tif",
@"image/x-tiff":@"tif",
supportedImageMIMETypesToExtensionTypes = @{@"image/jpeg":@"jpeg", @"image/bmp":@"bmp",
@"image/pjpeg":@"jpeg", @"image/x-windows-bmp":@"bmp"
@"image/png":@"png", };
@"image/gif":@"gif", }
@"image/tiff":@"tif",
@"image/x-tiff":@"tif", + (NSDictionary*)supportedVideoExtensionTypesToMIMETypes{
@"image/bmp":@"bmp", return @{@"3gp":@"video/3gpp",
@"image/x-windows-bmp":@"bmp" @"3gpp":@"video/3gpp",
}; @"3gp2":@"video/3gpp2",
@"3gpp2":@"video/3gpp2",
@"mp4":@"video/mp4",
supportedVideoExtensionTypesToMIMETypes = @{@"3gp":@"video/3gpp", @"mov":@"video/quicktime",
@"3gpp":@"video/3gpp", @"mqv":@"video/quicktime",
@"3gp2":@"video/3gpp2", @"m4v":@"video/x-m4v"
@"3gpp2":@"video/3gpp2", };
@"mp4":@"video/mp4", }
@"mov":@"video/quicktime", + (NSDictionary*)supportedAudioExtensionTypesToMIMETypes{
@"mqv":@"video/quicktime", return @{@"3gp":@"audio/3gpp",
@"m4v":@"video/x-m4v" @"3gpp":@"@audio/3gpp",
}; @"3g2":@"audio/3gpp2",
@"3gp2":@"audio/3gpp2",
supportedAudioExtensionTypesToMIMETypes = @{@"3gp":@"audio/3gpp", @"aiff":@"audio/aiff",
@"3gpp":@"@audio/3gpp", @"aif":@"audio/aiff",
@"3g2":@"audio/3gpp2", @"aifc":@"audio/aiff",
@"3gp2":@"audio/3gpp2", @"cdda":@"audio/aiff",
@"aiff":@"audio/aiff", @"amr":@"audio/amr",
@"aif":@"audio/aiff", @"mp3":@"audio/mp3",
@"aifc":@"audio/aiff", @"swa":@"audio/mp3",
@"cdda":@"audio/aiff", @"mp4":@"audio/mp4",
@"amr":@"audio/amr", @"mpeg":@"audio/mpeg",
@"mp3":@"audio/mp3", @"mpg":@"audio/mpeg",
@"swa":@"audio/mp3", @"wav":@"audio/wav",
@"mp4":@"audio/mp4", @"bwf":@"audio/wav",
@"mpeg":@"audio/mpeg", @"m4a":@"audio/x-m4a",
@"mpg":@"audio/mpeg", @"m4b":@"audio/x-m4b",
@"wav":@"audio/wav", @"m4p":@"audio/x-m4p"
@"bwf":@"audio/wav", };
@"m4a":@"audio/x-m4a", }
@"m4b":@"audio/x-m4b",
@"m4p":@"audio/x-m4p" + (NSDictionary*)supportedImageExtensionTypesToMIMETypes{
}; return @{@"png":@"image/png",
@"x-png":@"image/png",
supportedImageExtensionTypesToMIMETypes = @{@"png":@"image/png", @"jfif":@"image/jpeg",
@"x-png":@"image/png", @"jfif":@"image/pjpeg",
@"jfif":@"image/jpeg", @"jfif-tbnl":@"image/jpeg",
@"jfif":@"image/pjpeg", @"jpe":@"image/jpeg",
@"jfif-tbnl":@"image/jpeg", @"jpe":@"image/pjpeg",
@"jpe":@"image/jpeg", @"jpeg":@"image/jpeg",
@"jpe":@"image/pjpeg", @"jpg":@"image/jpeg",
@"jpeg":@"image/jpeg", @"gif":@"image/gif",
@"jpg":@"image/jpeg", @"tif":@"image/tiff",
@"gif":@"image/gif", @"tiff":@"image/tiff"
@"tif":@"image/tiff", };
@"tiff":@"image/tiff"
};
} }
+(BOOL) isSupportedVideoMIMEType:(NSString*)contentType { +(BOOL) isSupportedVideoMIMEType:(NSString*)contentType {
return [supportedVideoMIMETypesToExtensionTypes objectForKey:contentType]!=nil; return [[self supportedVideoMIMETypesToExtensionTypes] objectForKey:contentType]!=nil;
} }
+(BOOL) isSupportedAudioMIMEType:(NSString*)contentType { +(BOOL) isSupportedAudioMIMEType:(NSString*)contentType {
return [supportedAudioMIMETypesToExtensionTypes objectForKey:contentType]!=nil; return [[self supportedAudioMIMETypesToExtensionTypes] objectForKey:contentType]!=nil;
} }
+(BOOL) isSupportedImageMIMEType:(NSString*)contentType { +(BOOL) isSupportedImageMIMEType:(NSString*)contentType {
return [supportedImageMIMETypesToExtensionTypes objectForKey:contentType]!=nil; return [[self supportedImageMIMETypesToExtensionTypes] objectForKey:contentType]!=nil;
} }
+(BOOL) isSupportedMIMEType:(NSString*)contentType { +(BOOL) isSupportedMIMEType:(NSString*)contentType {
@ -114,48 +112,48 @@ static NSDictionary *supportedImageExtensionTypesToMIMETypes;
} }
+(BOOL) isSupportedVideoFile:(NSString*) filePath { +(BOOL) isSupportedVideoFile:(NSString*) filePath {
return [supportedVideoExtensionTypesToMIMETypes objectForKey:[filePath pathExtension]]!=nil; return [[self supportedVideoExtensionTypesToMIMETypes] objectForKey:[filePath pathExtension]]!=nil;
} }
+(BOOL) isSupportedAudioFile:(NSString*) filePath { +(BOOL) isSupportedAudioFile:(NSString*) filePath {
return [supportedAudioExtensionTypesToMIMETypes objectForKey:[filePath pathExtension]]!=nil; return [[self supportedAudioExtensionTypesToMIMETypes] objectForKey:[filePath pathExtension]]!=nil;
} }
+(BOOL) isSupportedImageFile:(NSString*) filePath { +(BOOL) isSupportedImageFile:(NSString*) filePath {
return [supportedImageExtensionTypesToMIMETypes objectForKey:[filePath pathExtension]]!=nil; return [[self supportedImageExtensionTypesToMIMETypes] objectForKey:[filePath pathExtension]]!=nil;
} }
+(NSString*) getSupportedExtensionFromVideoMIMEType:(NSString*)supportedMIMEType { +(NSString*) getSupportedExtensionFromVideoMIMEType:(NSString*)supportedMIMEType {
return [supportedVideoMIMETypesToExtensionTypes objectForKey:supportedMIMEType]; return [[self supportedVideoMIMETypesToExtensionTypes] objectForKey:supportedMIMEType];
} }
+(NSString*) getSupportedExtensionFromAudioMIMEType:(NSString*)supportedMIMEType { +(NSString*) getSupportedExtensionFromAudioMIMEType:(NSString*)supportedMIMEType {
return [supportedAudioMIMETypesToExtensionTypes objectForKey:supportedMIMEType]; return [[self supportedAudioMIMETypesToExtensionTypes] objectForKey:supportedMIMEType];
} }
+(NSString*) getSupportedExtensionFromImageMIMEType:(NSString*)supportedMIMEType { +(NSString*) getSupportedExtensionFromImageMIMEType:(NSString*)supportedMIMEType {
return [supportedImageMIMETypesToExtensionTypes objectForKey:supportedMIMEType]; return [[self supportedImageMIMETypesToExtensionTypes] objectForKey:supportedMIMEType];
} }
+(NSString*) getSupportedMIMETypeFromVideoFile:(NSString*)supportedVideoFile { +(NSString*) getSupportedMIMETypeFromVideoFile:(NSString*)supportedVideoFile {
return [supportedVideoExtensionTypesToMIMETypes objectForKey:[supportedVideoFile pathExtension]]; return [[self supportedVideoExtensionTypesToMIMETypes] objectForKey:[supportedVideoFile pathExtension]];
} }
+(NSString*) getSupportedMIMETypeFromAudioFile:(NSString*)supportedAudioFile { +(NSString*) getSupportedMIMETypeFromAudioFile:(NSString*)supportedAudioFile {
return [supportedAudioExtensionTypesToMIMETypes objectForKey:[supportedAudioFile pathExtension]]; return [[self supportedAudioExtensionTypesToMIMETypes] objectForKey:[supportedAudioFile pathExtension]];
} }
+(NSString*) getSupportedMIMETypeFromImageFile:(NSString*)supportedImageFile { +(NSString*) getSupportedMIMETypeFromImageFile:(NSString*)supportedImageFile {
return [supportedImageExtensionTypesToMIMETypes objectForKey:[supportedImageFile pathExtension]]; return [[self supportedImageExtensionTypesToMIMETypes] objectForKey:[supportedImageFile pathExtension]];
} }
#pragma mark uses bytes #pragma mark uses bytes
+(NSString*) getSupportedImageMIMETypeFromImage:(UIImage*)image { +(NSString*) getSupportedImageMIMETypeFromImage:(UIImage*)image {
return [image contentType]; return [image contentType];
} }
+(BOOL) getIsSupportedTypeFromImage:(UIImage*)image { +(BOOL) getIsSupportedTypeFromImage:(UIImage*)image {
return [image isSupportedImageType]; return [image isSupportedImageType];
} }
#pragma mark full attachment utilities #pragma mark full attachment utilities
@ -189,7 +187,7 @@ static NSDictionary *supportedImageExtensionTypesToMIMETypes;
+(NSURL*) simLinkCorrectExtensionOfFile:(NSURL*)mediaURL ofMIMEType:(NSString*)contentType { +(NSURL*) simLinkCorrectExtensionOfFile:(NSURL*)mediaURL ofMIMEType:(NSString*)contentType {
if([self isAudio:contentType]) { if([self isAudio:contentType]) {
// Audio files in current framework require changing to have extension for player // Audio files in current framework require changing to have extension for player
return [self changeFile:mediaURL toHaveExtension:[supportedAudioMIMETypesToExtensionTypes objectForKey:contentType]]; return [self changeFile:mediaURL toHaveExtension:[[self supportedAudioMIMETypesToExtensionTypes] objectForKey:contentType]];
} }
return mediaURL; return mediaURL;
} }

Loading…
Cancel
Save