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/dos.h>
30 #include <proto/intuition.h>
31 #include <proto/asl.h>
32 #include <proto/diskimage.h>
34 void InsertOrEjectDisk (void) {
38 unit_num
= GetSelectedUnit();
43 disk_type
= DITYPE_NONE
;
45 DITAG_DiskImageType
, &disk_type
,
47 if (disk_type
== DITYPE_NONE
) {
54 void InsertDisk (void) {
55 struct Window
*window
;
61 GetAttr(WINDOW_Window
, Gui
.windows
[WID_MAIN
], (Tag
*)&window
);
62 listbrowser
= Gui
.gadgets
[GID_DRIVELIST
];
65 GetAttr(LISTBROWSER_SelectedNode
, Gui
.gadgets
[GID_DRIVELIST
], (Tag
*)&node
);
66 unit_num
= GetUnitNumber(node
);
72 SetWindowBusy(~0, TRUE
);
74 if (AslRequestTags(FileReq
,
75 ASLFR_Screen
, Gui
.screen
,
79 filename
= CombinePaths(FileReq
->fr_Drawer
, FileReq
->fr_File
);
81 ULONG disk_type
= DITYPE_NONE
;
82 LONG error
= NO_ERROR
;
83 TEXT error_buffer
[256];
87 DITAG_DiskImageType
, &disk_type
,
90 if (disk_type
!= DITYPE_NONE
) {
92 disk_type
= DITYPE_NONE
;
96 msge
= UnitControl(unit_num
,
98 DITAG_ErrorString
, error_buffer
,
99 DITAG_ErrorStringLength
, sizeof(error_buffer
),
100 DITAG_Plugin
, GetSelectedPlugin(),
101 DITAG_CurrentDir
, GetCurrentDir(),
102 DITAG_Filename
, filename
,
103 DITAG_DiskImageType
, &disk_type
,
106 if (error_buffer
[0]) {
107 ErrorStringRequester(error_buffer
);
109 IoErrRequester(error
? error
: msge
);
112 SetAttrs(listbrowser
,
113 LISTBROWSER_Labels
, ~0,
116 SetListBrowserNodeAttrs(node
,
117 LBNA_Column
, DRIVE_COL_DISKIMAGE
,
118 LBNCA_CopyText
, disk_type
? TRUE
: FALSE
,
119 LBNCA_Text
, disk_type
? FilePart(filename
) : GetString(&LocaleInfo
, MSG_NO_DISK
),
122 SetGadgetAttrs(GA(listbrowser
), window
, NULL
,
123 LISTBROWSER_Labels
, Gui
.lists
[LID_DRIVELIST
],
132 SetWindowBusy(~0, FALSE
);
136 void EjectDisk (void) {
137 struct Window
*window
;
144 GetAttr(WINDOW_Window
, Gui
.windows
[WID_MAIN
], (Tag
*)&window
);
145 listbrowser
= Gui
.gadgets
[GID_DRIVELIST
];
148 GetAttr(LISTBROWSER_SelectedNode
, Gui
.gadgets
[GID_DRIVELIST
], (Tag
*)&node
);
149 unit_num
= GetUnitNumber(node
);
150 if (unit_num
== -1) {
154 disk_type
= DITYPE_NONE
;
155 UnitControl(unit_num
,
156 DITAG_Filename
, NULL
,
157 DITAG_DiskImageType
, &disk_type
,
159 if (disk_type
== DITYPE_NONE
) {
160 SetAttrs(listbrowser
,
161 LISTBROWSER_Labels
, ~0,
164 SetListBrowserNodeAttrs(node
,
165 LBNA_Column
, DRIVE_COL_DISKIMAGE
,
166 LBNCA_Text
, GetString(&LocaleInfo
, MSG_NO_DISK
),
169 SetGadgetAttrs(GA(listbrowser
), window
, NULL
,
170 LISTBROWSER_Labels
, Gui
.lists
[LID_DRIVELIST
],
177 void ToggleWriteProtect (void) {
178 struct Window
*window
;
186 GetAttr(WINDOW_Window
, Gui
.windows
[WID_MAIN
], (Tag
*)&window
);
187 listbrowser
= Gui
.gadgets
[GID_DRIVELIST
];
190 GetAttr(LISTBROWSER_SelectedNode
, listbrowser
, (Tag
*)&node
);
191 unit_num
= GetUnitNumber(node
);
192 if (unit_num
== -1) {
197 writeprotect
= FALSE
;
198 GetListBrowserNodeAttrs(node
,
199 LBNA_Column
, DRIVE_COL_WP
,
202 UnitControl(unit_num
,
203 DITAG_WriteProtect
, !image
,
204 DITAG_GetWriteProtect
, &writeprotect
,
206 if (writeprotect
== !image
) {
207 SetAttrs(listbrowser
,
208 LISTBROWSER_Labels
, ~0,
211 SetListBrowserNodeAttrs(node
,
212 LBNA_Column
, DRIVE_COL_WP
,
213 LBNCA_Image
, writeprotect
? Gui
.images
[IID_LIST_WRITEPROTECTED
] : NULL
,
216 SetGadgetAttrs(GA(listbrowser
), window
, NULL
,
217 LISTBROWSER_Labels
, Gui
.lists
[LID_DRIVELIST
],