|
|
1.1 root 1: /*
2: Hatari - dlgNewDisk.c
3:
1.1.1.7 root 4: This file is distributed under the GNU General Public License, version 2
5: or at your option any later version. Read the file gpl.txt for details.
1.1 root 6: */
1.1.1.4 root 7: const char DlgNewDisk_fileid[] = "Hatari dlgNewDisk.c : " __DATE__ " " __TIME__;
1.1 root 8:
9: #include "main.h"
10: #include "configuration.h"
11: #include "createBlankImage.h"
12: #include "dialog.h"
13: #include "sdlgui.h"
14: #include "file.h"
1.1.1.5 root 15: #include "log.h"
1.1 root 16:
17: #define DLGNEWDISK_DECTRACK 3
18: #define DLGNEWDISK_TRACKSTR 4
19: #define DLGNEWDISK_INCTRACK 5
20: #define DLGNEWDISK_SECTORS9 7
21: #define DLGNEWDISK_SECTORS10 8
22: #define DLGNEWDISK_SECTORS11 9
1.1.1.5 root 23: #define DLGNEWDISK_SECTORS18 10
24: #define DLGNEWDISK_SECTORS36 11
25: #define DLGNEWDISK_SIDES1 13
26: #define DLGNEWDISK_SIDES2 14
1.1.1.9 ! root 27: #define DLGNEWDISK_LABEL 16
! 28: #define DLGNEWDISK_SAVE 17
! 29: #define DLGNEWDISK_EXIT 18
1.1 root 30:
31: static char szTracks[3];
32: static int nTracks = 80;
33:
1.1.1.9 ! root 34: #define DLGNEWDISK_LABEL_SIZE (8+3)
! 35: static char dlgLabel[ DLGNEWDISK_LABEL_SIZE+1 ];
! 36:
1.1 root 37: /* The new disk image dialog: */
38: static SGOBJ newdiskdlg[] =
39: {
1.1.1.9 ! root 40: { SGBOX, 0, 0, 0,0, 29,16, NULL },
1.1 root 41: { SGTEXT, 0, 0, 6,1, 16,1, "New floppy image" },
42: { SGTEXT, 0, 0, 2,3, 7,1, "Tracks:" },
1.1.1.8 root 43: { SGBUTTON, 0, 0, 12,3, 1,1, "\x04", SG_SHORTCUT_LEFT },
1.1 root 44: { SGTEXT, 0, 0, 14,3, 2,1, szTracks },
1.1.1.8 root 45: { SGBUTTON, 0, 0, 17,3, 1,1, "\x03", SG_SHORTCUT_RIGHT },
1.1 root 46: { SGTEXT, 0, 0, 2,5, 8,1, "Sectors:" },
1.1.1.8 root 47: { SGRADIOBUT, 0, SG_SELECTED, 12,5, 4,1, " _9" },
48: { SGRADIOBUT, 0, 0, 17,5, 4,1, "1_0" },
1.1 root 49: { SGRADIOBUT, 0, 0, 22,5, 4,1, "11" },
1.1.1.8 root 50: { SGRADIOBUT, 0, 0, 12,6, 9,1, "1_8 (HD)" },
51: { SGRADIOBUT, 0, 0, 12,7, 9,1, "3_6 (ED)" },
1.1.1.5 root 52: { SGTEXT, 0, 0, 2,9, 6,1, "Sides:" },
1.1.1.8 root 53: { SGRADIOBUT, 0, 0, 12,9, 3,1, "_1" },
54: { SGRADIOBUT, 0, SG_SELECTED, 17,9, 3,1, "_2" },
1.1.1.9 ! root 55: { SGTEXT, 0, 0, 2,11, 6,1, "Label:" },
! 56: { SGEDITFIELD, 0, 0, 12,11, DLGNEWDISK_LABEL_SIZE,1, dlgLabel },
! 57: { SGBUTTON, SG_DEFAULT, 0, 4,14, 8,1, "_Create" },
! 58: { SGBUTTON, SG_CANCEL, 0, 18,14, 6,1, "_Back" },
! 59: { SGSTOP, 0, 0, 0,0, 0,0, NULL }
1.1 root 60: };
61:
62: #define DEFAULT_DISK_NAME "new_disk.st"
63:
1.1.1.5 root 64:
65: /*-----------------------------------------------------------------------*/
66: /**
67: * Handle creation of a the "new blank disk image".
68: * return true if disk created, false otherwise.
69: */
70: static bool DlgNewDisk_CreateDisk(const char *path)
71: {
72: int nSectors, nSides;
73:
74: /* (potentially non-existing) filename? */
75: if (File_DirExists(path))
76: {
77: Log_AlertDlg(LOG_ERROR, "ERROR: '%s' isn't a file!", path);
78: return false;
79: }
80:
81: /* Get number of sectors */
82: if (newdiskdlg[DLGNEWDISK_SECTORS36].state & SG_SELECTED)
83: nSectors = 36;
84: else if (newdiskdlg[DLGNEWDISK_SECTORS18].state & SG_SELECTED)
85: nSectors = 18;
86: else if (newdiskdlg[DLGNEWDISK_SECTORS11].state & SG_SELECTED)
87: nSectors = 11;
88: else if (newdiskdlg[DLGNEWDISK_SECTORS10].state & SG_SELECTED)
89: nSectors = 10;
90: else
91: nSectors = 9;
92:
93: /* Get number of sides */
94: if (newdiskdlg[DLGNEWDISK_SIDES1].state & SG_SELECTED)
95: nSides = 1;
96: else
97: nSides = 2;
98:
1.1.1.9 ! root 99: return CreateBlankImage_CreateFile(path, nTracks, nSectors, nSides, dlgLabel);
1.1.1.5 root 100: }
101:
102:
1.1 root 103: /*-----------------------------------------------------------------------*/
1.1.1.5 root 104: /**
105: * Show and process the "new blank disk image" dialog.
106: * Return file name of last created diskimage or NULL if none created.
107: * Caller needs to free the name.
108: */
109: char *DlgNewDisk_Main(void)
1.1 root 110: {
111: int but;
1.1.1.5 root 112: char *szNewDiskName, *tmpname, *retname = NULL;
1.1 root 113: sprintf(szTracks, "%i", nTracks);
114:
115: SDLGui_CenterDlg(newdiskdlg);
116:
117: /* Initialize disk image name: */
1.1.1.2 root 118: szNewDiskName = File_MakePath(ConfigureParams.DiskImage.szDiskImageDirectory, "new_disk.st", NULL);
1.1 root 119: if (!szNewDiskName)
1.1.1.5 root 120: return NULL;
1.1 root 121:
122: /* Draw and process the dialog */
123: do
124: {
1.1.1.8 root 125: but = SDLGui_DoDialog(newdiskdlg, NULL, false);
1.1 root 126: switch(but)
127: {
128: case DLGNEWDISK_DECTRACK:
129: if (nTracks > 40)
130: nTracks -= 1;
131: sprintf(szTracks, "%i", nTracks);
132: break;
133: case DLGNEWDISK_INCTRACK:
134: if (nTracks < 85)
135: nTracks += 1;
136: sprintf(szTracks, "%i", nTracks);
137: break;
138: case DLGNEWDISK_SAVE:
1.1.1.8 root 139: tmpname = SDLGui_FileSelect("New floppy image:", szNewDiskName, NULL, true);
1.1 root 140: if (tmpname)
141: {
1.1.1.5 root 142: if (DlgNewDisk_CreateDisk(tmpname))
1.1.1.6 root 143: {
1.1.1.9 ! root 144: free(retname);
1.1.1.5 root 145: retname = tmpname;
1.1.1.6 root 146: }
1.1.1.5 root 147: else
148: free(tmpname);
1.1 root 149: }
150: break;
151: }
152: }
153: while (but != DLGNEWDISK_EXIT && but != SDLGUI_QUIT
154: && but != SDLGUI_ERROR && !bQuitProgram);
155:
156: free(szNewDiskName);
1.1.1.5 root 157: return retname;
1.1 root 158: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.