Check for SYS/GL during library init. Reason is that
[AROS.git] / workbench / devs / diskimage / zune_gui / driveops.c
blobafd7a30e505e42b28d157b6ba1d271c90cefa8c8
1 /* Copyright 2007-2012 Fredrik Wikstrom. All rights reserved.
2 **
3 ** Redistribution and use in source and binary forms, with or without
4 ** modification, are permitted provided that the following conditions
5 ** are met:
6 **
7 ** 1. Redistributions of source code must retain the above copyright
8 ** notice, this list of conditions and the following disclaimer.
9 **
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>
33 #include <SDI_hook.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) {
48 struct DriveEntry *e;
49 DoMethod(Gui.gad[GID_DRIVELIST], MUIM_List_GetEntry, MUIV_List_GetEntry_Active, &e);
50 if (e) {
51 SetWindowBusy(~0, TRUE);
52 if (MUI_AslRequest(FileReq, NULL)) {
53 STRPTR filename;
54 filename = CombinePaths(FileReq->fr_Drawer, FileReq->fr_File);
55 if (filename) {
56 LONG error = NO_ERROR;
57 TEXT error_buffer[256];
58 LONG msge;
59 FreeVec(e->diskimage);
60 e->diskimage = NULL;
61 error_buffer[0] = 0;
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,
69 TAG_END);
70 FreeVec(filename);
71 if (error_buffer[0]) {
72 ErrorStringRequester(error_buffer);
73 } else {
74 IoErrRequester(error ? error : msge);
76 DoMethod(Gui.gad[GID_DRIVELIST], MUIM_List_Redraw, e->list_pos);
79 SetWindowBusy(~0, FALSE);
81 return 0;
84 HOOKPROTO(EjectFunc, IPTR, Object *app, IPTR *params) {
85 struct DriveEntry *e;
86 DoMethod(Gui.gad[GID_DRIVELIST], MUIM_List_GetEntry, MUIV_List_GetEntry_Active, &e);
87 if (e) {
88 FreeVec(e->diskimage);
89 e->diskimage = NULL;
90 UnitControl(e->unit_num,
91 DITAG_Filename, (IPTR)NULL,
92 DITAG_GetImageName, (IPTR)&e->diskimage,
93 TAG_END);
94 DoMethod(Gui.gad[GID_DRIVELIST], MUIM_List_Redraw, e->list_pos);
96 return 0;
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);
102 if (e) {
103 UnitControl(e->unit_num,
104 DITAG_WriteProtect, !e->writeprotect,
105 DITAG_GetWriteProtect, (IPTR)&e->writeprotect,
106 TAG_END);
107 DoMethod(Gui.gad[GID_DRIVELIST], MUIM_List_Redraw, e->list_pos);
109 return 0;
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);
115 if (e) {
116 LONG active;
117 ULONG sigs;
118 SetWindowBusy(~0, TRUE);
119 switch (e->device_type) {
120 case DG_CDROM:
121 active = 1;
122 break;
123 default:
124 active = 0;
125 break;
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);
132 if (sigs) {
133 sigs |= (1UL << DiskChangeSignal);
134 sigs = Wait(sigs|SIGBREAKF_CTRL_C);
135 if (sigs & SIGBREAKF_CTRL_C) {
136 break;
138 if (sigs & (1UL << DiskChangeSignal)) {
139 ScanUnits();
143 SetWindowBusy(~0, FALSE);
145 return 0;
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);
151 switch (active) {
152 case 1:
153 e->device_type = DG_CDROM;
154 break;
155 default:
156 e->device_type = DG_DIRECT_ACCESS;
157 break;
159 UnitControl(e->unit_num,
160 DITAG_SetDeviceType, e->device_type,
161 DITAG_GetDeviceType, (IPTR)&e->device_type,
162 TAG_END);
163 DoMethod(Gui.gad[GID_DRIVELIST], MUIM_List_Redraw, e->list_pos);
164 set(Gui.wnd[WID_SETDEVICETYPE], MUIA_Window_Open, FALSE);
165 return 0;