|
|
1.1 root 1: /*
2: Hatari - dlgDisk.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 DlgDisk_rcsid[] = "Hatari $Id: dlgDisk.c,v 1.2 2008/03/18 00:56:32 thothy Exp $";
1.1 root 8:
9: #include <assert.h>
10: #include "main.h"
11: #include "configuration.h"
12: #include "dialog.h"
13: #include "sdlgui.h"
14: #include "file.h"
15: #include "floppy.h"
16:
17:
18: #define DISKDLG_EJECTA 4
19: #define DISKDLG_BROWSEA 5
20: #define DISKDLG_DISKA 6
21: #define DISKDLG_EJECTB 8
22: #define DISKDLG_BROWSEB 9
23: #define DISKDLG_DISKB 10
24: #define DISKDLG_IMGDIR 12
25: #define DISKDLG_BROWSEIMG 13
26: #define DISKDLG_AUTOB 14
27: #define DISKDLG_CREATEIMG 15
28: #define DISKDLG_PROTOFF 17
29: #define DISKDLG_PROTON 18
30: #define DISKDLG_PROTAUTO 19
31: #define DISKDLG_EJECTHDIMG 23
32: #define DISKDLG_BROWSEHDIMG 24
33: #define DISKDLG_DISKHDIMG 25
34: #define DISKDLG_UNMOUNTGDOS 27
35: #define DISKDLG_BROWSEGDOS 28
36: #define DISKDLG_DISKGDOS 29
37: #define DISKDLG_BOOTHD 30
38: #define DISKDLG_EXIT 31
39:
40:
41: /* The disks dialog: */
42: static SGOBJ diskdlg[] =
43: {
44: { SGBOX, 0, 0, 0,0, 64,25, NULL },
45:
46: { SGBOX, 0, 0, 1,1, 62,12, NULL },
47: { SGTEXT, 0, 0, 25,1, 12,1, "Floppy disks" },
48: { SGTEXT, 0, 0, 2,2, 8,1, "Drive A:" },
49: { SGBUTTON, 0, 0, 46,2, 7,1, "Eject" },
50: { SGBUTTON, 0, 0, 54,2, 8,1, "Browse" },
51: { SGTEXT, 0, 0, 3,3, 58,1, NULL },
52: { SGTEXT, 0, 0, 2,4, 8,1, "Drive B:" },
53: { SGBUTTON, 0, 0, 46,4, 7,1, "Eject" },
54: { SGBUTTON, 0, 0, 54,4, 8,1, "Browse" },
55: { SGTEXT, 0, 0, 3,5, 58,1, NULL },
56: { SGTEXT, 0, 0, 2,7, 32,1, "Default floppy images directory:" },
57: { SGTEXT, 0, 0, 3,8, 58,1, NULL },
58: { SGBUTTON, 0, 0, 54,7, 8,1, "Browse" },
59: { SGCHECKBOX, 0, 0, 2,10, 16,1, "Auto insert B" },
60: { SGBUTTON, 0, 0, 42,10, 20,1, "Create blank image" },
61: { SGTEXT, 0, 0, 2,12, 17,1, "Write protection:" },
62: { SGRADIOBUT, 0, 0, 21,12, 5,1, "Off" },
63: { SGRADIOBUT, 0, 0, 28,12, 5,1, "On" },
64: { SGRADIOBUT, 0, 0, 34,12, 6,1, "Auto" },
65:
66: { SGBOX, 0, 0, 1,14, 62,8, NULL },
67: { SGTEXT, 0, 0, 27,14, 10,1, "Hard disks" },
68: { SGTEXT, 0, 0, 2,15, 9,1, "HD image:" },
69: { SGBUTTON, 0, 0, 46,15, 7,1, "Eject" },
70: { SGBUTTON, 0, 0, 54,15, 8,1, "Browse" },
71: { SGTEXT, 0, 0, 3,16, 58,1, NULL },
72: { SGTEXT, 0, 0, 2,17, 13,1, "GEMDOS drive:" },
73: { SGBUTTON, 0, 0, 46,17, 7,1, "Eject" },
74: { SGBUTTON, 0, 0, 54,17, 8,1, "Browse" },
75: { SGTEXT, 0, 0, 3,18, 58,1, NULL },
76: { SGCHECKBOX, 0, 0, 2,20, 14,1, "Boot from HD" },
77:
78: { SGBUTTON, SG_DEFAULT, 0, 22,23, 20,1, "Back to main menu" },
79: { -1, 0, 0, 0,0, 0,0, NULL }
80: };
81:
82:
83: /**
84: * Let user browse given disk, insert disk if one selected.
85: * return FALSE if no disk selected, otherwise return TRUE.
86: */
87: static BOOL DlgDisk_BrowseDisk(char *dlgname, int drive, int diskid)
88: {
89: char *selname, *zip_path;
90: const char *tmpname;
91:
92: assert(drive >= 0 && drive < 2);
93: if (EmulationDrives[drive].bDiskInserted)
94: tmpname = EmulationDrives[drive].szFileName;
95: else
96: tmpname = DialogParams.DiskImage.szDiskImageDirectory;
97:
98: selname = SDLGui_FileSelect(tmpname, &zip_path, FALSE);
99: if (selname)
100: {
101: if (!File_DoesFileNameEndWithSlash(selname) && File_Exists(selname))
102: {
103: char *realname;
104: /* FIXME: This shouldn't be done here but in Dialog_CopyDialogParamsToConfiguration */
105: realname = Floppy_ZipInsertDiskIntoDrive(drive, selname, zip_path);
106: /* TODO: error dialog when this fails */
107: if (realname)
108: {
109: File_ShrinkName(dlgname, realname, diskdlg[diskid].w);
110: free(realname);
111: }
112: if (zip_path)
113: free(zip_path);
114: }
115: else
116: {
117: /* FIXME: This shouldn't be done here but in Dialog_CopyDialogParamsToConfiguration */
118: Floppy_EjectDiskFromDrive(0, FALSE);
119: dlgname[0] = 0;
120: }
121: free(selname);
122: return TRUE;
123: }
124: return FALSE;
125: }
126:
127:
128: /**
129: * Let user browse given directory, set directory if one selected.
130: * return FALSE if none selected, otherwise return TRUE.
131: */
132: static BOOL DlgDisk_BrowseDir(char *dlgname, char *confname, int maxlen)
133: {
134: char *str, *selname;
135:
136: selname = SDLGui_FileSelect(confname, NULL, FALSE);
137: if (selname)
138: {
139: strcpy(confname, selname);
140: free(selname);
141:
1.1.1.2 ! root 142: str = strrchr(confname, PATHSEP);
1.1 root 143: if (str != NULL)
144: str[1] = 0;
145: File_CleanFileName(confname);
146: File_ShrinkName(dlgname, confname, maxlen);
147: return TRUE;
148: }
149: return FALSE;
150: }
151:
152: /*-----------------------------------------------------------------------*/
153: /*
154: Show and process the disk image dialog.
155: */
156: void Dialog_DiskDlg(void)
157: {
158: int but, i;
159: char dlgnamea[64], dlgnameb[64], dlgdiskdir[64];
160: char dlgnamegdos[64], dlgnamehdimg[64];
161:
162: SDLGui_CenterDlg(diskdlg);
163:
164: /* Set up dialog to actual values: */
165:
166: /* Disk name A: */
167: if (EmulationDrives[0].bDiskInserted)
168: File_ShrinkName(dlgnamea, EmulationDrives[0].szFileName,
169: diskdlg[DISKDLG_DISKA].w);
170: else
171: dlgnamea[0] = 0;
172: diskdlg[DISKDLG_DISKA].txt = dlgnamea;
173:
174: /* Disk name B: */
175: if (EmulationDrives[1].bDiskInserted)
176: File_ShrinkName(dlgnameb, EmulationDrives[1].szFileName,
177: diskdlg[DISKDLG_DISKB].w);
178: else
179: dlgnameb[0] = 0;
180: diskdlg[DISKDLG_DISKB].txt = dlgnameb;
181:
182: /* Default image directory: */
183: File_ShrinkName(dlgdiskdir, DialogParams.DiskImage.szDiskImageDirectory,
184: diskdlg[DISKDLG_IMGDIR].w);
185: diskdlg[DISKDLG_IMGDIR].txt = dlgdiskdir;
186:
187: /* Auto insert disk B: */
188: if (DialogParams.DiskImage.bAutoInsertDiskB)
189: diskdlg[DISKDLG_AUTOB].state |= SG_SELECTED;
190: else
191: diskdlg[DISKDLG_AUTOB].state &= ~SG_SELECTED;
192:
193: /* Write protection */
194: for (i = DISKDLG_PROTOFF; i <= DISKDLG_PROTAUTO; i++)
195: {
196: diskdlg[i].state &= ~SG_SELECTED;
197: }
198: diskdlg[DISKDLG_PROTOFF+DialogParams.DiskImage.nWriteProtection].state |= SG_SELECTED;
199:
200: /* Boot from harddisk? */
201: if (DialogParams.HardDisk.bBootFromHardDisk)
202: diskdlg[DISKDLG_BOOTHD].state |= SG_SELECTED;
203: else
204: diskdlg[DISKDLG_BOOTHD].state &= ~SG_SELECTED;
205:
206: /* GEMDOS hard disk directory: */
207: if (DialogParams.HardDisk.bUseHardDiskDirectories)
208: File_ShrinkName(dlgnamegdos, DialogParams.HardDisk.szHardDiskDirectories[0],
209: diskdlg[DISKDLG_DISKGDOS].w);
210: else
211: dlgnamegdos[0] = 0;
212: diskdlg[DISKDLG_DISKGDOS].txt = dlgnamegdos;
213:
214: /* Hard disk image: */
215: if (DialogParams.HardDisk.bUseHardDiskImage)
216: File_ShrinkName(dlgnamehdimg, DialogParams.HardDisk.szHardDiskImage,
217: diskdlg[DISKDLG_DISKHDIMG].w);
218: else
219: dlgnamehdimg[0] = 0;
220: diskdlg[DISKDLG_DISKHDIMG].txt = dlgnamehdimg;
221:
222: /* Draw and process the dialog */
223: do
224: {
225: but = SDLGui_DoDialog(diskdlg, NULL);
226: switch (but)
227: {
228: case DISKDLG_EJECTA: /* Eject disk in drive A: */
229: Floppy_EjectDiskFromDrive(0, FALSE);
230: dlgnamea[0] = 0;
231: break;
232: case DISKDLG_BROWSEA: /* Choose a new disk A: */
233: DlgDisk_BrowseDisk(dlgnamea, 0, DISKDLG_DISKA);
234: break;
235: case DISKDLG_EJECTB: /* Eject disk in drive B: */
236: Floppy_EjectDiskFromDrive(1, FALSE);
237: dlgnameb[0] = 0;
238: break;
239: case DISKDLG_BROWSEB: /* Choose a new disk B: */
240: DlgDisk_BrowseDisk(dlgnameb, 1, DISKDLG_DISKB);
241: break;
242: case DISKDLG_BROWSEIMG:
243: DlgDisk_BrowseDir(dlgdiskdir,
244: DialogParams.DiskImage.szDiskImageDirectory,
245: diskdlg[DISKDLG_IMGDIR].w);
246: break;
247: case DISKDLG_CREATEIMG:
248: DlgNewDisk_Main();
249: break;
250: case DISKDLG_UNMOUNTGDOS:
251: DialogParams.HardDisk.bUseHardDiskDirectories = FALSE;
252: dlgnamegdos[0] = 0;
253: break;
254: case DISKDLG_BROWSEGDOS:
255: if (DlgDisk_BrowseDir(dlgnamegdos,
256: DialogParams.HardDisk.szHardDiskDirectories[0],
257: diskdlg[DISKDLG_DISKGDOS].w))
258: DialogParams.HardDisk.bUseHardDiskDirectories = TRUE;
259: break;
260: case DISKDLG_EJECTHDIMG:
261: DialogParams.HardDisk.bUseHardDiskImage = FALSE;
262: dlgnamehdimg[0] = 0;
263: break;
264: case DISKDLG_BROWSEHDIMG:
265: if (SDLGui_FileConfSelect(dlgnamehdimg,
266: DialogParams.HardDisk.szHardDiskImage,
267: diskdlg[DISKDLG_DISKHDIMG].w, FALSE))
268: DialogParams.HardDisk.bUseHardDiskImage = TRUE;
269: break;
270: }
271: }
272: while (but != DISKDLG_EXIT && but != SDLGUI_QUIT
273: && but != SDLGUI_ERROR && !bQuitProgram);
274:
275: /* Read values from dialog: */
276:
277: for (i = DISKDLG_PROTOFF; i <= DISKDLG_PROTAUTO; i++)
278: {
279: if (diskdlg[i].state & SG_SELECTED)
280: {
281: DialogParams.DiskImage.nWriteProtection = i-DISKDLG_PROTOFF;
282: break;
283: }
284: }
285:
286: DialogParams.DiskImage.bAutoInsertDiskB = (diskdlg[DISKDLG_AUTOB].state & SG_SELECTED);
287: DialogParams.HardDisk.bBootFromHardDisk = (diskdlg[DISKDLG_BOOTHD].state & SG_SELECTED);
288: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.