fix some warnings

This commit is contained in:
Jesús A. Álvarez 2016-05-26 21:33:09 +02:00
parent 38933ff6e1
commit ce7552af33
2 changed files with 14 additions and 27 deletions

View File

@ -11,6 +11,5 @@
@interface UIImage (DiskImageIcon) @interface UIImage (DiskImageIcon)
+ (UIImage *)imageWithIconForDiskImage:(NSString *)path; + (UIImage *)imageWithIconForDiskImage:(NSString *)path;
+ (NSCache<NSString*,UIImage*> *)diskImageIconCache;
@end @end

View File

@ -214,13 +214,8 @@ static uint8_t maskReplacement[][128] = {
RFILE *rfile = res_open_funcs(rsrcFork, mfs_fkseek, mfs_fkread); RFILE *rfile = res_open_funcs(rsrcFork, mfs_fkseek, mfs_fkread);
// get icon // get icon
CGImageRef iconImage = [self appIconForResourceFile:rfile creator:ntohl(rec->flUsrWds.creator)]; UIImage *icon = [self appIconForResourceFile:rfile creator:ntohl(rec->flUsrWds.creator)];
UIImage *icon = nil;
if (iconImage) {
icon = [UIImage imageWithCGImage:iconImage];
CGImageRelease(iconImage);
}
// close stuff // close stuff
res_close(rfile); res_close(rfile);
mfs_fkclose(rsrcFork); mfs_fkclose(rsrcFork);
@ -282,12 +277,8 @@ static uint8_t maskReplacement[][128] = {
hfs_umount(vol); hfs_umount(vol);
return nil; return nil;
} }
CGImageRef iconImage = [self appIconForResourceFile:rfile creator:ntohl(*(uint32_t *)ent.u.file.creator)]; icon = [self appIconForResourceFile:rfile creator:ntohl(*(uint32_t *)ent.u.file.creator)];
if (iconImage) {
icon = [UIImage imageWithCGImage:iconImage];
CGImageRelease(iconImage);
}
// close stuff // close stuff
res_close(rfile); res_close(rfile);
hfs_close(hfile); hfs_close(hfile);
@ -431,15 +422,10 @@ static uint8_t maskReplacement[][128] = {
} }
return nil; return nil;
} }
// read icon family // read icon family
NSDictionary *iconFamily = [self iconFamilyID:-16455 inResourceFile:rfile]; NSDictionary *iconFamily = [self iconFamilyID:-16455 inResourceFile:rfile];
icon = [self iconImageFromFamily:iconFamily];
// create image
CGImageRef iconImage = [self iconImageFromFamily:iconFamily];
if (iconImage) {
icon = [UIImage imageWithCGImage:iconImage];
CGImageRelease(iconImage);
}
res_close(rfile); res_close(rfile);
if (hfile) { if (hfile) {
@ -459,7 +445,7 @@ static uint8_t maskReplacement[][128] = {
#pragma mark - Resource Access #pragma mark - Resource Access
- (CGImageRef)appIconForResourceFile:(RFILE *)rfile creator:(OSType)creator { - (UIImage*)appIconForResourceFile:(RFILE *)rfile creator:(OSType)creator {
// load bundle // load bundle
size_t numBundles; size_t numBundles;
ResAttr *bundles = res_list(rfile, 'BNDL', NULL, 0, 0, &numBundles, NULL); ResAttr *bundles = res_list(rfile, 'BNDL', NULL, 0, 0, &numBundles, NULL);
@ -481,7 +467,7 @@ static uint8_t maskReplacement[][128] = {
} }
// read bundle // read bundle
int iconID = [self iconFamilyIDForType:'APPL' inBundle:bundle inResourceFile:rfile]; NSInteger iconID = [self iconFamilyIDForType:'APPL' inBundle:bundle inResourceFile:rfile];
free(bundle); free(bundle);
if (iconID == NSNotFound) { if (iconID == NSNotFound) {
return nil; return nil;
@ -524,7 +510,7 @@ static uint8_t maskReplacement[][128] = {
return iconFamily; return iconFamily;
} }
- (int)iconFamilyIDForType:(OSType)type inBundle:(void *)bndl inResourceFile:(RFILE *)rfile { - (NSInteger)iconFamilyIDForType:(OSType)type inBundle:(void *)bndl inResourceFile:(RFILE *)rfile {
short numIconFamilies = RSHORT(bndl, 0x0C) + 1; short numIconFamilies = RSHORT(bndl, 0x0C) + 1;
short *iconFamily = (short *)(bndl + 0x0E); short *iconFamily = (short *)(bndl + 0x0E);
short numFileRefs = RSHORT(bndl, (numIconFamilies * 4) + 0x12) + 1; short numFileRefs = RSHORT(bndl, (numIconFamilies * 4) + 0x12) + 1;
@ -559,7 +545,7 @@ static uint8_t maskReplacement[][128] = {
return NSNotFound; return NSNotFound;
} }
- (CGImageRef)iconImageFromFamily:(NSDictionary *)iconFamily { - (UIImage*)iconImageFromFamily:(NSDictionary *)iconFamily {
NSData *iconData, *iconMask; NSData *iconData, *iconMask;
if ((iconMask = [iconFamily objectForKey:@"IMK#"])) { if ((iconMask = [iconFamily objectForKey:@"IMK#"])) {
// has large mask, find best large icon // has large mask, find best large icon
@ -585,7 +571,7 @@ static uint8_t maskReplacement[][128] = {
return NULL; return NULL;
} }
- (CGImageRef)iconImageWithData:(NSData *)iconData mask:(NSData *)iconMask size:(int)size depth:(int)depth { - (UIImage*)iconImageWithData:(NSData *)iconData mask:(NSData *)iconMask size:(int)size depth:(int)depth {
if (iconData == nil || iconMask == nil) { if (iconData == nil || iconMask == nil) {
return NULL; return NULL;
} }
@ -657,10 +643,12 @@ static uint8_t maskReplacement[][128] = {
// create image // create image
CGDataProviderRef provider = CGDataProviderCreateWithCFData(pixels); CGDataProviderRef provider = CGDataProviderCreateWithCFData(pixels);
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB(); CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
CGImageRef image = CGImageCreate(size, size, 8, 32, size * 4, colorSpace, kCGImageAlphaFirst | kCGBitmapByteOrder32Big, provider, NULL, false, kCGRenderingIntentDefault); CGImageRef cgImage = CGImageCreate(size, size, 8, 32, size * 4, colorSpace, kCGImageAlphaFirst | kCGBitmapByteOrder32Big, provider, NULL, false, kCGRenderingIntentDefault);
CGDataProviderRelease(provider); CGDataProviderRelease(provider);
CGColorSpaceRelease(colorSpace); CGColorSpaceRelease(colorSpace);
CFRelease(pixels); CFRelease(pixels);
UIImage *image = [UIImage imageWithCGImage:cgImage];
CGImageRelease(cgImage);
return image; return image;
} }