--- hatari/src/gui-osx/CreateFloppyController.m 2019/04/01 07:13:04 1.1 +++ hatari/src/gui-osx/CreateFloppyController.m 2019/04/09 08:54:10 1.1.1.5 @@ -1,8 +1,8 @@ /* Hatari - CreateFloppyController.m - This file is distributed under the GNU Public License, version 2 or at - your option any later version. Read the file gpl.txt for details. + This file is distributed under the GNU General Public License, version 2 + or at your option any later version. Read the file gpl.txt for details. Create floppy image window controller implementation file @@ -15,47 +15,52 @@ #include "main.h" #include "configuration.h" #include "createBlankImage.h" +#include "floppy.h" @implementation CreateFloppyController +char szPath[FILENAME_MAX] ; + - (IBAction)createFloppyImage:(id)sender { - // Create a SavePanel - NSSavePanel *savePanel = [NSSavePanel savePanel]; + BOOL cRet; + int ret, cTracks, cSectors, cSides ; + NSString *defaultDir ; + NSString *newCnf ; - // Set its allowed file types - NSArray* allowedFileTypes = [NSArray arrayWithObjects: @"st", @"msa", @"dim", @"gz", nil]; - [savePanel setAllowedFileTypes:allowedFileTypes]; - // Get the default images directory - NSString* defaultDir = [NSString stringWithCString:ConfigureParams.DiskImage.szDiskImageDirectory]; + defaultDir = [NSString stringWithCString:ConfigureParams.DiskImage.szDiskImageDirectory encoding:NSASCIIStringEncoding]; // Run the SavePanel, then check if the user clicked OK - if ( NSOKButton == [savePanel runModalForDirectory:defaultDir file:nil] ) + newCnf = [NSApp hsavefile:YES defoDir:defaultDir defoFile:nil types:[NSArray arrayWithObjects: allF, nil] ] ; + if ([newCnf length] != 0) { - // Get the path to the chosen file - NSString *path = [savePanel filename]; - - // Make a non-const C string out of it - const char* constSzPath = [path cString]; - size_t cbPath = strlen(constSzPath) + 1; - char szPath[cbPath]; - strncpy(szPath, constSzPath, cbPath); - + [newCnf getCString:szPath maxLength:FILENAME_MAX-1 encoding:NSASCIIStringEncoding] ; // Get the tracks, sectors and sides values - int cTracks = [[tracks selectedCell] tag]; - int cSectors = [[sectors selectedCell] tag]; - int cSides = [[sides selectedCell] tag]; - + cTracks = [[tracks selectedCell] tag]; + cSectors = [[sectors selectedCell] tag]; + cSides = [[sides selectedCell] tag]; + // Create the image - CreateBlankImage_CreateFile(szPath, cTracks, cSectors, cSides); - } + cRet=CreateBlankImage_CreateFile(szPath, cTracks, cSectors, cSides); + if(cRet==TRUE) + { + ret = NSRunAlertPanel(@"Hatari", localize(@"Insert newly created disk in"), localize(@"Ignore"), @" A: ", @" B: "); + if (ret == NSAlertDefaultReturn) + return ; + + printf("%d\n",ret); + ret = ret == NSAlertAlternateReturn ? 0 : 1 ; + Floppy_SetDiskFileName(ret, szPath, NULL); + Floppy_InsertDiskIntoDrive(ret); + } ; + } ; } - (void)awakeFromNib { // Fill the "Tracks" dropdown - [tracks removeAllItems]; + [tracks removeAllItems]; int i; for (i = 40; i <= 85; i++) { @@ -71,7 +76,9 @@ - (IBAction)runModal:(id)sender { - [[ModalWrapper alloc] runModal:window]; + ModalWrapper *mw=[[ModalWrapper alloc] init]; + [mw runModal:window]; + [mw release]; }