]> git.sesse.net Git - pistorm/blob - platforms/amiga/pistorm-dev/pistorm_dev_amiga/gui_interact.c
Add file retrieval to GUI
[pistorm] / platforms / amiga / pistorm-dev / pistorm_dev_amiga / gui_interact.c
1 // SPDX-License-Identifier: MIT
2
3 #include <proto/intuition.h>
4 #include <proto/dos.h>
5 #include <intuition/intuition.h>
6 #include <proto/exec.h>
7 #include <proto/dos.h>
8 #include <workbench/startup.h>
9 #include <clib/expansion_protos.h>
10 #include <libraries/reqtools.h>
11 #include <clib/reqtools_protos.h>
12
13 #include "pistorm_dev.h"
14 #include "../pistorm-dev-enums.h"
15
16 #include <stdio.h>
17 #include <string.h>
18 #include <stdlib.h>
19 extern unsigned int pistorm_base_addr;
20 struct ReqToolsBase *ReqToolsBase;
21
22 #define VERSION "v0.2"
23
24 #define button1w 54
25 #define button1h 20
26
27 #define button2w 87
28 #define button2h 20
29
30 #define button3w 100
31 #define button3h 20
32
33 #define tbox1w 130
34 #define tbox1h 18
35
36 #define statusbarw 507
37 #define statusbarh 10
38
39 SHORT SharedBordersPairs0[] =
40 {
41     0, 0, 0, button1h - 1, 1, button1h - 2, 1, 0, button1w - 2, 0
42 };
43 SHORT SharedBordersPairs1[] =
44 {
45     1, button1h - 1, button1w - 2, button1h - 1, button1w - 2, 1, button1w - 1, 0, button1w - 1, button1h - 1
46 };
47
48 SHORT SharedBordersPairs2[] =
49 {
50     0, 0, 0, button3h - 1, 1, button3h - 2, 1, 0, button3w - 2, 0
51 };
52 SHORT SharedBordersPairs3[] =
53 {
54     1, button3h - 1, button3w - 2, button3h - 1, button3w - 2, 1, button3w - 1, 0, button3w - 1, button3h - 1
55 };
56
57 SHORT SharedBordersPairs4[] =
58 {
59     0, 0, 0, button2h - 1, 1, button2h - 2, 1, 0, button2w - 2, 0
60 };
61 SHORT SharedBordersPairs5[] =
62 {
63     1, button2h - 1, button2w - 2, button2h - 1, button2w - 2, 1, button2w - 1, 0, button2w - 1, button2h - 1
64 };
65
66 SHORT SharedBordersPairs6[] =
67 {
68     -2, -1, -2, tbox1h - 1, -1, tbox1h - 2, -1, -1, tbox1w - 2, -1
69 };
70
71 SHORT SharedBordersPairs7[] =
72 {
73     -1, tbox1h - 1, tbox1w - 2, tbox1h - 1, tbox1w - 2, 0, tbox1w - 1, -1, tbox1w - 1, tbox1h - 1
74 };
75
76 SHORT SharedBordersPairs8[] =
77 {
78     0, 0, statusbarw - 2, 0, statusbarw - 2, 0, 0, 0, 0, 0
79 };
80
81 SHORT SharedBordersPairs9[] =
82 {
83     0, 0, 0, tbox1h - 1, 1, tbox1h - 2, 1, 0, tbox1w - 2, 0
84 };
85 SHORT SharedBordersPairs10[] =
86 {
87     1, tbox1h - 1, tbox1w - 2, tbox1h - 1, tbox1w - 2, 1, tbox1w - 1, 0, tbox1w - 1, tbox1h - 1
88 };
89
90
91 struct Border SharedBorders[] =
92 {
93     0, 0, 2, 0, JAM2, 5, (SHORT *) &SharedBordersPairs0[0], &SharedBorders[1], // Button 1
94     0, 0, 1, 0, JAM2, 5, (SHORT *) &SharedBordersPairs1[0], NULL,
95     0, 0, 2, 0, JAM2, 5, (SHORT *) &SharedBordersPairs2[0], &SharedBorders[3], // Button 3
96     0, 0, 1, 0, JAM2, 5, (SHORT *) &SharedBordersPairs3[0], NULL,
97     0, 0, 2, 0, JAM2, 5, (SHORT *) &SharedBordersPairs4[0], &SharedBorders[5], // Button 2
98     0, 0, 1, 0, JAM2, 5, (SHORT *) &SharedBordersPairs5[0], NULL,
99     0, 0, 1, 0, JAM2, 5, (SHORT *) &SharedBordersPairs6[0], &SharedBorders[7], // TBox
100     0, 0, 2, 0, JAM2, 5, (SHORT *) &SharedBordersPairs7[0], NULL,
101     0, 0, 1, 0, JAM2, 5, (SHORT *) &SharedBordersPairs8[0], NULL, // Statusbar
102     0, 0, 2, 0, JAM2, 5, (SHORT *) &SharedBordersPairs9[0], &SharedBorders[10], // TBox inverted
103     0, 0, 1, 0, JAM2, 5, (SHORT *) &SharedBordersPairs10[0], NULL,
104 };
105
106 struct Border SharedBordersInvert[] =
107 {
108     0, 0, 1, 0, JAM2, 5, (SHORT *) &SharedBordersPairs0[0], &SharedBordersInvert[1], // Button 1
109     0, 0, 2, 0, JAM2, 5, (SHORT *) &SharedBordersPairs1[0], NULL,
110     0, 0, 1, 0, JAM2, 5, (SHORT *) &SharedBordersPairs2[0], &SharedBordersInvert[3], // Button 3
111     0, 0, 2, 0, JAM2, 5, (SHORT *) &SharedBordersPairs3[0], NULL,
112     0, 0, 1, 0, JAM2, 5, (SHORT *) &SharedBordersPairs4[0], &SharedBordersInvert[5], // Button 2
113     0, 0, 2, 0, JAM2, 5, (SHORT *) &SharedBordersPairs5[0], NULL,
114     0, 0, 1, 0, JAM2, 5, (SHORT *) &SharedBordersPairs9[0], &SharedBordersInvert[7], // TBox inverted
115     0, 0, 2, 0, JAM2, 5, (SHORT *) &SharedBordersPairs10[0], NULL,
116 };
117
118 UBYTE DestinationValue_buf[255];
119
120 struct IntuiText Destination_text[] =
121 {
122     1, 0, JAM2, -98, 6, NULL, "Destination:", &Destination_text[1],
123     1, 0, JAM2, 4, 4, NULL, DestinationValue_buf, NULL,
124 };
125
126 #define GADGETDESTINATION 11
127
128 struct Gadget GetDestination =
129 {
130     NULL, 108, 117, tbox1w, tbox1h,
131     GADGHIMAGE,
132     RELVERIFY,
133     BOOLGADGET,
134     (APTR) &SharedBorders[9], (APTR) &SharedBordersInvert[6],
135     Destination_text, 0, NULL, GADGETDESTINATION, NULL
136 };
137
138 struct IntuiText RebootButton_text =
139 {
140     1, 0, JAM2, 2, 6, NULL, (UBYTE *)"Reboot", NULL
141 };
142
143 #define GADREBOOT 10
144
145 struct Gadget RebootButton =
146 {
147     &GetDestination, 4, 166, button1w, button1h,
148     GADGHIMAGE,
149     RELVERIFY,
150     BOOLGADGET,
151     (APTR) &SharedBorders[0], (APTR) &SharedBordersInvert[0],
152     &RebootButton_text, 0, NULL, GADREBOOT, NULL
153 };
154
155 UBYTE StatusBar_buf[128] = "PiStorm...";
156
157 struct IntuiText StatusBar_text =
158 {
159     1, 0, JAM2, 4, 2, NULL, (UBYTE *)StatusBar_buf, NULL
160 };
161
162 #define GADSTATUSBAR 9
163
164 struct Gadget StatusBar =
165 {
166     &RebootButton, 3, 188, 508, 10,
167     GADGHIMAGE,
168     0,
169     BOOLGADGET,
170     (APTR) &SharedBorders[8], NULL,
171     &StatusBar_text, 0, NULL, GADSTATUSBAR, NULL
172 };
173
174
175 struct IntuiText RetrieveButton_text =
176 {
177     1, 0, JAM2, 10, 6, NULL, (UBYTE *)"Retrieve", NULL
178 };
179
180 #define GADRETRIEVEBUTTON 8
181
182 struct Gadget RetrieveButton =
183 {
184     &StatusBar, 244, 117, button2w, button2h,
185     GADGHIMAGE,
186     RELVERIFY,
187     BOOLGADGET,
188     (APTR) &SharedBorders[4], (APTR) &SharedBordersInvert[4],
189     &RetrieveButton_text, 0, NULL, GADRETRIEVEBUTTON, NULL
190 };
191
192 UBYTE GetFileValue_buf[255];
193
194 struct StringInfo GetFileValue =
195 {
196     GetFileValue_buf, NULL, 0, 255, 0, 0, 0, 0, 4, 4, NULL, 0, NULL
197 };
198
199 struct IntuiText GetFile_text[] =
200 {
201     1, 0, JAM2, -98, -15, NULL, "Get file", &GetFile_text[1],
202     1, 0, JAM2, -98, 4, NULL, "Source:", NULL,
203 };
204
205 #define GADGETFILE 7
206
207 struct Gadget GetFile =
208 {
209     &RetrieveButton, 108, 93, tbox1w, tbox1h,
210     GADGHIMAGE,
211     0,
212     STRGADGET,
213     (APTR) &SharedBorders[6], NULL,
214     GetFile_text, 0, (APTR)&GetFileValue, GADGETFILE, NULL
215 };
216
217 struct IntuiText ConfigDefault_text =
218 {
219     1, 0, JAM2, 2, 6, NULL, (UBYTE *)"Load Default", NULL
220 };
221
222 #define GADCONFIGDEFAULT 6
223
224 struct Gadget ConfigDefault =
225 {
226     &GetFile, 304, 39, button3w, button3h,
227     GADGHIMAGE,
228     RELVERIFY,
229     BOOLGADGET,
230     (APTR) &SharedBorders[2], (APTR) &SharedBordersInvert[2],
231     &ConfigDefault_text, 0, NULL, GADCONFIGDEFAULT, NULL
232 };
233
234 struct IntuiText ConfigCommit_text =
235 {
236     1, 0, JAM2, 2, 6, NULL, (UBYTE *)"Commit", NULL
237 };
238
239 #define GADCONFIGCOMMIT 5
240
241 struct Gadget ConfigCommit =
242 {
243     &ConfigDefault, 244, 39, button1w, button1h,
244     GADGHIMAGE,
245     RELVERIFY,
246     BOOLGADGET,
247     (APTR) &SharedBorders[0], (APTR) &SharedBordersInvert[0],
248     &ConfigCommit_text, 0, NULL, GADCONFIGCOMMIT, NULL
249 };
250
251
252 UBYTE ConfigFileValue_buf[255];
253
254 struct StringInfo ConfigFileValue =
255 {
256     ConfigFileValue_buf, NULL, 0, 255, 0, 0, 0, 0, 4, 4, NULL, 0, NULL
257 };
258
259 struct IntuiText ConfigFile_text =
260 {
261     1, 0, JAM2, -98, 4, NULL, "Config file:", NULL
262 };
263
264 #define GADCONFIGFILE 4
265
266 struct Gadget ConfigFile =
267 {
268     &ConfigCommit, 108, 41, tbox1w, tbox1h,
269     GADGHIMAGE,
270     0,
271     STRGADGET,
272     (APTR) &SharedBorders[6], NULL,
273     &ConfigFile_text, 0, (APTR)&ConfigFileValue, GADCONFIGFILE, NULL
274 };
275
276 UBYTE RTGStatus_buf[64] = "RTG status";
277
278 struct IntuiText RTGStatus_text =
279 {
280     1, 0, JAM2, 4, 4, NULL, (UBYTE *)RTGStatus_buf, NULL
281 };
282
283 #define GADRTGSTATUS 3
284
285 struct Gadget RTGStatus =
286 {
287     &ConfigFile, 14, 15, tbox1w, tbox1h,
288     GADGHIMAGE,
289     0,
290     BOOLGADGET,
291     (APTR) &SharedBorders[6], NULL,
292     &RTGStatus_text, 0, NULL, GADRTGSTATUS, NULL
293 };
294
295 UBYTE RTG_buf[64] = "RTG Enable";
296
297 struct IntuiText RTG_text =
298 {
299     1, 0, JAM2, 8, 6, NULL, (UBYTE *)RTG_buf, NULL
300 };
301
302 #define GADRTGBUTTON 2
303
304 struct Gadget RTGButton =
305 {
306     &RTGStatus, 150, 13, button3w, button3h,
307     GADGHIMAGE,
308     RELVERIFY,
309     BOOLGADGET,
310     (APTR) &SharedBorders[2], (APTR) &SharedBordersInvert[2],
311     &RTG_text, 0, NULL, GADRTGBUTTON, NULL
312 };
313
314 struct IntuiText AboutButton_text =
315 {
316     1, 0, JAM2, 8, 6, NULL, (UBYTE *)"About", NULL
317 };
318
319 #define GADABOUT 1
320
321 struct Gadget AboutButton =
322 {
323     &RTGButton, 356, 166, button1w, button1h,
324     GADGHIMAGE,
325     RELVERIFY,
326     BOOLGADGET,
327     (APTR) &SharedBorders[0], (APTR) &SharedBordersInvert[0],
328     &AboutButton_text, 0, NULL, GADABOUT, NULL
329 };
330
331
332 struct IntuiText QuitButton_text =
333 {
334     1, 0, JAM2, 12, 6, NULL, (UBYTE *)"Quit", NULL
335 };
336
337 #define GADQUIT 0
338
339 struct Gadget QuitButton =
340 {
341     &AboutButton, 438, 166, button1w, button1h,
342     GADGHIMAGE,
343     RELVERIFY,
344     BOOLGADGET,
345     (APTR) &SharedBorders[0], (APTR) &SharedBordersInvert[0],
346     &QuitButton_text, 0, NULL, GADQUIT, NULL
347 };
348
349
350 struct NewWindow winlayout =
351 {
352     20, 20,
353     512, 200,
354     -1, -1,
355     CLOSEWINDOW | GADGETUP | GADGETDOWN,
356     ACTIVATE | WINDOWCLOSE | WINDOWDRAG | WINDOWDEPTH,
357     &QuitButton, NULL,
358     (STRPTR)"PiStorm Interaction Tool",
359     NULL, NULL,
360     0, 0,
361     600, 400,
362     WBENCHSCREEN
363 };
364
365 // Pads what we are writing to screen with spaces, otherwise we get bits of
366 // old text still showing
367 static void WriteGadgetText(const char *text, UBYTE *buffer, struct Window *window, struct Gadget *gadget)
368 {
369     ULONG newlen = strlen(text);
370     ULONG oldlen = strlen((char *)buffer);
371
372     if (newlen < oldlen)
373     {
374         snprintf((char *)buffer, 64, "%s%*.*s", text, (int)(oldlen - newlen),
375                  (int)(oldlen - newlen), " ");
376     }
377     else
378     {
379         strncpy((char *)buffer, text, 64);
380     }
381
382     RefreshGadgets(gadget, window, NULL);
383 }
384 static void updateRTG(struct Window *window)
385 {
386     unsigned short rtg = pi_get_rtg_status();
387     if (rtg & 0x01)
388     {
389         WriteGadgetText("Disable RTG", RTG_buf, window, &RTGButton);
390         if (rtg & 0x02)
391         {
392             WriteGadgetText("RTG in use", RTGStatus_buf, window, &RTGStatus);
393         }
394         else
395         {
396             WriteGadgetText("RTG not in use", RTGStatus_buf, window, &RTGStatus);
397         }
398     }
399     else
400     {
401         WriteGadgetText("Enable RTG", RTG_buf, window, &RTGButton);
402         WriteGadgetText("RTG disabled", RTGStatus_buf, window, &RTGStatus);
403     }
404 }
405
406 static char *GetSavePath()
407 {
408     struct rtFileRequester *filereq;
409     char filename[128];
410     char *fullpath = malloc(256 * sizeof(char));
411     UBYTE *buf = NULL;
412
413     if ((filereq = (struct rtFileRequester*)rtAllocRequestA (RT_FILEREQ, NULL)))
414     {
415         filename[0] = 0;
416
417         if (!rtFileRequest(filereq, filename, "Pick a destination directory",
418                            RTFI_Flags, FREQF_NOFILES, TAG_END))
419         {
420             free(fullpath);
421             return NULL;
422         }
423
424     }
425     else
426     {
427         rtEZRequest("Out of memory!", "Oh no!", NULL, NULL);
428     }
429
430     strncpy(fullpath, (char*)filereq->Dir, 256);
431     return fullpath;
432 }
433
434
435 int main()
436 {
437     struct Window *myWindow;
438
439     IntuitionBase = (struct IntuitionBase *) OpenLibrary("intuition.library", 0);
440     if (IntuitionBase == NULL)
441     {
442         return RETURN_FAIL;
443     }
444
445     if (!(ReqToolsBase = (struct ReqToolsBase *)
446                          OpenLibrary (REQTOOLSNAME, REQTOOLSVERSION)))
447     {
448         static struct IntuiText pos;
449         struct IntuiText msg[] =
450         {
451             1, 0, JAM2, 0, 0, NULL, "You need reqtools.library V38 or higher!.", &msg[1],
452             1, 0, JAM2, 0, 10, NULL, "Please install it in your Libs: drirectory.", NULL,
453         };
454         AutoRequest(NULL, msg, NULL, &pos, 0, 0, 0, 0);
455         return RETURN_FAIL;
456     }
457
458     pistorm_base_addr = pi_find_pistorm();
459     myWindow = OpenWindow(&winlayout);
460     BOOL no_board = FALSE;
461
462     if (pistorm_base_addr == 0xFFFFFFFF)
463     {
464         static struct IntuiText msg, pos;
465         msg.IText = "Unable to find PiStorm autoconf device.";
466         pos.IText = "OK";
467         AutoRequest(myWindow, &msg, NULL, &pos, 0, 0, 0, 0);
468         no_board = TRUE;
469         WriteGadgetText("PiStorm not found", StatusBar_buf, myWindow, &StatusBar);
470     }
471     if (!no_board)
472     {
473         updateRTG(myWindow);
474     }
475
476     FOREVER
477     {
478         BOOL closewin = FALSE;
479         struct IntuiMessage *message;
480         Wait(1 << myWindow->UserPort->mp_SigBit);
481
482         while ((message = (struct IntuiMessage*)GetMsg(myWindow->UserPort)))
483         {
484             ULONG class = message->Class;
485             struct Gadget *address = (struct Gadget*)message->IAddress;
486             ReplyMsg((struct Message*)message);
487
488             if (class == CLOSEWINDOW)
489             {
490                 closewin = TRUE;
491             }
492             else if (class == GADGETUP)
493             {
494                 if (no_board && (address->GadgetID != GADQUIT) && (address->GadgetID != GADABOUT))
495                 {
496                     continue;
497                 }
498                 switch (address->GadgetID)
499                 {
500                     case GADQUIT:
501                         closewin = TRUE;
502                         break;
503                     case GADABOUT:
504                         {
505                             static struct IntuiText pos;
506                             UBYTE buf[64], buf2[64], buf3[64];
507                             if (!no_board)
508                             {
509                                 unsigned short hw_rev = pi_get_hw_rev();
510                                 unsigned short sw_rev = pi_get_sw_rev();
511                                 snprintf((char*)buf2, 64, "PiStorm hardware: %d.%d", (hw_rev >> 8), (hw_rev & 0xFF));
512                                 snprintf((char*)buf3, 64, "PiStorm software: %d.%d", (sw_rev >> 8), (sw_rev & 0xFF));
513                             }
514                             else
515                             {
516                                 snprintf((char*)buf2, 64, "PiStorm hardware not found!");
517                             }
518                             struct IntuiText msg[] =
519                             {
520                                 1, 0, JAM2, 0, 0, NULL, (UBYTE *)buf, &msg[1],
521                                 1, 0, JAM2, 0, 10, NULL, "Tool written by beeanyew and LinuxJedi", &msg[2],
522                                 1, 0, JAM2, 0, 20, NULL, (UBYTE*)buf2, &msg[3],
523                                 1, 0, JAM2, 0, 30, NULL, (UBYTE*)buf3, &msg[4],
524                                 1, 0, JAM2, 0, 50, NULL, "Now with 53% more Nibbles!", NULL,
525                             };
526                             snprintf(buf, 64, "PiStorm Interaction Tool %s", VERSION);
527                             pos.IText = "OK";
528                             AutoRequest(myWindow, msg, NULL, &pos, 0, 0, 0, 0);
529                             break;
530                         }
531                     case GADRTGBUTTON:
532                         {
533                             unsigned short rtgStatus = pi_get_rtg_status() & 0x01;
534                             pi_enable_rtg(!rtgStatus);
535                             updateRTG(myWindow);
536                             break;
537                         }
538                     case GADCONFIGCOMMIT:
539                         {
540                             unsigned short ret = pi_handle_config(PICFG_LOAD, ConfigFileValue_buf);
541                             if (ret == PI_RES_FILENOTFOUND)
542                             {
543                                 static struct IntuiText msg, pos;
544                                 msg.IText = "PiStorm says: \"file not found\"";
545                                 pos.IText = "OK";
546                                 AutoRequest(myWindow, &msg, NULL, &pos, 0, 0, 0, 0);
547                             }
548                             break;
549                         }
550                     case GADCONFIGDEFAULT:
551                         {
552                             pi_handle_config(PICFG_DEFAULT, NULL);
553                             break;
554                         }
555                     case GADRETRIEVEBUTTON:
556                         {
557                             unsigned int filesize = 0;
558                             char outpath[128];
559                             unsigned char *buf;
560
561                             if (pi_get_filesize(GetFileValue_buf, &filesize) == PI_RES_FILENOTFOUND)
562                             {
563                                 static struct IntuiText msg, pos;
564                                 msg.IText = "PiStorm says: \"file not found\"";
565                                 pos.IText = "OK";
566                                 AutoRequest(myWindow, &msg, NULL, &pos, 0, 0, 0, 0);
567                                 break;
568                             }
569                             buf = malloc(filesize);
570                             if (buf == NULL)
571                             {
572                                 static struct IntuiText msg, pos;
573                                 msg.IText = "Could not allocate enough memory to transfer file";
574                                 pos.IText = "OK";
575                                 AutoRequest(myWindow, &msg, NULL, &pos, 0, 0, 0, 0);
576                                 break;
577                             }
578                             WriteGadgetText("Retrieving file...", StatusBar_buf, myWindow, &StatusBar);
579                             if (pi_transfer_file(GetFileValue_buf, buf) != PI_RES_OK)
580                             {
581                                 static struct IntuiText msg, pos;
582                                 msg.IText = "PiStorm says: \"something went wrong with the file transfer\"";
583                                 pos.IText = "OK";
584                                 AutoRequest(myWindow, &msg, NULL, &pos, 0, 0, 0, 0);
585                                 WriteGadgetText("File transfer failed", StatusBar_buf, myWindow, &StatusBar);
586                                 free(buf);
587                                 break;
588                             }
589                             char *fname = strrchr(GetFileValue_buf, '/');
590                             if (!fname)
591                             {
592                                 fname = GetFileValue_buf;
593                             }
594                             char *destfile = malloc(256);
595                             // Turns out WB doesn't like DF0:/filename.ext
596                             if (DestinationValue_buf[(strlen(DestinationValue_buf) - 1)] == ':')
597                             {
598                                 snprintf(destfile, 255, "%s%s", DestinationValue_buf, GetFileValue_buf);
599                             }
600                             else if (!strlen(DestinationValue_buf))
601                             {
602                                 snprintf(destfile, 255, "%s", GetFileValue_buf);
603                             }
604                             else
605                             {
606                                 snprintf(destfile, 255, "%s/%s", DestinationValue_buf, GetFileValue_buf);
607                             }
608                             BPTR fh = Open(destfile, MODE_NEWFILE);
609                             if (!fh)
610                             {
611                                 char errbuf[64];
612                                 snprintf(errbuf, 64, "Error code: %ld", IoErr());
613                                 struct IntuiText msg[] =
614                                 {
615                                     1, 0, JAM2, 0, 0, NULL, "Could not open file for writing", &msg[1],
616                                     1, 0, JAM2, 0, 10, NULL, destfile, &msg[2],
617                                     1, 0, JAM2, 0, 20, NULL, (UBYTE*)errbuf, NULL,
618                                 };
619                                 static struct IntuiText pos;
620                                 pos.IText = "OK";
621                                 AutoRequest(myWindow, msg, NULL, &pos, 0, 0, 0, 0);
622                                 WriteGadgetText("File transfer failed", StatusBar_buf, myWindow, &StatusBar);
623                                 free(buf);
624                                 free(destfile);
625                                 break;
626                             }
627                             Write(fh, buf, filesize);
628                             Close(fh);
629                             free(destfile);
630                             WriteGadgetText("File transfer complete", StatusBar_buf, myWindow, &StatusBar);
631                             free(buf);
632                             break;
633                         }
634                     case GADREBOOT:
635                         {
636                             WriteGadgetText("Rebooting PiStorm", StatusBar_buf, myWindow, &StatusBar);
637                             pi_reset_amiga(0);
638                             break;
639                         }
640                     case GADGETDESTINATION:
641                         {
642                             char *fileName = GetSavePath();
643                             if (fileName)
644                             {
645                                 WriteGadgetText(fileName, DestinationValue_buf, myWindow, &GetDestination);
646                                 free(fileName);
647                             }
648                         }
649                 }
650             }
651             if (closewin)
652             {
653                 break;
654             }
655         }
656         if (closewin)
657         {
658             break;
659         }
660     };
661     if (myWindow) CloseWindow(myWindow);
662     CloseLibrary((struct Library*)ReqToolsBase);
663     return 0;
664 }