open disk images and ROM file from other apps

This commit is contained in:
Jesús A. Álvarez 2016-05-07 20:48:53 +02:00
parent 5cad8eef18
commit ce02b3ad73
4 changed files with 170 additions and 9 deletions

View File

@ -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;

View File

@ -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

View File

@ -49,5 +49,115 @@
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>UTExportedTypeDeclarations</key>
<array>
<dict>
<key>UTTypeConformsTo</key>
<array>
<string>public.archive</string>
<string>public.data</string>
<string>public.disk-image</string>
</array>
<key>UTTypeDescription</key>
<string>Disk Image</string>
<key>UTTypeIdentifier</key>
<string>com.apple.disk-image</string>
<key>UTTypeTagSpecification</key>
<dict>
<key>public.filename-extension</key>
<array>
<string>img</string>
<string>dsk</string>
</array>
</dict>
</dict>
<dict>
<key>UTTypeConformsTo</key>
<array>
<string>com.apple.disk-image</string>
<string>public.archive</string>
<string>public.data</string>
<string>public.disk-image</string>
</array>
<key>UTTypeDescription</key>
<string>Disk Copy 4.2 Image</string>
<key>UTTypeIdentifier</key>
<string>com.apple.disk-image-dc42</string>
<key>UTTypeTagSpecification</key>
<dict>
<key>com.apple.ostype</key>
<array>
<string>dImg</string>
</array>
<key>public.filename-extension</key>
<array>
<string>dc42</string>
<string>diskcopy42</string>
</array>
</dict>
</dict>
<dict>
<key>UTTypeConformsTo</key>
<array>
<string>public.data</string>
</array>
<key>UTTypeDescription</key>
<string>ROM image</string>
<key>UTTypeIdentifier</key>
<string>net.namedfork.minivmac.rom</string>
<key>UTTypeTagSpecification</key>
<dict>
<key>public.filename-extension</key>
<array>
<string>rom</string>
</array>
</dict>
</dict>
</array>
<key>CFBundleDocumentTypes</key>
<array>
<dict>
<key>CFBundleTypeIconFiles</key>
<array/>
<key>CFBundleTypeName</key>
<string>Disk Image</string>
<key>CFBundleTypeRole</key>
<string>Editor</string>
<key>LSHandlerRank</key>
<string>Owner</string>
<key>LSItemContentTypes</key>
<array>
<string>com.apple.disk-image</string>
</array>
</dict>
<dict>
<key>CFBundleTypeIconFiles</key>
<array/>
<key>CFBundleTypeName</key>
<string>Disk Copy 4.2 Disk Image</string>
<key>CFBundleTypeRole</key>
<string>Editor</string>
<key>LSHandlerRank</key>
<string>Owner</string>
<key>LSItemContentTypes</key>
<array>
<string>com.apple.disk-image-dc42</string>
</array>
</dict>
<dict>
<key>CFBundleTypeIconFiles</key>
<array/>
<key>CFBundleTypeName</key>
<string>ROM image</string>
<key>CFBundleTypeRole</key>
<string>Editor</string>
<key>LSHandlerRank</key>
<string>Owner</string>
<key>LSItemContentTypes</key>
<array>
<string>net.namedfork.minivmac.rom</string>
</array>
</dict>
</array>
</dict>
</plist>

View File

@ -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)