cache disk icons
This commit is contained in:
parent
6a4dfaa4fc
commit
a4d235426b
|
@ -879,6 +879,7 @@
|
|||
28F6B4961CF07DDD002D76D0 /* Release */,
|
||||
);
|
||||
defaultConfigurationIsVisible = 0;
|
||||
defaultConfigurationName = Release;
|
||||
};
|
||||
28F6B4AE1CF07EC9002D76D0 /* Build configuration list for PBXNativeTarget "libmfs" */ = {
|
||||
isa = XCConfigurationList;
|
||||
|
@ -887,6 +888,7 @@
|
|||
28F6B4B01CF07EC9002D76D0 /* Release */,
|
||||
);
|
||||
defaultConfigurationIsVisible = 0;
|
||||
defaultConfigurationName = Release;
|
||||
};
|
||||
28F6B4BC1CF07F32002D76D0 /* Build configuration list for PBXNativeTarget "libres" */ = {
|
||||
isa = XCConfigurationList;
|
||||
|
@ -895,6 +897,7 @@
|
|||
28F6B4BE1CF07F32002D76D0 /* Release */,
|
||||
);
|
||||
defaultConfigurationIsVisible = 0;
|
||||
defaultConfigurationName = Release;
|
||||
};
|
||||
/* End XCConfigurationList section */
|
||||
};
|
||||
|
|
|
@ -11,5 +11,6 @@
|
|||
@interface UIImage (DiskImageIcon)
|
||||
|
||||
+ (UIImage *)imageWithIconForDiskImage:(NSString *)path;
|
||||
+ (NSCache<NSString*,UIImage*> *)diskImageIconCache;
|
||||
|
||||
@end
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
#import "libhfs.h"
|
||||
#import "res.h"
|
||||
#import "mfs.h"
|
||||
#import "AppDelegate.h"
|
||||
|
||||
#define kDiskImageHasDC42Header 1 << 0
|
||||
#define RSHORT(base, offset) ntohs(*((short *)((base) + (offset))))
|
||||
|
@ -22,10 +23,37 @@
|
|||
|
||||
@end
|
||||
|
||||
static NSCache<NSString*,UIImage*> *diskImageIconCache = nil;
|
||||
|
||||
@implementation UIImage (DiskImageIcon)
|
||||
|
||||
+ (NSCache<NSString*,UIImage*> *)diskImageIconCache {
|
||||
static dispatch_once_t onceToken;
|
||||
dispatch_once(&onceToken, ^{
|
||||
diskImageIconCache = [NSCache new];
|
||||
diskImageIconCache.name = @"net.namedfork.minivmac.icon-cache";
|
||||
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(_didEjectDisk:) name:MNVMDidEjectDiskNotification object:nil];
|
||||
});
|
||||
return diskImageIconCache;
|
||||
}
|
||||
|
||||
+ (void)_didEjectDisk:(NSNotification*)notification {
|
||||
NSString *path = [notification.userInfo[@"path"] stringByStandardizingPath];
|
||||
// reload icon
|
||||
[diskImageIconCache removeObjectForKey:path];
|
||||
[self imageWithIconForDiskImage:path];
|
||||
}
|
||||
|
||||
+ (UIImage *)imageWithIconForDiskImage:(NSString *)path {
|
||||
return [[DiskImageIconReader new] iconForDiskImage:path];
|
||||
path = path.stringByStandardizingPath;
|
||||
UIImage *icon = [[self diskImageIconCache] objectForKey:path];
|
||||
if (icon == nil) {
|
||||
icon = [[DiskImageIconReader new] iconForDiskImage:path];
|
||||
if (icon != nil) {
|
||||
[diskImageIconCache setObject:icon forKey:path];
|
||||
}
|
||||
}
|
||||
return icon;
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
Loading…
Reference in New Issue