grub2: bring back build of aros-side grub2 tools
[AROS.git] / workbench / tools / HDToolBox / gui.c
blob033ead5fc332282328283954082fda0baa70a6c8
1 /*
2 Copyright © 1995-2015, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 /* "TODO: fs support" */
8 #define __CONSOLE_NOLIBBASE__
10 #include <proto/alib.h>
11 #include <proto/exec.h>
12 #include <proto/dos.h>
13 #include <proto/console.h>
14 #include <proto/icon.h>
15 #include <proto/intuition.h>
16 #include <proto/muimaster.h>
18 #include <exec/memory.h>
19 #include <devices/rawkeycodes.h>
20 #include <intuition/gadgetclass.h>
21 #include <intuition/icclass.h>
22 #include <intuition/intuition.h>
23 #include <intuition/sghooks.h>
24 #include <libraries/asl.h>
25 #include <libraries/locale.h>
26 #include <libraries/mui.h>
27 #include <resources/filesysres.h>
28 #include <workbench/workbench.h>
29 #ifdef HAVE_COOLIMAGES
30 #include <libraries/coolimages.h>
31 #endif
33 #include <stdio.h>
34 #include <stdlib.h>
35 #include <strings.h>
37 #define DEBUG 0
38 #include "debug.h"
40 #include "gui.h"
41 #include "devices.h"
42 #include "error.h"
43 #include "harddisks.h"
44 #include "hdtoolbox_support.h"
45 #include "locale.h"
46 #include "platform.h"
47 #include "ptclass.h"
48 #include "prefs.h"
50 #undef CATCOMP_STRINGS
51 #undef CATCOMP_NUMBERS
52 #define CATCOMP_NUMBERS
53 #include "strings.h"
55 #define SIMPLEBUTTON(text) SimpleButton(MSG(text))
57 #ifdef HAVE_COOLIMAGES
58 #define IMAGEBUTTON(text,imgid) CoolImageIDButton(MSG(text),imgid)
59 #else
60 #define IMAGEBUTTON(text,imgid) SIMPLEBUTTON(text)
61 #endif
63 struct Library *MUIMasterBase = NULL;
64 struct Library *ConsoleDevice = NULL;
66 Object *app;
67 Object *mainwin;
68 Object *about_item;
69 Object *quit_item;
70 Object *part_item;
71 Object *createml_item;
72 struct GUIGadgets gadgets;
74 struct Hook hook_display;
75 struct Hook hook_buttons;
76 struct Hook hook_createml;
77 struct Hook hook_lv_doubleclick;
78 struct Hook hook_lv_click;
80 struct AddDeviceGadgets {
81 Object *win;
82 Object *disk;
83 Object *file;
84 Object *ok;
85 Object *cancel;
86 } adddevicegadgets;
88 Class *ptclass;
90 struct AddPartitionGadgets {
91 Object *win;
92 Object *pt;
93 Object *ok;
94 Object *cancel;
95 } addpartitiongadgets;
97 struct PartitionTypeGadgets {
98 Object *win;
99 struct TableTypeNode *ttn;
100 Object *lv;
101 Object *base;
102 struct Hook hook_hexidedit;
103 Object *hexid;
104 struct PartitionType type;
105 struct ListNode *iln;
106 Object *ok;
107 Object *cancel;
108 } partitiontypegadgets;
110 struct PartitionTableTypeGadgets {
111 Object *win;
112 Object *lv;
113 struct ListNode *iln;
114 Object *ok;
115 Object *cancel;
116 } partitiontabletypegadgets;
118 struct ResizeMoveGadgets {
119 Object *win;
120 Object *pt;
121 Object *lowcyl;
122 Object *highcyl;
123 Object *totalcyl;
124 Object *size;
125 Object *ok;
126 Object *cancel;
127 } resizemovegadgets;
129 struct RenameGadgets {
130 Object *win;
131 Object *name;
132 struct ListNode *iln;
133 Object *ok;
134 Object *cancel;
135 } renamegadgets;
137 struct DosEnvecGadgets {
138 Object *win;
139 Object *mask;
140 Object *maxtransfer;
141 Object *custboot;
142 Object *numcustboot;
143 Object *reservedblocksstart;
144 Object *reservedblocksend;
145 Object *blocksize;
146 Object *buffers;
147 struct ListNode *iln;
148 Object *ok;
149 Object *cancel;
150 } dosenvecgadgets;
152 struct MountBootGadgets {
153 Object *win;
154 Object *active;
155 Object *automount;
156 Object *bootable;
157 Object *bootpri;
158 struct ListNode *iln;
159 Object *ok;
160 Object *cancel;
161 } mountbootgadgets;
163 char *editcycleentries[] = {"0x", NULL};
164 char *blocksizecycleentries[] = {"512","1024","2048","4096", NULL};
166 void setChanged(struct ListNode *iln)
168 struct ListNode *parent = iln;
170 D(bug("[HDToolBox] setChanged()\n"));
172 while (parent)
174 parent->change_count++;
175 parent = parent->parent;
177 DoMethod(gadgets.leftlv, MUIM_List_Redraw, MUIV_List_Redraw_All);
178 DoMethod(gadgets.leftlv, MUIM_CallHook, (IPTR)&hook_lv_click);
181 void unsetChanged(struct ListNode *iln)
183 struct ListNode *sub = iln;
184 struct ListNode *parent;
186 D(bug("[HDToolBox] unsetChanged()\n"));
188 /* remove changed from all first generation child partitions */
189 sub = (struct ListNode *)iln->list.lh_Head;
190 while (sub->ln.ln_Succ)
192 if (sub->change_count)
194 parent = sub->parent;
195 while (parent)
197 parent->change_count -= sub->change_count;
198 parent = parent->parent;
200 sub->change_count = 0;
202 sub = (struct ListNode *)sub->ln.ln_Succ;
204 if (iln->flags & LNF_ToSave)
206 iln->flags &= ~LNF_ToSave;
207 /* we saved it so there can't be a change_count */
208 if (iln->change_count)
210 parent = iln->parent;
211 while (parent)
213 parent->change_count -= iln->change_count;
214 parent = parent->parent;
216 iln->change_count = 0;
219 DoMethod(gadgets.leftlv, MUIM_List_Redraw, MUIV_List_Redraw_Active);
222 AROS_UFH3(void, hexidedit_function,
223 AROS_UFHA(struct Hook *, h, A0),
224 AROS_UFHA(struct SGWork *, sgwork, A2),
225 AROS_UFHA(ULONG *, msg, A1))
227 AROS_USERFUNC_INIT
229 D(bug("[HDToolBox] hexidedit_function()\n"));
231 if (*msg == SGH_KEY)
233 D(bug("[HDToolBox] hexidedit_function: KEY PRESS\n"));
236 AROS_USERFUNC_EXIT
239 AROS_UFH3(void, display_function,
240 AROS_UFHA(struct Hook *, h, A0),
241 AROS_UFHA(const char **, strings, A2),
242 AROS_UFHA(struct ListNode *, entry, A1))
244 AROS_USERFUNC_INIT
246 static char buf[16];
247 static char bu2[64];
249 D(bug("[HDToolBox] display_function()\n"));
251 if (entry)
253 int i=0;
254 if (entry->change_count)
255 buf[i++] = '*';
256 if (entry->flags & LNF_ToSave)
257 buf[i++] = 'S';
258 buf[i] = 0;
259 strings[0] = buf;
260 if ((entry->flags & LNF_Listable) || (entry->ln.ln_Type == LNT_Parent))
262 sprintf(bu2,"\0333%s",entry->ln.ln_Name);
263 strings[1] = bu2;
265 else
266 strings[1] = entry->ln.ln_Name;
268 else
270 strings[0] = MSG(WORD_Changed);
271 strings[1] = MSG(WORD_Name);
274 AROS_USERFUNC_EXIT
277 void setTypeString(struct PartitionType *type, Object *strgad)
279 char str[256];
280 char *cur=str;
281 LONG len=0;
283 D(bug("[HDToolBox] setTypeString()\n"));
285 while (len!=type->id_len)
287 sprintf(cur, "%02x ", type->id[len]);
288 cur += 3;
289 len++;
291 cur[-1]=0;
292 set(strgad, MUIA_String_Contents, str);
295 LONG askSave(STRPTR name)
297 struct EasyStruct es =
299 sizeof(struct EasyStruct), 0,
300 "HDToolBox",
301 MSG(MSG_ASK_SAVE),
302 NULL
304 char yesno[32];
306 D(bug("[HDToolBox] askSave('%s')\n", name));
308 sprintf(yesno, "%s|%s|%s", MSG_STD(YESSTR), MSG(WORD_All), MSG_STD(NOSTR));
309 es.es_GadgetFormat = yesno;
310 return EasyRequestArgs(0, &es, 0, (RAWARG)&name);
314 LONG saveChanges(struct ListNode *iln, LONG asksave)
316 struct ListNode *sub;
318 D(bug("[HDToolBox] saveChanges()\n"));
320 if (iln->change_count)
322 sub = (struct ListNode *)iln->list.lh_Head;
323 while (sub->ln.ln_Succ)
325 asksave = saveChanges(sub, asksave);
326 sub = (struct ListNode *)sub->ln.ln_Succ;
328 if (iln->flags & LNF_ToSave)
330 struct HDTBPartition *partition;
331 partition = (struct HDTBPartition *)iln;
332 if (partition->table)
334 LONG result=1;
335 if (asksave)
336 result = askSave(iln->ln.ln_Name);
337 if (result == 2)
338 asksave = FALSE;
339 if (result)
341 if (WritePartitionTable(partition->ph) == 0)
342 unsetChanged(iln);
343 else
344 set(gadgets.text, MUIA_Text_Contents, MSG(MSG_WriteTableError));
349 return asksave;
352 AROS_UFH3(void, buttons_function,
353 AROS_UFHA(struct Hook *, h, A0),
354 AROS_UFHA(Object *, object, A2),
355 AROS_UFHA(ULONG *, arg, A1))
357 AROS_USERFUNC_INIT
359 LONG active = MUIV_List_Active_Off;
360 struct ListNode *iln;
361 int i;
363 D(bug("[HDToolBox] buttons_function()\n"));
365 for (i=GB_FIRST;i<=GB_LAST;i++)
366 if (object == gadgets.buttons[i])
367 break;
369 if (i > GB_LAST)
371 if (object == gadgets.leftlv)
374 else if (object == adddevicegadgets.ok)
376 char *str = NULL;
377 struct HDTBDevice *dn;
379 get(adddevicegadgets.file, MUIA_String_Contents, &str);
380 if (str[0])
381 dn = addDeviceName(str);
383 if (!dn) {
384 /* FIXME: Should we fail here? */
387 else if (object == addpartitiongadgets.ok)
389 struct DosEnvec *de = NULL;
391 get(addpartitiongadgets.pt, PTCT_ActivePartition, &de);
392 if (de)
394 struct HDTBPartition *table;
395 struct HDTBPartition *partition;
397 get(addpartitiongadgets.pt, PTCT_PartitionTable, &iln);
398 table = (struct HDTBPartition *)iln;
399 partition = addPartition(table, de);
400 if (partition)
402 setChanged(&partition->listnode);
403 partition->listnode.parent->flags |= LNF_ToSave;
404 InsertList(gadgets.leftlv, &partition->listnode);
406 else
407 set(gadgets.text, MUIA_Text_Contents, MSG(MSG_NO_MEMORY));
410 else if (object == addpartitiongadgets.pt);
411 else if (object == partitiontypegadgets.hexid)
413 char *str = NULL;
415 DoMethod(gadgets.leftlv, MUIM_List_GetEntry, active, (IPTR)&iln);
416 get(object, MUIA_String_Contents, &str);
417 partitiontypegadgets.type.id_len=strcpyESC(partitiontypegadgets.type.id, str);
419 else if (object == partitiontypegadgets.lv)
421 get(partitiontypegadgets.lv, MUIA_List_Active, &active);
422 if (active != MUIV_List_Active_Off)
424 struct TypeNode *tn;
425 STRPTR name;
426 DoMethod(partitiontypegadgets.lv, MUIM_List_GetEntry, active, (IPTR)&name);
427 tn = (struct TypeNode *)FindName(partitiontypegadgets.ttn->typelist, name);
428 setTypeString(&tn->type, partitiontypegadgets.hexid);
429 CopyMem(&tn->type, &partitiontypegadgets.type, sizeof(struct PartitionType));
432 else if (object == partitiontypegadgets.ok)
434 struct HDTBPartition *partition;
435 partition = (struct HDTBPartition *)partitiontypegadgets.iln;
436 CopyMem(&partitiontypegadgets.type, &partition->type, sizeof(struct PartitionType));
437 SetPartitionAttrsA(partition->ph, PT_TYPE, &partition->type, TAG_DONE);
438 GetPartitionAttrsA(partition->ph, PT_DOSENVEC, &partition->de, TAG_DONE);
439 partitiontypegadgets.iln->parent->flags |= LNF_ToSave;
440 setChanged(partitiontypegadgets.iln);
442 else if (object == partitiontabletypegadgets.ok)
444 get(partitiontabletypegadgets.lv, MUIA_List_Active, &active);
445 if (active != MUIV_List_Active_Off)
447 struct TableTypeNode *ttn;
448 struct HDTBPartition *table;
449 STRPTR name;
450 DoMethod(partitiontabletypegadgets.lv, MUIM_List_GetEntry, active, (IPTR)&name);
451 ttn = findTableTypeNodeName(name);
452 table = (struct HDTBPartition *)partitiontabletypegadgets.iln;
453 if (
454 (table->table == NULL) ||
455 (ttn->pti->pti_Type != table->table->type)
458 if (makePartitionTable(table, ttn->pti->pti_Type))
460 table->listnode.flags |= LNF_Listable;
461 table->listnode.flags |= LNF_ToSave;
462 setChanged(partitiontabletypegadgets.iln);
464 else
465 set(gadgets.text, MUIA_Text_Contents, MSG(MSG_CreateTableError));
469 else if (object == resizemovegadgets.ok)
471 struct HDTBPartition *table = NULL;
472 struct HDTBPartition *partition;
474 get(resizemovegadgets.pt, PTCT_PartitionTable, &table);
475 partition = (struct HDTBPartition *)table->listnode.list.lh_Head;
476 table->listnode.flags |= LNF_ToSave;
477 while (partition->listnode.ln.ln_Succ)
479 if (partition->listnode.flags & LNF_IntermedChange)
481 partition->listnode.flags &= ~LNF_IntermedChange;
482 setChanged(&partition->listnode);
483 SetPartitionAttrsA(partition->ph, PT_DOSENVEC, &partition->de, TAG_DONE);
485 partition = (struct HDTBPartition *)partition->listnode.ln.ln_Succ;
488 else if (object == resizemovegadgets.cancel)
490 struct HDTBPartition *table = NULL;
491 struct HDTBPartition *partition;
493 get(resizemovegadgets.pt, PTCT_PartitionTable, &table);
494 partition = (struct HDTBPartition *)table->listnode.list.lh_Head;
495 while (partition->listnode.ln.ln_Succ)
497 if (partition->listnode.flags & LNF_IntermedChange)
499 partition->listnode.flags &= ~LNF_IntermedChange;
500 GetPartitionAttrsA(partition->ph, PT_DOSENVEC, &partition->de, TAG_DONE);
502 partition = (struct HDTBPartition *)partition->listnode.ln.ln_Succ;
505 else if (object == resizemovegadgets.pt)
507 LONG type = 0;
508 struct DosEnvec *de = NULL;
509 char str[32];
511 D(bug("[HDToolBox] buttons_function() - Resize/Move Partition Display:\n"));
512 get(resizemovegadgets.pt, PTCT_ActiveType, &type);
513 if (type == PTS_EMPTY_AREA)
515 get(resizemovegadgets.pt, PTCT_ActivePartition, &de);
517 else
519 struct HDTBPartition *partition = NULL;
521 get(resizemovegadgets.pt, PTCT_ActivePartition, &partition);
522 de = &partition->de;
523 if (*arg == PTCT_PartitionMove)
525 partition->listnode.flags |= LNF_IntermedChange;
528 nnset(resizemovegadgets.lowcyl, MUIA_String_Integer, de->de_LowCyl);
529 nnset(resizemovegadgets.highcyl, MUIA_String_Integer, de->de_HighCyl);
530 nnset(resizemovegadgets.totalcyl, MUIA_String_Integer, de->de_HighCyl-de->de_LowCyl+1);
531 getSizeStr(str, (((de->de_HighCyl - de->de_LowCyl + 1) * de->de_Surfaces * de->de_BlocksPerTrack)-1)/2);
532 nnset(resizemovegadgets.size, MUIA_String_Contents, str);
533 D(bug("[HDToolBox] buttons_function() - Resize/Move Partition Display successful\n"));
535 else if (object == resizemovegadgets.lowcyl)
537 LONG type = 0;
538 ULONG value = 0;
540 D(bug("[HDToolBox] buttons_function() - Resize/Move Lowcyl:\n"));
541 get(object, MUIA_String_Integer, &value);
542 get(resizemovegadgets.pt, PTCT_ActiveType, &type);
543 if (type == PTS_PARTITION)
545 struct HDTBPartition *table = NULL;
546 struct HDTBPartition *partition = NULL;
547 ULONG block;
549 get(resizemovegadgets.pt, PTCT_PartitionTable, &table);
550 get(resizemovegadgets.pt, PTCT_ActivePartition, &partition);
551 D(bug("[HDToolBox] - Type : Partition\n"));
552 D(bug("[HDToolBox] - Old value : %ld\n", partition->de.de_LowCyl));
553 D(bug("[HDToolBox] - New value : %ld\n", value));
554 D(bug("[HDToolBox] - Partition table : %p\n", table));
555 D(bug("[HDToolBox] - Active partition : %p\n", partition));
556 if (value != partition->de.de_LowCyl)
558 block =
559 value*partition->de.de_Surfaces*partition->de.de_BlocksPerTrack;
560 if (validValue(table, partition, block))
562 char str[32];
563 partition->listnode.flags |= LNF_IntermedChange;
564 partition->de.de_LowCyl = value;
565 set(resizemovegadgets.totalcyl, MUIA_String_Integer, partition->de.de_HighCyl-partition->de.de_LowCyl+1);
566 set(resizemovegadgets.pt, PTCT_PartitionTable, table);
567 getSizeStr
569 str,
572 (partition->de.de_HighCyl-partition->de.de_LowCyl+1)*
573 partition->de.de_Surfaces*partition->de.de_BlocksPerTrack
577 set(resizemovegadgets.size, MUIA_String_Contents, str);
579 else
580 set(object, MUIA_String_Integer, partition->de.de_LowCyl);
583 else if (type == PTS_EMPTY_AREA)
585 struct DosEnvec *de = NULL;
587 get(resizemovegadgets.pt, PTCT_ActivePartition, &de);
588 if (value != de->de_LowCyl)
589 set(object, MUIA_String_Integer, de->de_LowCyl);
591 else
592 set(object, MUIA_String_Integer, 0);
594 else if (object == resizemovegadgets.highcyl)
596 LONG type = 0;
597 ULONG value = 0;
599 D(bug("[HDToolBox] buttons_function() - Resize/Move Highcyl:\n"));
600 get(object, MUIA_String_Integer, &value);
601 get(resizemovegadgets.pt, PTCT_ActiveType, &type);
602 if (type == PTS_PARTITION)
604 struct HDTBPartition *table = NULL;
605 struct HDTBPartition *partition = NULL;
606 ULONG block;
608 get(resizemovegadgets.pt, PTCT_PartitionTable, &table);
609 get(resizemovegadgets.pt, PTCT_ActivePartition, &partition);
610 D(bug("[HDToolBox] - Type : Partition\n"));
611 D(bug("[HDToolBox] - Old value : %ld\n", partition->de.de_HighCyl));
612 D(bug("[HDToolBox] - New value : %ld\n", value));
613 D(bug("[HDToolBox] - Partition table : %p\n", table));
614 D(bug("[HDToolBox] - Active partition : %p\n", partition));
615 if (value != partition->de.de_HighCyl)
617 block =
619 (value+1)*
620 partition->de.de_Surfaces*partition->de.de_BlocksPerTrack
621 )-1;
622 if (validValue(table, partition, block))
624 char str[32];
625 partition->listnode.flags |= LNF_IntermedChange;
626 partition->de.de_HighCyl = value;
627 nnset(resizemovegadgets.totalcyl, MUIA_String_Integer, partition->de.de_HighCyl-partition->de.de_LowCyl+1);
628 nnset(resizemovegadgets.pt, PTCT_PartitionTable, table);
629 getSizeStr
631 str,
634 (partition->de.de_HighCyl-partition->de.de_LowCyl+1)*
635 partition->de.de_Surfaces*partition->de.de_BlocksPerTrack
639 nnset(resizemovegadgets.size, MUIA_String_Contents, str);
641 else
642 nnset(object, MUIA_String_Integer, partition->de.de_HighCyl);
645 else if (type == PTS_EMPTY_AREA)
647 struct DosEnvec *de = NULL;
649 D(bug("[HDToolBox] - Type : Empty Area\n"));
650 get(resizemovegadgets.pt, PTCT_ActivePartition, &de);
651 if (value != de->de_HighCyl)
652 set(object, MUIA_String_Integer, de->de_HighCyl);
654 else
655 nnset(object, MUIA_String_Integer, 0);
657 else if (object == resizemovegadgets.totalcyl)
659 LONG type = 0;
660 ULONG value = 0;
662 get(object, MUIA_String_Integer, &value);
663 get(resizemovegadgets.pt, PTCT_ActiveType, &type);
664 if (type == PTS_PARTITION)
666 struct HDTBPartition *table = NULL;
667 struct HDTBPartition *partition = NULL;
668 ULONG block;
670 get(resizemovegadgets.pt, PTCT_PartitionTable, &table);
671 get(resizemovegadgets.pt, PTCT_ActivePartition, &partition);
672 if (value != (partition->de.de_HighCyl-partition->de.de_LowCyl+1))
674 block =
676 (partition->de.de_LowCyl+value)*
677 partition->de.de_Surfaces*partition->de.de_BlocksPerTrack
678 )-1;
679 if (validValue(table, partition, block))
681 char str[32];
682 partition->listnode.flags |= LNF_IntermedChange;
683 partition->de.de_HighCyl = partition->de.de_LowCyl+value-1;
684 set(resizemovegadgets.highcyl, MUIA_String_Integer, partition->de.de_HighCyl);
685 set(resizemovegadgets.pt, PTCT_PartitionTable, table);
686 getSizeStr
688 str,
691 (partition->de.de_HighCyl-partition->de.de_LowCyl+1)*
692 partition->de.de_Surfaces*partition->de.de_BlocksPerTrack
696 set(resizemovegadgets.size, MUIA_String_Contents, str);
698 else
699 set(object, MUIA_String_Integer, partition->de.de_HighCyl-partition->de.de_LowCyl+1);
702 else if (type == PTS_EMPTY_AREA)
704 struct DosEnvec *de = NULL;
706 get(resizemovegadgets.pt, PTCT_ActivePartition, &de);
707 if (value != (de->de_HighCyl-de->de_LowCyl+1))
708 set(object, MUIA_String_Integer, de->de_HighCyl-de->de_LowCyl+1);
710 else
711 set(object, MUIA_String_Integer, 0);
713 else if (object == resizemovegadgets.size)
715 char val[32];
716 struct DosEnvec *de = NULL;
717 STRPTR *str = NULL;
718 ULONG size = 0;
719 ULONG type = 0;
721 get(resizemovegadgets.pt, PTCT_ActiveType, &type);
722 if (type == PTS_PARTITION)
724 struct HDTBPartition *partition = NULL;
726 get(resizemovegadgets.pt, PTCT_ActivePartition, &partition);
727 de = &partition->de;
728 get(object, MUIA_String_Contents, &str);
729 size = sizeStrToUL((STRPTR)str);
730 size = (size*2+1)/partition->de.de_BlocksPerTrack/partition->de.de_Surfaces+1;
732 else if (type == PTS_EMPTY_AREA)
734 get(resizemovegadgets.pt, PTCT_ActivePartition, &de);
736 set(resizemovegadgets.totalcyl, MUIA_String_Integer, size);
737 set(resizemovegadgets.totalcyl, MUIA_String_Acknowledge, TRUE);
738 getSizeStr
740 val,
743 (de->de_HighCyl-de->de_LowCyl+1)*
744 de->de_Surfaces*de->de_BlocksPerTrack
748 set(resizemovegadgets.size, MUIA_String_Contents, val);
750 else if (object == renamegadgets.ok)
752 struct HDTBPartition *partition;
753 STRPTR name = NULL;
755 partition = (struct HDTBPartition *)renamegadgets.iln;
756 get(renamegadgets.name, MUIA_String_Contents, &name);
757 if (strcmp(name, partition->listnode.ln.ln_Name) != 0)
759 SetPartitionAttrsA(partition->ph, PT_NAME, name, TAG_DONE);
760 strcpy(partition->listnode.ln.ln_Name, name);
761 renamegadgets.iln->parent->flags |= LNF_ToSave;
762 setChanged(renamegadgets.iln);
765 else if (object == dosenvecgadgets.ok)
767 BOOL changed = FALSE;
768 LONG check = 0;
769 ULONG value = 0;
770 STRPTR str = NULL;
771 char *end;
772 struct HDTBPartition *partition;
774 partition = (struct HDTBPartition *)dosenvecgadgets.iln;
775 get(dosenvecgadgets.mask, MUIA_String_Integer, &value);
776 if (value != partition->de.de_Mask)
778 partition->de.de_Mask = value;
779 changed = TRUE;
781 get(dosenvecgadgets.maxtransfer, MUIA_String_Contents, &str);
782 value = strtoul(str, &end, 0);
783 if (*end == 0)
785 if (value != partition->de.de_MaxTransfer)
787 partition->de.de_MaxTransfer = value;
788 changed = TRUE;
791 get(dosenvecgadgets.custboot, MUIA_Selected, &check);
792 if (check)
794 if (partition->de.de_TableSize<(DE_BOOTBLOCKS+1))
796 partition->de.de_TableSize = DE_BOOTBLOCKS+1;
797 changed = TRUE;
799 get(dosenvecgadgets.numcustboot, MUIA_String_Integer, &value);
800 if (value != partition->de.de_BootBlocks)
802 partition->de.de_BootBlocks = value;
803 changed = TRUE;
806 else
808 if (partition->de.de_TableSize>=(DE_BOOTBLOCKS+1))
810 partition->de.de_TableSize = DE_BOOTBLOCKS;
811 partition->de.de_BootBlocks = 0;
812 changed = TRUE;
815 get(dosenvecgadgets.reservedblocksstart, MUIA_String_Integer, &value);
816 if (value != partition->de.de_Reserved)
818 partition->de.de_Reserved = value;
819 changed = TRUE;
821 get(dosenvecgadgets.reservedblocksend, MUIA_String_Integer, &value);
822 if (value != partition->de.de_PreAlloc)
824 partition->de.de_PreAlloc = value;
825 changed = TRUE;
827 get(dosenvecgadgets.blocksize, MUIA_Cycle_Active, &value);
828 value = 1<<(value+7);
829 if (value != partition->de.de_SizeBlock)
831 partition->de.de_SizeBlock = value;
832 changed = TRUE;
834 get(dosenvecgadgets.buffers, MUIA_String_Integer, &value);
835 if (value != partition->de.de_NumBuffers)
837 partition->de.de_NumBuffers = value;
838 changed = TRUE;
840 if (changed)
842 SetPartitionAttrsA(partition->ph, PT_DOSENVEC, &partition->de, TAG_DONE);
843 dosenvecgadgets.iln->parent->flags |= LNF_ToSave;
844 setChanged(dosenvecgadgets.iln);
847 else if (object == mountbootgadgets.ok)
849 struct HDTBPartition *partition;
850 BOOL changeda = FALSE;
851 BOOL changed = FALSE;
852 LONG check = 0;
853 ULONG value = 0;
855 partition = (struct HDTBPartition *)mountbootgadgets.iln;
856 get(mountbootgadgets.active, MUIA_Selected, &check);
857 if (check)
859 if (!(partition->flags & PNF_ACTIVE))
861 partition->flags |= PNF_ACTIVE;
862 changeda = TRUE;
865 else
867 if (partition->flags & PNF_ACTIVE)
869 partition->flags &= ~PNF_ACTIVE;
870 changeda = TRUE;
873 if (changeda)
875 if (partition->flags & PNF_ACTIVE)
877 struct HDTBPartition *other;
878 other = (struct HDTBPartition *)partition->listnode.ln.ln_Pred;
879 while (other->listnode.ln.ln_Pred)
881 if (other->listnode.ln.ln_Type == LNT_Partition)
883 if (other->flags & PNF_ACTIVE)
885 other->flags &= ~PNF_ACTIVE;
886 SetPartitionAttrsA(other->ph, PT_ACTIVE, FALSE, TAG_DONE);
887 setChanged(&other->listnode);
890 other = (struct HDTBPartition *)other->listnode.ln.ln_Pred;
892 other = (struct HDTBPartition *)partition->listnode.ln.ln_Succ;
893 while (other->listnode.ln.ln_Succ)
895 if (other->listnode.ln.ln_Type == LNT_Partition)
897 if (other->flags & PNF_ACTIVE)
899 other->flags &= ~PNF_ACTIVE;
900 SetPartitionAttrsA(other->ph, PT_ACTIVE, FALSE, TAG_DONE);
901 setChanged(&other->listnode);
904 other = (struct HDTBPartition *)other->listnode.ln.ln_Succ;
907 SetPartitionAttrsA(partition->ph, PT_ACTIVE, check, TAG_DONE);
908 changed = TRUE;
910 changeda = FALSE;
911 get(mountbootgadgets.automount, MUIA_Selected, &check);
912 if (check)
914 if (!(partition->flags & PNF_AUTOMOUNT))
916 partition->flags |= PNF_AUTOMOUNT;
917 changeda = TRUE;
920 else
922 if (partition->flags & PNF_AUTOMOUNT)
924 partition->flags &= ~PNF_AUTOMOUNT;
925 changeda = TRUE;
928 if (changeda)
930 SetPartitionAttrsA(partition->ph, PT_AUTOMOUNT, check, TAG_DONE);
931 changed = TRUE;
933 changeda = FALSE;
934 get(mountbootgadgets.bootable, MUIA_Selected, &check);
935 if (check)
937 if (!(partition->flags & PNF_BOOTABLE))
939 partition->flags |= PNF_BOOTABLE;
940 changeda = TRUE;
942 get(mountbootgadgets.bootpri, MUIA_String_Integer, &value);
943 if (value != partition->de.de_BootPri)
945 partition->de.de_BootPri = value;
946 changeda = TRUE;
949 else
951 if (partition->flags & PNF_BOOTABLE)
953 partition->flags &= ~PNF_BOOTABLE;
954 partition->de.de_BootPri = 0;
955 changeda = TRUE;
958 if (changeda)
960 SetPartitionAttrsA(partition->ph, PT_BOOTABLE, check, PT_DOSENVEC, &partition->de, TAG_DONE);
961 changed = TRUE;
963 if (changed)
965 mountbootgadgets.iln->parent->flags |= LNF_ToSave;
966 setChanged(mountbootgadgets.iln);
970 else
972 switch (i)
974 case GB_ADD_ENTRY:
975 DoMethod(gadgets.leftlv, MUIM_List_GetEntry, 0, (IPTR)&iln);
976 if (
977 (iln == NULL) ||
978 ((iln) && (iln->parent->parent == NULL))
981 set(adddevicegadgets.win, MUIA_Window_Open, TRUE);
983 else if ((iln->parent->ln.ln_Type == LNT_Harddisk) || (iln->parent->ln.ln_Type == LNT_Partition))
985 struct HDTBPartition *table;
986 table = (struct HDTBPartition *)iln->parent;
987 if (
989 (table->table->max_partitions) &&
990 (countNodes(&table->listnode.list, LNT_Partition)<table->table->max_partitions)
991 ) ||
992 (table->table->max_partitions == 0)
995 DoMethod
997 addpartitiongadgets.win,
998 MUIM_Notify, MUIA_Window_Open, TRUE, (IPTR)addpartitiongadgets.pt, 3,
999 MUIM_Set, PTCT_PartitionTable, (IPTR)table
1001 set(addpartitiongadgets.win, MUIA_Window_Open, TRUE);
1003 else
1004 set(gadgets.text, MUIA_Text_Contents, MSG(MSG_PARTITION_TABLE_FULL));
1006 break;
1007 case GB_REMOVE_ENTRY:
1008 get(gadgets.leftlv, MUIA_List_Active, &active);
1009 if (active != MUIV_List_Active_Off)
1011 DoMethod(gadgets.leftlv, MUIM_List_GetEntry, active, (IPTR)&iln);
1012 switch (iln->ln.ln_Type)
1014 case LNT_Device:
1015 DoMethod(gadgets.leftlv, MUIM_List_Remove, active);
1016 Remove(&iln->ln);
1017 freeDeviceNode((struct HDTBDevice *)iln);
1018 break;
1019 case LNT_Partition:
1021 struct HDTBPartition *partition;
1022 partition = (struct HDTBPartition *)iln;
1023 iln->parent->flags |= LNF_ToSave;
1024 setChanged(iln);
1025 DoMethod(gadgets.leftlv, MUIM_List_Remove, active);
1026 Remove(&iln->ln);
1027 DeletePartition(partition->ph);
1028 freePartitionNode(partition);
1032 break;
1033 case GB_CREATE_TABLE:
1034 case GB_CHANGE_TYPE:
1035 get(gadgets.leftlv, MUIA_List_Active, &active);
1036 if (active != MUIV_List_Active_Off)
1038 DoMethod(gadgets.leftlv, MUIM_List_GetEntry, active, (IPTR)&iln);
1039 if (
1040 (iln->ln.ln_Type == LNT_Harddisk) ||
1041 ((i==2) && (iln->ln.ln_Type == LNT_Partition))
1044 struct HDTBPartition *table;
1045 ULONG type = 0;
1046 partitiontabletypegadgets.iln = iln;
1047 table = (struct HDTBPartition *)iln;
1048 if (table->table)
1049 type = table->table->type;
1050 DoMethod(partitiontabletypegadgets.lv, MUIM_List_Clear);
1051 for (i=0;PartitionBase->tables[i] != NULL;i++)
1053 DoMethod
1055 partitiontabletypegadgets.lv,
1056 MUIM_List_InsertSingle, (IPTR)PartitionBase->tables[i]->pti_Name, MUIV_List_Insert_Bottom
1058 if (type == PartitionBase->tables[i]->pti_Type)
1059 set(partitiontabletypegadgets.lv, MUIA_List_Active, i);
1061 set(partitiontabletypegadgets.win, MUIA_Window_Open, TRUE);
1063 else if ((i==3) && (iln->ln.ln_Type == LNT_Partition))
1065 struct TypeNode *tn;
1066 struct HDTBPartition *partition;
1067 partitiontypegadgets.iln = iln;
1068 i = 0;
1069 DoMethod(partitiontypegadgets.lv, MUIM_List_Clear);
1070 partition = (struct HDTBPartition *)iln;
1071 partitiontypegadgets.ttn = findTableTypeNode(partition->root->table->type);
1072 if (partitiontypegadgets.ttn)
1074 tn = (struct TypeNode *)partitiontypegadgets.ttn->typelist->lh_Head;
1075 while (tn->ln.ln_Succ)
1077 DoMethod
1079 partitiontypegadgets.lv,
1080 MUIM_List_InsertSingle, (IPTR)tn->ln.ln_Name, MUIV_List_Insert_Bottom
1082 if (tn->type.id_len == partition->type.id_len)
1083 if (memcmp(tn->type.id, partition->type.id, tn->type.id_len) == 0)
1084 set(partitiontypegadgets.lv, MUIA_List_Active, i);
1085 tn = (struct TypeNode *)tn->ln.ln_Succ;
1086 i++;
1089 setTypeString(&partition->type, partitiontypegadgets.hexid);
1090 set(partitiontypegadgets.win, MUIA_Window_Open, TRUE);
1093 break;
1094 case GB_RESIZE_MOVE:
1095 break;
1096 case GB_PARENT:
1097 DoMethod(gadgets.leftlv, MUIM_List_GetEntry, 0, (IPTR)&iln);
1098 if (iln->ln.ln_Type == LNT_Parent)
1100 set(gadgets.leftlv, MUIA_List_Active, 0);
1101 set(gadgets.leftlv, MUIA_Listview_DoubleClick, TRUE);
1103 break;
1104 case GB_RENAME:
1105 get(gadgets.leftlv, MUIA_List_Active, &active);
1106 if (active != MUIV_List_Active_Off)
1108 DoMethod(gadgets.leftlv, MUIM_List_GetEntry, active, (IPTR)&iln);
1109 if (iln->ln.ln_Type == LNT_Partition)
1111 struct HDTBPartition *partition;
1112 partition = (struct HDTBPartition *)iln;
1113 if (getAttrInfo(partition->root->table->pattrlist, PTA_NAME) & PLAM_READ)
1115 renamegadgets.iln = iln;
1116 set(renamegadgets.name, MUIA_String_Contents, iln->ln.ln_Name);
1117 set(renamegadgets.win, MUIA_Window_Open, TRUE);
1121 break;
1122 case GB_DOSENVEC:
1123 get(gadgets.leftlv, MUIA_List_Active, &active);
1124 if (active != MUIV_List_Active_Off)
1126 DoMethod(gadgets.leftlv, MUIM_List_GetEntry, active, (IPTR)&iln);
1127 if (iln->ln.ln_Type == LNT_Partition)
1129 struct HDTBPartition *partition;
1130 partition = (struct HDTBPartition *)iln;
1131 if (getAttrInfo(partition->root->table->pattrlist, PTA_DOSENVEC) & PLAM_READ)
1133 char str[32];
1134 dosenvecgadgets.iln = iln;
1135 set(dosenvecgadgets.mask, MUIA_String_Integer, partition->de.de_Mask);
1136 sprintf(str, "0x%08lx", partition->de.de_MaxTransfer);
1137 set(dosenvecgadgets.maxtransfer, MUIA_String_Contents, str);
1138 if (partition->de.de_TableSize>=(DE_BOOTBLOCKS+1))
1140 set(dosenvecgadgets.custboot, MUIA_Selected, TRUE);
1141 set(dosenvecgadgets.numcustboot, MUIA_String_Integer, partition->de.de_BootBlocks);
1143 else
1144 set(dosenvecgadgets.custboot, MUIA_Selected, FALSE);
1145 set(dosenvecgadgets.reservedblocksstart, MUIA_String_Integer, partition->de.de_Reserved);
1146 set(dosenvecgadgets.reservedblocksend, MUIA_String_Integer, partition->de.de_PreAlloc);
1147 set(dosenvecgadgets.blocksize, MUIA_Cycle_Active, getBitNum(partition->de.de_SizeBlock>>7));
1148 set(dosenvecgadgets.buffers, MUIA_String_Integer, partition->de.de_NumBuffers);
1149 set(dosenvecgadgets.win, MUIA_Window_Open, TRUE);
1153 break;
1154 case GB_SWITCHES:
1155 get(gadgets.leftlv, MUIA_List_Active, &active);
1156 if (active != MUIV_List_Active_Off)
1158 DoMethod(gadgets.leftlv, MUIM_List_GetEntry, active, (IPTR)&iln);
1159 if (iln->ln.ln_Type == LNT_Partition)
1161 struct HDTBPartition *partition;
1162 BOOL active;
1163 BOOL automount;
1164 BOOL bootable;
1165 partition = (struct HDTBPartition *)iln;
1166 active = getAttrInfo(partition->root->table->pattrlist, PTA_ACTIVE);
1167 automount = getAttrInfo(partition->root->table->pattrlist, PTA_AUTOMOUNT);
1168 bootable = getAttrInfo(partition->root->table->pattrlist, PTA_BOOTABLE);
1169 if ((active | automount | bootable) & PLAM_READ)
1171 mountbootgadgets.iln = iln;
1172 set(mountbootgadgets.active, MUIA_Disabled, !(active & PLAM_READ));
1173 set(mountbootgadgets.automount, MUIA_Disabled, !(automount & PLAM_READ));
1174 set(mountbootgadgets.bootable, MUIA_Disabled, !(bootable & PLAM_READ));
1175 set(mountbootgadgets.bootpri, MUIA_Disabled, !(bootable & PLAM_READ));
1176 set(mountbootgadgets.active, MUIA_Selected, (partition->flags & PNF_ACTIVE) ? TRUE : FALSE);
1177 set(mountbootgadgets.automount, MUIA_Selected, (partition->flags & PNF_AUTOMOUNT) ? TRUE : FALSE);
1178 if (partition->flags & PNF_BOOTABLE)
1180 set(mountbootgadgets.bootable, MUIA_Selected, TRUE);
1181 set(mountbootgadgets.bootpri, MUIA_String_Integer, partition->de.de_BootPri);
1183 else
1184 set(mountbootgadgets.bootable, MUIA_Selected, FALSE);
1185 set(mountbootgadgets.win, MUIA_Window_Open, TRUE);
1189 break;
1190 case GB_SAVE_CHANGES:
1191 get(gadgets.leftlv, MUIA_List_Active, &active);
1192 if (active != MUIV_List_Active_Off)
1194 DoMethod(gadgets.leftlv, MUIM_List_GetEntry, active, (IPTR)&iln);
1195 saveChanges(iln, TRUE);
1197 break;
1201 AROS_USERFUNC_EXIT
1205 * DosEnvec of all partitions holds cylinder numbers relative to partition start.
1206 * This function returns absolute start cylinder number for the partition.
1208 static ULONG GetStartCyl(struct HDTBPartition *part)
1210 ULONG blockspercyl = part->de.de_Surfaces * part->de.de_BlocksPerTrack;
1211 ULONG ret = 0;
1213 while (part->listnode.parent)
1215 part = (struct HDTBPartition *)part->listnode.parent;
1217 if (part->listnode.ln.ln_Type != LNT_Partition)
1218 break;
1221 * Calculate start offset in blocks. This can be done because theoretically
1222 * partitions can have different virtual geometries.
1224 ret += part->de.de_LowCyl * part->de.de_Surfaces * part->de.de_BlocksPerTrack;
1228 * FIXME: What if this can't be divided in interegs?
1229 * This can happen for example if the disk was partitioned on another machine where
1230 * disk driver reported different (virtual) geometry. In this case we should be able
1231 * to adjust mountlist geometry (Surfaces and BlocksPerTrack) so that division works
1232 * correctly and CHS-LBA relationship is still not broken.
1234 return ret / blockspercyl;
1237 static struct FileSysEntry *FindFileSysEntry(ULONG dostype)
1239 struct FileSysEntry *fse;
1240 struct FileSysResource *fsr = OpenResource("FileSystem.resource");
1242 if (!fsr)
1243 return NULL;
1245 ForeachNode(&fsr->fsr_FileSysEntries, fse)
1247 if (fse->fse_DosType == dostype)
1248 return fse;
1251 return NULL;
1254 AROS_UFH3(void, createml_function,
1255 AROS_UFHA(struct Hook *, h, A0),
1256 AROS_UFHA(Object *, object, A2),
1257 AROS_UFHA(ULONG *, arg, A1))
1259 AROS_USERFUNC_INIT
1261 IPTR active = MUIA_List_Active;
1262 struct HDTBPartition *partition = NULL;
1264 get(gadgets.leftlv, MUIA_List_Active, &active);
1265 if (active != MUIV_List_Active_Off)
1267 struct FileRequester *req;
1268 struct TagItem asltags[] =
1270 {ASLFR_InitialDrawer, (IPTR)"SYS:Storage/DOSDrivers"},
1271 {ASLFR_InitialFile , 0},
1272 {ASLFR_DoSaveMode , TRUE},
1273 {TAG_DONE , 0}
1276 DoMethod(gadgets.leftlv, MUIM_List_GetEntry, active, &partition);
1277 asltags[1].ti_Data = (IPTR)partition->listnode.ln.ln_Name;
1279 req = MUI_AllocAslRequest(ASL_FileRequest, asltags);
1281 if (!req)
1282 return;
1284 if (MUI_AslRequest(req, NULL))
1286 ULONG len = strlen(req->fr_Drawer) + strlen(req->fr_File) + 2;
1287 STRPTR pathname = AllocMem(len, MEMF_ANY);
1289 if (pathname)
1291 BPTR file;
1293 strcpy(pathname, req->fr_Drawer);
1294 AddPart(pathname, req->fr_File, len);
1296 file = Open(pathname, MODE_NEWFILE);
1297 FreeMem(pathname, len);
1299 if (file)
1301 struct DiskObject *icon;
1302 CONST_STRPTR args[2];
1303 ULONG argu[18];
1304 struct FileSysEntry *fse;
1305 ULONG startcyl = GetStartCyl(partition);
1307 args[ 0] = "";
1308 args[ 1] = partition->ph->bd->ioreq->iotd_Req.io_Device->dd_Library.lib_Node.ln_Name;
1310 argu[ 0] = ((struct HDNode *)partition->root)->unit;
1311 argu[ 1] = partition->de.de_SizeBlock * 4; /* block size in longs */
1312 argu[ 2] = partition->de.de_Surfaces;
1313 argu[ 3] = partition->de.de_SectorPerBlock;
1314 argu[ 4] = partition->de.de_BlocksPerTrack;
1315 argu[ 5] = partition->de.de_Reserved;
1316 argu[ 6] = partition->de.de_PreAlloc;
1317 argu[ 7] = partition->de.de_Interleave;
1318 argu[ 8] = partition->de.de_MaxTransfer;
1319 argu[ 9] = partition->de.de_Mask;
1320 argu[10] = partition->de.de_LowCyl + startcyl;
1321 argu[11] = partition->de.de_HighCyl + startcyl;
1322 argu[12] = partition->de.de_NumBuffers;
1323 argu[13] = partition->de.de_BufMemType;
1324 argu[14] = 16384;
1325 argu[15] = 0;
1326 argu[16] = -1;
1327 argu[17] = partition->de.de_DosType;
1330 * Some things can be fetched only from FileSystem.resource.
1331 * Let's try to do it.
1333 fse = FindFileSysEntry(partition->de.de_DosType);
1334 if (fse)
1336 if (fse->fse_PatchFlags & FSEF_HANDLER)
1337 args[0] = AROS_BSTR_ADDR(fse->fse_Handler);
1339 if (fse->fse_PatchFlags & FSEF_STACKSIZE)
1340 argu[14] = fse->fse_StackSize;
1342 if (fse->fse_PatchFlags & FSEF_PRIORITY)
1343 argu[15] = fse->fse_Priority;
1345 if (fse->fse_PatchFlags & FSEF_GLOBALVEC)
1346 argu[16] = (ULONG)(IPTR)fse->fse_GlobalVec;
1349 VFPrintf(file, "FileSystem = %s\n"
1350 "Device = %s\n",
1351 (RAWARG)args);
1352 VFPrintf(file,"Unit = %ld\n"
1353 "BlockSize = %ld\n"
1354 "Surfaces = %ld\n"
1355 "SectorsPerBlock = %ld\n"
1356 "BlocksPerTrack = %ld\n"
1357 "Reserved = %ld\n"
1358 "PreAlloc = %ld\n"
1359 "Interleave = %ld\n"
1360 "MaxTransfer = 0x%08lx\n"
1361 "Mask = 0x%08lx\n"
1362 "LowCyl = %ld\n"
1363 "HighCyl = %ld\n"
1364 "Buffers = %ld\n"
1365 "BufMemType = %ld\n"
1366 "StackSize = %ld\n"
1367 "Priority = %ld\n"
1368 "GlobVec = %ld\n"
1369 "DosType = 0x%08lx\n"
1370 "Activate = 1\n",
1371 (RAWARG)argu);
1373 Close(file);
1375 icon = GetDiskObject("ENVARC:Sys/def_Mountlist");
1376 if (icon)
1378 PutDiskObject(pathname, icon);
1379 FreeDiskObject(icon);
1385 MUI_FreeAslRequest(req);
1388 AROS_USERFUNC_EXIT
1391 /************************* general List functions ***************************/
1393 LONG InitListNode(struct ListNode *node, struct ListNode *parent)
1395 struct ListNode *new;
1397 D(bug("[HDToolBox] InitListNode()\n"));
1399 NEWLIST(&node->list);
1400 new = AllocMem(sizeof(struct ListNode), MEMF_PUBLIC | MEMF_CLEAR);
1401 if (new)
1403 node->parent = parent;
1404 new->ln.ln_Name = "..";
1405 new->ln.ln_Type = LNT_Parent;
1406 new->ln.ln_Pri = 127;
1407 new->parent = node;
1408 AddTail(&node->list, &new->ln);
1409 return TRUE;
1411 return FALSE;
1414 void UninitListNode(struct ListNode *node)
1416 struct ListNode *parent, *next;
1418 D(bug("[HDToolBox] UninitListNode()\n"));
1420 /* free parent entry */
1421 parent = (struct ListNode *)node->list.lh_Head;
1422 while (parent->ln.ln_Succ)
1424 next = (struct ListNode *)parent->ln.ln_Succ;
1425 if (parent->ln.ln_Type == LNT_Parent)
1427 Remove(&parent->ln);
1428 FreeMem(parent, sizeof(struct ListNode));
1429 return;
1431 parent = next;
1435 void InsertList(Object *list, struct ListNode *node)
1437 D(bug("[HDToolBox] InsertList()\n"));
1439 DoMethod(list, MUIM_List_InsertSingle, (IPTR)node, MUIV_List_Insert_Bottom);
1442 void ShowList(Object *list, struct List *lh)
1444 struct ListNode *lnode;
1446 D(bug("[HDToolBox] ShowList()\n"));
1448 DoMethod(list, MUIM_List_Clear);
1449 lnode = (struct ListNode *)lh->lh_Head;
1450 while (lnode->ln.ln_Succ)
1452 if (
1454 ((lnode->ln.ln_Type == LNT_Parent) && (lnode->parent->parent != NULL)) ||
1455 (lnode->ln.ln_Type != LNT_Parent)
1456 ) &&
1457 (!(lnode->flags & LNF_Invalid))
1460 DoMethod(list, MUIM_List_InsertSingle, (IPTR)lnode, MUIV_List_Insert_Bottom);
1462 lnode = (struct ListNode *)lnode->ln.ln_Succ;
1466 void disableObject(Object *object)
1468 LONG disabled = FALSE;
1470 D(bug("[HDToolBox] disableObject()\n"));
1472 get(object, MUIA_Disabled, &disabled);
1473 if (disabled == FALSE)
1475 set(object, MUIA_Disabled, TRUE);
1479 void enableObject(Object *object)
1481 LONG disabled = FALSE;
1483 D(bug("[HDToolBox] enableObject()\n"));
1485 get(object, MUIA_Disabled, &disabled);
1486 if (disabled == TRUE)
1488 set(object, MUIA_Disabled, FALSE);
1493 /********************************** Left Listview ***************************/
1495 struct LeftListview__Data
1497 struct IOStdReq ioreq;
1498 struct MUI_EventHandlerNode ehn;
1501 BOOPSI_DISPATCHER(IPTR, LeftListview_Dispatcher, CLASS, self, message)
1503 IPTR retval = 0;
1505 switch (message->MethodID)
1507 case OM_NEW:
1509 struct opSet *msg = (struct opSet *)message;
1511 retval = DoSuperMethod(CLASS, self, OM_NEW, msg->ops_AttrList, NULL);
1512 if (retval)
1514 struct LeftListview__Data *data = INST_DATA(CLASS, retval);
1515 data->ehn.ehn_Events = IDCMP_RAWKEY;
1516 data->ehn.ehn_Priority = 0;
1517 data->ehn.ehn_Flags = 0;
1518 data->ehn.ehn_Object = (Object *)retval;
1519 data->ehn.ehn_Class = CLASS;
1521 break;
1523 case MUIM_Setup:
1525 if ((retval = DoSuperMethodA(CLASS, self, message)))
1527 struct LeftListview__Data *data = INST_DATA(CLASS, self);
1529 if (0 == OpenDevice("console.device", -1, (struct IORequest *)&data->ioreq, 0)) {
1530 ConsoleDevice = (struct Library *)data->ioreq.io_Device;
1531 DoMethod(_win(self), MUIM_Window_AddEventHandler, (IPTR) &data->ehn);
1534 break;
1536 case MUIM_Cleanup:
1538 struct LeftListview__Data *data = INST_DATA(CLASS, self);
1540 if (ConsoleDevice)
1542 DoMethod(_win(self), MUIM_Window_RemEventHandler, (IPTR) &data->ehn);
1543 CloseDevice((struct IORequest *)&data->ioreq);
1546 retval = DoSuperMethodA(CLASS, self, message);
1547 break;
1549 case MUIM_HandleEvent:
1551 struct MUIP_HandleEvent *msg = (struct MUIP_HandleEvent *)message;
1553 if ((ConsoleDevice) && (msg->imsg) && (msg->imsg->Class == IDCMP_RAWKEY))
1555 unsigned char buffer[10];
1556 struct InputEvent keyEvent;
1557 UBYTE numchars;
1559 keyEvent.ie_Class = IECLASS_RAWKEY;
1560 keyEvent.ie_Code = msg->imsg->Code;
1561 keyEvent.ie_Qualifier = msg->imsg->Qualifier;
1562 keyEvent.ie_EventAddress = (APTR) (msg->imsg->IAddress);
1564 numchars = RawKeyConvert(&keyEvent, (char *)buffer, sizeof(buffer), NULL);
1566 if ((numchars == 1) && (buffer[0] == 13))
1568 SET(self, MUIA_Listview_DoubleClick, TRUE);
1569 retval = MUI_EventHandlerRC_Eat;
1571 break;
1575 default:
1576 retval = DoSuperMethodA(CLASS, self, message);
1579 return retval;
1581 BOOPSI_DISPATCHER_END
1583 AROS_UFH3(void, lv_doubleclick,
1584 AROS_UFHA(struct Hook *, h, A0),
1585 AROS_UFHA(Object *, object, A2),
1586 AROS_UFHA(void *, arg, A1))
1588 AROS_USERFUNC_INIT
1590 LONG active = MUIV_List_Active_Off;
1591 LONG type = -1;
1592 struct ListNode *iln;
1594 D(bug("[HDToolBox] lv_doubleclick()\n"));
1596 get(object, MUIA_List_Active, &active);
1597 if (active != MUIV_List_Active_Off)
1599 DoMethod(object,MUIM_List_GetEntry,active, (IPTR)&iln);
1600 if (iln->flags & LNF_Listable)
1602 ShowList(object, &iln->list);
1603 type = iln->ln.ln_Type;
1605 else if (iln->ln.ln_Type == LNT_Parent)
1607 if (iln->parent->parent)
1609 ShowList(object, &iln->parent->parent->list);
1610 type = iln->parent->parent->ln.ln_Type;
1611 iln = iln->parent;
1614 switch (type)
1616 case LNT_Root:
1617 enableObject(gadgets.buttons[GB_ADD_ENTRY]);
1618 disableObject(gadgets.buttons[GB_REMOVE_ENTRY]);
1619 disableObject(gadgets.buttons[GB_CREATE_TABLE]);
1620 disableObject(gadgets.buttons[GB_CHANGE_TYPE]);
1621 disableObject(gadgets.buttons[GB_RESIZE_MOVE]);
1622 disableObject(gadgets.buttons[GB_PARENT]);
1623 disableObject(gadgets.buttons[GB_RENAME]);
1624 disableObject(gadgets.buttons[GB_DOSENVEC]);
1625 disableObject(gadgets.buttons[GB_SWITCHES]);
1626 disableObject(gadgets.buttons[GB_SAVE_CHANGES]);
1627 break;
1628 case LNT_Device:
1629 disableObject(gadgets.buttons[GB_ADD_ENTRY]);
1630 disableObject(gadgets.buttons[GB_REMOVE_ENTRY]);
1631 disableObject(gadgets.buttons[GB_CREATE_TABLE]);
1632 disableObject(gadgets.buttons[GB_CHANGE_TYPE]);
1633 disableObject(gadgets.buttons[GB_RESIZE_MOVE]);
1634 enableObject(gadgets.buttons[GB_PARENT]);
1635 disableObject(gadgets.buttons[GB_RENAME]);
1636 disableObject(gadgets.buttons[GB_DOSENVEC]);
1637 disableObject(gadgets.buttons[GB_SWITCHES]);
1638 disableObject(gadgets.buttons[GB_SAVE_CHANGES]);
1639 break;
1640 case LNT_Harddisk:
1641 case LNT_Partition:
1642 enableObject(gadgets.buttons[GB_ADD_ENTRY]);
1643 disableObject(gadgets.buttons[GB_REMOVE_ENTRY]);
1644 disableObject(gadgets.buttons[GB_CREATE_TABLE]);
1645 disableObject(gadgets.buttons[GB_CHANGE_TYPE]);
1646 enableObject(gadgets.buttons[GB_RESIZE_MOVE]);
1647 enableObject(gadgets.buttons[GB_PARENT]);
1648 disableObject(gadgets.buttons[GB_RENAME]);
1649 disableObject(gadgets.buttons[GB_DOSENVEC]);
1650 disableObject(gadgets.buttons[GB_SWITCHES]);
1651 disableObject(gadgets.buttons[GB_SAVE_CHANGES]);
1652 DoMethod(gadgets.buttons[GB_RESIZE_MOVE], MUIM_KillNotify, MUIA_Pressed);
1653 DoMethod
1655 gadgets.buttons[GB_RESIZE_MOVE],
1656 MUIM_Notify, MUIA_Pressed, FALSE, (IPTR)resizemovegadgets.win, 3,
1657 MUIM_Set, MUIA_Window_Open, TRUE
1659 DoMethod
1661 resizemovegadgets.win,
1662 MUIM_Notify, MUIA_Window_Open, TRUE, (IPTR)resizemovegadgets.pt, 3,
1663 MUIM_Set, PTCT_PartitionTable, (IPTR)iln
1665 break;
1669 AROS_USERFUNC_EXIT
1672 AROS_UFH3(void, lv_click,
1673 AROS_UFHA(struct Hook *, h, A0),
1674 AROS_UFHA(Object *, object, A2),
1675 AROS_UFHA(void *, arg, A1))
1677 AROS_USERFUNC_INIT
1679 LONG active = MUIV_List_Active_Off;
1680 struct ListNode *iln;
1681 char str[64];
1682 char sizestr[16];
1684 D(bug("[HDToolBox] lv_click()\n"));
1686 get(object, MUIA_List_Active, &active);
1687 if (active != MUIV_List_Active_Off)
1689 DoMethod(object,MUIM_List_GetEntry,active, (IPTR)&iln);
1690 DoMethod(gadgets.rightlv, MUIM_List_Clear);
1691 switch (iln->ln.ln_Type)
1693 case LNT_Device:
1694 sprintf(str, "%s: %d", MSG(WORD_Units),(int)countNodes(&iln->list, LNT_Harddisk));
1695 DoMethod(gadgets.rightlv, MUIM_List_InsertSingle, (IPTR)str, MUIV_List_Insert_Bottom);
1696 enableObject(gadgets.buttons[GB_REMOVE_ENTRY]);
1697 if (iln->change_count > 0)
1698 enableObject(gadgets.buttons[GB_SAVE_CHANGES]);
1699 else
1700 disableObject(gadgets.buttons[GB_SAVE_CHANGES]);
1701 break;
1702 case LNT_Harddisk:
1703 case LNT_Partition:
1705 struct HDTBPartition *partition;
1706 partition = (struct HDTBPartition *)iln;
1707 getSizeStr
1709 sizestr,
1712 (partition->de.de_HighCyl-partition->de.de_LowCyl+1)*
1713 partition->de.de_Surfaces*partition->de.de_BlocksPerTrack
1717 sprintf(str, "%s: %s", MSG(WORD_Size), sizestr);
1718 DoMethod(gadgets.rightlv, MUIM_List_InsertSingle, (IPTR)str, MUIV_List_Insert_Bottom);
1719 sprintf(str, "%s: ", MSG(WORD_Partition_Table));
1720 if (partition->table)
1722 struct TableTypeNode *ttn;
1723 ttn = findTableTypeNode(partition->table->type);
1724 strcat(str, ttn->pti->pti_Name);
1725 DoMethod(gadgets.rightlv, MUIM_List_InsertSingle, (IPTR)str, MUIV_List_Insert_Bottom);
1726 sprintf(str, "%s: %d", MSG(WORD_Partitions), (int)countNodes(&iln->list, LNT_Partition));
1727 DoMethod(gadgets.rightlv, MUIM_List_InsertSingle, (IPTR)str, MUIV_List_Insert_Bottom);
1729 else
1731 strcat(str, MSG(WORD_Unknown));
1732 DoMethod(gadgets.rightlv, MUIM_List_InsertSingle, (IPTR)str, MUIV_List_Insert_Bottom);
1734 if (iln->ln.ln_Type == LNT_Partition)
1736 struct TypeNode *type;
1737 type = findPartitionType(&partition->type, partition->root->table->type);
1738 sprintf(str, "%s: ", MSG(WORD_Partition_Type));
1739 if (type)
1740 strcat(str, type->ln.ln_Name);
1741 else
1742 strcat(str, MSG(WORD_Unknown));
1743 DoMethod(gadgets.rightlv, MUIM_List_InsertSingle, (IPTR)str, MUIV_List_Insert_Bottom);
1744 sprintf(str, "%s: ", MSG(WORD_Active));
1745 if (partition->flags & PNF_ACTIVE)
1746 strcat(str, MSG_STD(YESSTR));
1747 else
1748 strcat(str, MSG_STD(NOSTR));
1749 DoMethod(gadgets.rightlv, MUIM_List_InsertSingle, (IPTR)str, MUIV_List_Insert_Bottom);
1750 sprintf(str, "%s: ", MSG(WORD_Bootable));
1751 if (partition->flags & PNF_BOOTABLE)
1752 strcat(str, MSG_STD(YESSTR));
1753 else
1754 strcat(str, MSG_STD(NOSTR));
1755 DoMethod(gadgets.rightlv, MUIM_List_InsertSingle, (IPTR)str, MUIV_List_Insert_Bottom);
1756 sprintf(str, "%s: ", MSG(WORD_Automount));
1757 if (partition->flags & PNF_AUTOMOUNT)
1758 strcat(str, MSG_STD(YESSTR));
1759 else
1760 strcat(str, MSG_STD(NOSTR));
1761 DoMethod(gadgets.rightlv, MUIM_List_InsertSingle, (IPTR)str, MUIV_List_Insert_Bottom);
1762 enableObject(gadgets.buttons[GB_REMOVE_ENTRY]);
1763 enableObject(gadgets.buttons[GB_RENAME]);
1764 enableObject(gadgets.buttons[GB_DOSENVEC]);
1765 enableObject(gadgets.buttons[GB_SWITCHES]);
1766 SetAttrs(part_item, MUIA_Menu_Enabled, !partition->table, TAG_DONE);
1768 else if (iln->ln.ln_Type == LNT_Harddisk)
1770 if (iln->change_count > 0)
1771 enableObject(gadgets.buttons[GB_SAVE_CHANGES]);
1772 else
1773 disableObject(gadgets.buttons[GB_SAVE_CHANGES]);
1775 enableObject(gadgets.buttons[GB_CREATE_TABLE]);
1776 enableObject(gadgets.buttons[GB_CHANGE_TYPE]);
1778 break;
1779 case LNT_Parent:
1780 disableObject(gadgets.buttons[GB_REMOVE_ENTRY]);
1781 disableObject(gadgets.buttons[GB_RENAME]);
1782 disableObject(gadgets.buttons[GB_DOSENVEC]);
1783 disableObject(gadgets.buttons[GB_SWITCHES]);
1784 disableObject(gadgets.buttons[GB_CREATE_TABLE]);
1785 disableObject(gadgets.buttons[GB_CHANGE_TYPE]);
1786 disableObject(gadgets.buttons[GB_SAVE_CHANGES]);
1787 SetAttrs(part_item, MUIA_Menu_Enabled, FALSE, TAG_DONE);
1788 break;
1792 AROS_USERFUNC_EXIT
1795 /**************************************** Main ******************************/
1797 LONG initGUI(void)
1799 struct MUI_CustomClass *listcc;
1800 int i;
1802 D(bug("[HDToolBox] initGUI()\n"));
1804 MUIMasterBase = OpenLibrary("muimaster.library", 0);
1805 if (!MUIMasterBase)
1806 return ERR_MUIMASTER;
1808 ptclass = makePTClass();
1809 if (ptclass == NULL)
1810 return ERR_GADGETS;
1812 listcc = MUI_CreateCustomClass(NULL, MUIC_Listview, NULL,
1813 sizeof(struct LeftListview__Data), LeftListview_Dispatcher);
1814 if (listcc == NULL)
1815 return ERR_GADGETS;
1817 hook_display.h_Entry = (HOOKFUNC)display_function;
1818 hook_buttons.h_Entry = (HOOKFUNC)buttons_function;
1819 hook_createml.h_Entry = (HOOKFUNC)createml_function;
1820 hook_lv_doubleclick.h_Entry = (HOOKFUNC)lv_doubleclick;
1821 hook_lv_click.h_Entry = (HOOKFUNC)lv_click;
1822 partitiontypegadgets.hook_hexidedit.h_Entry = (HOOKFUNC)hexidedit_function;
1824 app = ApplicationObject,
1825 MUIA_Application_Title , "HDToolBox",
1826 MUIA_Application_Version , "$VER: HDToolBox 0.5 (19.5.2015)",
1827 MUIA_Application_Copyright , "(c) 1995-2014 AROS Development Team",
1828 MUIA_Application_Author , "Bearly, Ogun, Fats and others at AROS",
1829 MUIA_Application_Description, "Partition your disks.",
1830 MUIA_Application_Base , "HDTOOLBOX",
1831 MUIA_Application_Menustrip, MenustripObject,
1832 MUIA_Family_Child, MenuObject,
1833 MUIA_Menu_Title, MSG(WORD_MENU_Project),
1834 MUIA_Family_Child,
1835 about_item = MenuitemObject, MUIA_Menuitem_Title, MSG(WORD_MENU_About),
1836 End,
1837 MUIA_Family_Child,
1838 quit_item = MenuitemObject, MUIA_Menuitem_Title, MSG(WORD_MENU_Quit),
1839 End,
1840 End,
1841 MUIA_Family_Child,
1842 part_item = MenuObject,
1843 MUIA_Menu_Title, MSG(WORD_MENU_Partition),
1844 MUIA_Menu_Enabled, FALSE,
1845 MUIA_Family_Child,
1846 createml_item = MenuitemObject,
1847 MUIA_Menuitem_Title, MSG(WORD_MENU_CreateMountlist),
1848 End,
1849 End,
1850 End,
1851 SubWindow, mainwin = WindowObject,
1852 MUIA_Window_Title, "HDToolBox",
1853 MUIA_Window_ID, MAKE_ID('H','D','T','B'),
1854 MUIA_Window_Activate, TRUE,
1855 MUIA_Window_Height, MUIV_Window_Height_Visible(50),
1856 MUIA_Window_Width, MUIV_Window_Width_Visible(60),
1857 WindowContents, VGroup,
1858 Child, VGroup,
1859 GroupFrame,
1860 Child, gadgets.text = TextObject,
1861 TextFrame,
1862 MUIA_Text_Contents, MSG(MSG_Welcome),
1863 End,
1864 Child, HGroup,
1865 Child, (gadgets.leftlv = NewObject(listcc->mcc_Class, NULL,
1866 MUIA_Listview_List, ListObject,
1867 InputListFrame,
1868 MUIA_CycleChain, 1,
1869 MUIA_List_DisplayHook, &hook_display,
1870 MUIA_List_Format, ",",
1871 MUIA_List_Title, TRUE,
1872 End,
1873 TAG_DONE)),
1874 Child, ListviewObject,
1875 MUIA_Listview_List, (gadgets.rightlv = ListObject,
1876 ReadListFrame,
1877 MUIA_List_Title, TRUE,
1878 MUIA_List_ConstructHook, MUIV_List_ConstructHook_String,
1879 MUIA_List_DestructHook, MUIV_List_DestructHook_String,
1880 End),
1881 MUIA_Listview_Input, FALSE,
1882 End,
1883 End,
1884 End,
1885 Child, VGroup,
1886 GroupFrame,
1887 Child, HGroup,
1888 Child, VGroup,
1889 Child, gadgets.buttons[GB_ADD_ENTRY] = SIMPLEBUTTON(WORD_AddEntry),
1890 Child, gadgets.buttons[GB_REMOVE_ENTRY] = SIMPLEBUTTON(WORD_RemoveEntry),
1891 End,
1892 Child, VGroup,
1893 Child, gadgets.buttons[GB_CREATE_TABLE] = SIMPLEBUTTON(WORD_Create_Table),
1894 Child, gadgets.buttons[GB_CHANGE_TYPE] = SIMPLEBUTTON(WORD_Change_Type),
1895 End,
1896 Child, VGroup,
1897 Child, gadgets.buttons[GB_RESIZE_MOVE] = SIMPLEBUTTON(WORD_Resize_Move),
1898 Child, gadgets.buttons[GB_PARENT] = SIMPLEBUTTON(WORD_Parent),
1899 End,
1900 Child, VGroup,
1901 Child, gadgets.buttons[GB_RENAME] = SIMPLEBUTTON(WORD_Rename),
1902 Child, gadgets.buttons[GB_DOSENVEC] = SIMPLEBUTTON(WORD_DosEnvec),
1903 End,
1904 Child, VGroup,
1905 Child, gadgets.buttons[GB_SWITCHES] = SIMPLEBUTTON(WORD_Switches),
1906 Child, HVSpace,
1907 End,
1908 End,
1909 Child, HGroup,
1910 MUIA_Group_SameWidth, TRUE,
1911 MUIA_FixHeight, 1,
1912 Child, gadgets.buttons[GB_SAVE_CHANGES] = IMAGEBUTTON(WORD_Save_Changes, COOL_SAVEIMAGE_ID),
1913 Child, gadgets.buttons[GB_EXIT] = IMAGEBUTTON(WORD_Exit, COOL_CANCELIMAGE_ID),
1914 End,
1915 End,
1916 End,
1917 End,
1918 SubWindow, adddevicegadgets.win = WindowObject,
1919 MUIA_Window_Title, MSG(WORD_Devices),
1920 MUIA_Window_Activate, TRUE,
1921 WindowContents, VGroup,
1922 Child, PopaslObject,
1923 MUIA_Popstring_String, adddevicegadgets.file = StringObject,
1924 StringFrame,
1925 End,
1926 MUIA_Popstring_Button, PopButton(MUII_PopFile),
1927 End,
1928 Child, HGroup,
1929 MUIA_Group_SameWidth, TRUE,
1930 MUIA_FixHeight, 1,
1931 Child, adddevicegadgets.ok = IMAGEBUTTON(WORD_Ok, COOL_USEIMAGE_ID),
1932 Child, adddevicegadgets.cancel = IMAGEBUTTON(WORD_Cancel, COOL_CANCELIMAGE_ID),
1933 End,
1934 End,
1935 End,
1936 SubWindow, addpartitiongadgets.win = WindowObject,
1937 MUIA_Window_Title, MSG(MSG_Select_Empty_Area),
1938 MUIA_Window_Activate, TRUE,
1939 WindowContents, VGroup,
1940 Child, addpartitiongadgets.pt = BoopsiObject,
1941 GroupFrame,
1942 MUIA_Boopsi_Class, ptclass,
1943 MUIA_Boopsi_MinWidth, 600,
1944 MUIA_Boopsi_MinHeight, 100,
1945 MUIA_Boopsi_TagDrawInfo, GA_DrawInfo,
1946 MUIA_Boopsi_Remember, PTCT_PartitionTable,
1947 MUIA_Boopsi_Remember, PTCT_Flags,
1948 PTCT_Flags, PTCTF_NoPartitionMove | PTCTF_EmptySelectOnly,
1949 GA_Left, 0,
1950 GA_Top, 0,
1951 GA_Width, 0,
1952 GA_Height, 0,
1953 GA_DrawInfo, 0,
1954 MUIA_VertWeight, 10,
1955 ICA_TARGET, ICTARGET_IDCMP,
1956 End,
1957 Child, HGroup,
1958 MUIA_Group_SameWidth, TRUE,
1959 MUIA_FixHeight, 1,
1960 Child, addpartitiongadgets.ok = IMAGEBUTTON(WORD_Ok, COOL_USEIMAGE_ID),
1961 Child, addpartitiongadgets.cancel = IMAGEBUTTON(WORD_Cancel, COOL_CANCELIMAGE_ID),
1962 End,
1963 End,
1964 End,
1965 SubWindow, partitiontypegadgets.win = WindowObject,
1966 MUIA_Window_Title, MSG(WORD_Partition_Type),
1967 MUIA_Window_Activate, TRUE,
1968 WindowContents, VGroup,
1969 Child, partitiontypegadgets.lv = ListviewObject,
1970 MUIA_Listview_List, ListObject,
1971 InputListFrame,
1972 MUIA_List_ConstructHook, MUIV_List_ConstructHook_String,
1973 MUIA_List_DestructHook, MUIV_List_DestructHook_String,
1974 MUIA_List_Title, TRUE,
1975 End,
1976 End,
1977 Child, HGroup,
1978 Child, partitiontypegadgets.base = CycleObject,
1979 ButtonFrame,
1980 MUIA_Cycle_Entries, editcycleentries,
1981 MUIA_HorizWeight, 1,
1982 End,
1983 Child, partitiontypegadgets.hexid = StringObject,
1984 StringFrame,
1985 MUIA_String_EditHook, &partitiontypegadgets.hook_hexidedit,
1986 End,
1987 End,
1988 Child, HGroup,
1989 MUIA_Group_SameWidth, TRUE,
1990 MUIA_FixHeight, 1,
1991 Child, partitiontypegadgets.ok = IMAGEBUTTON(WORD_Ok, COOL_USEIMAGE_ID),
1992 Child, partitiontypegadgets.cancel = IMAGEBUTTON(WORD_Cancel, COOL_CANCELIMAGE_ID),
1993 End,
1994 End,
1995 End,
1996 SubWindow, partitiontabletypegadgets.win = WindowObject,
1997 MUIA_Window_Title, MSG(WORD_Partition_Table_Type),
1998 MUIA_Window_Activate, TRUE,
1999 WindowContents, VGroup,
2000 Child, partitiontabletypegadgets.lv = ListviewObject,
2001 MUIA_Listview_List, ListObject,
2002 InputListFrame,
2003 MUIA_List_ConstructHook, MUIV_List_ConstructHook_String,
2004 MUIA_List_DestructHook, MUIV_List_DestructHook_String,
2005 MUIA_List_Title, TRUE,
2006 End,
2007 End,
2008 Child, HGroup,
2009 MUIA_Group_SameWidth, TRUE,
2010 MUIA_FixHeight, 1,
2011 Child, partitiontabletypegadgets.ok = IMAGEBUTTON(WORD_Ok, COOL_USEIMAGE_ID),
2012 Child, partitiontabletypegadgets.cancel = IMAGEBUTTON(WORD_Cancel, COOL_CANCELIMAGE_ID),
2013 End,
2014 End,
2015 End,
2016 SubWindow, resizemovegadgets.win = WindowObject,
2017 MUIA_Window_Title, MSG(MSG_Select_Partition_Resize_Move),
2018 MUIA_Window_Activate, TRUE,
2019 WindowContents, VGroup,
2020 Child, resizemovegadgets.pt = BoopsiObject,
2021 GroupFrame,
2022 MUIA_Boopsi_Class, ptclass,
2023 MUIA_Boopsi_MinWidth, 600,
2024 MUIA_Boopsi_MinHeight, 100,
2025 MUIA_Boopsi_TagDrawInfo, GA_DrawInfo,
2026 MUIA_Boopsi_Remember, PTCT_PartitionTable,
2027 MUIA_Boopsi_Remember, PTCT_Flags,
2028 PTCT_Flags, 0,
2029 GA_Left, 0,
2030 GA_Top, 0,
2031 GA_Width, 0,
2032 GA_Height, 0,
2033 GA_DrawInfo, 0,
2034 MUIA_VertWeight, 10,
2035 ICA_TARGET, ICTARGET_IDCMP,
2036 End,
2037 Child, VGroup,
2038 GroupFrame,
2039 MUIA_FrameTitle, MSG(WORD_Geometry),
2040 Child, HGroup,
2041 Child, VGroup,
2042 Child, HGroup,
2043 Child, Label2("Low Cyl"),
2044 Child, resizemovegadgets.lowcyl=StringObject,
2045 StringFrame,
2046 MUIA_String_Integer, 0,
2047 MUIA_String_Accept, "0123456789",
2048 End,
2049 End,
2050 Child, HGroup,
2051 Child, Label2("High Cyl"),
2052 Child, resizemovegadgets.highcyl=StringObject,
2053 StringFrame,
2054 MUIA_String_Integer, 0,
2055 MUIA_String_Accept, "0123456789",
2056 End,
2057 End,
2058 Child, HGroup,
2059 Child, Label2("Total Cyl"),
2060 Child, resizemovegadgets.totalcyl=StringObject,
2061 StringFrame,
2062 MUIA_String_Integer, 0,
2063 MUIA_String_Accept, "0123456789",
2064 End,
2065 End,
2066 MUIA_HorizWeight, 10,
2067 End,
2068 Child, Label2("Size"),
2069 Child, resizemovegadgets.size=StringObject,
2070 ButtonFrame,
2071 MUIA_String_Accept, "0123456789GM.",
2072 MUIA_HorizWeight, 3,
2073 End,
2074 End,
2075 End,
2076 Child, HGroup,
2077 MUIA_Group_SameWidth, TRUE,
2078 MUIA_FixHeight, 1,
2079 Child, resizemovegadgets.ok = IMAGEBUTTON(WORD_Ok, COOL_USEIMAGE_ID),
2080 Child, resizemovegadgets.cancel = IMAGEBUTTON(WORD_Cancel, COOL_CANCELIMAGE_ID),
2081 End,
2082 End,
2083 End,
2084 SubWindow, renamegadgets.win = WindowObject,
2085 MUIA_Window_Title, MSG(WORD_Rename),
2086 MUIA_Window_Activate, TRUE,
2087 WindowContents, VGroup,
2088 Child, renamegadgets.name = StringObject,
2089 StringFrame,
2090 End,
2091 Child, HGroup,
2092 MUIA_Group_SameWidth, TRUE,
2093 MUIA_FixHeight, 1,
2094 Child, renamegadgets.ok = IMAGEBUTTON(WORD_Ok, COOL_USEIMAGE_ID),
2095 Child, renamegadgets.cancel = IMAGEBUTTON(WORD_Cancel, COOL_CANCELIMAGE_ID),
2096 End,
2097 End,
2098 End,
2099 SubWindow, dosenvecgadgets.win = WindowObject,
2100 MUIA_Window_Title, MSG(WORD_DosEnvec),
2101 MUIA_Window_Activate, TRUE,
2102 WindowContents, VGroup,
2103 Child, VGroup,
2104 GroupFrame,
2105 Child, HGroup,
2106 Child, Label2("Mask"),
2107 Child, dosenvecgadgets.mask=StringObject,
2108 StringFrame,
2109 MUIA_String_Integer, -2,
2110 MUIA_String_Accept, "0123456789",
2111 End,
2112 End,
2113 Child, HGroup,
2114 Child, Label2("MaxTransfer"),
2115 Child, dosenvecgadgets.maxtransfer=StringObject,
2116 StringFrame,
2117 MUIA_String_Contents, "0x7FFFFF",
2118 MUIA_String_Accept, "0123456789x",
2119 End,
2120 End,
2121 End,
2122 Child, VGroup,
2123 GroupFrame,
2124 Child, HGroup,
2125 Child, Label("_Custom Bootcode"),
2126 Child, HVSpace,
2127 Child, dosenvecgadgets.custboot=MUI_MakeObject
2129 MUIO_Checkmark,
2130 (IPTR)"_Custom Bootcode"
2132 End,
2133 Child, HGroup,
2134 Child, Label2("Nr. of Custom Bootblocks"),
2135 Child, dosenvecgadgets.numcustboot=StringObject,
2136 StringFrame,
2137 MUIA_String_Integer, 0,
2138 MUIA_String_Accept, "0123456789",
2139 End,
2140 End,
2141 End,
2142 Child, VGroup,
2143 GroupFrame,
2144 MUIA_FrameTitle, "Reserved Blocks at",
2145 Child, HGroup,
2146 Child, Label2("Beginning"),
2147 Child, dosenvecgadgets.reservedblocksstart=StringObject,
2148 StringFrame,
2149 MUIA_String_Integer, 0,
2150 MUIA_String_Accept, "0123456789",
2151 End,
2152 End,
2153 Child, HGroup,
2154 Child, Label2("End"),
2155 Child, dosenvecgadgets.reservedblocksend=StringObject,
2156 StringFrame,
2157 MUIA_String_Integer, 0,
2158 MUIA_String_Accept, "0123456789",
2159 End,
2160 End,
2161 End,
2162 Child, VGroup,
2163 GroupFrame,
2164 Child, HGroup,
2165 Child, Label("BlockSize"),
2166 Child, dosenvecgadgets.blocksize=CycleObject,
2167 ButtonFrame,
2168 MUIA_Cycle_Entries, blocksizecycleentries,
2169 End,
2170 End,
2171 Child, HGroup,
2172 Child, Label2("Buffers"),
2173 Child, dosenvecgadgets.buffers=StringObject,
2174 StringFrame,
2175 MUIA_String_Integer, 20,
2176 MUIA_String_Accept, "0123456789",
2177 End,
2178 End,
2179 End,
2180 Child, HGroup,
2181 MUIA_Group_SameWidth, TRUE,
2182 MUIA_FixHeight, 1,
2183 Child, dosenvecgadgets.ok = IMAGEBUTTON(WORD_Ok, COOL_USEIMAGE_ID),
2184 Child, dosenvecgadgets.cancel = IMAGEBUTTON(WORD_Cancel, COOL_CANCELIMAGE_ID),
2185 End,
2186 End,
2187 End,
2188 SubWindow, mountbootgadgets.win = WindowObject,
2189 MUIA_Window_Title, MSG(WORD_Switches),
2190 MUIA_Window_Activate, TRUE,
2191 WindowContents, VGroup,
2192 Child, HGroup,
2193 Child, Label(MSG(WORD_Active)),
2194 Child, HVSpace,
2195 Child, mountbootgadgets.active=MUI_MakeObject
2197 MUIO_Checkmark,
2198 MSG(WORD_Active)
2200 End,
2201 Child, HGroup,
2202 Child, Label(MSG(WORD_Automount)),
2203 Child, HVSpace,
2204 Child, mountbootgadgets.automount=MUI_MakeObject
2206 MUIO_Checkmark,
2207 MSG(WORD_Automount)
2209 End,
2210 Child, HGroup,
2211 Child, Label(MSG(WORD_Bootable)),
2212 Child, HVSpace,
2213 Child, mountbootgadgets.bootable=MUI_MakeObject
2215 MUIO_Checkmark,
2216 MSG(WORD_Bootable)
2218 End,
2219 Child, HGroup,
2220 Child, Label(MSG(WORD_BootPri)),
2221 Child, mountbootgadgets.bootpri=StringObject,
2222 StringFrame,
2223 MUIA_String_Integer, 0,
2224 MUIA_String_Accept, "-0123456789",
2225 End,
2226 End,
2227 Child, HGroup,
2228 MUIA_Group_SameWidth, TRUE,
2229 MUIA_FixHeight, 1,
2230 Child, mountbootgadgets.ok = IMAGEBUTTON(WORD_Ok, COOL_USEIMAGE_ID),
2231 Child, mountbootgadgets.cancel = IMAGEBUTTON(WORD_Cancel, COOL_CANCELIMAGE_ID),
2232 End,
2233 End,
2234 End,
2235 End;
2237 if (!app)
2238 return ERR_GADGETS;
2240 /* Main Window */
2241 DoMethod
2243 mainwin, MUIM_Notify, MUIA_Window_CloseRequest, TRUE, (IPTR)app, 2,
2244 MUIM_Application_ReturnID, MUIV_Application_ReturnID_Quit
2246 DoMethod
2248 gadgets.buttons[GB_EXIT], MUIM_Notify, MUIA_Pressed, FALSE, (IPTR)app, 2,
2249 MUIM_Application_ReturnID, MUIV_Application_ReturnID_Quit
2251 DoMethod
2253 gadgets.leftlv,
2254 MUIM_Notify, MUIA_Listview_DoubleClick, TRUE, (IPTR)gadgets.leftlv, 2,
2255 MUIM_CallHook, (IPTR)&hook_lv_doubleclick
2257 DoMethod
2259 gadgets.leftlv, MUIM_Notify, MUIA_List_Active, MUIV_EveryTime,
2260 (IPTR)gadgets.leftlv, 2, MUIM_CallHook, (IPTR)&hook_lv_click
2262 for (i=GB_FIRST;i<GB_EXIT;i++)
2264 DoMethod
2266 gadgets.buttons[i],
2267 MUIM_Notify, MUIA_Pressed, FALSE, (IPTR)gadgets.buttons[i], 2,
2268 MUIM_CallHook, (IPTR)&hook_buttons
2270 /* MUIM_CallHook, hook */
2272 disableObject(gadgets.buttons[GB_REMOVE_ENTRY]);
2273 disableObject(gadgets.buttons[GB_CREATE_TABLE]);
2274 disableObject(gadgets.buttons[GB_CHANGE_TYPE]);
2275 disableObject(gadgets.buttons[GB_RESIZE_MOVE]);
2276 disableObject(gadgets.buttons[GB_PARENT]);
2277 disableObject(gadgets.buttons[GB_RENAME]);
2278 disableObject(gadgets.buttons[GB_DOSENVEC]);
2279 disableObject(gadgets.buttons[GB_SWITCHES]);
2280 disableObject(gadgets.buttons[GB_SAVE_CHANGES]);
2281 DoMethod
2283 quit_item,
2284 MUIM_Notify, MUIA_Menuitem_Trigger, MUIV_EveryTime, (IPTR)app, 2,
2285 MUIM_Application_ReturnID, MUIV_Application_ReturnID_Quit
2287 DoMethod(createml_item,
2288 MUIM_Notify, MUIA_Menuitem_Trigger, MUIV_EveryTime, app, 2,
2289 MUIM_CallHook, &hook_createml);
2290 /* add device window */
2291 DoMethod
2293 adddevicegadgets.win,
2294 MUIM_Notify, MUIA_Window_Open, TRUE, (IPTR)mainwin, 3,
2295 MUIM_Set, MUIA_Window_Sleep, TRUE
2297 DoMethod
2299 adddevicegadgets.win,
2300 MUIM_Notify, MUIA_Window_Open, FALSE, (IPTR)mainwin, 3,
2301 MUIM_Set, MUIA_Window_Sleep, FALSE
2303 DoMethod
2305 adddevicegadgets.win,
2306 MUIM_Notify, MUIA_Window_CloseRequest, TRUE, (IPTR)adddevicegadgets.win, 3,
2307 MUIM_Set, MUIA_Window_Open, FALSE
2309 DoMethod
2311 adddevicegadgets.ok,
2312 MUIM_Notify, MUIA_Pressed, FALSE, (IPTR)adddevicegadgets.ok, 2,
2313 MUIM_CallHook, (IPTR)&hook_buttons
2315 DoMethod
2317 adddevicegadgets.ok,
2318 MUIM_Notify, MUIA_Pressed, FALSE, (IPTR)adddevicegadgets.win, 3,
2319 MUIM_Set, MUIA_Window_Open, FALSE
2321 DoMethod
2323 adddevicegadgets.cancel,
2324 MUIM_Notify, MUIA_Pressed, FALSE, (IPTR)adddevicegadgets.win, 3,
2325 MUIM_Set, MUIA_Window_Open, FALSE
2327 /* add partition window */
2328 DoMethod
2330 addpartitiongadgets.win,
2331 MUIM_Notify, MUIA_Window_CloseRequest, TRUE, (IPTR)addpartitiongadgets.win, 3,
2332 MUIM_Set, MUIA_Window_Open, FALSE
2334 DoMethod
2336 addpartitiongadgets.ok,
2337 MUIM_Notify, MUIA_Pressed, FALSE, (IPTR)addpartitiongadgets.ok, 2,
2338 MUIM_CallHook, (IPTR)&hook_buttons
2340 DoMethod
2342 addpartitiongadgets.ok,
2343 MUIM_Notify, MUIA_Pressed, FALSE, (IPTR)addpartitiongadgets.win, 3,
2344 MUIM_Set, MUIA_Window_Open, FALSE
2346 DoMethod
2348 addpartitiongadgets.cancel,
2349 MUIM_Notify, MUIA_Pressed, FALSE, (IPTR)addpartitiongadgets.win, 3,
2350 MUIM_Set, MUIA_Window_Open, FALSE
2352 DoMethod
2354 addpartitiongadgets.pt,
2355 MUIM_Notify, PTCT_Selected, TRUE, (IPTR)addpartitiongadgets.pt, 2,
2356 MUIM_CallHook, (IPTR)&hook_buttons
2358 /* partition type window */
2359 DoMethod
2361 partitiontypegadgets.win,
2362 MUIM_Notify, MUIA_Window_CloseRequest, TRUE, (IPTR)partitiontypegadgets.win, 3,
2363 MUIM_Set, MUIA_Window_Open, FALSE
2365 DoMethod
2367 partitiontypegadgets.hexid,
2368 MUIM_Notify, MUIA_String_Acknowledge, MUIV_EveryTime,
2369 (IPTR)partitiontypegadgets.hexid, 2,
2370 MUIM_CallHook, (IPTR)&hook_buttons
2372 /* "FIXME: notify doesn't work" */
2373 DoMethod
2375 partitiontypegadgets.ok,
2376 MUIM_Notify, MUIA_Pressed, FALSE, (IPTR)partitiontypegadgets.ok, 2,
2377 MUIM_CallHook, (IPTR)&hook_buttons
2379 DoMethod
2381 partitiontypegadgets.ok,
2382 MUIM_Notify, MUIA_Pressed, FALSE, (IPTR)partitiontypegadgets.win, 3,
2383 MUIM_Set, MUIA_Window_Open, FALSE
2385 DoMethod
2387 partitiontypegadgets.cancel,
2388 MUIM_Notify, MUIA_Pressed, FALSE, (IPTR)partitiontypegadgets.win, 3,
2389 MUIM_Set, MUIA_Window_Open, FALSE
2391 DoMethod
2393 partitiontypegadgets.lv, MUIM_Notify, MUIA_List_Active,
2394 MUIV_EveryTime, (IPTR)partitiontypegadgets.lv, 2, MUIM_CallHook,
2395 (IPTR)&hook_buttons
2397 /* partition table type window */
2398 DoMethod
2400 partitiontabletypegadgets.win,
2401 MUIM_Notify, MUIA_Window_CloseRequest, TRUE, (IPTR)partitiontabletypegadgets.win, 3,
2402 MUIM_Set, MUIA_Window_Open, FALSE
2404 DoMethod
2406 partitiontabletypegadgets.ok,
2407 MUIM_Notify, MUIA_Pressed, FALSE, (IPTR)partitiontabletypegadgets.ok, 2,
2408 MUIM_CallHook, (IPTR)&hook_buttons
2410 DoMethod
2412 partitiontabletypegadgets.ok,
2413 MUIM_Notify, MUIA_Pressed, FALSE, (IPTR)partitiontabletypegadgets.win, 3,
2414 MUIM_Set, MUIA_Window_Open, FALSE
2416 DoMethod
2418 partitiontabletypegadgets.cancel,
2419 MUIM_Notify, MUIA_Pressed, FALSE, (IPTR)partitiontabletypegadgets.win, 3,
2420 MUIM_Set, MUIA_Window_Open, FALSE
2422 /* resize/move window */
2423 DoMethod
2425 resizemovegadgets.win,
2426 MUIM_Notify, MUIA_Window_CloseRequest, TRUE, (IPTR)resizemovegadgets.win, 3,
2427 MUIM_Set, MUIA_Window_Open, FALSE
2429 DoMethod
2431 resizemovegadgets.ok,
2432 MUIM_Notify, MUIA_Pressed, FALSE, (IPTR)resizemovegadgets.ok, 2,
2433 MUIM_CallHook, (IPTR)&hook_buttons
2435 DoMethod
2437 resizemovegadgets.ok,
2438 MUIM_Notify, MUIA_Pressed, FALSE, (IPTR)resizemovegadgets.win, 3,
2439 MUIM_Set, MUIA_Window_Open, FALSE
2441 DoMethod
2443 resizemovegadgets.size,
2444 MUIM_Notify, MUIA_String_Acknowledge, MUIV_EveryTime,
2445 (IPTR)resizemovegadgets.size, 2,
2446 MUIM_CallHook, (IPTR)&hook_buttons
2448 DoMethod
2450 resizemovegadgets.cancel,
2451 MUIM_Notify, MUIA_Pressed, FALSE, (IPTR)resizemovegadgets.cancel, 2,
2452 MUIM_CallHook, (IPTR)&hook_buttons
2454 DoMethod
2456 resizemovegadgets.cancel,
2457 MUIM_Notify, MUIA_Pressed, FALSE, (IPTR)resizemovegadgets.win, 3,
2458 MUIM_Set, MUIA_Window_Open, FALSE
2460 DoMethod
2462 resizemovegadgets.pt,
2463 MUIM_Notify, PTCT_Selected, TRUE, (IPTR)resizemovegadgets.pt, 3,
2464 MUIM_CallHook, (IPTR)&hook_buttons, PTCT_Selected
2466 DoMethod
2468 resizemovegadgets.pt,
2469 MUIM_Notify, PTCT_PartitionMove, TRUE, (IPTR)resizemovegadgets.pt, 3,
2470 MUIM_CallHook, (IPTR)&hook_buttons, PTCT_PartitionMove
2472 DoMethod
2474 resizemovegadgets.highcyl,
2475 MUIM_Notify, MUIA_String_Acknowledge, MUIV_EveryTime, (IPTR)resizemovegadgets.highcyl, 2,
2476 MUIM_CallHook, (IPTR)&hook_buttons
2478 DoMethod
2480 resizemovegadgets.lowcyl,
2481 MUIM_Notify, MUIA_String_Acknowledge, MUIV_EveryTime, (IPTR)resizemovegadgets.lowcyl, 2,
2482 MUIM_CallHook, (IPTR)&hook_buttons
2484 DoMethod
2486 resizemovegadgets.totalcyl,
2487 MUIM_Notify, MUIA_String_Acknowledge, MUIV_EveryTime, (IPTR)resizemovegadgets.totalcyl, 2,
2488 MUIM_CallHook, (IPTR)&hook_buttons
2490 /* rename window */
2491 DoMethod
2493 renamegadgets.win,
2494 MUIM_Notify, MUIA_Window_CloseRequest, TRUE, (IPTR)renamegadgets.win, 3,
2495 MUIM_Set, MUIA_Window_Open, FALSE
2497 DoMethod
2499 renamegadgets.ok,
2500 MUIM_Notify, MUIA_Pressed, FALSE, (IPTR)renamegadgets.ok, 2,
2501 MUIM_CallHook, (IPTR)&hook_buttons
2503 DoMethod
2505 renamegadgets.ok,
2506 MUIM_Notify, MUIA_Pressed, FALSE, (IPTR)renamegadgets.win, 3,
2507 MUIM_Set, MUIA_Window_Open, FALSE
2509 DoMethod
2511 renamegadgets.cancel,
2512 MUIM_Notify, MUIA_Pressed, FALSE, (IPTR)renamegadgets.win, 3,
2513 MUIM_Set, MUIA_Window_Open, FALSE
2515 /* dosenvec window */
2516 DoMethod
2518 dosenvecgadgets.win,
2519 MUIM_Notify, MUIA_Window_CloseRequest, TRUE, (IPTR)dosenvecgadgets.win, 3,
2520 MUIM_Set, MUIA_Window_Open, FALSE
2522 DoMethod
2524 dosenvecgadgets.ok,
2525 MUIM_Notify, MUIA_Pressed, FALSE, (IPTR)dosenvecgadgets.ok, 2,
2526 MUIM_CallHook, (IPTR)&hook_buttons
2528 DoMethod
2530 dosenvecgadgets.ok,
2531 MUIM_Notify, MUIA_Pressed, FALSE, (IPTR)dosenvecgadgets.win, 3,
2532 MUIM_Set, MUIA_Window_Open, FALSE
2534 DoMethod
2536 dosenvecgadgets.cancel,
2537 MUIM_Notify, MUIA_Pressed, FALSE, (IPTR)dosenvecgadgets.win, 3,
2538 MUIM_Set, MUIA_Window_Open, FALSE
2540 /* automount/boot window */
2541 DoMethod
2543 mountbootgadgets.win,
2544 MUIM_Notify, MUIA_Window_CloseRequest, TRUE, (IPTR)mountbootgadgets.win, 3,
2545 MUIM_Set, MUIA_Window_Open, FALSE
2547 DoMethod
2549 mountbootgadgets.ok,
2550 MUIM_Notify, MUIA_Pressed, FALSE, (IPTR)mountbootgadgets.ok, 2,
2551 MUIM_CallHook, (IPTR)&hook_buttons
2553 DoMethod
2555 mountbootgadgets.ok,
2556 MUIM_Notify, MUIA_Pressed, FALSE, (IPTR)mountbootgadgets.win, 3,
2557 MUIM_Set, MUIA_Window_Open, FALSE
2559 DoMethod
2561 mountbootgadgets.cancel,
2562 MUIM_Notify, MUIA_Pressed, FALSE, (IPTR)mountbootgadgets.win, 3,
2563 MUIM_Set, MUIA_Window_Open, FALSE
2565 set(mainwin, MUIA_Window_Open, TRUE);
2566 return 0;
2569 void deinitGUI()
2571 D(bug("[HDToolBox] deinitGUI()\n"));
2573 if (app)
2574 MUI_DisposeObject(app);
2575 if (ptclass != NULL)
2576 FreeClass(ptclass);
2577 if (MUIMasterBase)
2578 CloseLibrary(MUIMasterBase);
2581 BOOL QuitGUI(ULONG *sigs)
2583 // moved debug from this place because it produces too much garbage
2585 if ((IPTR)DoMethod(app, MUIM_Application_NewInput, (IPTR)sigs) == MUIV_Application_ReturnID_Quit)
2587 D(bug("[HDToolBox] QuitGUI()\n"));
2588 return TRUE;
2590 return FALSE;