|
|
1.1 root 1: /*
2: Hatari - dlgNewDisk.c
3:
4: This file is distributed under the GNU Public License, version 2 or at
5: your option any later version. Read the file gpl.txt for details.
6: */
1.1.1.2 ! root 7: const char DlgNewDisk_rcsid[] = "Hatari $Id: dlgNewDisk.c,v 1.3 2008/11/18 20:12:03 eerot Exp $";
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"
15:
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
23: #define DLGNEWDISK_SIDES1 11
24: #define DLGNEWDISK_SIDES2 12
25: #define DLGNEWDISK_SAVE 13
26: #define DLGNEWDISK_EXIT 14
27:
28: static char szTracks[3];
29: static int nTracks = 80;
30:
31: /* The new disk image dialog: */
32: static SGOBJ newdiskdlg[] =
33: {
34: { SGBOX, 0, 0, 0,0, 28,12, NULL },
35: { SGTEXT, 0, 0, 6,1, 16,1, "New floppy image" },
36: { SGTEXT, 0, 0, 2,3, 7,1, "Tracks:" },
37: { SGBUTTON, 0, 0, 12,3, 1,1, "\x04" }, /* Left-arrow button */
38: { SGTEXT, 0, 0, 14,3, 2,1, szTracks },
39: { SGBUTTON, 0, 0, 17,3, 1,1, "\x03" }, /* Right-arrow button */
40: { SGTEXT, 0, 0, 2,5, 8,1, "Sectors:" },
41: { SGRADIOBUT, 0, SG_SELECTED, 12,5, 4,1, "9" },
42: { SGRADIOBUT, 0, 0, 17,5, 4,1, "10" },
43: { SGRADIOBUT, 0, 0, 22,5, 4,1, "11" },
44: { SGTEXT, 0, 0, 2,7, 6,1, "Sides:" },
45: { SGRADIOBUT, 0, 0, 12,7, 4,1, "1" },
46: { SGRADIOBUT, 0, SG_SELECTED, 17,7, 4,1, "2" },
47: { SGBUTTON, 0, 0, 4,10, 8,1, "Create" },
48: { SGBUTTON, 0, 0, 18,10, 6,1, "Back" },
49: { -1, 0, 0, 0,0, 0,0, NULL }
50: };
51:
52: #define DEFAULT_DISK_NAME "new_disk.st"
53:
54: /*-----------------------------------------------------------------------*/
55: /*
56: Show and process the "new blank disk image" dialog.
57: */
58: void DlgNewDisk_Main(void)
59: {
60: int but;
61: char *szNewDiskName, *tmpname;
62: sprintf(szTracks, "%i", nTracks);
63:
64: SDLGui_CenterDlg(newdiskdlg);
65:
66: /* Initialize disk image name: */
1.1.1.2 ! root 67: szNewDiskName = File_MakePath(ConfigureParams.DiskImage.szDiskImageDirectory, "new_disk.st", NULL);
1.1 root 68: if (!szNewDiskName)
69: return;
70:
71: /* Draw and process the dialog */
72: do
73: {
74: but = SDLGui_DoDialog(newdiskdlg, NULL);
75: switch(but)
76: {
77: case DLGNEWDISK_DECTRACK:
78: if (nTracks > 40)
79: nTracks -= 1;
80: sprintf(szTracks, "%i", nTracks);
81: break;
82: case DLGNEWDISK_INCTRACK:
83: if (nTracks < 85)
84: nTracks += 1;
85: sprintf(szTracks, "%i", nTracks);
86: break;
87: case DLGNEWDISK_SAVE:
88: tmpname = SDLGui_FileSelect(szNewDiskName, NULL, TRUE);
89: if (tmpname)
90: {
1.1.1.2 ! root 91: /* (potentially non-existing) filename? */
! 92: if (!File_DirExists(tmpname))
1.1 root 93: {
94: int nSectors, nSides;
95:
96: /* Get number of sectors */
97: if (newdiskdlg[DLGNEWDISK_SECTORS11].state & SG_SELECTED)
98: nSectors = 11;
99: else if (newdiskdlg[DLGNEWDISK_SECTORS10].state & SG_SELECTED)
100: nSectors = 10;
101: else
102: nSectors = 9;
103:
104: /* Get number of sides */
105: if (newdiskdlg[DLGNEWDISK_SIDES1].state & SG_SELECTED)
106: nSides = 1;
107: else
108: nSides = 2;
109:
110: CreateBlankImage_CreateFile(tmpname, nTracks, nSectors, nSides);
111: }
112: free(tmpname);
113: }
114: break;
115: }
116: }
117: while (but != DLGNEWDISK_EXIT && but != SDLGUI_QUIT
118: && but != SDLGUI_ERROR && !bQuitProgram);
119:
120: free(szNewDiskName);
121: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.