Format GUI wasn't properly initialized when started from its icon.
[AROS.git] / workbench / system / BHFormat / gui.c
blob1ec4e68ec690623ecf76ce8cfe9ce21cad6be534
1 /*
2 * Format -- disk formatting and file-system creation program
3 * Copyright (C) 1999 Ben Hutchings <womble@zzumbouk.demon.co.uk>
4 * Copyright (C) 2008 Pavel Fedin <sonic_amiga@rambler.ru>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 * Layout of the main window of version 40 in English is:
24 * +-------------------------------------------------------------+
25 * | Format - <device> |
26 * +-------------------------------------------------------------+
27 * | Current Information: Device '<device>' |
28 * | Volume '<volume>' |
29 * | <size> capacity <usage>% used |
30 * | _________________________________ |
31 * | New Volume Name: |Empty____________________________| |
32 * | __ |
33 * | Put Trashcan: |./| |
34 * | __ |
35 * | Fast File System: |__| |
36 * | __ |
37 * | International Mode: |__| |
38 * | __ |
39 * | Directory Cache: |__| |
40 * | |
41 * | +-----------------+ +-----------------+ +-----------------+ |
42 * | | Format | | Quick Format | | Cancel | |
43 * | +-----------------+ +-----------------+ +-----------------+ |
44 * +-------------------------------------------------------------+
46 * For ID_NOT_REALLY_DOS and ID_UNREADABLE_DISK volumes, the information
47 * takes the format:
48 * Device '<device>'
49 * <size> capacity
51 * For non-native file-systems, the lower three checkboxes are not shown.
53 * <size> is the whole number of kilobytes (units of 2^10 bytes)
54 * followed by `K', if this number is less than or equal to 9999;
55 * otherwise the whole number of megabytes (units of 2^20 bytes).
57 * The progress window has this layout:
59 * +-----------------------------------------------------------------------+
60 * | Format - <device> |
61 * +-----------------------------------------------------------------------+
62 * | |
63 * | Formatting disk... |
64 * | +-------------------------------------------------------------------+ |
65 * | | | |
66 * | +----------------+----------------+----------------+----------------+ |
67 * | 0% 50% 100% |
68 * | |
69 * | +--------------------+ |
70 * | | Stop | |
71 * | +--------------------+ |
72 * +-----------------------------------------------------------------------+
74 * The contents of this window are replaced by the text `Initializing
75 * disk...' for the file-system creation and trashcan creation stages.
78 #define MUIMASTER_YES_INLINE_STDARG
79 #include <libraries/mui.h>
80 #include <proto/muimaster.h>
82 #include <dos/dosextens.h>
83 #include <dos/filehandler.h>
84 #include <intuition/intuition.h>
85 #include <stdarg.h>
86 #include <workbench/startup.h>
88 #include <proto/alib.h>
89 #include <proto/dos.h>
90 #include <proto/exec.h>
91 #include <proto/gadtools.h>
92 #include <proto/graphics.h>
93 #include <proto/intuition.h>
95 #include <string.h>
97 #include "format.h"
98 #include "locale.h"
100 static char szCapacityInfo[5+1+8+2+2+2+4+1];
101 static Object *app, *mainwin, *formatwin, *chk_trash, *chk_intl, *chk_ffs, *chk_cache;
102 static Object *txt_action, *str_volume, *gauge;
103 static struct DosList * pdlVolume = 0;
104 static struct Hook btn_format_hook;
105 static struct Hook list_consfunc_hook;
106 static struct Hook list_desfunc_hook;
107 static struct Hook list_dispfunc_hook;
109 static void message(CONST_STRPTR s);
111 struct SFormatEntry
113 TEXT deviceName[32];
114 TEXT volumeName[32];
115 TEXT capacityInfo[64];
118 AROS_UFH3S(IPTR, consfunc,
119 AROS_UFHA(struct Hook *, h, A0),
120 AROS_UFHA(IPTR*, pool, A2),
121 AROS_UFHA(struct SFormatEntry *, entry,A1))
123 AROS_USERFUNC_INIT
125 int size = sizeof(struct SFormatEntry);
127 struct SFormatEntry *new = AllocPooled(pool, size);
129 if (new) memcpy(new, entry, size);
131 return (IPTR)new;
133 AROS_USERFUNC_EXIT
136 AROS_UFH3S(void, desfunc,
137 AROS_UFHA(struct Hook *, h, A0),
138 AROS_UFHA(IPTR*, pool, A2),
139 AROS_UFHA(struct SFormatEntry *, entry,A1))
141 AROS_USERFUNC_INIT
143 FreePooled(pool, entry, sizeof(struct SFormatEntry));
145 AROS_USERFUNC_EXIT
148 AROS_UFH3S(LONG, dispfunc,
149 AROS_UFHA(struct Hook *, h, A0),
150 AROS_UFHA(char **, array, A2),
151 AROS_UFHA(struct SFormatEntry *, entry,A1))
153 AROS_USERFUNC_INIT
155 static char s[128];
157 strcpy(s, "(");
158 if (strlen(entry->volumeName))
160 strcat(s, entry->volumeName);
161 strcat(s, ", ");
163 strcat(s, entry->capacityInfo);
164 strcat(s, ")");
166 *array++ = entry->deviceName;
167 *array = s;
169 return 0;
171 AROS_USERFUNC_EXIT
174 BOOL ObjectTypeOk(struct DosList* device)
176 struct FileSysStartupMsg *pfssm;
177 struct DosEnvec *pdenDevice;
179 if( (pfssm = (struct FileSysStartupMsg *)
180 BADDR(device->dol_misc.dol_handler.dol_Startup)) == 0
181 || (IPTR)device->dol_misc.dol_handler.dol_Startup == 1 // RAW: device
182 || TypeOfMem(pfssm) == 0
183 || pfssm->fssm_Device == 0
184 || (pdenDevice = (struct DosEnvec *)BADDR(pfssm->fssm_Environ)) == 0
185 || TypeOfMem(pdenDevice) == 0
186 || pdenDevice->de_TableSize < DE_DOSTYPE
187 /* Check that parameters that should always be 0, are */
188 || pdenDevice->de_SecOrg != 0
189 || pdenDevice->de_Interleave != 0 )
191 /* error object wrong type */
192 return FALSE;
195 ULLONG cbyTrack = (ULLONG)pdenDevice->de_BlocksPerTrack * (ULLONG)(pdenDevice->de_SizeBlock * sizeof(LONG));
196 ULLONG cbyCylinder = cbyTrack * pdenDevice->de_Surfaces;
198 ibyStart = pdenDevice->de_LowCyl * cbyCylinder;
199 ibyEnd = (pdenDevice->de_HighCyl + 1) * cbyCylinder;
201 return TRUE;
204 void ComputeCapacity(struct DosList *pdlVolume, struct InfoData *pInfoData)
206 /* The units of the size are initially bytes, but we shift the
207 number until the units are kilobytes, megabytes or
208 something larger and the number of units has at most 4
209 digits. */
210 ULLONG cUnits;
211 /* The unit symbols go up to exabytes, since the maximum
212 possible disk size is 2^64 bytes = 16 exabytes. */
213 const char * pchUnitSymbol = _(MSG_UNITS);
215 D(Printf("Calculating capacity info...\n"));
216 cUnits = ibyEnd - ibyStart;
217 while( (cUnits >>= 10) > 9999 )
218 ++pchUnitSymbol;
220 if(pdlVolume && pInfoData)
221 RawDoFmtSz( szCapacityInfo, _(MSG_CAPACITY_USED),
222 (ULONG)cUnits, (ULONG)*pchUnitSymbol,
223 /* Calculate percentage used, to nearest point. */
224 (ULONG)(((ULLONG)pInfoData->id_NumBlocksUsed*100ULL
225 + pInfoData->id_NumBlocks/2) / pInfoData->id_NumBlocks) );
226 else
227 RawDoFmtSz( szCapacityInfo, "%lu%lc capacity",
228 (ULONG)cUnits, (ULONG)*pchUnitSymbol );
229 D(Printf("Done: %s\n", szCapacityInfo));
232 void VolumesToList(Object* listObject)
234 ULONG flags = LDF_READ | LDF_DEVICES | LDF_VOLUMES;
235 struct DosList *adl, *device, *volume;
237 adl = device = AttemptLockDosList(flags);
239 if (adl == NULL) return;
241 while((device = NextDosEntry(device, flags - LDF_VOLUMES)) != NULL)
243 TEXT name[128];
244 strcpy(name, AROS_BSTR_ADDR(device->dol_Name));
245 strcat(name, ":");
247 /* exclude RAM, NIL, RAW, CON, ... */
248 if (!ObjectTypeOk(device)) continue;
250 /* floppy, cdrom and unformatted disks can't be locked */
251 BPTR lock = Lock(name, SHARED_LOCK);
252 BOOL addDevice = TRUE;
253 struct InfoData *pInfoData = NULL;
255 if (lock)
257 struct InfoData infoData;
259 /* XPIPE and PIPEFS fails here */
260 if (Info(lock, &infoData))
262 pInfoData = &infoData;
264 else addDevice = FALSE;
266 UnLock(lock);
269 if (addDevice)
271 struct SFormatEntry entry;
272 strcpy(entry.deviceName, AROS_BSTR_ADDR(device->dol_Name));
273 volume = adl;
277 if ((volume = NextDosEntry(volume, LDF_VOLUMES)) == 0) break;
278 } while (strcmp(AROS_BSTR_ADDR(volume->dol_Name), AROS_BSTR_ADDR(device->dol_Name)) != 0);
280 if (volume) strcpy(entry.volumeName, AROS_BSTR_ADDR(volume->dol_Name));
281 else strcpy(entry.volumeName, "");
283 ComputeCapacity(volume, pInfoData);
284 strcpy(entry.capacityInfo, szCapacityInfo);
286 DoMethod(listObject, MUIM_List_InsertSingle, &entry,
287 MUIV_List_Insert_Top);
291 UnLockDosList(flags);
294 struct SFormatEntry* SelectDevice(void)
296 Object *app, *wnd, *list, *ok, *cancel;
298 list_consfunc_hook.h_Entry = (HOOKFUNC)consfunc;
299 list_desfunc_hook.h_Entry = (HOOKFUNC)desfunc;
300 list_dispfunc_hook.h_Entry = (HOOKFUNC)dispfunc;
302 app = (Object *)ApplicationObject,
303 MUIA_Application_Title, __(MSG_APPLICATION_TITLE),
304 MUIA_Application_Version, (IPTR)szVersion,
305 MUIA_Application_Description, __(MSG_DESCRIPTION),
306 MUIA_Application_Copyright, __(MSG_COPYRIGHT),
307 MUIA_Application_Author, __(MSG_AUTHOR),
308 MUIA_Application_Base, (IPTR)"FORMAT",
309 SubWindow, (IPTR)(wnd = (Object *)WindowObject,
310 MUIA_Window_ID, MAKE_ID('F','R','M','D'),
311 MUIA_Window_CloseGadget, (IPTR)FALSE,
312 MUIA_Window_Title, (IPTR)_(MSG_APPLICATION_TITLE),
313 WindowContents, (IPTR)(VGroup,
314 Child, (IPTR)(TextObject,
315 MUIA_Text_Contents, (IPTR)_(MSG_SELECTDEVICE),
316 End),
317 Child, (IPTR)(list = (Object *)ListviewObject,
318 MUIA_Listview_List, (IPTR)ListObject,
319 InputListFrame,
320 MUIA_List_ConstructHook, (IPTR)&list_consfunc_hook,
321 MUIA_List_DestructHook, (IPTR)&list_desfunc_hook,
322 MUIA_List_DisplayHook, (IPTR)&list_dispfunc_hook,
323 MUIA_List_Format, (IPTR)",",
324 MUIA_List_AdjustWidth, (IPTR)TRUE,
325 End,
326 End),
327 Child, (IPTR)(HGroup,
328 Child, (IPTR)(ok = SimpleButton(_(MSG_OK))),
329 Child, (IPTR)RectangleObject, End,
330 Child, (IPTR)(cancel = SimpleButton(_(MSG_CANCEL))),
331 End),
332 End),
333 End),
334 End;
336 if(app == NULL) return NULL;
338 VolumesToList(list);
340 DoMethod(list, MUIM_Notify, MUIA_List_Active, MUIV_EveryTime,
341 ok , 3, MUIM_Set, MUIA_Disabled, FALSE);
342 DoMethod(ok, MUIM_Notify, MUIA_Pressed, FALSE,
343 app, 2, MUIM_Application_ReturnID, (IPTR)ok);
344 DoMethod(cancel, MUIM_Notify, MUIA_Pressed, FALSE,
345 app, 2, MUIM_Application_ReturnID, MUIV_Application_ReturnID_Quit);
347 set(ok, MUIA_Disabled, TRUE);
348 set(wnd, MUIA_Window_Open, TRUE);
350 ULONG sigs = 0;
352 // Main loop
353 struct SFormatEntry* selectedEntry = NULL;
354 IPTR returnId;
355 while((returnId = (IPTR)DoMethod(app, MUIM_Application_NewInput, (IPTR)&sigs))
356 != MUIV_Application_ReturnID_Quit)
358 if (sigs)
360 if ((Object*) returnId == ok)
362 IPTR active = XGET(list, MUIA_List_Active);
363 struct SFormatEntry *entry;
364 DoMethod(list, MUIM_List_GetEntry, active, &entry);
365 selectedEntry = AllocMem(sizeof(struct SFormatEntry), 0L);
366 if (selectedEntry)
367 memcpy(selectedEntry, entry, sizeof(struct SFormatEntry));
368 break;
371 sigs = Wait(sigs | SIGBREAKF_CTRL_C);
373 if (sigs & SIGBREAKF_CTRL_C)
374 break;
378 MUI_DisposeObject(app);
380 return selectedEntry;
383 AROS_UFH3S(void, btn_format_function,
384 AROS_UFHA(struct Hook *, h, A0),
385 AROS_UFHA(Object *, object, A2),
386 AROS_UFHA(IPTR *, msg, A1))
388 AROS_USERFUNC_INIT
390 BOOL bDoFormat = *msg;
391 BOOL bMakeTrashcan, bFFS, bIntl;
392 BOOL bDirCache = FALSE;
393 LONG rc = FALSE;
395 D(Printf("Full format? %d\n", bDoFormat));
397 if(!bSetSzDosDeviceFromSz(szDosDevice))
398 goto cleanup;
400 /* TODO: set volume name same as old one if name is null string */
401 if( !bSetSzVolumeFromSz( (char *)XGET(str_volume, MUIA_String_Contents) ) )
403 goto cleanup;
406 bMakeTrashcan = XGET(chk_trash, MUIA_Selected);
407 bFFS = XGET(chk_ffs, MUIA_Selected);
408 bIntl = XGET(chk_intl, MUIA_Selected);
409 bDirCache = XGET(chk_cache, MUIA_Selected);
410 #ifdef __AROS__
411 bDirCache = FALSE;
412 #endif
414 if(bDoFormat)
416 set(txt_action, MUIA_Text_Contents, _(MSG_GUI_FORMATTING) );
418 else
420 set(txt_action, MUIA_Text_Contents, _(MSG_GUI_INITIALIZING) );
423 set(mainwin, MUIA_Window_Open, FALSE);
424 set(formatwin, MUIA_Window_Open, TRUE);
427 char szVolumeId[11 + MAX_FS_NAME_LEN];
428 if(pdlVolume)
429 RawDoFmtSz( szVolumeId, "%b", pdlVolume->dol_Name );
430 else
431 RawDoFmtSz( szVolumeId, _(MSG_IN_DEVICE), szDosDevice );
432 if( MUI_Request ( app, formatwin, 0,
433 _(MSG_FORMAT_REQUEST_TITLE), _(MSG_FORMAT_REQUEST_GADGETS),
434 _(MSG_FORMAT_REQUEST_TEXT),
435 szVolumeId, szCapacityInfo) != 1)
436 goto cleanup;
439 BOOL formatOk = TRUE;
440 if(bDoFormat)
442 ULONG icyl, sigs;
443 if(!bGetExecDevice(TRUE))
444 goto cleanup;
445 D(PutStr("GetExecDevice done\n"));
446 set(gauge, MUIA_Gauge_Max, HighCyl-LowCyl);
447 for( icyl = LowCyl; icyl <= HighCyl; ++icyl )
449 DoMethod(app, MUIM_Application_Input, (IPTR)&sigs);
450 /* interrupted by user? */
451 if(XGET(formatwin, MUIA_UserData) == 1)
453 formatOk = FALSE;
454 break;
456 if(!bFormatCylinder(icyl) || !bVerifyCylinder(icyl))
458 formatOk = FALSE;
459 break;
461 set(gauge, MUIA_Gauge_Current, icyl-LowCyl);
463 FreeExecDevice();
464 D(PutStr("FreeExecDevice done\n"));
467 if(formatOk)
468 if( bMakeFileSys( bFFS, !bFFS, bIntl, !bIntl, bDirCache, !bDirCache )
469 && (!bMakeTrashcan || bMakeFiles(FALSE)) )
470 rc = RETURN_OK;
472 cleanup:
473 DoMethod(app, MUIM_Application_ReturnID, MUIV_Application_ReturnID_Quit);
475 if (rc != RETURN_OK) {
476 /* Shouldn't we do something if rc != RETURN_OK? */
479 AROS_USERFUNC_EXIT
482 int rcGuiMain(void)
484 static char szTitle[6+3+30+1];
485 char szVolumeInfo[6+2+MAX_FS_NAME_LEN+2];
486 char szDeviceInfo[6+2+MAX_FS_NAME_LEN+2];
487 char szVolumeName[108];
488 struct DosList *pdlDevice = NULL;
489 szVolumeInfo[0] = '\0';
490 struct FileLock * pflVolume = 0;
491 static struct InfoData dinf __attribute__((aligned (4)));
492 LONG rc = RETURN_FAIL;
494 #if DEBUG
495 BPTR bpfhStdErr =
496 Open("CON:0/50/640/400/Format Debug Output/CLOSE/WAIT",MODE_READWRITE);
497 BPTR OldInput = SelectInput(bpfhStdErr);
498 BPTR OldOutput = SelectOutput(bpfhStdErr);
499 #endif
501 if( _WBenchMsg->sm_NumArgs > 1 )
503 struct DosList *pdlList;
505 if( _WBenchMsg->sm_ArgList[1].wa_Lock == 0 )
507 D(Printf("Object specified by name: %s\n", _WBenchMsg->sm_ArgList[1].wa_Name);)
508 /* it's a device */
509 if( !bSetSzDosDeviceFromSz(_WBenchMsg->sm_ArgList[1].wa_Name) ) {
510 D(Printf("Bad device name wrom Workbench: %s\n", _WBenchMsg->sm_ArgList[1].wa_Name));
511 /* Workbench is playing silly buggers */
512 goto cleanup;
515 else if( _WBenchMsg->sm_ArgList[1].wa_Name[0] == 0 )
517 /* it's a volume */
519 D(Printf("Object specified by lock\n"));
520 /* make sure it's mounted before looking for its device */
521 if( !Info( _WBenchMsg->sm_ArgList[1].wa_Lock, &dinf ) )
523 ReportErrSz( ertFailure, 0, 0 );
524 goto cleanup;
526 pflVolume =
527 (struct FileLock *)BADDR(_WBenchMsg->sm_ArgList[1].wa_Lock);
528 pdlVolume = (struct DosList *)BADDR(pflVolume->fl_Volume);
529 pdlList = LockDosList( LDF_DEVICES | LDF_READ );
530 pdlDevice = pdlList;
533 if ((pdlDevice = NextDosEntry(pdlDevice, LDF_DEVICES)) == 0)
534 break;
536 while( pdlDevice->dol_Task != pflVolume->fl_Task );
537 if (!pdlDevice)
539 ReportErrSz( ertFailure, ERROR_DEVICE_NOT_MOUNTED, 0 );
540 goto cleanup;
542 RawDoFmtSz( szDosDevice, "%b", pdlDevice->dol_Name );
543 pchDosDeviceColon = szDosDevice + strlen(szDosDevice);
544 *(pchDosDeviceColon+1) = 0;
546 else
548 ReportErrSz( ertFailure, ERROR_OBJECT_WRONG_TYPE, 0 );
549 goto cleanup;
552 ComputeCapacity(pdlVolume, &dinf );
554 if (pdlVolume)
555 strcpy(szVolumeName, AROS_BSTR_ADDR(pdlVolume->dol_Name));
557 else if ( _WBenchMsg->sm_NumArgs == 1 )
559 /* message(_(MSG_ERROR_WANDERER) ); */
560 struct SFormatEntry* entry = SelectDevice();
561 if (!entry)
562 goto cleanup;
563 strcpy(szDosDevice, entry->deviceName);
564 strcat(szDosDevice, ":");
565 strcpy(szVolumeName, entry->volumeName);
566 strcpy(szCapacityInfo, entry->capacityInfo);
567 FreeMem(entry, sizeof(struct SFormatEntry));
569 D(Printf("Object name selected via SelectDevice: %s\n", szDosDevice));
570 /* it's a device */
571 if( !bSetSzDosDeviceFromSz(szDosDevice) ) {
572 D(Printf("Bad device name from SelectDevice: %s\n", szDosDevice));
573 goto cleanup;
577 if (!bGetDosDevice(pdlDevice, LDF_DEVICES|LDF_READ))
578 goto cleanup;
580 RawDoFmtSz( szTitle, _(MSG_WINDOW_TITLE), szDosDevice );
581 D(Printf("Setting window title to '%s'\n", szTitle));
584 Object *btn_format, *btn_qformat, *btn_cancel, *btn_stop;
586 btn_format_hook.h_Entry = (HOOKFUNC)btn_format_function;
588 RawDoFmtSz( szDeviceInfo, _(MSG_DEVICE), szDosDevice );
589 RawDoFmtSz( szVolumeInfo, _(MSG_VOLUME), szVolumeName );
591 D(Printf("Creating GUI...\n"));
593 app = (Object *)ApplicationObject,
594 MUIA_Application_Title, __(MSG_APPLICATION_TITLE),
595 MUIA_Application_Version, (IPTR)szVersion,
596 MUIA_Application_Description, __(MSG_DESCRIPTION),
597 MUIA_Application_Copyright, __(MSG_COPYRIGHT),
598 MUIA_Application_Author, __(MSG_AUTHOR),
599 MUIA_Application_Base, (IPTR)"FORMAT",
600 MUIA_Application_SingleTask, FALSE,
601 SubWindow, (IPTR)(mainwin = (Object *)WindowObject,
602 MUIA_Window_ID, MAKE_ID('F','R','M','1'),
603 MUIA_Window_Title, (IPTR)szTitle,
604 WindowContents, (IPTR)(VGroup,
605 Child, (IPTR)(ColGroup(2),
606 Child, (IPTR)Label2( _(MSG_LABEL_CURRENT_INFORMATION) ),
607 Child, (IPTR)(TextObject,
608 (IPTR)TextFrame,
609 MUIA_Text_Contents, (IPTR)szDeviceInfo,
610 End),
611 Child, (IPTR)Label2(""),
612 Child, (IPTR)(TextObject,
613 TextFrame,
614 MUIA_Text_Contents, (IPTR)szVolumeInfo,
615 End),
616 Child, (IPTR)Label2(""),
617 Child, (IPTR)(TextObject,
618 TextFrame,
619 MUIA_Text_Contents, (IPTR)szCapacityInfo,
620 End),
621 Child, (IPTR)Label2( _(MSG_LABEL_NEW_VOLUME_NAME) ),
622 Child, (IPTR)(str_volume = (Object *)StringObject,
623 StringFrame,
624 MUIA_String_Contents, __(MSG_DEFAULT_VOLUME_NAME),
625 MUIA_String_MaxLen, MAX_FS_NAME_LEN,
626 End),
627 Child, (IPTR)Label2( _(MSG_LABEL_PUT_TRASHCAN) ),
628 Child, (IPTR)(chk_trash = MUI_MakeObject(MUIO_Checkmark, NULL)),
629 Child, (IPTR)Label2( _(MSG_LABEL_FFS) ),
630 Child, (IPTR)(chk_ffs = MUI_MakeObject(MUIO_Checkmark, NULL)),
631 Child, (IPTR)Label2( _(MSG_LABEL_INTL)),
632 Child, (IPTR)(chk_intl = MUI_MakeObject(MUIO_Checkmark, NULL)),
633 Child, (IPTR)Label2( _(MSG_LABEL_CACHE) ),
634 Child, (IPTR)(chk_cache = MUI_MakeObject(MUIO_Checkmark, NULL)),
635 End), /* ColGroup */
636 Child, (IPTR) (RectangleObject,
637 MUIA_Rectangle_HBar, TRUE,
638 MUIA_FixHeight, 2,
639 End),
640 Child, (IPTR)(HGroup,
641 Child, (IPTR)(btn_format = ImageButton( _(MSG_BTN_FORMAT) , "THEME:Images/Gadgets/Prefs/Save")),
642 Child, (IPTR)(btn_qformat = ImageButton( _(MSG_BTN_QFORMAT), "THEME:Images/Gadgets/Prefs/Save")),
643 Child, (IPTR)(btn_cancel = ImageButton( _(MSG_BTN_CANCEL) , "THEME:Images/Gadgets/Prefs/Cancel")),
644 End), /* HGroup */
645 End), /* VGroup */
646 End), /* Window */
647 SubWindow, (IPTR)(formatwin = (Object *)WindowObject,
648 MUIA_Window_ID, MAKE_ID('F','R','M','2'),
649 MUIA_Window_Title, (IPTR)szTitle,
650 MUIA_Window_CloseGadget, (IPTR)FALSE,
651 WindowContents, (IPTR)(VGroup,
652 Child, (IPTR)(txt_action = (Object *)TextObject,
653 TextFrame,
654 End),
655 Child, (IPTR)(gauge = (Object *)GaugeObject,
656 GaugeFrame,
657 MUIA_Gauge_Horiz, (IPTR)TRUE,
658 MUIA_FixHeightTxt, (IPTR)"|",
659 End),
660 Child, (IPTR)(HGroup,
661 Child, (IPTR)RectangleObject, End,
662 Child, (IPTR)(btn_stop = SimpleButton( _(MSG_BTN_STOP) )),
663 Child, (IPTR)RectangleObject, End,
664 End),
665 End), /* VGroup */
666 End), /* Window */
667 End; /* Application */
669 if ( ! app)
671 message( _(MSG_ERROR_NO_APPLICATION) );
672 goto cleanup;
675 DoMethod(mainwin, MUIM_Notify, MUIA_Window_CloseRequest, TRUE,
676 app, 2, MUIM_Application_ReturnID, MUIV_Application_ReturnID_Quit);
677 DoMethod(btn_cancel, MUIM_Notify, MUIA_Pressed, FALSE,
678 app, 2, MUIM_Application_ReturnID, MUIV_Application_ReturnID_Quit);
679 DoMethod(btn_format, MUIM_Notify, MUIA_Pressed, FALSE,
680 app, 3, MUIM_CallHook, (IPTR)&btn_format_hook, TRUE);
681 DoMethod(btn_qformat, MUIM_Notify, MUIA_Pressed, FALSE,
682 app, 3, MUIM_CallHook, (IPTR)&btn_format_hook, FALSE);
683 DoMethod(btn_stop, MUIM_Notify, MUIA_Pressed, FALSE,
684 formatwin, 3, MUIM_Set, MUIA_UserData, 1);
686 set(chk_trash, MUIA_Selected, TRUE);
687 if( DosType >= 0x444F5300 && DosType <= 0x444F5305 )
689 set(chk_ffs, MUIA_Selected, DosType & 1UL);
690 set(chk_intl, MUIA_Selected, DosType & 6UL);
691 set(chk_cache, MUIA_Selected, DosType & 4UL);
693 else
695 set(chk_ffs, MUIA_Disabled, TRUE);
696 set(chk_intl, MUIA_Disabled, TRUE);
697 set(chk_cache, MUIA_Disabled, TRUE);
699 #ifdef __AROS__
700 set(chk_cache, MUIA_Disabled, TRUE);
701 #endif
702 set(mainwin, MUIA_Window_Open, TRUE);
704 if (! XGET(mainwin, MUIA_Window_Open))
706 message( _(MSG_ERROR_NO_WINDOW) );
707 goto cleanup;
709 DoMethod(app, MUIM_Application_Execute);
710 rc = RETURN_OK;
713 cleanup:
714 MUI_DisposeObject(app);
716 #if DEBUG
717 SelectInput(OldInput);
718 SelectOutput(OldOutput);
719 Close(bpfhStdErr);
720 #endif
722 return rc;
725 static void message(CONST_STRPTR s)
727 if (s)
729 D(Printf(s));
730 MUI_Request(app, NULL, 0, _(MSG_REQ_ERROR_TITLE), _(MSG_OK), s);