Wanderer/Info: fix compilation
[AROS.git] / workbench / system / Wanderer / Tools / Info / main.c
blobbfc2e14eda3fa163ff5b211408280c3be951bd19
1 /*
2 Copyright © 2003-2016, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #define MUIMASTER_YES_INLINE_STDARG
8 #define DEBUG 0
9 #include <aros/debug.h>
11 #include <proto/exec.h>
12 #include <proto/intuition.h>
13 #include <proto/muimaster.h>
14 #include <proto/workbench.h>
15 #include <proto/dos.h>
16 #include <proto/alib.h>
17 #include <proto/icon.h>
19 #include <dos/dos.h>
20 #include <dos/datetime.h>
21 #include <exec/memory.h>
22 #include <libraries/asl.h>
23 #include <libraries/commodities.h>
24 #include <libraries/mui.h>
25 #include <workbench/startup.h>
26 #include <workbench/workbench.h>
27 #include <workbench/icon.h>
28 #include <devices/inputevent.h>
30 #include <mui/TextEditor_mcc.h>
31 #include <zune/iconimage.h>
33 #include "locale.h"
35 #include <stdio.h>
37 #include <string.h>
39 #define RETURNID_SLEEP 1
40 #define RETURNID_WAKE 2
41 #define RETURNID_ABOUT 3
42 #define RETURNID_NEWKEY 4
43 #define RETURNID_DELKEY 5
44 #define RETURNID_LVACK 6
45 #define RETURNID_STRINGACK 7
46 #define RETURNID_SAVE 8
47 #define RETURNID_TOOLACK 9
48 #define RETURNID_STACKACK 10
49 #define RETURNID_COMMENTACK 11
50 #define RETURNID_QUERYVERSION 12
51 #define RETURNID_PROTECT 13
52 #define RETURNID_SCANSIZE 14
53 #define RETURNID_OPENPATH 15
55 #define MAX_PATH_LEN 1024
56 #define MAX_TOOLTYPE_LINE 256
57 #define BUFFERSIZE 1024
59 #define USE_TEXTEDITOR 1
61 #define SCANDIE 1
62 #define SCANRUN 0
64 static Object *window, *commentspace, *filename_string, *stackspace, *savebutton;
65 static Object *readobject, *writeobject, *executeobject, *deleteobject;
66 static Object *scriptobject, *pureobject, *archiveobject, *sizespace = NULL;
67 struct DirScanProcess
69 struct Process *scanProcess;
70 Object *scanSizeObj;
71 char *scanSize;
72 char *scanDir;
73 IPTR scanState;
76 static struct DirScanProcess *scanStruct = NULL;
78 #if USE_TEXTEDITOR
79 static Object *editor, *slider;
80 #else
81 static Object *list, *editor, *liststr;
82 #endif
84 BOOL file_altered = FALSE;
85 BOOL icon_altered = FALSE;
86 char loadedcomment[MAXCOMMENTLENGTH];
88 void getReadableSize(UBYTE *buf, UQUAD size, BOOL accurate)
90 UQUAD d;
91 char *ch;
92 struct
94 IPTR val;
95 IPTR dec;
96 } array =
98 size,
102 /*if (size >= (1024 * 1024 * 1024 * 1024 * 1024 * 1024))
104 //Exabytes
105 array.val = size >> 60;
106 d = (size * 10 + ((1024 * 1024 * 1024 * 1024 * 1024 * 1024) / 2)) / (1024 * 1024 * 1024 * 1024 * 1024 * 1024);
107 array.dec = d % 10;
108 ch = "EiB";
110 else if (size >= (1024 * 1024 * 1024 * 1024 * 1024))
112 //Petabytes
113 array.val = size >> 50;
114 d = (size * 10 + ((1024 * 1024 * 1024 * 1024 * 1024) / 2)) / (1024 * 1024 * 1024 * 1024 * 1024);
115 array.dec = d % 10;
116 ch = "PiB";
118 else if (size >= (1024 * 1024 * 1024 * 1024))
120 //Terabytes
121 array.val = size >> 40;
122 d = (size * 10 + ((1024 * 1024 * 1024 * 1024) / 2)) / (1024 * 1024 * 1024 * 1024);
123 array.dec = d % 10;
124 ch = "TiB";
126 if (size >= (1024 * 1024 * 1024))
128 //Gigabytes
129 array.val = size >> 30;
130 d = (size * 10 + ((1024 * 1024 * 1024) / 2)) / (1024 * 1024 * 1024);
131 array.dec = d % 10;
132 ch = "GiB";
134 else if (size >= (1024 * 1024))
136 //Megabytes
137 array.val = size >> 20;
138 d = (size * 10 + ((1024 * 1024) / 2)) / (1024 * 1024);
139 array.dec = d % 10;
140 ch = "MiB";
142 else if (size >= 1024)
144 //Kilobytes
145 array.val = size >> 10;
146 d = (size * 10 + (1024 / 2)) / 1024;
147 array.dec = d % 10;
148 ch = "KiB";
150 else
152 //Bytes
153 array.val = size;
154 array.dec = 0;
155 d = 0;
156 if (size == 1)
157 ch = "Byte";
158 else
159 ch = "Bytes";
162 if (!array.dec && (d > array.val * 10))
163 array.val++;
165 if (!accurate)
167 buf[0] = '~';
168 buf++;
171 RawDoFmt(array.dec ? "%lu.%lu" : "%lu", (RAWARG)&array, NULL, buf);
173 while (*buf)
174 buf++;
176 sprintf((char *)buf," %s", ch);
179 #define kExallBufSize (4096)
181 UQUAD calculateDirectorySize(struct DirScanProcess *scan, UQUAD base, CONST_STRPTR directory, UQUAD * lastrefreshsize)
183 UBYTE *buffer = NULL;
184 BPTR directoryLock = BNULL;
185 UQUAD directorySize = 0;
186 BOOL loop = TRUE;
188 D(bug("[WBInfo] calculateDirectorySize('%s')\n", directory));
190 directoryLock = Lock(directory, SHARED_LOCK);
192 /* Allocate buffer for ExAll */
193 if ((buffer = AllocVec(kExallBufSize, MEMF_CLEAR|MEMF_PUBLIC)) == NULL)
195 UnLock(directoryLock);
196 return 0;
199 struct ExAllData *ead = (struct ExAllData*)buffer;
200 struct ExAllControl *eac = AllocDosObject(DOS_EXALLCONTROL, NULL);
201 eac->eac_LastKey = 0;
203 struct ExAllData *oldEad = ead;
207 ead = oldEad;
208 loop = ExAll(directoryLock, ead, kExallBufSize, ED_COMMENT, eac);
210 if(!loop && IoErr() != ERROR_NO_MORE_ENTRIES) break;
212 if(eac->eac_Entries != 0)
216 if (ead->ed_Type == ST_FILE)
218 directorySize += ead->ed_Size;
219 /* Refresh size only every 25% grow */
220 if ((((base + directorySize) * 100) / (*lastrefreshsize)) > 125) /* 25 % */
222 getReadableSize(scan->scanSize, (base + directorySize), FALSE);
223 set(sizespace, MUIA_Text_Contents, (IPTR) scan->scanSize);
224 *lastrefreshsize = base + directorySize;
227 else if (ead->ed_Type == ST_USERDIR)
229 ULONG subdirlen = strlen(directory) + strlen(ead->ed_Name) + 1;
230 char * subdirectory = AllocVec(subdirlen + 1, MEMF_CLEAR);
231 CopyMem(directory, subdirectory, strlen(directory));
232 AddPart(subdirectory, ead->ed_Name, subdirlen + 1);
233 directorySize += calculateDirectorySize(scan, (base + directorySize), subdirectory, lastrefreshsize);
235 ead = ead->ed_Next;
236 } while((ead != NULL) && (scan->scanState == SCANRUN));
238 } while((loop) && (scan->scanState == SCANRUN));
240 FreeDosObject(DOS_EXALLCONTROL, eac);
241 UnLock(directoryLock);
242 FreeVec(buffer);
244 return directorySize;
248 * child process to calculate directory content size..
250 AROS_UFH3(void, scanDir_Process,
251 AROS_UFHA(STRPTR, argPtr, A0),
252 AROS_UFHA(ULONG, argSize, D0),
253 AROS_UFHA(struct ExecBase *, SysBase, A6))
255 AROS_USERFUNC_INIT
257 struct Task *taskSelf = FindTask(NULL);
258 struct DirScanProcess *scan = taskSelf->tc_UserData;
259 UQUAD directorySize = 0;
261 if (scan->scanState == SCANRUN)
263 UQUAD lastrefreshsize = 1;
264 D(bug("[WBInfo] scanDir_Process('%s')\n", scan->scanDir));
265 scan->scanSize = AllocVec(64, MEMF_CLEAR);
266 directorySize = calculateDirectorySize(scan, directorySize, scan->scanDir, &lastrefreshsize);
267 D(bug("[WBInfo] scanDir_Process: End size = %d bytes\n", directorySize));
268 getReadableSize(scan->scanSize, directorySize, TRUE);
269 set(sizespace, MUIA_Text_Contents, (IPTR) scan->scanSize);
270 FreeVec(scan->scanSize);
272 scan->scanProcess = NULL;
274 AROS_USERFUNC_EXIT
277 UBYTE **BuildToolTypes(UBYTE **src_ttypes)
279 #if USE_TEXTEDITOR
280 APTR pool = CreatePool(MEMF_CLEAR, 200, 200);
281 STRPTR contents, sp, *dst_ttypes;
282 ULONG lines = 1;
284 if (!pool) return NULL;
285 contents = (STRPTR)DoMethod(editor, MUIM_TextEditor_ExportText);
287 if (!contents || !contents[0])
289 DeletePool(pool);
290 return NULL;
293 sp = contents;
295 while((sp = strchr(sp, '\n')))
297 sp++;
298 lines++;
301 dst_ttypes = AllocPooled(pool, (lines + 3) * sizeof(STRPTR));
302 if (!dst_ttypes)
304 FreeVec(contents);
305 DeletePool(pool);
306 return NULL;
309 *dst_ttypes++ = (STRPTR)pool;
310 *dst_ttypes++ = (STRPTR)contents;
312 for(sp = contents, lines = 0; sp; lines++)
314 dst_ttypes[lines] = sp;
315 sp = strchr(sp, '\n');
316 if (sp)
318 *sp++ = '\0';
321 dst_ttypes[lines] = 0;
323 return dst_ttypes;
324 #else
325 APTR pool = CreatePool(MEMF_CLEAR, 200, 200);
326 Object *listobj = list;
327 WORD list_index = 0, num_ttypes = 0, alloc_ttypes = 10;
328 UBYTE **dst_ttypes;
330 if (!pool) return NULL;
332 dst_ttypes = AllocPooled(pool, (alloc_ttypes + 2) * sizeof(UBYTE *));
333 if (!dst_ttypes)
335 DeletePool(pool);
336 return NULL;
339 get(listobj, MUIA_List_Entries, &list_index);
340 while(num_ttypes<list_index)
342 STRPTR text = NULL;
343 DoMethod(listobj, MUIM_List_GetEntry, num_ttypes, (IPTR)&text);
344 if (num_ttypes >= alloc_ttypes)
346 UBYTE **new_dst_ttypes = AllocPooled(pool, (alloc_ttypes + 10 + 2) * sizeof(UBYTE *));
347 if (!new_dst_ttypes)
349 DeletePool(pool);
350 return NULL;
352 CopyMem(dst_ttypes + 1, new_dst_ttypes + 1, alloc_ttypes * sizeof(UBYTE *));
353 dst_ttypes = new_dst_ttypes;
354 alloc_ttypes += 10;
356 dst_ttypes[num_ttypes + 1] = AllocPooled(pool, strlen(text) + 1);
357 if (!dst_ttypes[num_ttypes + 1])
359 DeletePool(pool);
360 return NULL;
362 CopyMem(text, dst_ttypes[num_ttypes + 1], strlen(text) + 1);
363 D(bug("[WBInfo] tooltype #%ld %s\n", num_ttypes + 1, text));
364 num_ttypes++;
366 dst_ttypes[0] = (APTR)pool;
367 return dst_ttypes + 1;
368 #endif
371 void FreeToolTypes(UBYTE **ttypes)
373 #if USE_TEXTEDITOR
374 if (ttypes)
376 FreeVec((APTR)ttypes[-1]);
377 DeletePool((APTR)ttypes[-2]);
379 #else
380 if (ttypes)
382 DeletePool((APTR)ttypes[-1]);
384 #endif
387 void SaveIcon(struct DiskObject *icon, STRPTR name, BPTR cd)
389 STRPTR tool = NULL, stack = NULL;
390 BPTR restored_cd;
391 long int ls;
392 UBYTE **ttypes = NULL, **old_ttypes = NULL;
394 restored_cd = CurrentDir(cd);
396 switch(icon->do_Type)
398 case WBPROJECT:
399 get(filename_string, MUIA_String_Contents, &tool);
400 icon->do_DefaultTool = tool;
401 get(stackspace, MUIA_String_Contents, &stack);
402 stcd_l(stack, &ls);
403 icon->do_StackSize = (LONG)ls;
404 break;
405 case WBTOOL:
406 get(stackspace, MUIA_String_Contents, &stack);
407 stcd_l(stack, &ls);
408 icon->do_StackSize = (LONG)ls;
409 break;
412 old_ttypes = (UBYTE **)icon->do_ToolTypes;
413 ttypes = BuildToolTypes(old_ttypes);
414 icon->do_ToolTypes = ttypes;
416 PutIconTags(name, icon, TAG_DONE);
418 icon->do_ToolTypes = old_ttypes;
419 if (ttypes)
421 FreeToolTypes(ttypes);
423 CurrentDir(restored_cd);
424 icon_altered = FALSE;
427 void SaveFile(struct AnchorPath * ap, BPTR cd)
429 ULONG protection = 0;
430 STRPTR text=NULL;
431 BPTR restored_cd;
432 restored_cd = CurrentDir(cd);
434 get(commentspace, MUIA_String_Contents, &text);
435 if (text)
436 SetComment(ap->ap_Buf, text);
438 if (XGET(scriptobject, MUIA_Selected))
439 protection |= FIBF_SCRIPT;
440 if (XGET(pureobject, MUIA_Selected))
441 protection |= FIBF_PURE;
442 if (XGET(archiveobject, MUIA_Selected))
443 protection |= FIBF_ARCHIVE;
445 if (! XGET(readobject, MUIA_Selected))
446 protection |= FIBF_READ;
447 if (! XGET(writeobject, MUIA_Selected))
448 protection |= FIBF_WRITE;
449 if (! XGET(executeobject, MUIA_Selected))
450 protection |= FIBF_EXECUTE;
451 if (! XGET(deleteobject, MUIA_Selected))
452 protection |= FIBF_DELETE;
454 SetProtection(ap->ap_Buf, protection);
456 CurrentDir(restored_cd);
457 file_altered = FALSE;
460 #if !USE_TEXTEDITOR
461 void ListToString(void)
463 STRPTR text = NULL;
464 DoMethod(list, MUIM_List_GetEntry, MUIV_List_GetEntry_Active, (IPTR) &text);
465 if (text)
467 set(liststr, MUIA_String_Contents, text);
468 nnset(liststr, MUIA_Disabled, FALSE);
469 set(window, MUIA_Window_ActiveObject, (IPTR)liststr);
473 void StringToKey(void)
475 STRPTR text = NULL;
476 STRPTR input = NULL;
478 icon_altered = TRUE;
480 DoMethod(list, MUIM_List_GetEntry, MUIV_List_GetEntry_Active, (IPTR) &text);
481 if (text)
483 get(liststr, MUIA_String_Contents, &input);
484 DoMethod(list, MUIM_List_InsertSingle, input, MUIV_List_Insert_Active);
485 set(list, MUIA_List_Active, MUIV_List_Active_Down);
486 DoMethod(list, MUIM_List_Remove, MUIV_List_Remove_Active);
487 nnset(liststr, MUIA_String_Contents, (IPTR) "");
488 nnset(liststr, MUIA_Disabled, TRUE);
489 set(window, MUIA_Window_ActiveObject, (IPTR)savebutton);
493 void NewKey(void)
495 nnset(liststr, MUIA_String_Contents, "");
496 nnset(liststr, MUIA_Disabled, FALSE);
497 DoMethod(list, MUIM_List_InsertSingle, "", MUIV_List_Insert_Bottom);
498 nnset(list, MUIA_List_Active, MUIV_List_Active_Bottom);
499 set(window, MUIA_Window_ActiveObject, (IPTR) liststr);
502 void DelKey(void)
504 STRPTR text = NULL;
505 DoMethod(list, MUIM_List_GetEntry, MUIV_List_GetEntry_Active, (IPTR)&text);
507 if (text)
509 DoMethod(list, MUIM_List_Remove, MUIV_List_Remove_Active);
510 DoMethod(list, MUIM_List_GetEntry, MUIV_List_GetEntry_Active, (IPTR)&text);
511 if (!text)
513 nnset(liststr, MUIA_String_Contents, (IPTR) "");
514 nnset(liststr, MUIA_Disabled, TRUE);
515 ListToString();
516 } else {
517 ListToString();
521 #endif
523 static char * GetVersion(STRPTR name, BPTR cd)
525 D(bug("[WBINFO/Getversion] Name %s\n", name));
526 STRPTR commandline = NULL;
527 ULONG commandlineSize;
528 static TEXT result[100]; // must be static because we return its address
529 char *retval = result;
530 TEXT tmpfilename[40];
531 int nr = 0;
532 int i;
533 BPTR output = BNULL;
534 BPTR restored_cd = (BPTR)-1;
536 if (name == NULL)
538 D(bug("[WBINFO/Getversion] Name is Null\n"));
539 goto exit;
542 memset(result, 0, sizeof(result));
543 result[0] = '?';
545 commandlineSize = strlen(name) + 20;
546 commandline = AllocVec(commandlineSize, MEMF_CLEAR);
547 if (commandline == NULL)
549 D(bug("[WBInfo/GetVersion] Can't allocate RAM for commandline\n"));
550 goto exit;
553 restored_cd = CurrentDir(cd);
555 //search for non-existing temp file name
558 nr++;
559 if (nr > 30)
561 D(bug("[WBINFO/Getversion] Can't find non-existing tmpfile"));
562 goto exit;
564 sprintf(tmpfilename, "t:tmp_version_%d", nr);
565 output = Open(tmpfilename, MODE_OLDFILE);
566 if (output)
568 Close(output);
570 } while (output != BNULL);
572 D(bug("[WBInfo/Getversion] tmpfilename %s\n", tmpfilename));
573 output = Open(tmpfilename, MODE_NEWFILE);
574 if (output == BNULL)
576 D(bug("[WBInfo/Getversion] Can't create tmpfile\n"));
577 goto exit;
580 // call c:version
581 sprintf(commandline, "c:version \"%s\" full", name);
582 D(bug("[WBInfo/GetVersion] Commandline %s\n", commandline));
583 if (SystemTags(commandline,
584 SYS_Output, (IPTR) output,
585 //SYS_Error, (IPTR) NULL,
586 NP_StackSize, 16000,
587 TAG_DONE) != 0)
589 D(bug("[WBInfo/Getversion] SystemTags failed\n"));
590 goto exit;
593 // Seek didn't work for me on RAM-Disk, so we reopen the file
594 Close(output);
595 output = Open(tmpfilename, MODE_OLDFILE);
596 if (output == BNULL)
598 D(bug("[WBInfo/GetVersion] Can't open tmpfile\n"));
599 goto exit;
601 // read result
602 if (Read(output, result, sizeof(result) - 1) == -1)
604 D(bug("[WBInfo/GetVersion] Can't read from tmpfile\n"));
605 goto exit;
607 D(bug("[WBInfo/GetVersion] Result %s\n", result));
609 // remove illegal chars (e.g. newline) from result
610 for (i = 0 ; result[i] != 0 ; i++)
612 if (result[i] < 32)
613 result[i] = ' ';
616 // set string pointer after program name
617 while (*retval != ' ')
618 retval++;
620 exit:
621 FreeVec(commandline);
622 if (output)
624 Close(output);
625 DeleteFile(tmpfilename);
627 if (restored_cd != (BPTR)-1)
628 CurrentDir(restored_cd);
630 return retval;
633 static void AddStackField(Object * application, Object * group, STRPTR stack)
635 Object * stacklabel = NULL;
637 stackspace = (Object *)StringObject,
638 StringFrame,
639 MUIA_String_MaxLen, 16,
640 MUIA_String_Contents, (IPTR)stack,
641 MUIA_String_Format, MUIV_String_Format_Right,
642 MUIA_String_Accept, (IPTR)"0123456789",
643 End;
645 stacklabel = MUI_MakeObject(MUIO_Label, _(MSG_STACK), NULL);
647 if ((stackspace != NULL) && (stacklabel != NULL))
649 DoMethod(group, MUIM_Group_InitChange);
650 DoMethod(group, OM_ADDMEMBER, stacklabel);
651 DoMethod(group, OM_ADDMEMBER, stackspace);
652 DoMethod(group, MUIM_Group_ExitChange);
653 SetAttrs(stackspace, MUIA_CycleChain, 1, TAG_DONE);
654 DoMethod(stackspace, MUIM_Notify,
655 MUIA_String_Acknowledge, MUIV_EveryTime,
656 (IPTR) application, 2, MUIM_Application_ReturnID, RETURNID_STACKACK);
660 static void AddToolField(Object * application, Object * group, STRPTR tool)
662 Object * toolspace = MUI_NewObject(MUIC_Popasl, ASLFR_DoSaveMode, TRUE,
663 MUIA_Popstring_String, (IPTR)(filename_string = (Object *)StringObject,
664 StringFrame,
665 MUIA_String_MaxLen, MAX_PATH_LEN,
666 MUIA_String_Contents, (IPTR)tool,
667 End),
668 MUIA_Popstring_Button, (IPTR) PopButton(MUII_PopFile), TAG_DONE);
670 Object * toollabel = MUI_MakeObject(MUIO_Label, _(MSG_DEFTOOL), NULL);
672 if ((toolspace != NULL) && (toollabel != NULL)&&(filename_string != NULL))
674 DoMethod(group, MUIM_Group_InitChange);
675 DoMethod(group, OM_ADDMEMBER, toollabel);
676 DoMethod(group, OM_ADDMEMBER, toolspace);
677 DoMethod(group, MUIM_Group_ExitChange);
679 set(toolspace, MUIA_CycleChain, 1);
680 DoMethod(filename_string, MUIM_Notify,
681 MUIA_String_Acknowledge, MUIV_EveryTime,
682 (IPTR) application, 2, MUIM_Application_ReturnID, RETURNID_TOOLACK);
686 static void AddEmptySpace(Object * group)
688 Object * emptyspace = MUI_NewObject(MUIC_Rectangle, TAG_DONE);
689 if ((emptyspace != NULL))
691 DoMethod(group, MUIM_Group_InitChange);
692 DoMethod(group, OM_ADDMEMBER, emptyspace);
693 DoMethod(group, MUIM_Group_ExitChange);
697 int main(int argc, char **argv)
699 Object *application, *grouptool, *groupstack = NULL;
700 Object *registergroup = NULL, *infomenu = NULL, *protectmenu = NULL, *toolmenu = NULL;
701 Object *datespace = NULL, *typespace = NULL, *quit = NULL, *aboutmenu = NULL;
702 Object *sizegrp = NULL, *versiongrp = NULL, *versionspace = NULL;
703 Object *cancelbutton = NULL;
704 Object *pathspace = NULL, *btnopenpath;
705 #if !USE_TEXTEDITOR
706 Object *newkey = NULL, *delkey = NULL;
707 #endif
708 struct WBStartup *startup;
709 struct DiskObject *icon = NULL;
710 struct AnchorPath *ap = NULL;
711 struct DateStamp *ds = NULL;
712 struct DateTime dt;
713 #if 0 /* unused */
714 IPTR dte;
715 #endif
716 STRPTR name = NULL, file = NULL, type = NULL;
717 BPTR cd, lock;
718 LONG returnid = 0;
719 ULONG protection;
720 char stack[16];
721 char deftool[MAX_PATH_LEN];
722 char size[64];
723 char date[LEN_DATSTRING];
724 char time[LEN_DATSTRING];
725 char dow[LEN_DATSTRING];
726 char datetime[2*LEN_DATSTRING];
727 UBYTE flags[8] = {0}, lname[MAXFILENAMELENGTH];
729 char *pages[] = {_(MSG_INFORMATION),_(MSG_PROTECTION),_(MSG_TOOLTYPES),NULL};
730 char * typeNames[] =
732 NULL, /* not used */
733 _(MSG_DISK), /* 1 */
734 _(MSG_DRAWER), /* 2 */
735 _(MSG_TOOL), /* 3 */
736 _(MSG_PROJECT), /* 4 */
737 _(MSG_GARBAGE), /* 5 */
738 _(MSG_DEVICE), /* 6 */
739 _(MSG_KICK), /* 7 */
740 _(MSG_APPICON) /* 8 */
743 char pathname[1024];
745 int retval = RETURN_OK;
747 if (argc != 0)
749 /* start from wanderer only */
750 PrintFault(ERROR_FILE_NOT_OBJECT, argv[0]);
751 retval = RETURN_FAIL;
752 goto funcmain_exit;
755 startup = (struct WBStartup *) argv;
757 if (startup->sm_NumArgs < 2)
759 /* need atleast 1 arg */
760 PrintFault(ERROR_REQUIRED_ARG_MISSING, argv[0]);
761 D(bug("[WBInfo] required arg missing\n"));
762 retval = RETURN_FAIL;
763 goto funcmain_exit;
766 lock = startup->sm_ArgList[1].wa_Lock;
767 NameFromLock(lock, lname, MAXFILENAMELENGTH);
768 D(bug("[WBInfo] arg parent lock 0x%p: '%s'\n", lock, lname));
770 if (startup->sm_ArgList[1].wa_Name != NULL)
772 if ((name = AllocVec(strlen(startup->sm_ArgList[1].wa_Name) + 1, MEMF_CLEAR)) != NULL)
774 CopyMem(startup->sm_ArgList[1].wa_Name, name, strlen(startup->sm_ArgList[1].wa_Name));
775 if ((strlen(name) > 5)
776 && (strcmp(name + strlen(name) - 5, ".info") == 0))
778 file = AllocVec(strlen(name) - 4, MEMF_CLEAR);
779 CopyMem(name, file , strlen(name) - 5);
781 else
783 file = AllocVec(strlen(name) + 1, MEMF_CLEAR);
784 CopyMem(name, file, strlen(name));
786 D(bug("[WBInfo] arg name 0x%p: '%s', file = '%s'\n", name, name, file));
789 cd = CurrentDir(lock);
790 if (name == NULL)
792 /* directory not found*/
793 PrintFault(ERROR_DIR_NOT_FOUND, argv[0]);
794 D(bug("[WBInfo] dir not found\n"));
795 retval = RETURN_FAIL;
796 goto funcmain_exit;
799 ap = AllocVec(sizeof(struct AnchorPath) + MAX_PATH_LEN, MEMF_CLEAR);
800 if (ap == NULL)
802 PrintFault(ERROR_NO_FREE_STORE, argv[0]);
803 D(bug("[WBInfo] no free store\n"));
804 retval = RETURN_FAIL;
805 goto funcmain_exit;
808 ap->ap_Strlen = MAX_PATH_LEN;
810 if (0 != MatchFirst(name, ap))
812 D(bug("[WBInfo] pass to diskinfo\n"));
813 OpenWorkbenchObject(
814 "WANDERER:Tools/DiskInfo",
815 WBOPENA_ArgLock, (IPTR) startup->sm_ArgList[1].wa_Lock,
816 WBOPENA_ArgName, (IPTR) startup->sm_ArgList[1].wa_Name,
817 TAG_DONE);
819 retval = RETURN_OK;
820 goto funcmain_exit;
823 ap->ap_BreakBits = SIGBREAKF_CTRL_C;
825 if (!(ap->ap_Flags & APF_DIDDIR))
827 D(bug("[WBInfo] scan file\n"));
828 /* fill comment */
829 sprintf(loadedcomment,"%s",ap->ap_Info.fib_Comment);
831 /* fill date and time */
832 ds = &ap->ap_Info.fib_Date;
833 DateStamp((struct DateStamp *)&dt);
834 CopyMem(ds, &dt.dat_Stamp, sizeof(struct DateStamp));
835 dt.dat_Format = FORMAT_DOS;
836 dt.dat_Flags = 0;
837 dt.dat_StrDay = dow;
838 dt.dat_StrDate = date;
839 dt.dat_StrTime = time;
840 #if 0 /* unused */
841 dte =
842 #endif
843 DateToStr(&dt);
844 sprintf(datetime, "%s %s", time, date);
846 /* fill size */
847 getReadableSize(size, ap->ap_Info.fib_Size, TRUE);
849 /* fill protection */
850 protection = ap->ap_Info.fib_Protection;
852 /* Convert the protection bits to a boolean */
853 flags[0] = protection & FIBF_SCRIPT ? 1 : 0; /* s */
854 flags[1] = protection & FIBF_PURE ? 1 : 0; /* p */
855 flags[2] = protection & FIBF_ARCHIVE ? 1 : 0; /* a */
857 /* The following flags are high-active! */
858 flags[3] = protection & FIBF_READ ? 0 : 1; /* r */
859 flags[4] = protection & FIBF_WRITE ? 0 : 1; /* w */
860 flags[5] = protection & FIBF_EXECUTE ? 0 : 1; /* e */
861 flags[6] = protection & FIBF_DELETE ? 0 : 1; /* d */
862 flags[7] = 0x00; /* h */
865 /* read icon */
866 icon = GetIconTags(file,
867 ICONGETA_FailIfUnavailable, FALSE,
868 ICONGETA_IsDefaultIcon, FALSE,
869 TAG_DONE);
871 if (icon != NULL)
873 D(bug("[WBInfo] file has icon\n"));
874 type = (char *) typeNames[icon->do_Type];
875 D(bug("[WBInfo] icon type is: %s\n", type));
876 sprintf(stack, "%d", (int)icon->do_StackSize);
877 if (icon->do_DefaultTool)
878 sprintf(deftool, "%s", icon->do_DefaultTool);
879 else
880 *deftool = '\0';
881 } else {
882 PrintFault(ERROR_OBJECT_WRONG_TYPE, argv[0]);
884 retval = RETURN_FAIL;
885 goto funcmain_exit;
888 if (icon->do_Type == 2)
890 sizespace = (Object *)TextObject,
891 ButtonFrame,
892 MUIA_Background, MUII_TextBack,
893 MUIA_Text_PreParse, (IPTR) "\33r",
894 MUIA_Text_Contents, (IPTR) "?",
895 MUIA_InputMode, MUIV_InputMode_RelVerify,
896 End;
898 versionspace = (Object *)TextObject,
899 TextFrame,
900 MUIA_Background, MUII_TextBack,
901 MUIA_Text_PreParse, (IPTR) "\33r",
902 MUIA_Text_Contents, (IPTR) "N/A",
903 End;
905 else
907 sizespace = (Object *)TextObject,
908 TextFrame,
909 MUIA_Background, MUII_TextBack,
910 MUIA_Text_PreParse, (IPTR) "\33r",
911 MUIA_Text_Contents, (IPTR) size,
912 End;
914 versionspace = (Object *)TextObject,
915 ButtonFrame,
916 MUIA_Background, MUII_TextBack,
917 MUIA_Text_PreParse, (IPTR) "\33r",
918 MUIA_Text_Contents, (IPTR) "?",
919 MUIA_InputMode, MUIV_InputMode_RelVerify,
920 End;
923 if (icon->do_Type!=WBDRAWER)
925 sprintf(pathname, "%s",lname);
926 } else {
927 int path_x;
928 int path_y = 58;
929 char *ch;
931 sprintf(pathname, "%s",lname);
932 ch = strrchr (pathname, path_y);
933 path_x = strlen (ch);
935 if (path_x > 1)
936 sprintf(pathname, "%s/%s", lname, name);
937 else
938 sprintf(pathname, "%s%s", lname, name);
942 application = (Object *)ApplicationObject,
943 MUIA_Application_Title, __(MSG_TITLE),
944 MUIA_Application_Version, (IPTR) "$VER: Info 0.8 ("ADATE") © 2003-2016 The AROS Dev Team",
945 MUIA_Application_Description, __(MSG_DESCRIPTION),
946 MUIA_Application_Base, (IPTR) "INFO",
947 MUIA_Application_Menustrip, (IPTR) MenustripObject,
948 MUIA_Family_Child, (IPTR) MenuObject,
949 MUIA_Menu_Title, __(MSG_PROJECT),
950 MUIA_Family_Child, (IPTR)(infomenu = (Object *)MenuitemObject, MUIA_Menuitem_Title,
951 __(MSG_INFORMATION), MUIA_Menuitem_Shortcut, (IPTR) "I", End),
952 MUIA_Family_Child, (IPTR)(protectmenu = (Object *)MenuitemObject, MUIA_Menuitem_Title,
953 __(MSG_PROTECTION),MUIA_Menuitem_Shortcut, (IPTR) "P", End),
954 MUIA_Family_Child, (IPTR)(toolmenu = (Object *)MenuitemObject, MUIA_Menuitem_Title,
955 __(MSG_TOOLTYPES),MUIA_Menuitem_Shortcut, (IPTR) "T", End),
956 MUIA_Family_Child, (IPTR) MenuitemObject, MUIA_Menuitem_Title, ~0, End,
957 MUIA_Family_Child, (IPTR) (aboutmenu = (Object *)MenuitemObject, MUIA_Menuitem_Title,
958 __(MSG_ABOUT), (IPTR) MUIA_Menuitem_Shortcut, (IPTR) "?", End),
959 MUIA_Family_Child, (IPTR) MenuitemObject, MUIA_Menuitem_Title, ~0, End,
960 MUIA_Family_Child, (IPTR) (quit = (Object *)MenuitemObject, MUIA_Menuitem_Title,
961 __(MSG_QUIT), MUIA_Menuitem_Shortcut, (IPTR) "Q", End),
962 End,
963 End,
964 SubWindow, (IPTR) (window = (Object *)WindowObject,
965 MUIA_Window_Title, (IPTR) __(MSG_TITLE),
966 MUIA_Window_ID, MAKE_ID('I','N','F','O'),
967 MUIA_Window_Activate, TRUE,
968 WindowContents, (IPTR) VGroup,
969 Child, (IPTR) HGroup,
970 Child, (IPTR) VGroup,
971 Child, (IPTR) IconImageObject,
972 MUIA_InputMode, MUIV_InputMode_Toggle,
973 MUIA_IconImage_File, (IPTR) file,
974 End,
975 End,
976 Child, (IPTR) VGroup,
977 Child, (IPTR) TextObject,
978 TextFrame,
979 MUIA_Background, MUII_TextBack,
980 MUIA_Text_PreParse, (IPTR) "\33l",
981 MUIA_Text_Contents, (IPTR) FilePart(file),
982 End,
983 End,
984 End,
985 Child, (IPTR) (registergroup = (Object *)RegisterGroup(pages),
986 MUIA_CycleChain, 1,
987 Child, (IPTR) HGroup, /* hgroup information pannel */
988 Child, (IPTR) VGroup,
989 Child, (IPTR) HGroup,
990 Child, (IPTR) ColGroup(2),
991 Child, (IPTR) Label2(__(MSG_TYPE)),
992 Child, (IPTR) (typespace = (Object *)TextObject,
993 TextFrame,
994 MUIA_Background, MUII_TextBack,
995 MUIA_Text_PreParse, (IPTR) "\33r",
996 MUIA_Text_Contents, (IPTR) type,
997 End),
998 Child, (IPTR) Label2(__(MSG_DATE)),
999 Child, (IPTR) (datespace = (Object *)TextObject,
1000 TextFrame,
1001 MUIA_Background, MUII_TextBack,
1002 MUIA_Text_PreParse, (IPTR) "\33r",
1003 MUIA_Text_Contents, (IPTR) datetime,
1004 End),
1005 Child, (IPTR) Label2(__(MSG_VERSION)),
1006 Child, (IPTR) (versiongrp = (Object *)HGroup,
1007 Child, (IPTR) versionspace,
1008 End),
1009 Child, (IPTR) Label2(__(MSG_SIZE)),
1010 Child, (IPTR) (sizegrp = (Object *)HGroup,
1011 Child, (IPTR) sizespace,
1012 End),
1013 Child, (IPTR) Label2(__(MSG_PATH)),
1014 Child, (IPTR) HGroup,
1015 Child, (IPTR) (pathspace = (Object *)StringObject,
1016 StringFrame,
1017 MUIA_String_Contents, (IPTR)pathname,
1018 MUIA_Weight, 150,
1019 End),
1020 Child, (IPTR) (btnopenpath = SimpleButton(__(MSG_BTNPATH))),
1021 End,
1023 End,
1024 End,
1027 Child, (IPTR) HVSpace,
1028 Child, (IPTR) (grouptool = (Object *)HGroup,
1029 End),
1030 Child, (IPTR) (groupstack = (Object *)HGroup,
1031 End),
1032 Child, (IPTR) HGroup,
1033 Child, (IPTR) Label2(__(MSG_COMMENT)),
1034 Child, (IPTR) (commentspace = (Object *)StringObject,
1035 StringFrame,
1036 MUIA_CycleChain, 1,
1037 End),
1038 End,
1039 End,
1040 End, /* end hgroup information pannel */
1041 Child, (IPTR) HGroup, /* hgroup protections pannel */
1042 Child, (IPTR) HVSpace,
1043 Child, (IPTR) VGroup,
1044 Child, (IPTR) HVSpace,
1045 Child, (IPTR) ColGroup(4),
1046 Child, (IPTR) Label2(_(MSG_READ)),
1047 Child, (IPTR) (readobject = MUI_MakeObject(MUIO_Checkmark,NULL)),
1048 Child, (IPTR) Label2(_(MSG_SCRIPT)),
1049 Child, (IPTR) (scriptobject = MUI_MakeObject(MUIO_Checkmark,NULL)),
1050 Child, (IPTR) Label2(_(MSG_WRITE)),
1051 Child, (IPTR) (writeobject = MUI_MakeObject(MUIO_Checkmark,NULL)),
1052 Child, (IPTR) Label2(_(MSG_PURE)),
1053 Child, (IPTR) (pureobject = MUI_MakeObject(MUIO_Checkmark,NULL)),
1054 Child, (IPTR) Label2(_(MSG_EXECUTE)),
1055 Child, (IPTR) (executeobject = MUI_MakeObject(MUIO_Checkmark,NULL)),
1056 Child, (IPTR) Label2(_(MSG_ARCHIVED)),
1057 Child, (IPTR) (archiveobject = MUI_MakeObject(MUIO_Checkmark,NULL)),
1058 Child, (IPTR) Label2(_(MSG_DELETE)),
1059 Child, (IPTR) (deleteobject = MUI_MakeObject(MUIO_Checkmark,NULL)),
1060 Child, (IPTR) HVSpace,
1061 Child, (IPTR) HVSpace,
1062 End,
1063 Child, (IPTR) HVSpace,
1064 End,
1065 Child, (IPTR) HVSpace,
1066 End, /* end hgroup protections pannel */
1067 Child, (IPTR) HGroup, /* hgroup tooltypes pannel */
1068 Child, (IPTR) VGroup,
1069 Child, (IPTR) HGroup,
1070 Child, (IPTR) VGroup,
1071 GroupSpacing(0),
1072 #if !USE_TEXTEDITOR
1073 Child, (IPTR) ListviewObject,
1074 MUIA_Listview_List, (IPTR) (list = ListObject,
1075 InputListFrame,
1076 MUIA_List_ConstructHook, MUIV_List_ConstructHook_String,
1077 MUIA_List_DestructHook, MUIV_List_DestructHook_String,
1078 MUIA_List_AutoVisible, TRUE,
1079 End),
1080 End,
1081 Child, (IPTR) (liststr = StringObject,
1082 MUIA_Disabled, TRUE,
1083 StringFrame,
1084 End),
1085 #else
1086 Child, (IPTR) HGroup,
1087 GroupSpacing(0),
1088 Child, (IPTR) (editor = MUI_NewObject(MUIC_TextEditor,
1089 TAG_DONE)),
1090 Child, (IPTR) (slider = (Object *)ScrollbarObject,
1091 End),
1092 End,
1093 #endif
1094 End,
1095 End,
1096 #if !USE_TEXTEDITOR
1097 Child, (IPTR) HGroup,
1098 MUIA_Group_SameSize, TRUE,
1099 Child, (IPTR) (newkey = SimpleButton(__(MSG_NEW_KEY))),
1100 Child, (IPTR) (delkey = SimpleButton(__(MSG_DELETE_KEY))),
1101 End,
1102 #endif
1103 End,
1104 End, /* end hgroup tooltypes pannel */
1105 End),
1106 Child, (IPTR) HGroup,
1107 MUIA_Group_SameSize, TRUE,
1108 Child, (IPTR) (savebutton =
1109 ImageButton(_(MSG_SAVE),"THEME:Images/Gadgets/OK")),
1110 Child, (IPTR) (cancelbutton =
1111 ImageButton(_(MSG_CANCEL),"THEME:Images/Gadgets/Cancel")),
1112 End,
1113 End,
1114 End),
1115 End;
1117 CurrentDir(cd);
1119 if (application != NULL)
1121 ULONG signals = 0;
1123 #if !USE_TEXTEDITOR
1124 set(liststr, MUIA_String_AttachedList, (IPTR)list);
1125 #endif
1127 // menu
1128 DoMethod(aboutmenu, MUIM_Notify, MUIA_Menuitem_Trigger, MUIV_EveryTime,
1129 (IPTR) application, 2,
1130 MUIM_Application_ReturnID, RETURNID_ABOUT);
1131 DoMethod(infomenu, MUIM_Notify, MUIA_Menuitem_Trigger, MUIV_EveryTime,
1132 (IPTR) registergroup, 3, MUIM_Set, MUIA_Group_ActivePage, 0);
1133 DoMethod(protectmenu, MUIM_Notify, MUIA_Menuitem_Trigger, MUIV_EveryTime,
1134 (IPTR) registergroup, 3, MUIM_Set, MUIA_Group_ActivePage, 1);
1135 DoMethod(toolmenu, MUIM_Notify, MUIA_Menuitem_Trigger, MUIV_EveryTime,
1136 (IPTR) registergroup, 3, MUIM_Set, MUIA_Group_ActivePage, 2);
1137 DoMethod(quit, MUIM_Notify, MUIA_Menuitem_Trigger, MUIV_EveryTime,
1138 (IPTR) application, 2, MUIM_Application_ReturnID,
1139 MUIV_Application_ReturnID_Quit);
1141 DoMethod(cancelbutton, MUIM_Notify, MUIA_Pressed, FALSE,
1142 (IPTR) application, 2,
1143 MUIM_Application_ReturnID, MUIV_Application_ReturnID_Quit);
1144 DoMethod(savebutton, MUIM_Notify, MUIA_Pressed, FALSE,
1145 (IPTR) application, 2,
1146 MUIM_Application_ReturnID, RETURNID_SAVE);
1147 DoMethod(application, MUIM_Notify, MUIA_Application_Sleep, FALSE,
1148 (IPTR) application, 2,
1149 MUIM_Application_ReturnID, RETURNID_WAKE);
1150 DoMethod(application, MUIM_Notify, MUIA_Application_Sleep, TRUE,
1151 (IPTR) application, 2,
1152 MUIM_Application_ReturnID, RETURNID_SLEEP);
1153 DoMethod(window, MUIM_Notify, MUIA_Window_CloseRequest, TRUE,
1154 (IPTR) application, 2, MUIM_Application_ReturnID,
1155 MUIV_Application_ReturnID_Quit );
1156 #if !USE_TEXTEDITOR
1157 DoMethod(newkey, MUIM_Notify, MUIA_Pressed, FALSE,
1158 (IPTR) application, 2, MUIM_Application_ReturnID, RETURNID_NEWKEY);
1159 DoMethod(delkey, MUIM_Notify, MUIA_Pressed, FALSE,
1160 (IPTR) application, 2, MUIM_Application_ReturnID, RETURNID_DELKEY);
1161 DoMethod(list, MUIM_Notify, MUIA_List_Active, MUIV_EveryTime,
1162 (IPTR) application, 2, MUIM_Application_ReturnID, RETURNID_LVACK);
1163 DoMethod(liststr, MUIM_Notify, MUIA_String_Acknowledge, MUIV_EveryTime,
1164 (IPTR) application, 2, MUIM_Application_ReturnID, RETURNID_STRINGACK);
1165 #endif
1166 DoMethod(commentspace, MUIM_Notify, MUIA_String_Acknowledge, MUIV_EveryTime,
1167 (IPTR) application, 2, MUIM_Application_ReturnID, RETURNID_COMMENTACK);
1168 DoMethod(versionspace, MUIM_Notify, MUIA_Pressed, FALSE,
1169 (IPTR) application, 2,
1170 MUIM_Application_ReturnID, RETURNID_QUERYVERSION);
1171 DoMethod(sizespace, MUIM_Notify, MUIA_Pressed, FALSE,
1172 (IPTR) application, 2,
1173 MUIM_Application_ReturnID, RETURNID_SCANSIZE);
1174 DoMethod(readobject, MUIM_Notify, MUIA_Selected, MUIV_EveryTime,
1175 (IPTR) application, 2,
1176 MUIM_Application_ReturnID, RETURNID_PROTECT);
1177 DoMethod(writeobject, MUIM_Notify, MUIA_Selected, MUIV_EveryTime,
1178 (IPTR) application, 2,
1179 MUIM_Application_ReturnID, RETURNID_PROTECT);
1180 DoMethod(executeobject, MUIM_Notify, MUIA_Selected, MUIV_EveryTime,
1181 (IPTR) application, 2,
1182 MUIM_Application_ReturnID, RETURNID_PROTECT);
1183 DoMethod(deleteobject, MUIM_Notify, MUIA_Selected, MUIV_EveryTime,
1184 (IPTR) application, 2,
1185 MUIM_Application_ReturnID, RETURNID_PROTECT);
1186 DoMethod(scriptobject, MUIM_Notify, MUIA_Selected, MUIV_EveryTime,
1187 (IPTR) application, 2,
1188 MUIM_Application_ReturnID, RETURNID_PROTECT);
1189 DoMethod(pureobject, MUIM_Notify, MUIA_Selected, MUIV_EveryTime,
1190 (IPTR) application, 2,
1191 MUIM_Application_ReturnID, RETURNID_PROTECT);
1192 DoMethod(archiveobject, MUIM_Notify, MUIA_Selected, MUIV_EveryTime,
1193 (IPTR) application, 2,
1194 MUIM_Application_ReturnID, RETURNID_PROTECT);
1196 DoMethod(btnopenpath, MUIM_Notify, MUIA_Pressed, FALSE,
1197 (IPTR) application, 2,
1198 MUIM_Application_ReturnID, RETURNID_OPENPATH);
1200 #if USE_TEXTEDITOR
1201 set(editor, MUIA_TextEditor_Slider, slider);
1203 if (icon->do_ToolTypes)
1205 char *tt = NULL, *contents;
1206 int i = 0;
1207 ULONG len = 0;
1209 while ((tt = icon->do_ToolTypes[i]) != NULL)
1211 len += strlen(icon->do_ToolTypes[i]) + 1;
1212 i++;
1215 contents = AllocVec(len + 1, MEMF_ANY);
1216 if (contents)
1218 contents[0] = 0;
1219 i = 0;
1220 BOOL first = TRUE;
1222 while ((icon->do_ToolTypes[i]) != NULL)
1224 if ( ! first )
1226 strcat(contents, "\n");
1228 first = FALSE;
1229 strcat(contents, icon->do_ToolTypes[i]);
1231 i++;
1234 set(editor, MUIA_TextEditor_Contents, contents);
1235 FreeVec(contents);
1238 #else
1240 if (icon->do_ToolTypes)
1242 char *tt = NULL;
1243 int i = 0;
1244 while ((tt = icon->do_ToolTypes[i]) != NULL)
1246 DoMethod(list, MUIM_List_InsertSingle, tt, MUIV_List_Insert_Bottom);
1247 i++;
1250 #endif
1252 switch(icon->do_Type)
1254 case WBPROJECT:
1255 AddToolField(application, grouptool, deftool);
1256 AddStackField(application, groupstack, stack);
1257 break;
1258 case WBTOOL:
1259 AddEmptySpace(grouptool);
1260 AddStackField(application, groupstack, stack);
1261 break;
1262 case WBDRAWER:
1263 AddEmptySpace(grouptool);
1264 AddEmptySpace(groupstack);
1265 break;
1268 if (loadedcomment[0])
1269 nnset(commentspace, MUIA_String_Contents, loadedcomment);
1271 nnset(readobject, MUIA_Selected, flags[3]);
1272 nnset(writeobject, MUIA_Selected, flags[4]);
1273 nnset(executeobject, MUIA_Selected, flags[5]);
1274 nnset(deleteobject, MUIA_Selected, flags[6]);
1276 nnset(scriptobject, MUIA_Selected, flags[0]);
1277 nnset(pureobject, MUIA_Selected, flags[1]);
1278 nnset(archiveobject, MUIA_Selected, flags[2]);
1280 SetAttrs(window, MUIA_Window_Open, TRUE, TAG_DONE);
1282 while (returnid != MUIV_Application_ReturnID_Quit)
1284 #ifdef DEBUG
1285 if (returnid)
1287 D(bug("[WBInfo] broker command received: %ld\n", returnid));
1288 #endif
1289 switch(returnid)
1291 case RETURNID_SLEEP:
1292 set(window, MUIA_Window_Open, FALSE);
1293 set(window, MUIA_Window_Activate, TRUE);
1294 break;
1295 case RETURNID_WAKE:
1296 set(window, MUIA_Window_Open, TRUE);
1297 break;
1298 case RETURNID_ABOUT:
1299 if (MUI_RequestA(application, NULL, 0,
1300 _(MSG_ABOUT), _(MSG_OK), _(MSG_COPYRIGHT), NULL))
1301 break;
1302 #if !USE_TEXTEDITOR
1303 case RETURNID_NEWKEY:
1304 NewKey();
1305 break;
1306 case RETURNID_DELKEY:
1307 DelKey();
1308 icon_altered = TRUE;
1309 break;
1310 case RETURNID_LVACK:
1311 ListToString();
1312 break;
1313 case RETURNID_STRINGACK:
1314 StringToKey();
1315 icon_altered = TRUE;
1316 break;
1317 #endif
1318 case RETURNID_SAVE:
1319 #if !USE_TEXTEDITOR
1320 if (icon_altered)
1321 #endif
1322 SaveIcon(icon, file, lock);
1324 /* This is a workardound for String.mui not sending notification on contents change */
1325 STRPTR text = NULL;
1326 get(commentspace, MUIA_String_Contents, &text);
1327 if(strcmp(loadedcomment, text) != 0)
1328 file_altered = TRUE;
1331 if (file_altered)
1332 SaveFile(ap, lock);
1333 DoMethod(application, MUIM_Application_ReturnID, MUIV_Application_ReturnID_Quit);
1334 break;
1335 case RETURNID_STACKACK:
1336 set(window, MUIA_Window_ActiveObject, (IPTR)savebutton);
1337 icon_altered = TRUE;
1338 break;
1339 case RETURNID_TOOLACK:
1340 set(window, MUIA_Window_ActiveObject, (IPTR)savebutton);
1341 icon_altered = TRUE;
1342 break;
1343 case RETURNID_COMMENTACK:
1344 set(window, MUIA_Window_ActiveObject, (IPTR)savebutton);
1345 file_altered = TRUE;
1346 break;
1347 case RETURNID_OPENPATH:
1348 OpenWorkbenchObject(pathname, TAG_DONE);
1349 break;
1350 case RETURNID_QUERYVERSION:
1352 Object * oldversionspace = versionspace;
1354 D(bug("[WBInfo: RETURNID_QUERYVERSION\n"));
1356 versionspace = (Object *)TextObject,
1357 TextFrame,
1358 MUIA_Background, MUII_TextBack,
1359 MUIA_Text_SetMin, FALSE,
1360 MUIA_Text_PreParse, (IPTR) "\33r",
1361 MUIA_Text_Contents, (IPTR) GetVersion(name, lock),
1362 End;
1364 DoMethod(versiongrp, MUIM_Group_InitChange);
1365 DoMethod(versiongrp, OM_REMMEMBER, oldversionspace);
1366 DoMethod(versiongrp, OM_ADDMEMBER, versionspace);
1367 DoMethod(versiongrp, MUIM_Group_ExitChange);
1369 break;
1370 case RETURNID_SCANSIZE:
1372 Object * oldsizespace = sizespace;
1374 D(bug("[WBInfo]: RETURNID_SCANSIZE\n"));
1375 sizespace = (Object *)TextObject,
1376 TextFrame,
1377 MUIA_Background, MUII_TextBack,
1378 MUIA_Text_PreParse, (IPTR) "\33r",
1379 End;
1381 DoMethod(sizegrp, MUIM_Group_InitChange);
1382 DoMethod(sizegrp, OM_REMMEMBER, oldsizespace);
1383 DoMethod(sizegrp, OM_ADDMEMBER, sizespace);
1384 DoMethod(sizegrp, MUIM_Group_ExitChange);
1386 if (scanStruct == NULL)
1387 scanStruct = AllocMem(sizeof(struct DirScanProcess), MEMF_CLEAR);
1389 scanStruct->scanState = SCANDIE;
1390 waitscan:
1392 if (scanStruct->scanProcess != NULL)
1393 goto waitscan;
1395 ULONG dirnamelen = strlen(lname) + strlen(name);
1396 scanStruct->scanState = SCANRUN;
1397 scanStruct->scanDir = AllocVec(dirnamelen + 2, MEMF_CLEAR); /* 2 == path separator + \0 at end */
1398 D(bug("[WBInfo]: lname '%s', name '%s', (%d bytes)\n", lname, name, dirnamelen));
1400 CopyMem(lname, scanStruct->scanDir, strlen(lname));
1401 AddPart(scanStruct->scanDir, name, dirnamelen + 2);
1403 char * tmp_Name = AllocVec(strlen(scanStruct->scanDir) + 24, MEMF_CLEAR);
1404 sprintf(tmp_Name, "Calculating size of %s ..", scanStruct->scanDir);
1406 /* Fire up child process to perform scan of content size .. */
1407 scanStruct->scanProcess = CreateNewProcTags(
1408 NP_Entry, (IPTR)scanDir_Process,
1409 NP_Name, tmp_Name,
1410 NP_Synchronous , FALSE,
1411 NP_Priority, 0,
1412 NP_UserData, (IPTR)scanStruct,
1413 NP_StackSize, 140960,
1414 TAG_DONE);
1416 FreeVec(tmp_Name);
1418 break;
1419 case RETURNID_PROTECT:
1420 file_altered = TRUE;
1421 D(bug("[WBInfo: Protection bits changed\n"));
1422 break;
1424 #ifdef DEBUG
1426 #endif
1427 if (signals)
1429 signals = Wait(signals | SIGBREAKF_CTRL_C);
1430 if(signals & SIGBREAKF_CTRL_C) break;
1433 returnid = ((LONG) DoMethod(application, MUIM_Application_NewInput, (IPTR) &signals));
1435 if (scanStruct)
1437 scanStruct->scanState = SCANDIE;
1438 waitscan2:
1439 if (scanStruct->scanProcess != NULL)
1440 goto waitscan2;
1442 SetAttrs(window, MUIA_Window_Open, FALSE, TAG_DONE);
1443 MUI_DisposeObject(application);
1444 } else {
1445 PrintFault(ERROR_INVALID_RESIDENT_LIBRARY, argv[0]);
1446 D(bug("[WBInfo: Couldn't create app\n"));
1447 retval = RETURN_FAIL;
1450 funcmain_exit:
1451 if (scanStruct) FreeMem(scanStruct, sizeof(struct DirScanProcess));
1452 if (icon) FreeDiskObject(icon);
1453 FreeVec(ap);
1454 FreeVec(file);
1455 FreeVec(name);
1456 return retval;