Initial import of Scalos. To decrease size I have
[AROS-Contrib.git] / scalos / Modules / Delete.Gadtools / Copy_of_delete.c
blob97b34d1a24341e4664cbd33fad627568aaeca06b
1 #include <string.h>
2 #include <dos.h>
4 #include <exec/lists.h>
5 #include <exec/memory.h>
7 #include <dos/exall.h>
8 #include <dos/dostags.h>
9 #include <intuition/imageclass.h>
10 #include <workbench/startup.h>
11 #include <libraries/ctrequest.h>
13 #include <clib/exec_protos.h>
14 #include <clib/dos_protos.h>
15 #include <clib/icon_protos.h>
16 #include <clib/intuition_protos.h>
17 #include <clib/gadtools_protos.h>
18 #include <clib/graphics_protos.h>
19 #include <clib/ctrequest_protos.h>
20 #include <clib/utility_protos.h>
22 #include <pragmas/exec_sysbase_pragmas.h>
23 #include <pragmas/dos_pragmas.h>
24 #include <pragmas/icon_pragmas.h>
25 #include <pragmas/intuition_pragmas.h>
26 #include <pragmas/gadtools_pragmas.h>
27 #include <pragmas/graphics_pragmas.h>
28 #include <pragmas/ctrequest_pragmas.h>
29 #include <pragmas/utility_pragmas.h>
31 __stdargs void NewList( struct List *list );
33 IMPORT struct Library *GadToolsBase;
34 IMPORT struct Library *IntuitionBase;
35 IMPORT struct Library *SysBase;
36 IMPORT struct Library *GfxBase;
37 IMPORT struct Library *DOSBase;
38 IMPORT struct Library *UtilityBase;
40 struct Library *IconBase;
41 struct Library *CTRequestBase;
43 struct Screen *scr;
44 struct DrawInfo *drinfo;
45 APTR visualinfo;
46 ULONG offx,offy,fonty,sizeheight;
47 ULONG wndwidth,wndheight,drawerwidth;
49 struct Window *wnd;
50 struct Gadget *glist;
51 BOOL glistAttached;
52 BOOL fromWB;
54 const STATIC STRPTR engLocText[] =
56 "Warning! You cannot get back what you delete!\nOK to delete:",
57 "_OK",
58 "_Cancel",
59 "Delete",
60 "file(s) and",
61 "drawer(s) (and there contents)?",
62 "Delete|Abort",
63 "Deleting...",
64 "Path",
65 "Abort",
66 "Building Filelist...",
67 "Not Enough Memory",
68 "Error",
69 "couldn't be deleted",
70 "Skip it|Abort",
71 "is protected against deletion.\n\nDelete anywhy?",
72 "Delete|Skip it"
75 UWORD abort_key;
77 STRPTR locText[18];
79 static const STRPTR VerString = "$VER: delete.module 1.0 "__AMIGADATE__;
81 STATIC BOOL CreateGadgets(void);
83 //-------------------------------------
84 // Requester Support
86 #ifdef __SASC
88 STATIC VOID SR_LenFunc(VOID)
90 __emit(0x5293); // ADDQ.L #1,(A3)
93 STATIC VOID SR_CopyFunc(VOID)
95 __emit(0x16c0); // MOVE.B D0,(A3)+
98 STATIC VOID SR_CopyFuncNoUnderscore(VOID)
100 __emit(0xb03c); __emit(0x005f); // CMP.B #'_',D0
101 __emit(0x6702); // BEQ.B .end(RTS)
102 __emit(0x16c0); // MOVE.B D0,(A3)+
105 STATIC VOID SR_Dummy(VOID)
109 #else
111 VOID SR_LenFunc(VOID);
112 VOID SR_CopyFunc(VOID);
113 VOID SR_CopyFuncNoUnderscore(VOID);
114 VOID SR_Dummy(VOID);
116 #endif
118 //-------------------------------------
119 LONG SimpleRequestArgs( struct Window *wnd, struct EasyStruct *easy, ULONG *idcmp, STRPTR reqType, STRPTR fallBackType, APTR argList )
121 struct EasyCTRStruct *ctr;
123 // if ctrrequest.library isn't available call the
124 // intuituin function instead
125 if( !CTRequestBase )
127 STRPTR gadgetText = (STRPTR)easy->es_GadgetFormat;
128 STRPTR newGadgetText;
129 ULONG len;
130 APTR nd;
132 if( !gadgetText )
134 DisplayBeep(NULL);
135 return 0;
138 // Skip the text format
139 if( easy->es_TextFormat ) nd = RawDoFmt(easy->es_TextFormat,argList,(void(*)())SR_Dummy,NULL);
140 else nd = argList;
142 // Calculate the length of the formatted GadgetText
143 len = 0;
144 RawDoFmt(easy->es_GadgetFormat,nd,(void(*)())SR_LenFunc,&len);
146 newGadgetText = (STRPTR)AllocVec( len+2, 0 );
147 if( !newGadgetText ) return EasyRequestArgs(wnd,easy,idcmp,argList);
148 else
150 LONG val;
151 struct EasyStruct es;
153 // Format the gadgettext without underscores
154 RawDoFmt(easy->es_GadgetFormat,nd,(void(*)())SR_CopyFuncNoUnderscore,newGadgetText);
156 es.es_StructSize = sizeof(struct EasyStruct);
157 es.es_Flags = easy->es_Flags;
158 es.es_Title = easy->es_Title;
159 es.es_TextFormat = easy->es_TextFormat;
160 es.es_GadgetFormat = newGadgetText;
162 val = EasyRequestArgs(wnd,&es,idcmp,argList);
163 FreeVec( newGadgetText );
164 return val;
168 // Alloc an EasyCTRStruct
169 ctr = (struct EasyCTRStruct*)AllocVec( sizeof(struct EasyCTRStruct),MEMF_CLEAR);
170 if(ctr)
172 LONG val;
174 // Fill in special things
175 ctr->ectr_Title = easy->es_Title;
176 ctr->ectr_RequesterType = reqType;
177 ctr->ectr_RequesterType_FB =fallBackType;
178 ctr->ectr_TimeOutmodes = NULL;//timeOutmodes;
179 ctr->ectr_Screen = wnd?wnd->WScreen:NULL;
181 // Is any additional Arg given?
182 if( !argList )
184 // No - take the Body and Gadget strings like they are
185 ctr->ectr_Body = easy->es_TextFormat;
186 ctr->ectr_Gadgets = easy->es_GadgetFormat;
187 } else
189 // Yes
190 ULONG len=0;
192 // Calculate the length of the formatted body string
193 APTR nd = RawDoFmt(easy->es_TextFormat,argList,(void(*)())SR_LenFunc,&len);
194 if( len )
196 STRPTR body = (STRPTR)AllocVec( len+2, 0 );
198 // Perform final text formatting
199 if( body ) RawDoFmt(easy->es_TextFormat,argList,(void(*)())SR_CopyFunc,body);
200 ctr->ectr_Body = body;
203 len=0;
205 // Calculate the length of the formatted gadget string
206 RawDoFmt(easy->es_GadgetFormat,nd,(void(*)())SR_LenFunc,&len);
207 if( len )
209 STRPTR gadget = (STRPTR)AllocVec( len+2, 0 );
211 // Perform final gadget formatting
212 if( gadget ) RawDoFmt(easy->es_GadgetFormat,nd,(void(*)())SR_CopyFunc,gadget);
213 ctr->ectr_Gadgets = gadget;
217 // Check for IDCMPs
218 if( idcmp )
220 if( *idcmp & IDCMP_DISKINSERTED ) ctr->ectr_MonitorDiskInserted = TRUE;
221 if( *idcmp & IDCMP_DISKREMOVED ) ctr->ectr_MonitorDiskRemoved = TRUE;
223 // Clear the *idcmp variable
224 *idcmp = 0;
227 // And now the nice requester
228 val = EasyCTRequest(ctr);
229 if( val < -1 )
231 DisplayBeep(NULL);
232 val = 0;
233 } else
235 if( val == -1 && idcmp )
237 if( ctr->ectr_MonitorDiskInserted ) *idcmp |= IDCMP_DISKINSERTED;
238 if( ctr->ectr_MonitorDiskRemoved ) *idcmp |= IDCMP_DISKREMOVED;
242 // ArgList given?
243 if( argList )
245 // Yes - free the allocated memory
246 if( ctr->ectr_Gadgets ) FreeVec(ctr->ectr_Gadgets);
247 if( ctr->ectr_Body ) FreeVec(ctr->ectr_Body);
250 // Free the EasyCTRStruct
251 FreeVec(ctr);
252 return val;
256 //-------------------------------------
257 LONG SimpleRequest( struct Window *wnd, struct EasyStruct *easy, ULONG *idcmp, STRPTR reqType, STRPTR fallBackType, APTR args,... )
259 return SimpleRequestArgs( wnd, easy, idcmp, reqType, fallBackType, &args );
261 //-------------------------------------
263 //-------------------------------------
264 VOID sprintf( STRPTR buf, const STRPTR fmt,...)
266 RawDoFmt((const STRPTR)fmt,(const STRPTR*)&fmt+1,(void(*)())SR_CopyFunc,buf);
269 //-------------------------------------
270 ULONG StrLen( const STRPTR str )
272 if( !str) return 0;
273 return strlen(str);
275 //-------------------------------------
276 STRPTR StrCopy( const STRPTR str )
278 STRPTR dst;
279 if( !str ) return NULL;
280 if( !*str) return NULL;
282 dst = (STRPTR)AllocVec(strlen(str)+1,0);
283 if(dst) strcpy(dst,str);
284 return dst;
286 //-------------------------------------
287 STRPTR NameOfLock( BPTR lock )
289 STRPTR n;
290 BOOL again;
291 ULONG bufSize = 127;
292 if( !lock ) return NULL;
296 again = FALSE;
297 if((n = (STRPTR)AllocVec(bufSize, 0x10000 )))
299 if( NameFromLock( lock, n, bufSize-1 ) == DOSFALSE )
301 if( IoErr() == ERROR_LINE_TOO_LONG )
303 bufSize += 127;
304 again = TRUE;
306 FreeVec(n);
307 n = NULL;
310 } while(again);
312 return n;
314 //-------------------------------------
315 STRPTR WBArg2String( struct WBArg *arg, LONG numArgs )
317 struct WBArgNode
319 struct MinNode node;
320 STRPTR dirname;
321 STRPTR filename;
324 struct MinList list;
325 ULONG len=0;
326 STRPTR buf;
327 UWORD i;
329 NewList((struct List*)&list );
331 for( i=0; i<numArgs; i++)
333 struct WBArgNode *node = (struct WBArgNode*)AllocVec(sizeof(struct WBArgNode),0x10000);
334 if(node)
336 STRPTR n = NameOfLock(arg[i].wa_Lock);
337 node->dirname = n;
338 node->filename = arg[i].wa_Name;
340 len += StrLen( n )+StrLen(arg[i].wa_Name)+8;
341 AddTail((struct List*)&list, (struct Node*)node );
345 buf = (STRPTR)AllocVec(len+2,0x10000);
346 if(buf)
348 struct WBArgNode *node;
349 STRPTR bufPtr = buf;
351 while(( node = (struct WBArgNode*)RemHead((struct List*)&list)))
353 STRPTR n = node->dirname;
354 if( !n ) continue;
356 if( n[0] ) strcpy(bufPtr,n );
357 AddPart(bufPtr,node->filename,len-(bufPtr-buf));
359 bufPtr+=strlen(bufPtr);
360 if(list.mlh_Head->mln_Succ)
361 *bufPtr++=' ';
363 FreeVec(n);
364 FreeVec(node);
366 *bufPtr = 0;
368 return buf;
370 //-------------------------------------
371 STRPTR GetFullPath( const STRPTR drw, const STRPTR file )
373 ULONG length = StrLen(drw)+StrLen(file)+4;
374 STRPTR fp = (STRPTR)AllocVec( length+1,0 );
375 if( fp )
377 strcpy( fp, drw );
379 if( AddPart( fp, file, length )) return fp;
380 FreeVec( fp );
382 return NULL;
384 //-------------------------------------
385 STRPTR BuildIconName( const STRPTR name )
387 ULONG namelen=strlen(name);
388 STRPTR infoname = AllocVec(namelen+8,0);
389 if(infoname)
391 strcpy(infoname,name);
392 strcpy(infoname+namelen,".info");
394 return infoname;
396 //-------------------------------------
398 ULONG deleteAllProt;
400 STRPTR delprot_body = "is protected against deletion.\n\nDelete anyway?";
401 STRPTR couldnt_body = "couldn't be deleted:";
403 //-------------------------------------
404 // Readsupport
405 struct DirList
407 struct MinList list;
408 BPTR lock;
409 ULONG read;
412 struct DirNode
414 struct MinNode node;
415 STRPTR name;
416 struct DirList list;
417 struct DirList *parentList;
418 ULONG icon;
421 struct FileNode
423 struct MinNode node;
424 STRPTR name;
425 ULONG nameLen;
426 ULONG icon;
429 //-------------------------------------
430 ULONG PrintError( const ULONG ioerr, const STRPTR name, const STRPTR button )
432 struct EasyStruct easy;
433 char buffer[80];
435 easy.es_StructSize = sizeof(struct EasyStruct);
436 easy.es_Flags = 0;
437 easy.es_Title = "Scalos";
438 easy.es_TextFormat = "%s %s\n%s";
439 easy.es_GadgetFormat = "%s";
441 Fault( ioerr, NULL, buffer,80);
443 return (ULONG)SimpleRequest( NULL, &easy, NULL, ECTR_TYPE_WARNING, NULL, name, couldnt_body, buffer,button);
445 //-------------------------------------
446 BOOL IsDeletable( const STRPTR name, ULONG prot)
448 if(( prot & FIBF_DELETE ))
450 BOOL del=deleteAllProt;
451 if( !deleteAllProt)
453 struct EasyStruct easy;
454 easy.es_StructSize = sizeof(struct EasyStruct);
455 easy.es_Flags = 0;
456 easy.es_Title = "Scalos";
457 easy.es_TextFormat = "%s\n%s";
458 easy.es_GadgetFormat = "%s";
460 switch( SimpleRequest( NULL, &easy, NULL, ECTR_TYPE_WARNING, NULL, name, delprot_body, "Delete|DeleteAllProtect|Skip"))
462 case 0:
463 break;
465 case 1:
466 del=TRUE;
467 break;
469 case 2:
470 del=deleteAllProt=TRUE;
471 break;
474 return del;
476 return TRUE;
479 //-------------------------------------
480 ULONG Unprotect( const STRPTR name, const ULONG icon, ULONG prot)
482 if(( prot & FIBF_DELETE ))
484 BOOL ok;
485 if(SetProtection(name,NULL) != DOSFALSE ) ok=TRUE;
486 else
488 LONG ioerr = IoErr();
489 if( ioerr == ERROR_OBJECT_NOT_FOUND ) ok = TRUE;
490 else
492 ok = FALSE;
493 return PrintError(ioerr,name,"Skip|Abort");
497 if(ok && icon )
499 if( icon )
501 STRPTR infoname = BuildIconName(name);
502 if(infoname)
504 if(SetProtection(infoname,NULL)== DOSFALSE )
506 LONG ioerr = IoErr();
507 if( ioerr == ERROR_OBJECT_NOT_FOUND ) ok = TRUE;
508 else return PrintError(ioerr,name,"Skip|Abort");
511 FreeVec(infoname);
516 return 2;
518 //-------------------------------------
519 BOOL DeleteTheFile( const STRPTR name, const ULONG icon )
521 BOOL goon = TRUE;
522 struct TextExtent te;
523 ULONG len = strlen(name);
524 ULONG nc;
525 LONG ioerr;
526 BOOL onlyicon = FALSE;
528 struct IntuiMessage *imsg;
530 Move(wnd->RPort,offx+2,offy+drinfo->dri_Font->tf_Baseline+2+fonty+1);
531 nc = TextFit(wnd->RPort,(const STRPTR)name+len,len,&te,NULL,-1,wndwidth-2*offx-4,fonty);
532 Text(wnd->RPort,(const STRPTR)name+len-nc,nc);
534 if( te.te_Width < drawerwidth )
536 EraseRect(wnd->RPort,wnd->RPort->cp_x,offy+3+fonty,offx+2+drawerwidth,offy+2+2*fonty);
539 if(wnd)
541 while((imsg = (struct IntuiMessage*)GT_GetIMsg(wnd->UserPort)))
543 ULONG cl = imsg->Class;
545 if( cl == IDCMP_SIZEVERIFY )
547 if(glistAttached) RemoveGList( wnd, glist, -1 );
548 glistAttached = FALSE;
549 GT_ReplyIMsg(imsg);
550 continue;
553 GT_ReplyIMsg(imsg);
555 switch(cl)
557 case IDCMP_GADGETUP:
558 case IDCMP_CLOSEWINDOW:
559 return FALSE;
560 break;
562 case IDCMP_NEWSIZE:
563 if(glistAttached) RemoveGList( wnd, glist, -1 );
564 wndwidth = wnd->Width;
565 wndheight = wnd->Height;
566 EraseRect( wnd->RPort, wnd->BorderLeft, wnd->BorderTop+fonty+3,
567 wnd->Width-wnd->BorderRight-1, wnd->Height-wnd->BorderBottom-1 );
568 if(CreateGadgets())
570 AddGList( wnd, glist, -1,-1, NULL );
571 RefreshGList( glist, wnd, NULL, -1 );
572 glistAttached = TRUE;
573 SetFont(wnd->RPort,drinfo->dri_Font);
575 break;
580 drawerwidth = te.te_Width;
582 if(DeleteFile(name)==DOSFALSE)
584 ioerr = IoErr();
585 if( ioerr == ERROR_OBJECT_NOT_FOUND)
587 if(!DeleteDiskObject(name))
589 ioerr=IoErr();
590 if(ioerr==ERROR_OBJECT_NOT_FOUND) ioerr=0;
592 else ioerr=0;
593 onlyicon=TRUE;
595 } else ioerr=0;
597 if( ioerr )
599 switch( ioerr)
601 case ERROR_DELETE_PROTECTED:
603 BOOL del=deleteAllProt;
604 if( !deleteAllProt)
606 struct EasyStruct easy;
608 easy.es_StructSize = sizeof(struct EasyStruct);
609 easy.es_Flags = 0;
610 easy.es_Title = "Scalos";
611 easy.es_TextFormat = "%s\n%s";
612 easy.es_GadgetFormat = "%s";
614 switch( SimpleRequest( NULL, &easy, NULL, ECTR_TYPE_WARNING, NULL, name, delprot_body, "Delete|DeleteAllProtect|Skip"))
616 case 0:
617 del=FALSE;
618 break;
620 case 1:
621 del=TRUE;
622 break;
624 case 2:
625 del=deleteAllProt=TRUE;
626 break;
630 if(del)
632 BOOL ok = onlyicon;
633 if( !ok ) if(SetProtection(name,NULL) != DOSFALSE ) ok=TRUE;
635 if(ok)//nlyicon || SetProtection(name,NULL) != DOSFALSE )
637 BOOL error;
639 if( icon || onlyicon )
641 ULONG namelen=strlen(name);
642 STRPTR infoname = AllocVec(namelen+8,0);
643 error = TRUE;
644 if(infoname)
646 strcpy(infoname,name);
647 strcpy(infoname+namelen,".info");
649 if(SetProtection(infoname,NULL) != DOSFALSE )
650 error = FALSE;
652 FreeVec(infoname);
653 } else SetIoErr(103);
654 } else error=FALSE;
656 if( !error )
658 if( onlyicon )
660 if(DeleteDiskObject(name)) return TRUE;
661 } else
663 if(DeleteFile(name) != DOSFALSE )
665 if(icon)
667 if(DeleteDiskObject(name)) return TRUE;
668 } else return TRUE;
673 ioerr = IoErr();
674 } else break;
677 default:
678 /* {
679 struct EasyStruct easy;
680 char buffer[80];
682 easy.es_StructSize = sizeof(struct EasyStruct);
683 easy.es_Flags = 0;
684 easy.es_Title = "Scalos";
685 easy.es_TextFormat = "%s %s\n%s";
686 easy.es_GadgetFormat = "%s";
688 Fault( ioerr, NULL, buffer,80);
690 return (BOOL)SimpleRequest( NULL, &easy, NULL, ECTR_TYPE_WARNING, NULL, name, couldnt_body, buffer,"Skip|Abort");
692 return (BOOL)PrintError(ioerr,name,"Skip|Abort");
693 break;
695 } else
697 if( icon )
699 DeleteDiskObject(name);
703 return goon;
705 //-------------------------------------
706 BOOL ReadInDir( struct DirList *list, APTR dirPool )
708 BOOL retval = TRUE;
709 STRPTR lockName;
711 if( !list->lock )
713 Printf("No Lock!\n");
714 return FALSE;
717 if( list->read )
719 PutStr("Already read!\n");
720 return TRUE;
723 lockName = NameOfLock(list->lock);
724 if( lockName )
726 ULONG lockSize = strlen(lockName);
727 APTR filePool = CreatePool( 0,4096,4096);
728 if( filePool )
730 struct ExAllControl *eac;
731 eac = (struct ExAllControl*)AllocDosObject(DOS_EXALLCONTROL,NULL);
732 if( eac )
734 struct ExAllData *ead;
735 ead = (struct ExAllData*)AllocVec( 1032, 0x10000 );
736 if(ead)
738 LONG more;
739 struct MinList fileList;
740 NewList((struct List*)&fileList);
742 eac->eac_LastKey = 0;
743 eac->eac_MatchString = NULL;
745 list->read = TRUE;
749 struct ExAllData *ed = ead;
750 more = ExAll( list->lock, ed, 1024, ED_TYPE, eac );
751 if((!more) && (IoErr() != ERROR_NO_MORE_ENTRIES ))
753 retval = FALSE;
754 break;
757 if( eac->eac_Entries )
761 ULONG nlen = strlen(ed->ed_Name);
762 ULONG len = nlen+8+lockSize;
763 if( ed->ed_Type > 0 )
765 struct DirNode *dir = (struct DirNode*)AllocPooled(dirPool,sizeof(struct DirNode));
766 if( dir )
768 STRPTR name = (STRPTR)AllocPooled(dirPool,len);
769 if(name)
771 strcpy(name,lockName);
772 AddPart(name,ed->ed_Name,len);
774 dir->name = name;
775 dir->list.lock = Lock( name, ACCESS_READ);
776 dir->list.read = FALSE;
777 dir->parentList = list;
778 dir->icon = FALSE;
779 NewList((struct List*)&dir->list);
781 AddTail((struct List*)list, (struct Node*)dir);
784 } else
786 struct FileNode *file = (struct FileNode*)AllocPooled(filePool,sizeof(struct FileNode));
787 if( file )
789 STRPTR name = (STRPTR)AllocPooled(filePool,len);
790 if( name )
792 strcpy(name,lockName);
793 AddPart(name,ed->ed_Name,len);
795 file->name = name;
796 file->nameLen = strlen(name);
797 file->icon = FALSE;
798 AddTail((struct List*)&fileList, (struct Node*)file);
802 ed = ed->ed_Next;
803 } while(ed);
805 } while(more);
807 FreeVec(ead);
809 // Icons aussortieren
810 if( !IsListEmpty((struct List*)&fileList))
812 struct FileNode *node;
813 node = (struct FileNode*)fileList.mlh_Head;
814 while(node->node.mln_Succ && retval)
816 if( node->nameLen > 4 )
818 if( !Stricmp(".info",node->name+node->nameLen-5))
820 struct FileNode *fnode = (struct FileNode*)fileList.mlh_Head;
821 BOOL iconfound=FALSE;
822 node->name[node->nameLen-5]=0;
823 while(fnode->node.mln_Succ)
825 if( fnode != node )
827 if( !Stricmp(node->name,fnode->name))
829 fnode->icon = iconfound = TRUE;
830 break;
833 fnode = (struct FileNode*)fnode->node.mln_Succ;
836 if( !iconfound )
838 struct DirNode *dnode = (struct DirNode*)list->list.mlh_Head;
839 while(dnode->node.mln_Succ)
841 if( !Stricmp(node->name,dnode->name))
843 dnode->icon = iconfound = TRUE;
844 break;
847 dnode = (struct DirNode*)dnode->node.mln_Succ;
851 if( iconfound )
853 struct FileNode *tfn = node;
854 node = (struct FileNode*)node->node.mln_Succ;
855 Remove((struct Node*)tfn);
856 continue;
860 node = (struct FileNode*)node->node.mln_Succ;
863 node = (struct FileNode*)fileList.mlh_Head;
864 while(node->node.mln_Succ && retval)
866 retval = DeleteTheFile(node->name,node->icon);
867 node = (struct FileNode*)node->node.mln_Succ;
872 FreeDosObject(DOS_EXALLCONTROL,eac);
874 DeletePool(filePool);
876 FreeVec(lockName);
878 return retval;
880 //-------------------------------------
881 BOOL DeleteDir( struct DirList *root, APTR dirPool )
883 struct DirList *cl = root;
884 BOOL goon = TRUE;
885 while(cl)
887 // Printf("Readdir: %s 0x%lx\n",NameOfLock(cl->lock),cl);
888 if(goon)
890 if(!ReadInDir(cl,dirPool)) goon=FALSE;
893 if( !IsListEmpty((struct List*)cl))
895 struct DirNode *cn = (struct DirNode*)cl->list.mlh_Head;
896 cl = (struct DirList*)&cn->list;
897 } else
899 if(cl != root )
901 struct DirNode *cn = (struct DirNode*)(((ULONG*)cl)-3);
902 struct DirNode *ncn = (struct DirNode*)cn->node.mln_Succ;
904 if( !ncn->node.mln_Succ )
908 if( cl == root ) return TRUE;
910 cl = cn->parentList;
911 if( !cl )
913 PutStr("Ready...\n");
914 return TRUE;
917 if( IsListEmpty((struct List*)cl))
919 PutStr("Error!!\n");
920 return FALSE;
923 ncn = (struct DirNode*)RemHead((struct List*)cl);
924 cn = (struct DirNode*)(((ULONG*)cl)-3);
926 UnLock(ncn->list.lock);
927 ncn->list.lock = NULL;
928 if( goon )
930 goon = DeleteTheFile(ncn->name,ncn->icon);
931 /* {
932 cl = NULL;
933 break;
936 } while( IsListEmpty((struct List*)cl));
937 if( !cl ) break;
939 ncn = (struct DirNode*)cl->list.mlh_Head;
940 } else
942 Remove((struct Node*)cn);
943 UnLock(cn->list.lock);
945 if( goon ) goon=DeleteTheFile(cn->name,cn->icon);// break;
948 cl = (struct DirList*)&ncn->list;
949 } else return FALSE;
952 return FALSE;
954 //-------------------------------------
956 //-------------------------------------
957 STATIC BOOL SetupScreen(void)
959 if((scr = LockPubScreen(NULL)))
961 if((drinfo = GetScreenDrawInfo(scr)))
963 if((visualinfo = GetVisualInfoA(scr,NULL)))
965 Object *o = (Object*)NewObject( NULL, SYSICLASS,
966 SYSIA_DrawInfo,drinfo,
967 SYSIA_Which, SIZEIMAGE,
968 TAG_DONE);
969 if(o)
971 if(!GetAttr( IA_Height,o,&sizeheight)) sizeheight = 11;
972 DisposeObject(o);
973 } else sizeheight = 11;
974 return TRUE;
978 return FALSE;
980 //-------------------------------------
981 STATIC VOID FreeScreen(void)
983 if( visualinfo ) FreeVisualInfo(visualinfo);
984 if( drinfo ) FreeScreenDrawInfo(scr,drinfo);
985 if( scr ) UnlockPubScreen(NULL,scr);
987 //-------------------------------------
988 STATIC VOID Render(void)
990 Move(wnd->RPort,offx+2,offy+drinfo->dri_Font->tf_Baseline+2);
991 SetABPenDrMd(wnd->RPort,drinfo->dri_Pens[TEXTPEN],drinfo->dri_Pens[BACKGROUNDPEN],JAM2);
992 Text(wnd->RPort,"Deleting...",11);
994 //-------------------------------------
995 STATIC BOOL CreateGadgets(void)
997 struct Gadget *g;
999 if(glist)
1001 FreeGadgets(glist);
1002 glist = NULL;
1005 g = CreateContext( &glist );
1006 if( g )
1008 struct NewGadget ng;
1010 ng.ng_VisualInfo = visualinfo;
1011 ng.ng_TextAttr = NULL;
1012 ng.ng_GadgetText = "_Abort";
1013 ng.ng_GadgetID = 1;
1014 ng.ng_Flags = PLACETEXT_IN;
1015 ng.ng_UserData = NULL;
1016 ng.ng_LeftEdge = offx+2;
1017 ng.ng_TopEdge = offy+2*fonty+4;
1018 ng.ng_Width = wndwidth-2*ng.ng_LeftEdge;
1019 ng.ng_Height = fonty+6;
1021 g = CreateGadget( BUTTON_KIND, g, &ng,
1022 GT_Underscore,'_',
1023 TAG_DONE);
1024 if(g) return TRUE;
1026 FreeGadgets(glist);
1027 glist=NULL;
1029 return FALSE;
1031 //-------------------------------------
1032 STATIC VOID FreeGUI(void)
1034 if(wnd) CloseWindow(wnd);
1035 if(glist) FreeGadgets(glist);
1037 //-------------------------------------
1038 STATIC BOOL SetupGUI(void)
1040 fonty = drinfo->dri_Font->tf_YSize;
1041 offx = scr->WBorLeft;
1042 offy = scr->WBorTop + fonty + 1;
1044 wndwidth = 300;
1045 wndheight = offy + 2*fonty + sizeheight + 20;
1047 if( CreateGadgets())
1049 wnd = OpenWindowTags( NULL,
1050 WA_Left,(scr->Width-wndwidth)/2,
1051 WA_Top,(scr->Height-wndheight)/2,
1052 WA_Width, wndwidth,
1053 WA_Height, wndheight,
1054 WA_IDCMP, IDCMP_CLOSEWINDOW|IDCMP_NEWSIZE|BUTTONIDCMP|IDCMP_SIZEVERIFY|IDCMP_VANILLAKEY,
1055 WA_DragBar,TRUE,
1056 WA_SizeGadget, TRUE,
1057 WA_DepthGadget,TRUE,
1058 WA_CloseGadget, TRUE,
1059 WA_Title,"Delete",
1060 WA_RMBTrap, TRUE,
1061 WA_Gadgets, glist,
1062 WA_SizeBBottom,TRUE,
1063 WA_MaxWidth,-1,
1064 WA_Activate, TRUE,
1065 WA_PubScreen,scr,
1066 WA_NoCareRefresh,TRUE,
1067 TAG_DONE );
1068 if( wnd )
1070 glistAttached = TRUE;
1071 SetFont(wnd->RPort,drinfo->dri_Font);
1072 Render();
1073 return TRUE;
1075 glistAttached = FALSE;
1077 FreeGUI();
1078 return FALSE;
1080 //-------------------------------------
1081 /*STATIC BOOL HandleWnd(void)
1083 struct IntuiMessage *imsg;
1084 BOOL retVal = FALSE;
1086 while((imsg = GT_GetIMsg(wnd->UserPort)))
1088 ULONG cl = imsg->Class;
1089 UWORD code = imsg->Code;
1090 APTR iaddress = imsg->IAddress;
1092 if( cl == IDCMP_SIZEVERIFY )
1094 if(glistAttached) RemoveGList( wnd, glist, -1 );
1095 glistAttached = FALSE;
1096 GT_ReplyIMsg(imsg);
1097 continue;
1100 GT_ReplyIMsg(imsg);
1102 switch( cl )
1104 case IDCMP_CLOSEWINDOW:
1105 retVal = TRUE;
1106 break;
1108 case IDCMP_VANILLAKEY:
1109 if( code == 10 ) retVal = TRUE;
1110 else if( code == 27 )
1112 retVal = TRUE;
1114 break;
1116 case IDCMP_NEWSIZE:
1117 if(glistAttached) RemoveGList( wnd, glist, -1 );
1118 wndwidth = wnd->Width;
1119 wndheight = wnd->Height;
1120 EraseRect( wnd->RPort, wnd->BorderLeft, wnd->BorderTop+fonty+3,
1121 wnd->Width-wnd->BorderRight-1, wnd->Height-wnd->BorderBottom-1 );
1122 if(CreateGadgets())
1124 AddGList( wnd, glist, -1,-1, NULL );
1125 RefreshGList( glist, wnd, NULL, -1 );
1126 glistAttached = TRUE;
1127 SetFont(wnd->RPort,drinfo->dri_Font);
1128 } else
1130 glistAttached = FALSE;
1131 retVal = TRUE;
1133 break;
1135 case IDCMP_GADGETUP:
1136 switch( ((struct Gadget*)iaddress)->GadgetID )
1138 default:
1139 break;
1141 break;
1144 return retVal;
1146 //-------------------------------------
1148 STRPTR warning_body = "Warning! You cannot get back what you delete!\nOK to delete:";
1149 STRPTR files_body = "file(s) and";
1150 STRPTR drawers_body = "drawer(s) (and there contents)?";
1152 //-------------------------------------
1153 void main(void)
1155 /* if(SetupScreen())
1157 if( SetupGUI())
1159 BOOL ready = FALSE;
1160 ULONG wndsig = 1UL<<wnd->UserPort->mp_SigBit;
1161 ULONG appsig;
1163 if( appMsgPort ) appsig = 1UL<<appMsgPort->mp_SigBit;
1164 else appsig = 0UL;
1166 ActivateGadget(commandString,wnd,NULL);
1168 while( ready == FALSE )
1170 ULONG signal = Wait(wndsig|appsig|4096);
1172 if( signal & 4096 ) ready = TRUE;
1173 if( signal & wndsig ) ready = HandleWnd();
1174 if( signal & appsig ) HandleApp();
1176 FreeGUI();
1178 if( commandStr )
1180 STRPTR conName = BuildConName("Scalos Output Window",scr);
1181 if( conName )
1183 SystemTags( commandStr,
1184 SYS_Asynch, TRUE,
1185 SYS_Output, Open(conName,MODE_OLDFILE),
1186 SYS_Input, NULL,
1187 SYS_UserShell, TRUE,
1188 stackNum>=4096?NP_StackSize:TAG_IGNORE,stackNum,
1189 TAG_DONE);
1191 FreeVec(conName);
1193 SetVar("Scalos_last_cmd",commandStr,strlen(commandStr),GVF_GLOBAL_ONLY);
1194 FreeVec(commandStr);
1195 commandStr = NULL;
1198 FreeScreen();
1201 if(WorkbenchBase)CloseLibrary(WorkbenchBase);*/
1203 //-------------------------------------
1204 void wbmain(struct WBStartup *wbs )
1206 BOOL replied=FALSE;
1207 if( wbs->sm_NumArgs > 1 )
1209 if((IconBase = OpenLibrary("icon.library",37)))
1211 LONG numArgs=wbs->sm_NumArgs;
1212 struct WBArg *wbarg;
1214 main();
1216 wbarg = (struct WBArg*)AllocVec((numArgs+2)*sizeof(struct WBArg),0x10000);
1217 if( wbarg )
1219 ULONG num_files=0;
1220 ULONG num_drws=0;
1221 ULONG i;
1222 BOOL error=FALSE;
1224 for( i=1; i<numArgs; i++)
1226 if(!(wbarg[i-1].wa_Lock = /*((Lock("RAM:Unnamed1",ACCESS_READ)))/ */DupLock(wbs->sm_ArgList[i].wa_Lock)))
1228 error = TRUE;
1229 break;
1230 } else
1232 if(wbs->sm_ArgList[i].wa_Name)
1234 if(*wbs->sm_ArgList[i].wa_Name)
1236 if(!(wbarg[i-1].wa_Name = StrCopy(wbs->sm_ArgList[i].wa_Name)))
1238 error = TRUE;
1239 break;
1241 num_files++;
1243 else num_drws++;
1245 else num_drws++;
1249 if( !error )
1251 ReplyMsg((struct Message*)wbs);
1252 wbs=NULL;
1253 replied=TRUE;
1254 numArgs--;
1256 if( SetupScreen())
1258 struct EasyStruct easy;
1260 easy.es_StructSize = sizeof(struct EasyStruct);
1261 easy.es_Flags = 0;
1262 easy.es_Title = "Scalos";
1263 easy.es_TextFormat = "%s\n%ld %s %ld %s";
1264 easy.es_GadgetFormat = "%s";
1266 if( SimpleRequest( NULL, &easy, NULL, ECTR_TYPE_WARNING, NULL, warning_body, num_files, files_body, num_drws, drawers_body, "OK|Cancel"))
1268 if(SetupGUI())
1270 BOOL ready = FALSE;
1271 for( i=0; i<numArgs && !ready; i++)
1273 BOOL drawer = TRUE;
1275 if(wbarg[i].wa_Name)
1277 if(*wbarg[i].wa_Name) drawer = FALSE;
1280 if( drawer )
1282 APTR dirPool = CreatePool(NULL,4096,4096);
1283 if( dirPool )
1285 struct DirList list;
1286 STRPTR name=NameOfLock(wbarg[i].wa_Lock);
1287 if(name)
1289 struct FileInfoBlock *fib = (struct FileInfoBlock*)AllocDosObject(DOS_FIB,NULL);
1290 if(fib)
1292 if(Examine( wbarg[i].wa_Lock,fib)!=DOSFALSE)
1294 if(IsDeletable(name,fib->fib_Protection))
1296 NewList((struct List*)&list);
1298 list.lock = wbarg[i].wa_Lock;//Lock("RAM:",ACCESS_READ);
1299 list.read = FALSE;
1301 DeleteDir(&list,dirPool);
1303 UnLock(wbarg[i].wa_Lock);
1304 wbarg[i].wa_Lock=NULL;
1306 switch(Unprotect(name,TRUE,fib->fib_Protection))
1308 case 0: ready=TRUE;break;
1309 case 2: if(!DeleteTheFile(name,TRUE))ready=TRUE;
1312 } else PrintError(IoErr(),name,"OK");
1314 FreeVec(name);
1316 DeletePool(dirPool);
1318 } else
1320 STRPTR dname=NameOfLock(wbarg[i].wa_Lock);
1321 if(dname)
1323 ULONG len=strlen(dname)+8+strlen(wbarg[i].wa_Name);
1324 STRPTR name = (STRPTR)AllocVec(len,0);
1325 if(name)
1327 strcpy(name,dname);
1328 AddPart(name,wbarg[i].wa_Name,len);
1329 if(!DeleteTheFile(name,TRUE))
1331 ready=TRUE;
1337 FreeGUI();
1341 FreeScreen();
1345 for( i=0; i<numArgs; i++)
1347 if(wbarg[i].wa_Lock) UnLock(wbarg[i].wa_Lock);
1348 if(wbarg[i].wa_Name) FreeVec(wbarg[i].wa_Name);
1350 FreeVec(wbarg);
1352 CloseLibrary(IconBase);
1355 return replied;
1357 //-------------------------------------