--- hatari/src/gui-sdl/dlgNewDisk.c 2019/04/01 07:15:40 1.1.1.3 +++ hatari/src/gui-sdl/dlgNewDisk.c 2019/04/09 08:49:43 1.1.1.6 @@ -4,7 +4,7 @@ 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. */ -const char DlgNewDisk_rcsid[] = "Hatari $Id: dlgNewDisk.c,v 1.1.1.3 2019/04/01 07:15:40 root Exp $"; +const char DlgNewDisk_fileid[] = "Hatari dlgNewDisk.c : " __DATE__ " " __TIME__; #include "main.h" #include "configuration.h" @@ -12,7 +12,7 @@ const char DlgNewDisk_rcsid[] = "Hatari #include "dialog.h" #include "sdlgui.h" #include "file.h" - +#include "log.h" #define DLGNEWDISK_DECTRACK 3 #define DLGNEWDISK_TRACKSTR 4 @@ -20,10 +20,12 @@ const char DlgNewDisk_rcsid[] = "Hatari #define DLGNEWDISK_SECTORS9 7 #define DLGNEWDISK_SECTORS10 8 #define DLGNEWDISK_SECTORS11 9 -#define DLGNEWDISK_SIDES1 11 -#define DLGNEWDISK_SIDES2 12 -#define DLGNEWDISK_SAVE 13 -#define DLGNEWDISK_EXIT 14 +#define DLGNEWDISK_SECTORS18 10 +#define DLGNEWDISK_SECTORS36 11 +#define DLGNEWDISK_SIDES1 13 +#define DLGNEWDISK_SIDES2 14 +#define DLGNEWDISK_SAVE 15 +#define DLGNEWDISK_EXIT 16 static char szTracks[3]; static int nTracks = 80; @@ -31,34 +33,77 @@ static int nTracks = 80; /* The new disk image dialog: */ static SGOBJ newdiskdlg[] = { - { SGBOX, 0, 0, 0,0, 28,12, NULL }, + { SGBOX, 0, 0, 0,0, 29,14, NULL }, { SGTEXT, 0, 0, 6,1, 16,1, "New floppy image" }, { SGTEXT, 0, 0, 2,3, 7,1, "Tracks:" }, { SGBUTTON, 0, 0, 12,3, 1,1, "\x04" }, /* Left-arrow button */ { SGTEXT, 0, 0, 14,3, 2,1, szTracks }, { SGBUTTON, 0, 0, 17,3, 1,1, "\x03" }, /* Right-arrow button */ { SGTEXT, 0, 0, 2,5, 8,1, "Sectors:" }, - { SGRADIOBUT, 0, SG_SELECTED, 12,5, 4,1, "9" }, + { SGRADIOBUT, 0, SG_SELECTED, 12,5, 4,1, " 9" }, { SGRADIOBUT, 0, 0, 17,5, 4,1, "10" }, { SGRADIOBUT, 0, 0, 22,5, 4,1, "11" }, - { SGTEXT, 0, 0, 2,7, 6,1, "Sides:" }, - { SGRADIOBUT, 0, 0, 12,7, 4,1, "1" }, - { SGRADIOBUT, 0, SG_SELECTED, 17,7, 4,1, "2" }, - { SGBUTTON, 0, 0, 4,10, 8,1, "Create" }, - { SGBUTTON, 0, 0, 18,10, 6,1, "Back" }, + { SGRADIOBUT, 0, 0, 12,6, 9,1, "18 (HD)" }, + { SGRADIOBUT, 0, 0, 12,7, 9,1, "36 (ED)" }, + { SGTEXT, 0, 0, 2,9, 6,1, "Sides:" }, + { SGRADIOBUT, 0, 0, 12,9, 4,1, "1" }, + { SGRADIOBUT, 0, SG_SELECTED, 17,9, 4,1, "2" }, + { SGBUTTON, 0, 0, 4,12, 8,1, "Create" }, + { SGBUTTON, 0, 0, 18,12, 6,1, "Back" }, { -1, 0, 0, 0,0, 0,0, NULL } }; #define DEFAULT_DISK_NAME "new_disk.st" + /*-----------------------------------------------------------------------*/ -/* - Show and process the "new blank disk image" dialog. -*/ -void DlgNewDisk_Main(void) +/** + * Handle creation of a the "new blank disk image". + * return true if disk created, false otherwise. + */ +static bool DlgNewDisk_CreateDisk(const char *path) +{ + int nSectors, nSides; + + /* (potentially non-existing) filename? */ + if (File_DirExists(path)) + { + Log_AlertDlg(LOG_ERROR, "ERROR: '%s' isn't a file!", path); + return false; + } + + /* Get number of sectors */ + if (newdiskdlg[DLGNEWDISK_SECTORS36].state & SG_SELECTED) + nSectors = 36; + else if (newdiskdlg[DLGNEWDISK_SECTORS18].state & SG_SELECTED) + nSectors = 18; + else if (newdiskdlg[DLGNEWDISK_SECTORS11].state & SG_SELECTED) + nSectors = 11; + else if (newdiskdlg[DLGNEWDISK_SECTORS10].state & SG_SELECTED) + nSectors = 10; + else + nSectors = 9; + + /* Get number of sides */ + if (newdiskdlg[DLGNEWDISK_SIDES1].state & SG_SELECTED) + nSides = 1; + else + nSides = 2; + + return CreateBlankImage_CreateFile(path, nTracks, nSectors, nSides); +} + + +/*-----------------------------------------------------------------------*/ +/** + * Show and process the "new blank disk image" dialog. + * Return file name of last created diskimage or NULL if none created. + * Caller needs to free the name. + */ +char *DlgNewDisk_Main(void) { int but; - char *szNewDiskName, *tmpname; + char *szNewDiskName, *tmpname, *retname = NULL; sprintf(szTracks, "%i", nTracks); SDLGui_CenterDlg(newdiskdlg); @@ -66,7 +111,7 @@ void DlgNewDisk_Main(void) /* Initialize disk image name: */ szNewDiskName = File_MakePath(ConfigureParams.DiskImage.szDiskImageDirectory, "new_disk.st", NULL); if (!szNewDiskName) - return; + return NULL; /* Draw and process the dialog */ do @@ -85,31 +130,17 @@ void DlgNewDisk_Main(void) sprintf(szTracks, "%i", nTracks); break; case DLGNEWDISK_SAVE: - tmpname = SDLGui_FileSelect(szNewDiskName, NULL, TRUE); + tmpname = SDLGui_FileSelect(szNewDiskName, NULL, true); if (tmpname) { - /* (potentially non-existing) filename? */ - if (!File_DirExists(tmpname)) + if (DlgNewDisk_CreateDisk(tmpname)) { - int nSectors, nSides; - - /* Get number of sectors */ - if (newdiskdlg[DLGNEWDISK_SECTORS11].state & SG_SELECTED) - nSectors = 11; - else if (newdiskdlg[DLGNEWDISK_SECTORS10].state & SG_SELECTED) - nSectors = 10; - else - nSectors = 9; - - /* Get number of sides */ - if (newdiskdlg[DLGNEWDISK_SIDES1].state & SG_SELECTED) - nSides = 1; - else - nSides = 2; - - CreateBlankImage_CreateFile(tmpname, nTracks, nSectors, nSides); + if (retname) + free(retname); + retname = tmpname; } - free(tmpname); + else + free(tmpname); } break; } @@ -118,4 +149,5 @@ void DlgNewDisk_Main(void) && but != SDLGUI_ERROR && !bQuitProgram); free(szNewDiskName); + return retname; }