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