From ce02b3ad73e410c7288ba02cc2491171768214d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jesu=CC=81s=20A=2E=20A=CC=81lvarez?= Date: Sat, 7 May 2016 20:48:53 +0200 Subject: [PATCH] open disk images and ROM file from other apps --- Mini vMac/AppDelegate.h | 3 ++ Mini vMac/AppDelegate.m | 57 ++++++++++++++++++++- Mini vMac/Info.plist | 110 ++++++++++++++++++++++++++++++++++++++++ Mini vMac/MYOSGLUE.m | 9 +--- 4 files changed, 170 insertions(+), 9 deletions(-) diff --git a/Mini vMac/AppDelegate.h b/Mini vMac/AppDelegate.h index 8c57fad..cf19048 100644 --- a/Mini vMac/AppDelegate.h +++ b/Mini vMac/AppDelegate.h @@ -12,8 +12,11 @@ @property (strong, nonatomic) UIWindow *window; @property (assign, nonatomic, getter=isEmulatorRunning) BOOL emulatorRunning; +@property (nonatomic, readonly) NSString *documentsPath; + (instancetype)sharedInstance; +- (void)showAlertWithTitle:(NSString *)title message:(NSString *)message; + - (void)setMouseX:(NSInteger)x Y:(NSInteger)y; - (void)moveMouseX:(NSInteger)x Y:(NSInteger)y; - (void)setMouseButton:(BOOL)down; diff --git a/Mini vMac/AppDelegate.m b/Mini vMac/AppDelegate.m index 7500d5c..ef07ada 100644 --- a/Mini vMac/AppDelegate.m +++ b/Mini vMac/AppDelegate.m @@ -37,11 +37,64 @@ static AppDelegate *sharedAppDelegate = nil; } - (void)applicationDidEnterBackground:(UIApplication *)application { - SetSpeedStopped(trueblnr); + self.emulatorRunning = NO; } - (void)applicationWillEnterForeground:(UIApplication *)application { - SetSpeedStopped(falseblnr); + self.emulatorRunning = YES; +} + +- (void)showAlertWithTitle:(NSString *)title message:(NSString *)message { + if (![NSThread isMainThread]) { + dispatch_async(dispatch_get_main_queue(), ^{ + [self showAlertWithTitle:title message:message]; + }); + return; + } + UIAlertController *alert = [UIAlertController alertControllerWithTitle:title message:message preferredStyle:UIAlertControllerStyleAlert]; + [alert addAction:[UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:nil]]; + UIViewController *controller = self.window.rootViewController; + [controller presentViewController:alert animated:YES completion:nil]; +} + +#pragma mark - Files + +- (NSString *)documentsPath { + static dispatch_once_t onceToken; + static NSString *documentsPath; + dispatch_once(&onceToken, ^{ + documentsPath = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES).firstObject.stringByStandardizingPath; + [[NSFileManager defaultManager] createDirectoryAtPath:documentsPath withIntermediateDirectories:YES attributes:nil error:NULL]; + }); + return documentsPath; +} + +- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation { + if (url.fileURL) { + // opening file + NSFileManager *fileManager = [NSFileManager defaultManager]; + NSString *fileName = url.path.lastPathComponent; + NSString *destinationPath = [self.documentsPath stringByAppendingPathComponent:fileName]; + NSError *error = NULL; + NSInteger tries = 1; + while ([fileManager fileExistsAtPath:destinationPath]) { + NSString *newFileName; + if (fileName.pathExtension.length > 0) { + newFileName = [NSString stringWithFormat:@"%@ %d.%@", fileName.stringByDeletingPathExtension, (int)tries, fileName.pathExtension]; + } else { + newFileName = [NSString stringWithFormat:@"%@ %d", fileName, (int)tries]; + } + destinationPath = [self.documentsPath stringByAppendingPathComponent:newFileName]; + tries++; + } + [fileManager moveItemAtPath:url.path toPath:destinationPath error:&error]; + if (error) { + [self showAlertWithTitle:fileName message:error.localizedFailureReason]; + } else { + [self showAlertWithTitle:@"File Import" message:[NSString stringWithFormat:@"%@ imported to Documents", destinationPath.lastPathComponent]]; + } + } + return YES; } #pragma mark - Emulation diff --git a/Mini vMac/Info.plist b/Mini vMac/Info.plist index 315ea65..1196904 100644 --- a/Mini vMac/Info.plist +++ b/Mini vMac/Info.plist @@ -49,5 +49,115 @@ UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight + UTExportedTypeDeclarations + + + UTTypeConformsTo + + public.archive + public.data + public.disk-image + + UTTypeDescription + Disk Image + UTTypeIdentifier + com.apple.disk-image + UTTypeTagSpecification + + public.filename-extension + + img + dsk + + + + + UTTypeConformsTo + + com.apple.disk-image + public.archive + public.data + public.disk-image + + UTTypeDescription + Disk Copy 4.2 Image + UTTypeIdentifier + com.apple.disk-image-dc42 + UTTypeTagSpecification + + com.apple.ostype + + dImg + + public.filename-extension + + dc42 + diskcopy42 + + + + + UTTypeConformsTo + + public.data + + UTTypeDescription + ROM image + UTTypeIdentifier + net.namedfork.minivmac.rom + UTTypeTagSpecification + + public.filename-extension + + rom + + + + + CFBundleDocumentTypes + + + CFBundleTypeIconFiles + + CFBundleTypeName + Disk Image + CFBundleTypeRole + Editor + LSHandlerRank + Owner + LSItemContentTypes + + com.apple.disk-image + + + + CFBundleTypeIconFiles + + CFBundleTypeName + Disk Copy 4.2 Disk Image + CFBundleTypeRole + Editor + LSHandlerRank + Owner + LSItemContentTypes + + com.apple.disk-image-dc42 + + + + CFBundleTypeIconFiles + + CFBundleTypeName + ROM image + CFBundleTypeRole + Editor + LSHandlerRank + Owner + LSItemContentTypes + + net.namedfork.minivmac.rom + + + diff --git a/Mini vMac/MYOSGLUE.m b/Mini vMac/MYOSGLUE.m index 6a7b5f2..38d5b47 100644 --- a/Mini vMac/MYOSGLUE.m +++ b/Mini vMac/MYOSGLUE.m @@ -33,6 +33,7 @@ #include "MYOSGLUE.h" #include "STRCONST.h" #import "ScreenView.h" +#import "AppDelegate.h" #pragma mark - some simple utilities @@ -134,7 +135,7 @@ LOCALPROC Screen_UnInit(void) { LOCALVAR NSString *MyDataPath = nil; LOCALFUNC blnr InitCocoaStuff(void) { - MyDataPath = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES).firstObject; + MyDataPath = [AppDelegate sharedInstance].documentsPath; if (MyDataPath) { [MyDataPath retain]; } @@ -765,12 +766,6 @@ GLOBALFUNC tMacErr HTCEimport(tPbuf *r) { } #endif -#if EmLocalTalk - -#include "BPFILTER.h" - -#endif - #pragma mark - time, date, location #define dbglog_TimeStuff (0 && dbglog_HAVE)