1 /* Copyright 2007-2012 Fredrik Wikstrom. All rights reserved.
3 ** Redistribution and use in source and binary forms, with or without
4 ** modification, are permitted provided that the following conditions
7 ** 1. Redistributions of source code must retain the above copyright
8 ** notice, this list of conditions and the following disclaimer.
10 ** 2. Redistributions in binary form must reproduce the above copyright
11 ** notice, this list of conditions and the following disclaimer in the
12 ** documentation and/or other materials provided with the distribution.
14 ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
15 ** AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 ** IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 ** ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
18 ** LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
19 ** CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
20 ** SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
21 ** INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
22 ** CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
23 ** ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
24 ** POSSIBILITY OF SUCH DAMAGE.
27 #include "diskimagegui.h"
28 #include <proto/exec.h>
29 #include <proto/intuition.h>
30 #include <proto/muimaster.h>
31 #include <proto/diskimage.h>
32 #include <clib/alib_protos.h>
35 HOOKPROTO(InsertFunc
, IPTR
, Object
*app
, IPTR
*params
);
36 MakeHook(InsertHook
, InsertFunc
);
37 HOOKPROTO(EjectFunc
, IPTR
, Object
*app
, IPTR
*params
);
38 MakeHook(EjectHook
, EjectFunc
);
39 HOOKPROTO(WriteProtectFunc
, IPTR
, Object
*app
, IPTR
*params
);
40 MakeHook(WriteProtectHook
, WriteProtectFunc
);
41 HOOKPROTO(SetDeviceTypeFunc
, IPTR
, Object
*app
, IPTR
*params
);
42 MakeHook(SetDeviceTypeHook
, SetDeviceTypeFunc
);
43 HOOKPROTO(DoSetDeviceTypeFunc
, IPTR
, Object
*app
, IPTR
*params
);
44 MakeHook(DoSetDeviceTypeHook
, DoSetDeviceTypeFunc
);
47 HOOKPROTO(InsertFunc
, IPTR
, Object
*app
, IPTR
*params
) {
49 DoMethod(Gui
.gad
[GID_DRIVELIST
], MUIM_List_GetEntry
, MUIV_List_GetEntry_Active
, &e
);
51 SetWindowBusy(~0, TRUE
);
52 if (MUI_AslRequest(FileReq
, NULL
)) {
54 filename
= CombinePaths(FileReq
->fr_Drawer
, FileReq
->fr_File
);
56 LONG error
= NO_ERROR
;
57 TEXT error_buffer
[256];
59 FreeVec(e
->diskimage
);
62 msge
= UnitControl(e
->unit_num
,
63 DITAG_Error
, (IPTR
)&error
,
64 DITAG_ErrorString
, (IPTR
)error_buffer
,
65 DITAG_ErrorStringLength
, sizeof(error_buffer
),
66 DITAG_CurrentDir
, (IPTR
)GetCurrentDir(),
67 DITAG_Filename
, (IPTR
)filename
,
68 DITAG_GetImageName
, (IPTR
)&e
->diskimage
,
71 if (error_buffer
[0]) {
72 ErrorStringRequester(error_buffer
);
74 IoErrRequester(error
? error
: msge
);
76 DoMethod(Gui
.gad
[GID_DRIVELIST
], MUIM_List_Redraw
, e
->list_pos
);
79 SetWindowBusy(~0, FALSE
);
84 HOOKPROTO(EjectFunc
, IPTR
, Object
*app
, IPTR
*params
) {
86 DoMethod(Gui
.gad
[GID_DRIVELIST
], MUIM_List_GetEntry
, MUIV_List_GetEntry_Active
, &e
);
88 FreeVec(e
->diskimage
);
90 UnitControl(e
->unit_num
,
91 DITAG_Filename
, (IPTR
)NULL
,
92 DITAG_GetImageName
, (IPTR
)&e
->diskimage
,
94 DoMethod(Gui
.gad
[GID_DRIVELIST
], MUIM_List_Redraw
, e
->list_pos
);
99 HOOKPROTO(WriteProtectFunc
, IPTR
, Object
*app
, IPTR
*params
) {
100 struct DriveEntry
*e
;
101 DoMethod(Gui
.gad
[GID_DRIVELIST
], MUIM_List_GetEntry
, MUIV_List_GetEntry_Active
, &e
);
103 UnitControl(e
->unit_num
,
104 DITAG_WriteProtect
, !e
->writeprotect
,
105 DITAG_GetWriteProtect
, (IPTR
)&e
->writeprotect
,
107 DoMethod(Gui
.gad
[GID_DRIVELIST
], MUIM_List_Redraw
, e
->list_pos
);
112 HOOKPROTO(SetDeviceTypeFunc
, IPTR
, Object
*app
, IPTR
*params
) {
113 struct DriveEntry
*e
;
114 DoMethod(Gui
.gad
[GID_DRIVELIST
], MUIM_List_GetEntry
, MUIV_List_GetEntry_Active
, &e
);
118 SetWindowBusy(~0, TRUE
);
119 switch (e
->device_type
) {
127 DoSetDeviceTypeHook
.h_Data
= e
;
128 set(Gui
.gad
[GID_DEVICETYPE
], MUIA_Cycle_Active
, active
);
129 set(Gui
.wnd
[WID_SETDEVICETYPE
], MUIA_Window_Open
, TRUE
);
130 while (XGET(Gui
.wnd
[WID_SETDEVICETYPE
], MUIA_Window_Open
)) {
131 DoMethod(Gui
.app
, MUIM_Application_NewInput
, (IPTR
)&sigs
);
133 sigs
|= (1UL << DiskChangeSignal
);
134 sigs
= Wait(sigs
|SIGBREAKF_CTRL_C
);
135 if (sigs
& SIGBREAKF_CTRL_C
) {
138 if (sigs
& (1UL << DiskChangeSignal
)) {
143 SetWindowBusy(~0, FALSE
);
148 HOOKPROTO(DoSetDeviceTypeFunc
, IPTR
, Object
*app
, IPTR
*params
) {
149 struct DriveEntry
*e
= hook
->h_Data
;
150 LONG active
= XGET(Gui
.gad
[GID_DEVICETYPE
], MUIA_Cycle_Active
);
153 e
->device_type
= DG_CDROM
;
156 e
->device_type
= DG_DIRECT_ACCESS
;
159 UnitControl(e
->unit_num
,
160 DITAG_SetDeviceType
, e
->device_type
,
161 DITAG_GetDeviceType
, (IPTR
)&e
->device_type
,
163 DoMethod(Gui
.gad
[GID_DRIVELIST
], MUIM_List_Redraw
, e
->list_pos
);
164 set(Gui
.wnd
[WID_SETDEVICETYPE
], MUIA_Window_Open
, FALSE
);