mirror of
https://github.com/zydeco/minivmac4ios.git
synced 2024-06-13 01:29:28 +00:00
cache disk icons
This commit is contained in:
parent
6a4dfaa4fc
commit
a4d235426b
|
@ -879,6 +879,7 @@
|
||||||
28F6B4961CF07DDD002D76D0 /* Release */,
|
28F6B4961CF07DDD002D76D0 /* Release */,
|
||||||
);
|
);
|
||||||
defaultConfigurationIsVisible = 0;
|
defaultConfigurationIsVisible = 0;
|
||||||
|
defaultConfigurationName = Release;
|
||||||
};
|
};
|
||||||
28F6B4AE1CF07EC9002D76D0 /* Build configuration list for PBXNativeTarget "libmfs" */ = {
|
28F6B4AE1CF07EC9002D76D0 /* Build configuration list for PBXNativeTarget "libmfs" */ = {
|
||||||
isa = XCConfigurationList;
|
isa = XCConfigurationList;
|
||||||
|
@ -887,6 +888,7 @@
|
||||||
28F6B4B01CF07EC9002D76D0 /* Release */,
|
28F6B4B01CF07EC9002D76D0 /* Release */,
|
||||||
);
|
);
|
||||||
defaultConfigurationIsVisible = 0;
|
defaultConfigurationIsVisible = 0;
|
||||||
|
defaultConfigurationName = Release;
|
||||||
};
|
};
|
||||||
28F6B4BC1CF07F32002D76D0 /* Build configuration list for PBXNativeTarget "libres" */ = {
|
28F6B4BC1CF07F32002D76D0 /* Build configuration list for PBXNativeTarget "libres" */ = {
|
||||||
isa = XCConfigurationList;
|
isa = XCConfigurationList;
|
||||||
|
@ -895,6 +897,7 @@
|
||||||
28F6B4BE1CF07F32002D76D0 /* Release */,
|
28F6B4BE1CF07F32002D76D0 /* Release */,
|
||||||
);
|
);
|
||||||
defaultConfigurationIsVisible = 0;
|
defaultConfigurationIsVisible = 0;
|
||||||
|
defaultConfigurationName = Release;
|
||||||
};
|
};
|
||||||
/* End XCConfigurationList section */
|
/* End XCConfigurationList section */
|
||||||
};
|
};
|
||||||
|
|
|
@ -11,5 +11,6 @@
|
||||||
@interface UIImage (DiskImageIcon)
|
@interface UIImage (DiskImageIcon)
|
||||||
|
|
||||||
+ (UIImage *)imageWithIconForDiskImage:(NSString *)path;
|
+ (UIImage *)imageWithIconForDiskImage:(NSString *)path;
|
||||||
|
+ (NSCache<NSString*,UIImage*> *)diskImageIconCache;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
|
@ -10,6 +10,7 @@
|
||||||
#import "libhfs.h"
|
#import "libhfs.h"
|
||||||
#import "res.h"
|
#import "res.h"
|
||||||
#import "mfs.h"
|
#import "mfs.h"
|
||||||
|
#import "AppDelegate.h"
|
||||||
|
|
||||||
#define kDiskImageHasDC42Header 1 << 0
|
#define kDiskImageHasDC42Header 1 << 0
|
||||||
#define RSHORT(base, offset) ntohs(*((short *)((base) + (offset))))
|
#define RSHORT(base, offset) ntohs(*((short *)((base) + (offset))))
|
||||||
|
@ -22,10 +23,37 @@
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
static NSCache<NSString*,UIImage*> *diskImageIconCache = nil;
|
||||||
|
|
||||||
@implementation UIImage (DiskImageIcon)
|
@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 {
|
+ (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
|
@end
|
||||||
|
|
Loading…
Reference in New Issue
Block a user