2 Copyright © 2007-2009, The AROS Development Team. All rights reserved.
6 #include "filesystems.h"
8 struct TagItem DummyTags
[] = { {TAG_DONE
, 0}};
10 /* define some nonglobal data that can be used by the display hook */
13 void strcrem(char *s
, char *d
, char c
)
16 if (*s
!= c
) *d
++= *s
;
24 WORD
AskChoiceNew(char *title
, char *strg
, char *gadgets
, UWORD sel
, BOOL centered
)
28 Object
*button
, *bObject
, *selObject
;
33 char Buffer
[64], Buffer1
[64];
37 app
= MUI_NewObject(MUIC_Application
,
39 MUIA_Application_Title
, (IPTR
)"Requester",
40 MUIA_Application_Base
, (IPTR
)"WANDERER_REQ",
42 SubWindow
, (IPTR
)(win
= MUI_NewObject(MUIC_Window
,
43 MUIA_Window_Title
, title
,
44 MUIA_Window_Activate
, TRUE
,
45 MUIA_Window_DepthGadget
, TRUE
,
46 MUIA_Window_SizeGadget
, FALSE
,
47 MUIA_Window_AppWindow
, FALSE
,
48 MUIA_Window_CloseGadget
, FALSE
,
49 MUIA_Window_Borderless
, FALSE
,
50 MUIA_Window_TopEdge
, MUIV_Window_TopEdge_Moused
,
51 MUIA_Window_LeftEdge
, MUIV_Window_LeftEdge_Moused
,
53 WindowContents
, (IPTR
)MUI_NewObject(MUIC_Group
,
54 Child
, (IPTR
)MUI_NewObject(MUIC_Text
,
59 MUIA_InnerBottom
,(12),
60 MUIA_Background
, MUII_TextBack
,
61 MUIA_Text_PreParse
, (IPTR
)"\33c",
62 MUIA_Text_Contents
, (IPTR
)strg
,
64 Child
, (IPTR
)(bObject
= MUI_NewObject(MUIC_Group
,MUIA_Group_Horiz
, TRUE
,TAG_DONE
)),
78 old
= SplitName(gadgets
, '|', Buffer
, old
, sizeof(Buffer
));
79 if (old
== -1) back
= 10;
80 strcrem(Buffer
, Buffer1
, '_');
81 button
= SimpleButton(Buffer1
);
84 if ((back
-10) == sel
) selObject
= button
;
85 set(button
, MUIA_CycleChain
, 1);
86 DoMethod(bObject
, MUIM_Group_InitChange
);
87 DoMethod(bObject
, OM_ADDMEMBER
, button
);
88 DoMethod(bObject
, MUIM_Group_ExitChange
);
89 DoMethod(button
,MUIM_Notify
,MUIA_Pressed
, FALSE
, app
,2,MUIM_Application_ReturnID
,back
);
98 set (win
, MUIA_Window_TopEdge
, MUIV_Window_TopEdge_Centered
);
99 set (win
, MUIA_Window_LeftEdge
, MUIV_Window_LeftEdge_Centered
);
101 if (selObject
) set(win
, MUIA_Window_ActiveObject
, selObject
);
102 set(win
,MUIA_Window_Open
,TRUE
);
106 id
= DoMethod(app
,MUIM_Application_Input
,&signals
);
110 case MUIV_Application_ReturnID_Quit
:
150 if (running
&& signals
) Wait(signals
);
152 set(win
,MUIA_Window_Open
,FALSE
);
153 MUI_DisposeObject(app
);
160 WORD
AskChoice(char *title
, char *strg
, char *gadgets
, UWORD sel
)
162 return AskChoiceNew(title
, strg
, gadgets
, sel
, FALSE
);
166 ///AskChoiceCentered()
167 WORD
AskChoiceCentered(char *title
, char *strg
, char *gadgets
, UWORD sel
)
169 return AskChoiceNew(title
, strg
, gadgets
, sel
, TRUE
);
174 char *combinePath(APTR pool
, char *path
, char *file
)
178 if ((path
== NULL
) || (file
== NULL
)) return NULL
;
179 if (strlen(path
) == 0) return NULL
;
180 if (strlen(file
) == 0) return NULL
;
182 l
= strlen(path
) + strlen(file
) + 1;
183 if (path
[strlen(path
)-1] != '/') l
++;
185 if (pool
== NULL
) out
= AllocVec(l
, MEMF_CLEAR
);
186 else out
= AllocPooled(pool
, l
);
191 AddPart(out
, file
, l
);
198 char *allocPath(APTR pool
, char *str
)
209 for (l
=0; s0
!= s1
; s0
++,l
++);
211 s
= AllocPooled(pool
, l
+1);
212 if (s
) strncpy(s
, str
, l
);
219 void freeString(APTR pool
, char *str
)
226 FreePooled(pool
, str
, strlen(str
)+1);
233 ** allocates memory for a string and copies them to the new buffer
235 ** inputs: str source string
236 ** return: char pointer to string or NULL
239 char *allocString(APTR pool
, char *str
)
244 if (str
== NULL
) return NULL
;
249 b
= (char*) AllocVec(l
+1, MEMF_CLEAR
);
250 else b
= (char*) AllocPooled(pool
, l
+1);
252 if (b
&& (l
>0)) strncpy (b
, str
, l
);
258 void InfoRename(APTR pool
, char *from
, char *to
)
260 char *frominfo
, *toinfo
;
262 if ((from
== NULL
) || (to
== NULL
)) return;
264 frominfo
= AllocPooled(pool
, strlen(from
)+6);
268 strncpy (frominfo
, from
, strlen(from
));
269 strcat(frominfo
,".info");
270 toinfo
= AllocPooled(pool
, strlen(to
)+6);
274 strncpy (toinfo
, to
, strlen(to
));
275 strcat(toinfo
,".info");
276 if (Rename(from
, to
)) Rename(frominfo
, toinfo
);
277 freeString(pool
, toinfo
);
279 freeString(pool
, frominfo
);
284 ///allocPathFromLock()
285 char *allocPathFromLock(APTR pool
, BPTR lock
)
290 pathb
= AllocPooled(pool
, PATHBUFFERSIZE
);
293 if (NameFromLock(lock
, pathb
, PATHBUFFERSIZE
))
295 path
= allocString(pool
, pathb
);
297 FreePooled(pool
, pathb
, PATHBUFFERSIZE
);
304 char *CombineString(char *format
, ...) {
308 char *s
, *s1
, *str
, *p
;
313 while ((s
= strstr(s
,"%s")) != NULL
) {cnt
++; s
++; }
317 len
= strlen(format
) - 2*cnt
;
318 va_start(ap
, format
);
323 p
= va_arg(ap
, char *);
330 back
= AllocVec(len
, MEMF_CLEAR
);
335 va_start(ap
, format
);
336 while ((s1
= strstr(s
, "%s")) != NULL
)
338 p
= va_arg(ap
, char *);
340 strncpy(str
, s
, len
);
343 strncpy(str
, p
, strlen(p
));
346 if (s
) strncpy(str
, s
, strlen(s
));
356 ULONG
isPathRecursive(APTR pool
, char *source
, char *destination
)
358 BPTR srcLock
, destLock
;
363 srcLock
= Lock(source
, SHARED_LOCK
);
366 destLock
= Lock(destination
, SHARED_LOCK
);
369 p1
= allocPathFromLock(pool
, srcLock
);
372 p2
= allocPathFromLock(pool
, destLock
);
375 if (strstr(p2
, p1
) == p2
) back
= PATH_RECURSIVE
; else back
= PATH_NONRECURSIVE
;
377 freeString(pool
, p2
);
379 freeString(pool
, p1
);
390 BOOL
FileExists(char *name
)
398 win
= ((struct Process
*) t
)->pr_WindowPtr
;
399 ((struct Process
*) t
)->pr_WindowPtr
= (APTR
) -1; //disable error requester
402 nLock
= Lock(name
, SHARED_LOCK
);
408 ((struct Process
*) t
)->pr_WindowPtr
= win
; //enable error requester
414 LONG
GetFileLength(char *name
)
422 win
= ((struct Process
*) t
)->pr_WindowPtr
;
423 ((struct Process
*) t
)->pr_WindowPtr
= (APTR
) -1; //disable error requester
425 in
= Open(name
, MODE_OLDFILE
);
427 Seek(in
, 0, OFFSET_END
);
428 info
= Seek(in
, 0, OFFSET_BEGINNING
);
431 ((struct Process
*) t
)->pr_WindowPtr
= win
; //enable error requester
436 ///DisposeFileInformations()
437 void DisposeFileInformations(APTR pool
, struct FileInfo
*fi
)
439 if (fi
->comment
) freeString(pool
, fi
->comment
);
444 ///GetFileInformations()
445 BOOL
GetFileInformations(APTR pool
, char *name
, struct FileInfo
*fi
)
447 struct FileInfoBlock
*FIB
;
456 FIB
= (struct FileInfoBlock
*) AllocDosObject(DOS_FIB
,DummyTags
);
459 nLock
= Lock(name
, ACCESS_READ
);
462 Success2
= Examine(nLock
,FIB
);
466 fi
->len
= FIB
->fib_Size
;
467 if (strlen(FIB
->fib_Comment
) > 0) fi
->comment
= allocString(pool
, FIB
->fib_Comment
);
468 fi
->protection
= FIB
->fib_Protection
;
472 FreeDosObject (DOS_FIB
,(APTR
) FIB
);
479 LONG
GetFileInfo(char *name
)
481 struct FileInfoBlock
*FIB
;
487 FIB
= (struct FileInfoBlock
*) AllocDosObject(DOS_FIB
,DummyTags
);
490 nLock
= Lock(name
, ACCESS_READ
);
493 Success2
= Examine(nLock
,FIB
);
497 if (FIB
->fib_DirEntryType
>0) info
|= FILEINFO_DIR
;
498 if ((FIB
->fib_Protection
& FIBF_DELETE
) != 0) info
|= FILEINFO_PROTECTED
;
499 if ((FIB
->fib_Protection
& FIBF_WRITE
) != 0) info
|= FILEINFO_WRITE
;
503 FreeDosObject (DOS_FIB
,(APTR
) FIB
);
509 ///GetProtectionInfo()
510 LONG
GetProtectionInfo(char *name
)
512 struct FileInfoBlock
*FIB
;
518 FIB
= (struct FileInfoBlock
*) AllocDosObject(DOS_FIB
,DummyTags
);
521 nLock
= Lock(name
, ACCESS_READ
);
524 Success2
= Examine(nLock
,FIB
);
527 info
= FIB
->fib_Protection
;
531 FreeDosObject (DOS_FIB
,(APTR
) FIB
);
538 char *GetCommentInfo(APTR pool
, char *name
)
540 struct FileInfoBlock
*FIB
;
547 FIB
= (struct FileInfoBlock
*) AllocDosObject(DOS_FIB
,DummyTags
);
550 nLock
= Lock(name
, ACCESS_READ
);
553 Success2
= Examine(nLock
,FIB
);
556 info
= allocString(pool
, (char*) &FIB
->fib_Comment
);
560 FreeDosObject (DOS_FIB
,(APTR
) FIB
);
567 BOOL
deleteFile(char *file
) {
574 BOOL
copyFile(APTR pool
, char *file
, char *destpath
, struct FileInfoBlock
*fileinfo
, struct Hook
*displayHook
, struct dCopyStruct
*display
) {
575 struct FileInfoBlock
*fib
;
578 LONG bufferlen
= COPYLEN
;
585 if (display
!= NULL
) display
->totallen
= 0;
586 if (display
!= NULL
) display
->actlen
= 0;
589 filelen
= fileinfo
->fib_Size
;
590 if (fileinfo
->fib_Size
<= COPYLEN
) bufferlen
= fileinfo
->fib_Size
;
591 if (bufferlen
< 8192) bufferlen
= 8192;
596 fib
= (struct FileInfoBlock
*) AllocDosObject(DOS_FIB
,DummyTags
);
599 nLock
= Lock(file
, ACCESS_READ
);
602 if (Examine(nLock
,fib
) == 0)
608 filelen
= fib
->fib_Size
;
609 if (fib
->fib_Size
<= COPYLEN
) bufferlen
= fib
->fib_Size
;
610 if (bufferlen
< 8192) bufferlen
= 8192;
618 to
= combinePath(pool
, destpath
, FilePart(file
));
621 buffer
= AllocPooled(pool
, bufferlen
);
624 in
= Open(file
, MODE_OLDFILE
);
627 out
= Open(to
, MODE_NEWFILE
);
631 unsigned int difftime
= clock();
634 clen
= Read(in
, buffer
, bufferlen
);
635 if ((clen
!=0) && (clen
!= -1))
637 wlen
= Write(out
, buffer
,clen
);
640 display
->difftime
= clock() - difftime
;
641 if (display
->difftime
< 1) display
->difftime
= 1;
642 display
->actlen
= clen
;
643 display
->totallen
+= clen
;
644 display
->filelen
= filelen
;
647 display
->flags
|= ACTION_UPDATE
;
648 stop
= CallHook(displayHook
, (Object
*) display
, NULL
);
652 if (clen
!= wlen
) clen
= 0;
655 while ((clen
!=0) && (clen
!= -1) && !stop
);
663 SetComment(to
, fib
->fib_Comment
);
664 SetProtection(to
, fib
->fib_Protection
);
665 if (fileinfo
== NULL
) FreeDosObject (DOS_FIB
,(APTR
) fib
);
670 FreePooled(pool
, buffer
, bufferlen
);
672 freeString(pool
, to
);
679 BOOL
actionDir(APTR pool
, ULONG flags
, char *source
, char *dest
, BOOL quit
, UWORD delmode
, UWORD protectmode
, UWORD overwritemode
, struct Hook
*dHook
, struct Hook
*delHook
, APTR userdata
)
681 struct FileInfoBlock
*FIB
, *FIB2
;
682 struct dCopyStruct display
;
683 struct dCopyStruct delDisplay
;
684 struct FileEntry
*fe
, *fef
, *fel
;
686 BPTR NewLock
, cDir
, nDir
, nLock
;
687 WORD dmode
, pmode
, omode
, dm
, pm
, om
;
688 ULONG Success
, Success1
, Success2
, DosError
, len
;
689 char *dname
, *comment
, *dpath
;
690 BOOL del
, created
, unprotect
, failure
;
691 BOOL stop
, overwrite
;
694 if (quit
) return TRUE
;
696 display
.userdata
= userdata
;
697 delDisplay
.userdata
= userdata
;
700 omode
= overwritemode
;
706 FIB
= (struct FileInfoBlock
*) AllocDosObject(DOS_FIB
,DummyTags
);
709 FIB2
= (struct FileInfoBlock
*) AllocDosObject(DOS_FIB
,DummyTags
);
712 NewLock
= Lock(source
,ACCESS_READ
);
715 cDir
= CurrentDir(NewLock
);
717 Success1
=Examine(NewLock
,FIB
);
723 Success
=ExNext(NewLock
,FIB
);
725 if ((flags
& (ACTION_DELETE
| ACTION_COPY
)) == ACTION_DELETE
)
727 if (dmode
== DELMODE_NONE
) Success
= FALSE
;
730 if (Success
&& Success1
)
732 if (FIB
->fib_DirEntryType
>0)
737 if (((flags
& ACTION_COPY
) != 0) && dest
)
739 dname
= combinePath(pool
, dest
, FIB
->fib_FileName
);
743 nLock
= Lock(dname
, ACCESS_READ
);
746 Success2
= Examine(nLock
,FIB2
);
747 if (Success2
) if (FIB2
->fib_DirEntryType
>0) created
= TRUE
;
752 nDir
= CreateDir(dname
);
755 prot
= GetProtectionInfo(FIB
->fib_FileName
);
756 comment
= GetCommentInfo(pool
, FIB
->fib_FileName
);
757 if (comment
) SetComment(dname
, comment
);
758 SetProtection(dname
, prot
);
759 freeString(pool
, comment
);
770 if (delHook
&& (dmode
!= DELMODE_NONE
) && ((flags
& ACTION_DELETE
) != 0))
772 if ((dmode
== DELMODE_ASK
) || (dmode
== DELMODE_DELETE
) || (dmode
== DELMODE_ALL
) || (dmode
== DELMODE_NO
))
774 delDisplay
.spath
= FIB
->fib_FileName
;
775 delDisplay
.file
= NULL
;
777 delDisplay
.filelen
= FIB
->fib_Size
;
778 if (dmode
!= DELMODE_ALL
) dmode
= CallHook(delHook
, (Object
*) &delDisplay
, NULL
);
779 if ((dmode
== DELMODE_ALL
) || (dmode
== DELMODE_DELETE
))
783 info
= GetFileInfo(FIB
->fib_FileName
);
784 if ((info
& (FILEINFO_PROTECTED
|FILEINFO_WRITE
)) != 0)
786 if (pmode
!= DELMODE_NONE
)
789 (pmode
== DELMODE_ASK
) || (pmode
== DELMODE_DELETE
) ||
790 (pmode
== DELMODE_ALL
) || (pmode
== DELMODE_NO
)
793 delDisplay
.spath
= FIB
->fib_FileName
;
794 delDisplay
.file
= NULL
;
796 delDisplay
.filelen
= 0;
797 if (pmode
!= DELMODE_ALL
) pmode
= CallHook(delHook
, (Object
*) &delDisplay
, NULL
);
798 if ((pmode
== DELMODE_ALL
) || (pmode
== DELMODE_DELETE
))
800 SetProtection(FIB
->fib_FileName
, 0);
806 else unprotect
= TRUE
;
820 if (om
== DELMODE_NO
) om
= DELMODE_NONE
;
821 if (om
== DELMODE_DELETE
) om
= DELMODE_ALL
;
823 if (pm
== DELMODE_NO
) pm
= DELMODE_NONE
;
824 if (pm
== DELMODE_DELETE
) pm
= DELMODE_ALL
;
826 if (dm
== DELMODE_NO
) dm
= DELMODE_NONE
;
827 if (dm
== DELMODE_DELETE
) dm
= DELMODE_ALL
;
829 if (created
|| ((flags
& ACTION_DELETE
) !=0))
831 if (((dmode
== DELMODE_NO
) || (dmode
== DELMODE_NONE
)) && (flags
== ACTION_DELETE
))
837 quit
= actionDir(pool
, flags
, FIB
->fib_FileName
, dname
, quit
, dm
, pm
, om
, dHook
, delHook
, userdata
);
841 if (!quit
&& del
&& unprotect
)
843 if (FIB
->fib_FileName
)
845 len
= strlen(FIB
->fib_FileName
);
849 fe
= AllocPooled(pool
, sizeof(struct FileEntry
) + len
);
852 strcpy(fe
->name
, FIB
->fib_FileName
);
867 if (dname
) freeString(pool
, dname
);
873 display
.file
= FIB
->fib_FileName
;
874 display
.filelen
= FIB
->fib_Size
;
875 display
.spath
= source
;
876 display
.dpath
= dest
;
877 display
.flags
= (flags
&= ~ACTION_UPDATE
);
878 display
.totallen
= 0;
881 quit
= CallHook(dHook
, (Object
*) &display
, NULL
);
886 if (((flags
& ACTION_COPY
) != 0) && dest
)
888 dpath
= combinePath(pool
, dest
, FIB
->fib_FileName
);
891 info
= GetFileInfo(dpath
);
895 if (delHook
&& (omode
!= DELMODE_NONE
))
898 (omode
== DELMODE_ASK
) || (omode
== DELMODE_DELETE
) ||
899 (omode
== DELMODE_ALL
) || (omode
== DELMODE_NO
)
902 delDisplay
.spath
= dest
;
903 delDisplay
.file
= FIB
->fib_FileName
;
905 delDisplay
.filelen
= 0;
906 if (omode
!= DELMODE_ALL
) omode
= CallHook(delHook
, (Object
*) &delDisplay
, NULL
);
907 if ((omode
== DELMODE_ALL
) || (omode
== DELMODE_DELETE
))
909 if ((info
& (FILEINFO_PROTECTED
|FILEINFO_WRITE
)) !=0)
911 if (pmode
!= DELMODE_NONE
)
914 (pmode
== DELMODE_ASK
) || (pmode
== DELMODE_DELETE
) ||
915 (pmode
== DELMODE_ALL
) || (pmode
== DELMODE_NO
)
918 delDisplay
.spath
= dest
;
919 delDisplay
.file
= FIB
->fib_FileName
;
921 delDisplay
.filelen
= 0;
922 if (pmode
!= DELMODE_ALL
) pmode
= CallHook(delHook
, (Object
*) &delDisplay
, NULL
);
923 if ((pmode
== DELMODE_ALL
) || (pmode
== DELMODE_DELETE
))
926 SetProtection(dpath
, 0);
931 else overwrite
= TRUE
;
937 if (dpath
) freeString(pool
, dpath
);
941 if (!quit
&& ((flags
& ACTION_COPY
) !=0) && overwrite
)
943 display
.flags
= (flags
&= ~ACTION_UPDATE
);
944 failure
= copyFile(pool
, FIB
->fib_FileName
, dest
, FIB
, dHook
, &display
);
947 if (failure
&& !quit
)
951 delDisplay
.spath
= source
;
952 delDisplay
.file
= FIB
->fib_FileName
;
954 delDisplay
.filelen
= 0;
955 if (CallHook(delHook
, (Object
*) &delDisplay
, NULL
) == ACCESS_SKIP
)
956 quit
= FALSE
; else quit
= TRUE
;
961 if (!quit
&& delHook
&& (dmode
!= DELMODE_NONE
) && ((flags
& ACTION_DELETE
) !=0))
964 (dmode
== DELMODE_ASK
) || (dmode
== DELMODE_DELETE
) ||
965 (dmode
== DELMODE_ALL
) || (dmode
== DELMODE_NO
)
968 delDisplay
.spath
= source
;
969 delDisplay
.file
= FIB
->fib_FileName
;
971 delDisplay
.filelen
= FIB
->fib_Size
;
972 if (dmode
!= DELMODE_ALL
) dmode
= CallHook(delHook
, (Object
*) &delDisplay
, NULL
);
973 if ((dmode
== DELMODE_ALL
) || (dmode
== DELMODE_DELETE
))
976 info
= GetFileInfo(FIB
->fib_FileName
);
978 if ((info
& (FILEINFO_PROTECTED
|FILEINFO_WRITE
)) != 0)
980 if (pmode
!= DELMODE_NONE
)
983 (pmode
== DELMODE_ASK
) || (pmode
== DELMODE_DELETE
) ||
984 (pmode
== DELMODE_ALL
) || (pmode
== DELMODE_NO
)
987 delDisplay
.spath
= source
;
988 delDisplay
.file
= FIB
->fib_FileName
;
990 delDisplay
.filelen
= 0;
991 if (pmode
!= DELMODE_ALL
) pmode
= CallHook(delHook
, (Object
*) &delDisplay
, NULL
);
992 if ((pmode
== DELMODE_ALL
) || (pmode
== DELMODE_DELETE
))
995 SetProtection(FIB
->fib_FileName
, 0);
1000 else unprotect
= TRUE
;
1004 if (FIB
->fib_FileName
)
1006 len
= strlen(FIB
->fib_FileName
);
1010 fe
= AllocPooled(pool
, sizeof(struct FileEntry
) + len
);
1013 strcpy(fe
->name
, FIB
->fib_FileName
);
1037 if (DosError
!=ERROR_NO_MORE_ENTRIES
) Success
=TRUE
;
1040 while (Success
&& !quit
);
1045 len
= strlen(fef
->name
);
1048 deleteFile(fef
->name
);
1051 FreePooled(pool
, fef
, sizeof(struct FileEntry
) + len
);
1058 FreeDosObject (DOS_FIB
,(APTR
) FIB2
);
1060 FreeDosObject (DOS_FIB
,(APTR
) FIB
);
1068 BOOL
CopyContent(APTR p
, char *s
, char *d
, BOOL makeparentdir
, ULONG flags
, struct Hook
*displayHook
, struct Hook
*delHook
, APTR userdata
)
1071 struct FileInfoBlock
*FIB
;
1072 struct dCopyStruct display
;
1073 struct dCopyStruct delDisplay
;
1074 char *destname
, *dest
, *path
, *comment
, *dpath
, *infoname
, *destinfo
;
1076 LONG Success2
, prot
;
1079 BOOL created
= FALSE
;
1082 BOOL deletesrc
, unprotectsrc
;
1084 UWORD dmode
= DELMODE_ASK
;
1085 UWORD pmode
= DELMODE_ASK
;
1086 UWORD omode
= DELMODE_ASK
;
1090 pool
= CreatePool(MEMF_CLEAR
|MEMF_ANY
, POOLSIZE
, POOLSIZE
);
1094 if (pool
== NULL
) return FALSE
;
1096 infoname
= AllocPooled(pool
, strlen(s
)+6);
1097 display
.userdata
= userdata
;
1098 delDisplay
.userdata
= userdata
;
1102 strncpy (infoname
, s
, strlen(s
));
1103 strcat(infoname
,".info");
1106 if (d
) destinfo
= AllocPooled(pool
, strlen(d
)+6); else destinfo
= NULL
;
1110 strncpy (destinfo
, d
, strlen(d
));
1111 strcat(destinfo
,".info");
1114 destname
= FilePart(s
);
1116 info
= GetFileInfo(s
);
1120 freeString(pool
, infoname
);
1121 freeString(pool
, destinfo
);
1122 if (p
== NULL
) DeletePool(pool
);
1126 if ((info
& FILEINFO_DIR
) != 0) dir
= TRUE
; else dir
= FALSE
;
1130 if ((flags
& ACTION_COPY
) !=0 ) dest
= allocString(pool
, d
);
1132 if (makeparentdir
&& dir
&& dest
)
1136 if (strlen(destname
)>0)
1138 freeString(pool
, dest
);
1140 FIB
= (struct FileInfoBlock
*) AllocDosObject(DOS_FIB
,DummyTags
);
1143 dest
= combinePath(pool
, d
, destname
);
1146 nLock
= Lock(dest
, ACCESS_READ
);
1149 Success2
= Examine(nLock
,FIB
);
1150 if (Success2
) if (FIB
->fib_DirEntryType
>0) created
= TRUE
;
1155 nDir
= CreateDir(dest
);
1160 prot
= GetProtectionInfo(s
);
1161 comment
= GetCommentInfo(pool
, s
);
1162 if (comment
) SetComment(dest
, comment
);
1163 SetProtection(dest
, prot
);
1164 freeString(pool
, comment
);
1169 freeString(pool
, dest
);
1174 FreeDosObject (DOS_FIB
,(APTR
) FIB
);
1183 unprotectsrc
= TRUE
;
1184 if (delHook
&& ((flags
& ACTION_DELETE
) != 0) && ((makeparentdir
&& dir
) || !dir
))
1188 delDisplay
.spath
= s
;
1189 delDisplay
.file
= NULL
;
1193 path
= allocPath(pool
, s
);
1194 delDisplay
.spath
= path
;
1195 delDisplay
.file
= FilePart(s
);
1197 delDisplay
.type
= 0;
1199 dmode
= CallHook(delHook
, (Object
*) &delDisplay
, NULL
);
1200 if ((dmode
== DELMODE_ALL
) || (dmode
== DELMODE_DELETE
))
1203 if ((info
& (FILEINFO_PROTECTED
|FILEINFO_WRITE
)) != 0)
1205 delDisplay
.type
= 1;
1206 unprotectsrc
= FALSE
;
1207 pmode
= CallHook(delHook
, (Object
*) &delDisplay
, NULL
);
1208 if ((pmode
== DELMODE_ALL
) || (pmode
== DELMODE_DELETE
))
1210 SetProtection(s
, 0);
1211 if (infoname
) SetProtection(infoname
, 0);
1212 unprotectsrc
= TRUE
;
1220 if (delHook
&& !dir
)
1222 dpath
= combinePath(pool
, d
, FilePart(s
));
1225 info
= GetFileInfo(dpath
);
1228 if (delHook
&& (omode
!= DELMODE_NONE
))
1231 (omode
== DELMODE_ASK
) || (omode
== DELMODE_DELETE
) ||
1232 (omode
== DELMODE_ALL
) || (omode
== DELMODE_NO
)
1235 delDisplay
.spath
= d
;
1236 delDisplay
.file
= FilePart(s
);
1237 delDisplay
.type
= 2;
1238 if (omode
!= DELMODE_ALL
) omode
= CallHook(delHook
, (Object
*) &delDisplay
, NULL
);
1239 if ((omode
== DELMODE_ALL
) || (omode
== DELMODE_DELETE
))
1241 if (((info
& (FILEINFO_PROTECTED
|FILEINFO_WRITE
)) != 0) && (pmode
!= DELMODE_NONE
))
1244 (pmode
== DELMODE_ASK
) || (pmode
== DELMODE_DELETE
) ||
1245 (pmode
== DELMODE_ALL
) || (pmode
== DELMODE_NO
)
1248 delDisplay
.spath
= d
;
1249 delDisplay
.file
= FilePart(s
);
1250 delDisplay
.type
= 1;
1251 if (pmode
!= DELMODE_ALL
) pmode
= CallHook(delHook
, (Object
*) &delDisplay
, NULL
);
1252 if ((pmode
== DELMODE_ALL
) || (pmode
== DELMODE_DELETE
))
1254 SetProtection(dpath
, 0);
1263 freeString(pool
, dpath
);
1265 freeString(pool
, path
);
1270 if (dest
|| ((flags
& ACTION_DELETE
) != 0))
1273 ((dmode
== DELMODE_NONE
) || (dmode
== DELMODE_NO
)) &&
1274 (flags
& (ACTION_DELETE
|ACTION_COPY
)) == ACTION_DELETE
1282 pool
, flags
, s
, dest
, FALSE
, dmode
, pmode
, omode
, displayHook
, delHook
, userdata
1290 if (flags
== ACTION_DELETE
) back
= FALSE
;
1293 STRPTR path
= allocPath(pool
, s
);
1294 display
.file
= FilePart(s
);
1295 display
.filelen
= 0;
1296 display
.totallen
= 0;
1299 if (path
) display
.spath
= path
; else display
.spath
= s
;
1301 display
.flags
= (flags
&= ~ACTION_UPDATE
);
1302 if (displayHook
) CallHook(displayHook
, (Object
*) &display
, NULL
);
1303 back
= copyFile(pool
, s
, d
, NULL
, displayHook
, &display
);
1304 if (path
) freeString(pool
, path
);
1308 if (!back
&& destinfo
&& infoname
)
1310 SetProtection(destinfo
, 0);
1311 copyFile(pool
, infoname
, d
, NULL
, NULL
, NULL
);
1314 if (!back
&& delHook
&& (dmode
!= DELMODE_NONE
) && ((flags
& ACTION_DELETE
) !=0))
1316 if (unprotectsrc
&& deletesrc
)
1319 if (infoname
) deleteFile(infoname
);
1323 freeString(pool
, infoname
);
1324 freeString(pool
, destinfo
);
1325 freeString(pool
, dest
);