Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better import #50

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,11 @@
path = minivmac
url = https://github.com/zydeco/minivmac.git
branch = wintergames
[submodule "UniversalDetector"]
path = UniversalDetector
url = https://github.com/MacPaw/universal-detector.git
branch = master
[submodule "XADMaster"]
path = XADMaster
url = https://github.com/MacPaw/XADMaster.git
branch = master
306 changes: 303 additions & 3 deletions Mini vMac.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions Mini vMac/AppDelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,7 @@ extern NSString *DocumentsChangedNotification;
- (IBAction)showSettings:(id)sender;
- (IBAction)showGestureHelp:(id)sender;

- (void)showBrowser;

@end

51 changes: 49 additions & 2 deletions Mini vMac/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,18 @@
//

@import AVFoundation;
@import SafariServices;
#import "AppDelegate.h"
#import "SettingsViewController.h"
#import "InsertDiskViewController.h"
#import "HFSDiskImage.h"

static AppDelegate *sharedAppDelegate = nil;
static NSObject<Emulator> *sharedEmulator = nil;
NSString *DocumentsChangedNotification = @"documentsChanged";

@interface AppDelegate () <BTCMouseDelegate>

@interface AppDelegate () <BTCMouseDelegate, SFSafariViewControllerDelegate>
@property (nonatomic, strong) SFSafariViewController * browser;
@end

@implementation AppDelegate
Expand Down Expand Up @@ -281,7 +283,23 @@ - (BOOL)importFileToDocuments:(NSURL *)url copy:(BOOL)copy {
}

- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options {
[self.window.rootViewController dismissViewControllerAnimated:NO completion:nil];

if (url.fileURL) {

// FIXME: detect file type of imported file
// if archive first unarchive
// - if the resulting file(s) contain ROM files, copy to Documents
// - if the resulting file(s) contain disk images, copy those to Documents
// - if the resulting file(s) contain other files, embed them in an HFS Disk Image and copy that to Documents

// FIXME: this is temporary code to test importing files into disk images
HFSDiskImage * tempDiskImage = [HFSDiskImage importFileIntoTemporaryDiskImage:url.path];
if (tempDiskImage) {
[sharedEmulator insertDisk:tempDiskImage.path];
return YES;
}

// opening file
NSString *inboxPath = [self.documentsPath stringByAppendingPathComponent:@"Inbox"];
if ([url.path.stringByStandardizingPath hasPrefix:inboxPath]) {
Expand All @@ -304,4 +322,33 @@ - (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDiction
return YES;
}

- (void)showBrowser {
NSURL * url = [NSURL URLWithString:@"https://macintoshgarden.org"];
if (url == nil) {
return;
}

if (self.window.rootViewController.presentedViewController) {
__weak typeof(self) weakSelf = self;
[self.window.rootViewController dismissViewControllerAnimated:NO completion:^{
[weakSelf showBrowser];
}];
return;
}

SFSafariViewController * vc = self.browser;
if (vc == nil) {
vc = [[SFSafariViewController alloc] initWithURL:url];
vc.modalPresentationStyle = UIModalPresentationPageSheet;
vc.delegate = self;
self.browser = vc;
}

[self.window.rootViewController presentViewController:vc animated:YES completion:nil];
}

- (void)safariViewControllerDidFinish:(SFSafariViewController *)controller {
[self.window.rootViewController dismissViewControllerAnimated:YES completion:nil];
}

@end
11 changes: 11 additions & 0 deletions Mini vMac/CodeSigning.xcconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
//
// CodeSigning.xcconfig
// Mini vMac
//
// Created by Lieven Dekeyser on 13/03/2024.
//
// Configuration settings file format documentation can be found at:
// https://help.apple.com/xcode/#/dev745c5c974

// You can find your Team ID on https://developer.apple.com/account#MembershipDetailsCard
DEVELOPMENT_TEAM=UJXNDZ5TNU
42 changes: 42 additions & 0 deletions Mini vMac/HFSDiskImage.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
//
// HFSDiskImage.h
// Mini vMac
//
// Created by Lieven Dekeyser on 13/03/2024.
//

#import <Foundation/Foundation.h>

NS_ASSUME_NONNULL_BEGIN

@interface HFSDiskImage : NSObject

@property (nonatomic, readonly, copy) NSString * path;
@property (nonatomic, readonly, getter=isOpen) BOOL open;
@property (nonatomic, readonly, getter=isReadOnly) BOOL readOnly;

+ (nullable HFSDiskImage *)createDiskImageWithName:(NSString *)name size:(size_t)volumeSize atPath:(NSString *)path;

- (nullable instancetype)initWithPath:(NSString *)path;

- (instancetype)init __unavailable;
+ (instancetype)new __unavailable;

- (BOOL)openForReading;
- (BOOL)openForReadingAndWriting;

- (BOOL)close;

- (BOOL)addFile:(NSString *)sourceFile;

@end // HFSDiskImage


@interface HFSDiskImage (Import)

+ (nullable HFSDiskImage *)importFileIntoTemporaryDiskImage:(NSString *)sourceFile;

@end // HFSDiskImage (Import)


NS_ASSUME_NONNULL_END
Loading