Were did that svn:executable come from?
[AROS.git] / workbench / devs / diskimage / ra_gui / driveops.c
blobf76c7d5781d4f8fbfd6525ad32cb03cb3d66409d
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/dos.h>
30 #include <proto/intuition.h>
31 #include <proto/asl.h>
32 #include <proto/diskimage.h>
34 void InsertOrEjectDisk (void) {
35 LONG unit_num;
36 ULONG disk_type;
38 unit_num = GetSelectedUnit();
39 if (unit_num == -1) {
40 return;
43 disk_type = DITYPE_NONE;
44 UnitControl(unit_num,
45 DITAG_DiskImageType, &disk_type,
46 TAG_END);
47 if (disk_type == DITYPE_NONE) {
48 InsertDisk();
49 } else {
50 EjectDisk();
54 void InsertDisk (void) {
55 struct Window *window;
56 Object *listbrowser;
57 struct Node *node;
58 LONG unit_num;
60 window = NULL;
61 GetAttr(WINDOW_Window, Gui.windows[WID_MAIN], (Tag *)&window);
62 listbrowser = Gui.gadgets[GID_DRIVELIST];
64 node = NULL;
65 GetAttr(LISTBROWSER_SelectedNode, Gui.gadgets[GID_DRIVELIST], (Tag *)&node);
66 unit_num = GetUnitNumber(node);
67 if (unit_num == -1) {
68 return;
71 StopScreenNotify();
72 SetWindowBusy(~0, TRUE);
74 if (AslRequestTags(FileReq,
75 ASLFR_Screen, Gui.screen,
76 TAG_END))
78 STRPTR filename;
79 filename = CombinePaths(FileReq->fr_Drawer, FileReq->fr_File);
80 if (filename) {
81 ULONG disk_type = DITYPE_NONE;
82 LONG error = NO_ERROR;
83 TEXT error_buffer[256];
84 LONG msge;
86 UnitControl(unit_num,
87 DITAG_DiskImageType, &disk_type,
88 DITAG_Filename, NULL,
89 TAG_END);
90 if (disk_type != DITYPE_NONE) {
91 Delay(5);
92 disk_type = DITYPE_NONE;
95 error_buffer[0] = 0;
96 msge = UnitControl(unit_num,
97 DITAG_Error, &error,
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,
104 TAG_END);
106 if (error_buffer[0]) {
107 ErrorStringRequester(error_buffer);
108 } else {
109 IoErrRequester(error ? error : msge);
112 SetAttrs(listbrowser,
113 LISTBROWSER_Labels, ~0,
114 TAG_END);
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),
120 TAG_END);
122 SetGadgetAttrs(GA(listbrowser), window, NULL,
123 LISTBROWSER_Labels, Gui.lists[LID_DRIVELIST],
124 TAG_END);
126 FreeVec(filename);
128 UpdateSpeedBar();
132 SetWindowBusy(~0, FALSE);
133 BeginScreenNotify();
136 void EjectDisk (void) {
137 struct Window *window;
138 Object *listbrowser;
139 struct Node *node;
140 LONG unit_num;
141 ULONG disk_type;
143 window = NULL;
144 GetAttr(WINDOW_Window, Gui.windows[WID_MAIN], (Tag *)&window);
145 listbrowser = Gui.gadgets[GID_DRIVELIST];
147 node = NULL;
148 GetAttr(LISTBROWSER_SelectedNode, Gui.gadgets[GID_DRIVELIST], (Tag *)&node);
149 unit_num = GetUnitNumber(node);
150 if (unit_num == -1) {
151 return;
154 disk_type = DITYPE_NONE;
155 UnitControl(unit_num,
156 DITAG_Filename, NULL,
157 DITAG_DiskImageType, &disk_type,
158 TAG_END);
159 if (disk_type == DITYPE_NONE) {
160 SetAttrs(listbrowser,
161 LISTBROWSER_Labels, ~0,
162 TAG_END);
164 SetListBrowserNodeAttrs(node,
165 LBNA_Column, DRIVE_COL_DISKIMAGE,
166 LBNCA_Text, GetString(&LocaleInfo, MSG_NO_DISK),
167 TAG_END);
169 SetGadgetAttrs(GA(listbrowser), window, NULL,
170 LISTBROWSER_Labels, Gui.lists[LID_DRIVELIST],
171 TAG_END);
173 UpdateSpeedBar();
177 void ToggleWriteProtect (void) {
178 struct Window *window;
179 Object *listbrowser;
180 struct Node *node;
181 LONG unit_num;
182 Object *image;
183 BOOL writeprotect;
185 window = NULL;
186 GetAttr(WINDOW_Window, Gui.windows[WID_MAIN], (Tag *)&window);
187 listbrowser = Gui.gadgets[GID_DRIVELIST];
189 node = NULL;
190 GetAttr(LISTBROWSER_SelectedNode, listbrowser, (Tag *)&node);
191 unit_num = GetUnitNumber(node);
192 if (unit_num == -1) {
193 return;
196 image = NULL;
197 writeprotect = FALSE;
198 GetListBrowserNodeAttrs(node,
199 LBNA_Column, DRIVE_COL_WP,
200 LBNCA_Image, &image,
201 TAG_END);
202 UnitControl(unit_num,
203 DITAG_WriteProtect, !image,
204 DITAG_GetWriteProtect, &writeprotect,
205 TAG_END);
206 if (writeprotect == !image) {
207 SetAttrs(listbrowser,
208 LISTBROWSER_Labels, ~0,
209 TAG_END);
211 SetListBrowserNodeAttrs(node,
212 LBNA_Column, DRIVE_COL_WP,
213 LBNCA_Image, writeprotect ? Gui.images[IID_LIST_WRITEPROTECTED] : NULL,
214 TAG_END);
216 SetGadgetAttrs(GA(listbrowser), window, NULL,
217 LISTBROWSER_Labels, Gui.lists[LID_DRIVELIST],
218 TAG_END);