Skip to content

Commit 7723773

Browse files
committed
declare support for disk images to finder
1 parent 2f79c54 commit 7723773

3 files changed

Lines changed: 152 additions & 0 deletions

File tree

Mariani-Info.plist

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,23 @@
44
<dict>
55
<key>ATSApplicationFontsPath</key>
66
<string>.</string>
7+
<key>CFBundleDocumentTypes</key>
8+
<array>
9+
<dict>
10+
<key>CFBundleTypeIconSystemGenerated</key>
11+
<true/>
12+
<key>CFBundleTypeName</key>
13+
<string>Disk Image</string>
14+
<key>CFBundleTypeRole</key>
15+
<string>Viewer</string>
16+
<key>LSHandlerRank</key>
17+
<string>Alternate</string>
18+
<key>LSItemContentTypes</key>
19+
<array>
20+
<string>com.applewin.mariani.disk</string>
21+
</array>
22+
</dict>
23+
</array>
724
<key>CFBundleHelpBookFolder</key>
825
<string>Mariani.help</string>
926
<key>CFBundleHelpBookName</key>
@@ -12,5 +29,33 @@
1229
<true/>
1330
<key>OSAScriptingDefinition</key>
1431
<string>Mariani.sdef</string>
32+
<key>UTExportedTypeDeclarations</key>
33+
<array>
34+
<dict>
35+
<key>UTTypeConformsTo</key>
36+
<array>
37+
<string>public.data</string>
38+
</array>
39+
<key>UTTypeDescription</key>
40+
<string>Disk Image</string>
41+
<key>UTTypeIcons</key>
42+
<dict/>
43+
<key>UTTypeIdentifier</key>
44+
<string>com.applewin.mariani.disk</string>
45+
<key>UTTypeTagSpecification</key>
46+
<dict>
47+
<key>public.filename-extension</key>
48+
<array>
49+
<string>bin</string>
50+
<string>do</string>
51+
<string>dsk</string>
52+
<string>nib</string>
53+
<string>po</string>
54+
<string>woz</string>
55+
<string>hdv</string>
56+
</array>
57+
</dict>
58+
</dict>
59+
</array>
1560
</dict>
1661
</plist>

Mariani-Universal-Info.plist

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,23 @@
44
<dict>
55
<key>ATSApplicationFontsPath</key>
66
<string>.</string>
7+
<key>CFBundleDocumentTypes</key>
8+
<array>
9+
<dict>
10+
<key>CFBundleTypeIconSystemGenerated</key>
11+
<true/>
12+
<key>CFBundleTypeName</key>
13+
<string>Disk Image</string>
14+
<key>CFBundleTypeRole</key>
15+
<string>Viewer</string>
16+
<key>LSHandlerRank</key>
17+
<string>Alternate</string>
18+
<key>LSItemContentTypes</key>
19+
<array>
20+
<string>com.applewin.mariani.disk</string>
21+
</array>
22+
</dict>
23+
</array>
724
<key>CFBundleHelpBookFolder</key>
825
<string>Mariani.help</string>
926
<key>CFBundleHelpBookName</key>
@@ -12,5 +29,33 @@
1229
<true/>
1330
<key>OSAScriptingDefinition</key>
1431
<string>Mariani.sdef</string>
32+
<key>UTExportedTypeDeclarations</key>
33+
<array>
34+
<dict>
35+
<key>UTTypeConformsTo</key>
36+
<array>
37+
<string>public.data</string>
38+
</array>
39+
<key>UTTypeDescription</key>
40+
<string>Disk Image</string>
41+
<key>UTTypeIcons</key>
42+
<dict/>
43+
<key>UTTypeIdentifier</key>
44+
<string>com.applewin.mariani.disk</string>
45+
<key>UTTypeTagSpecification</key>
46+
<dict>
47+
<key>public.filename-extension</key>
48+
<array>
49+
<string>bin</string>
50+
<string>do</string>
51+
<string>dsk</string>
52+
<string>nib</string>
53+
<string>po</string>
54+
<string>woz</string>
55+
<string>hdv</string>
56+
</array>
57+
</dict>
58+
</dict>
59+
</array>
1560
</dict>
1661
</plist>

source/frontends/mariani/AppDelegate.mm

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,68 @@ - (void)applicationWillUnhide:(NSNotification *)notification {
277277
[self.emulatorVC start];
278278
}
279279

280+
- (BOOL)application:(NSApplication *)sender openFile:(nonnull NSString *)filename {
281+
// scan slots for floppy and hard drive controllers
282+
CardManager &cardManager = GetCardMgr();
283+
BOOL success = NO;
284+
int firstDisk2Slot = -1;
285+
int firstHDDSlot = -1;
286+
for (int slot = SLOT0; slot < NUM_SLOTS; slot++) {
287+
const SS_CARDTYPE cardType = cardManager.QuerySlot(slot);
288+
if (cardType == CT_GenericHDD) {
289+
if (firstHDDSlot < 0) {
290+
firstHDDSlot = slot;
291+
}
292+
// unplug all hard disks
293+
HarddiskInterfaceCard *hddCard = dynamic_cast<HarddiskInterfaceCard *>(cardManager.GetObj(slot));
294+
for (int idx = HARDDISK_1; idx < NUM_HARDDISKS; idx++) {
295+
hddCard->Unplug(idx);
296+
}
297+
}
298+
else if (cardType == CT_Disk2) {
299+
if (firstDisk2Slot < 0) {
300+
firstDisk2Slot = slot;
301+
}
302+
// eject all floppy disks
303+
Disk2InterfaceCard *disk2Card = dynamic_cast<Disk2InterfaceCard*>(cardManager.GetObj(slot));
304+
for (int idx = DRIVE_1; idx < NUM_DRIVES; idx++) {
305+
disk2Card->EjectDisk(idx);
306+
}
307+
}
308+
}
309+
310+
std::string fn(filename.UTF8String);
311+
if (firstHDDSlot >= 0 && [filename.lowercaseString hasSuffix:@".hdv"]) {
312+
HarddiskInterfaceCard *hddCard = dynamic_cast<HarddiskInterfaceCard *>(cardManager.GetObj(firstHDDSlot));
313+
if (hddCard->Insert(HARDDISK_1, fn)) {
314+
NSLog(@"Loaded '%@' as HDD 1", filename);
315+
success = YES;
316+
}
317+
else {
318+
NSLog(@"Failed to '%@' as HDD", filename);
319+
}
320+
}
321+
else if (firstDisk2Slot >= 0) {
322+
Disk2InterfaceCard *disk2Card = dynamic_cast<Disk2InterfaceCard*>(cardManager.GetObj(firstDisk2Slot));
323+
const ImageError_e error = disk2Card->InsertDisk(DRIVE_1, fn, IMAGE_USE_FILES_WRITE_PROTECT_STATUS, IMAGE_DONT_CREATE);
324+
if (error == eIMAGE_ERROR_NONE) {
325+
NSLog(@"Loaded '%@' into slot %d drive 1", filename, firstDisk2Slot);
326+
success = YES;
327+
}
328+
else {
329+
NSLog(@"Failed to load '%@' into slot %d drive 1 due to error %d",
330+
filename, firstDisk2Slot, error);
331+
disk2Card->NotifyInvalidImage(1, fn, error);
332+
}
333+
}
334+
335+
[self reconfigureDrives];
336+
[self updateDriveLights];
337+
[self.emulatorVC reboot];
338+
339+
return success;
340+
}
341+
280342
#pragma mark - NSWindowDelegate
281343

282344
- (BOOL)windowShouldClose:(NSWindow *)sender {

0 commit comments

Comments
 (0)