use ~/Documents/Mini vMac when not sandboxed

This commit is contained in:
Jesús A. Álvarez 2016-05-27 20:21:32 +02:00
parent aae7b67945
commit 671edf8bc0
2 changed files with 15 additions and 0 deletions

View File

@ -17,6 +17,7 @@ extern NSString * const MNVMDidEjectDiskNotification;
@property (assign, nonatomic, getter=isEmulatorRunning) BOOL emulatorRunning; @property (assign, nonatomic, getter=isEmulatorRunning) BOOL emulatorRunning;
@property (nonatomic, readonly) NSString *documentsPath; @property (nonatomic, readonly) NSString *documentsPath;
@property (nonatomic, readonly) NSArray<NSString*> *diskImageExtensions; @property (nonatomic, readonly) NSArray<NSString*> *diskImageExtensions;
@property (readonly, nonatomic, getter = isSandboxed) BOOL sandboxed;
+ (instancetype)sharedInstance; + (instancetype)sharedInstance;
- (void)showAlertWithTitle:(NSString *)title message:(NSString *)message; - (void)showAlertWithTitle:(NSString *)title message:(NSString *)message;

View File

@ -199,6 +199,16 @@ NSString * const MNVMDidEjectDiskNotification = @"MNVMDidEjectDisk";
#pragma mark - Files #pragma mark - Files
- (BOOL)isSandboxed {
static dispatch_once_t onceToken;
static BOOL sandboxed;
dispatch_once(&onceToken, ^{
NSString *bundlePath = [[NSBundle mainBundle] bundlePath];
sandboxed = ![bundlePath hasPrefix:@"/Applications/"];
});
return sandboxed;
}
- (NSArray<NSString *> *)diskImageExtensions { - (NSArray<NSString *> *)diskImageExtensions {
return @[@"dsk", @"img", @"dc42", @"diskcopy42"]; return @[@"dsk", @"img", @"dc42", @"diskcopy42"];
} }
@ -208,6 +218,10 @@ NSString * const MNVMDidEjectDiskNotification = @"MNVMDidEjectDisk";
static NSString *documentsPath; static NSString *documentsPath;
dispatch_once(&onceToken, ^{ dispatch_once(&onceToken, ^{
documentsPath = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES).firstObject.stringByStandardizingPath; documentsPath = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES).firstObject.stringByStandardizingPath;
if (!self.sandboxed) {
documentsPath = [documentsPath stringByAppendingPathComponent:@"Mini vMac"].stringByStandardizingPath;
}
[[NSFileManager defaultManager] createDirectoryAtPath:documentsPath withIntermediateDirectories:YES attributes:nil error:NULL];
[[NSFileManager defaultManager] createDirectoryAtPath:documentsPath withIntermediateDirectories:YES attributes:nil error:NULL]; [[NSFileManager defaultManager] createDirectoryAtPath:documentsPath withIntermediateDirectories:YES attributes:nil error:NULL];
}); });
return documentsPath; return documentsPath;