WIP: Update implementing basic changes for icon class, and Fix to memory size display...
[AROS.git] / workbench / system / Wanderer / filesystems.c
blob8ba32b4acb62a1e0ce7c20b3376968bd9e601203
1 /*
2 Copyright © 2007-2009, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #include "filesystems.h"
8 struct TagItem DummyTags[] = { {TAG_DONE, 0}};
10 /* define some nonglobal data that can be used by the display hook */
12 ///strcrem()
13 void strcrem(char *s, char *d, char c)
15 while (*s) {
16 if (*s != c) *d++= *s;
17 *s++;//"value computed is not used" ?
19 *d = 0;
21 ///
23 ///AskChoiceNew()
24 WORD AskChoiceNew(char *title, char *strg, char *gadgets, UWORD sel, BOOL centered)
27 Object *app, *win;
28 Object *button, *bObject, *selObject;
29 LONG back, old;
30 BOOL running = TRUE;
31 ULONG signals;
32 ULONG id;
33 char Buffer[64], Buffer1[64];
35 back = 0;
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,
55 TextFrame,
56 MUIA_InnerLeft,(12),
57 MUIA_InnerRight,(12),
58 MUIA_InnerTop,(12),
59 MUIA_InnerBottom,(12),
60 MUIA_Background, MUII_TextBack,
61 MUIA_Text_PreParse, (IPTR)"\33c",
62 MUIA_Text_Contents, (IPTR)strg,
63 TAG_DONE),
64 Child, (IPTR)(bObject = MUI_NewObject(MUIC_Group,MUIA_Group_Horiz, TRUE,TAG_DONE)),
65 TAG_DONE),
66 TAG_DONE)),
67 TAG_DONE);
70 if (app)
72 old = 0;
73 back = 11;
74 selObject = NULL;
76 while (old != -1)
78 old = SplitName(gadgets, '|', Buffer, old, sizeof(Buffer));
79 if (old == -1) back = 10;
80 strcrem(Buffer, Buffer1, '_');
81 button = SimpleButton(Buffer1);
82 if (button)
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);
91 back++;
94 back = -1;
96 if (centered)
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);
104 while (running)
106 id = DoMethod(app,MUIM_Application_Input,&signals);
107 switch (id)
110 case MUIV_Application_ReturnID_Quit:
111 running = FALSE;
112 break;
113 case 10:
114 running = FALSE;
115 back = 0;
116 break;
117 case 11:
118 running = FALSE;
119 back = 1;
120 break;
121 case 12:
122 running = FALSE;
123 back = 2;
124 break;
125 case 13:
126 running = FALSE;
127 back = 3;
128 break;
129 case 14:
130 running = FALSE;
131 back = 4;
132 break;
133 case 15:
134 running = FALSE;
135 back = 5;
136 break;
137 case 16:
138 running = FALSE;
139 back = 6;
140 break;
141 case 17:
142 running = FALSE;
143 back = 7;
144 break;
145 case 18:
146 running = FALSE;
147 back = 8;
148 break;
150 if (running && signals) Wait(signals);
152 set(win,MUIA_Window_Open,FALSE);
153 MUI_DisposeObject(app);
155 return back;
159 /// AskChoice()
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);
173 ///combinePath()
174 char *combinePath(APTR pool, char *path, char *file)
176 int l;
177 char *out;
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);
188 if (out)
190 strcpy(out, path);
191 AddPart(out, file, l);
193 return out;
197 ///allocPath()
198 char *allocPath(APTR pool, char *str)
200 char *s0, *s1, *s;
201 int l;
203 s = NULL;
204 s0 = str;
206 s1 = PathPart(str);
207 if (s1)
209 for (l=0; s0 != s1; s0++,l++);
211 s = AllocPooled(pool, l+1);
212 if (s) strncpy(s, str, l);
214 return s;
218 ///freeString()
219 void freeString(APTR pool, char *str)
221 if (str)
223 if (pool == NULL)
224 FreeVec(str);
225 else
226 FreePooled(pool, str, strlen(str)+1);
231 ///allocString()
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)
241 char *b;
242 int l;
244 if (str == NULL) return NULL;
246 l = strlen(str);
248 if (pool == 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);
253 return b;
257 ///InfoRename()
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);
266 if (frominfo)
268 strncpy (frominfo, from, strlen(from));
269 strcat(frominfo,".info");
270 toinfo = AllocPooled(pool, strlen(to)+6);
272 if (toinfo)
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)
287 char *pathb, *path;
289 path = NULL;
290 pathb = AllocPooled(pool, PATHBUFFERSIZE);
291 if (pathb)
293 if (NameFromLock(lock, pathb, PATHBUFFERSIZE))
295 path = allocString(pool, pathb);
297 FreePooled(pool, pathb, PATHBUFFERSIZE);
299 return path;
303 ///combineString()
304 char *CombineString(char *format, ...) {
306 int cnt = 0, cnt1;
307 int len;
308 char *s, *s1, *str, *p;
309 char *back = NULL;
311 va_list ap;
312 s = format;
313 while ((s = strstr(s,"%s")) != NULL) {cnt++; s++; }
315 if (cnt >0)
317 len = strlen(format) - 2*cnt;
318 va_start(ap, format);
319 cnt1 = cnt;
321 while (cnt1--)
323 p = va_arg(ap, char *);
324 len += strlen(p);
326 va_end(ap);
327 len++;
328 if (len>0)
330 back = AllocVec(len, MEMF_CLEAR);
331 if (back)
333 str = back;
334 s = format;
335 va_start(ap, format);
336 while ((s1 = strstr(s, "%s")) != NULL)
338 p = va_arg(ap, char *);
339 len = s1-s;
340 strncpy(str, s, len);
341 s = s1+2;
342 str += len;
343 strncpy(str, p, strlen(p));
344 str += strlen(p);
346 if (s) strncpy(str, s, strlen(s));
347 va_end(ap);
351 return back;
355 ///isPathRecursive()
356 ULONG isPathRecursive(APTR pool, char *source, char *destination)
358 BPTR srcLock, destLock;
359 ULONG back;
360 char *p1, *p2;
362 back = PATH_NOINFO;
363 srcLock = Lock(source, SHARED_LOCK);
364 if (srcLock)
366 destLock = Lock(destination, SHARED_LOCK);
367 if (destLock)
369 p1 = allocPathFromLock(pool, srcLock);
370 if (p1)
372 p2 = allocPathFromLock(pool, destLock);
373 if (p2)
375 if (strstr(p2, p1) == p2) back = PATH_RECURSIVE; else back = PATH_NONRECURSIVE;
377 freeString(pool, p2);
379 freeString(pool, p1);
381 UnLock(destLock);
383 UnLock(srcLock);
385 return back;
389 ///FileExists()
390 BOOL FileExists(char *name)
392 BOOL info;
393 BPTR nLock;
394 APTR win;
395 struct Task *t;
397 t = FindTask(NULL);
398 win = ((struct Process *) t)->pr_WindowPtr;
399 ((struct Process *) t)->pr_WindowPtr = (APTR) -1; //disable error requester
401 info = FALSE;
402 nLock = Lock(name, SHARED_LOCK);
403 if (nLock)
405 UnLock(nLock);
406 info = TRUE;
408 ((struct Process *) t)->pr_WindowPtr = win; //enable error requester
409 return info;
413 ///GetFileLength()
414 LONG GetFileLength(char *name)
416 LONG info = -1;
417 BPTR in;
418 APTR win;
419 struct Task *t;
421 t = FindTask(NULL);
422 win = ((struct Process *) t)->pr_WindowPtr;
423 ((struct Process *) t)->pr_WindowPtr = (APTR) -1; //disable error requester
425 in = Open(name, MODE_OLDFILE);
426 if (in) {
427 Seek(in, 0, OFFSET_END);
428 info = Seek(in, 0, OFFSET_BEGINNING);
429 Close(in);
431 ((struct Process *) t)->pr_WindowPtr = win; //enable error requester
432 return info;
436 ///DisposeFileInformations()
437 void DisposeFileInformations(APTR pool, struct FileInfo *fi)
439 if (fi->comment) freeString(pool, fi->comment);
440 fi->comment = NULL;
444 ///GetFileInformations()
445 BOOL GetFileInformations(APTR pool, char *name, struct FileInfo *fi)
447 struct FileInfoBlock *FIB;
448 LONG Success2;
449 BOOL info = FALSE;
450 BPTR nLock;
452 fi->len = 0;
453 fi->comment = NULL;
454 fi->protection = 0;
456 FIB = (struct FileInfoBlock*) AllocDosObject(DOS_FIB,DummyTags);
457 if (FIB)
459 nLock = Lock(name, ACCESS_READ);
460 if (nLock)
462 Success2 = Examine(nLock,FIB);
463 if (Success2)
465 info = TRUE;
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;
470 UnLock(nLock);
472 FreeDosObject (DOS_FIB,(APTR) FIB);
474 return info;
478 ///GetFileInfo()
479 LONG GetFileInfo(char *name)
481 struct FileInfoBlock *FIB;
482 LONG info,Success2;
483 BPTR nLock;
485 info = -1;
487 FIB = (struct FileInfoBlock*) AllocDosObject(DOS_FIB,DummyTags);
488 if (FIB)
490 nLock = Lock(name, ACCESS_READ);
491 if (nLock)
493 Success2 = Examine(nLock,FIB);
494 if (Success2)
496 info = 0;
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;
501 UnLock(nLock);
503 FreeDosObject (DOS_FIB,(APTR) FIB);
505 return info;
509 ///GetProtectionInfo()
510 LONG GetProtectionInfo(char *name)
512 struct FileInfoBlock *FIB;
513 LONG info,Success2;
514 BPTR nLock;
516 info = 0;
518 FIB = (struct FileInfoBlock*) AllocDosObject(DOS_FIB,DummyTags);
519 if (FIB)
521 nLock = Lock(name, ACCESS_READ);
522 if (nLock)
524 Success2 = Examine(nLock,FIB);
525 if (Success2)
527 info = FIB->fib_Protection;
529 UnLock(nLock);
531 FreeDosObject (DOS_FIB,(APTR) FIB);
533 return info;
537 ///GetCommentInfo()
538 char *GetCommentInfo(APTR pool, char *name)
540 struct FileInfoBlock *FIB;
541 LONG Success2;
542 BPTR nLock;
543 char *info;
545 info = NULL;
547 FIB = (struct FileInfoBlock*) AllocDosObject(DOS_FIB,DummyTags);
548 if (FIB)
550 nLock = Lock(name, ACCESS_READ);
551 if (nLock)
553 Success2 = Examine(nLock,FIB);
554 if (Success2)
556 info = allocString(pool, (char*) &FIB->fib_Comment);
558 UnLock(nLock);
560 FreeDosObject (DOS_FIB,(APTR) FIB);
562 return info;
566 ///deleteFile()
567 BOOL deleteFile(char *file) {
568 DeleteFile(file);
569 return TRUE;
573 ///copyFile()
574 BOOL copyFile(APTR pool, char *file, char *destpath, struct FileInfoBlock *fileinfo, struct Hook *displayHook, struct dCopyStruct *display) {
575 struct FileInfoBlock *fib;
576 char *to;
577 LONG clen, wlen;
578 LONG bufferlen = COPYLEN;
579 LONG filelen = 0;
580 BOOL quit = TRUE;
581 BPTR in, out;
582 BYTE *buffer;
583 BPTR nLock;
585 if (display != NULL) display->totallen = 0;
586 if (display != NULL) display->actlen = 0;
587 if (fileinfo)
589 filelen = fileinfo->fib_Size;
590 if (fileinfo->fib_Size <= COPYLEN) bufferlen = fileinfo->fib_Size;
591 if (bufferlen < 8192) bufferlen = 8192;
592 fib = fileinfo;
594 else
596 fib = (struct FileInfoBlock*) AllocDosObject(DOS_FIB,DummyTags);
597 if (fib)
599 nLock = Lock(file, ACCESS_READ);
600 if (nLock)
602 if (Examine(nLock,fib) == 0)
604 UnLock(nLock);
605 return TRUE;
607 UnLock(nLock);
608 filelen = fib->fib_Size;
609 if (fib->fib_Size <= COPYLEN) bufferlen = fib->fib_Size;
610 if (bufferlen < 8192) bufferlen = 8192;
613 else
615 return TRUE;
618 to = combinePath(pool, destpath, FilePart(file));
619 if (to)
621 buffer = AllocPooled(pool, bufferlen);
622 if (buffer)
624 in = Open(file, MODE_OLDFILE);
625 if (in)
627 out = Open(to, MODE_NEWFILE);
628 if (out)
630 BOOL stop = FALSE;
631 unsigned int difftime = clock();
634 clen = Read(in, buffer, bufferlen);
635 if ((clen !=0) && (clen != -1))
637 wlen = Write(out, buffer,clen);
638 if (display)
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;
645 if (displayHook)
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);
657 quit = stop;
659 Close(out);
661 if (fib)
663 SetComment(to, fib->fib_Comment);
664 SetProtection(to, fib->fib_Protection);
665 if (fileinfo == NULL) FreeDosObject (DOS_FIB,(APTR) fib);
668 Close(in);
670 FreePooled(pool, buffer, bufferlen);
672 freeString(pool, to);
674 return quit;
678 ///actionDir()
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;
692 LONG info, prot;
694 if (quit) return TRUE;
696 display.userdata = userdata;
697 delDisplay.userdata = userdata;
699 dmode = delmode;
700 omode = overwritemode;
701 pmode = protectmode;
703 fef = NULL;
704 fel = NULL;
706 FIB = (struct FileInfoBlock*) AllocDosObject(DOS_FIB,DummyTags);
707 if (FIB)
709 FIB2 = (struct FileInfoBlock*) AllocDosObject(DOS_FIB,DummyTags);
710 if (FIB2)
712 NewLock = Lock(source ,ACCESS_READ);
713 if (NewLock)
715 cDir = CurrentDir(NewLock);
717 Success1=Examine(NewLock,FIB);
718 if (Success1)
720 stop = quit;
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)
735 dname = NULL;
737 if (((flags & ACTION_COPY) != 0) && dest)
739 dname = combinePath(pool, dest, FIB->fib_FileName);
740 if (dname)
742 created = FALSE;
743 nLock = Lock(dname, ACCESS_READ);
744 if (nLock)
746 Success2 = Examine(nLock,FIB2);
747 if (Success2) if (FIB2->fib_DirEntryType>0) created = TRUE;
748 UnLock(nLock);
750 if (!created)
752 nDir = CreateDir(dname);
753 if (nDir)
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);
761 created = TRUE;
762 UnLock(nDir);
767 unprotect = FALSE;
768 del = FALSE;
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;
776 delDisplay.type = 0;
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))
782 unprotect = FALSE;
783 info = GetFileInfo(FIB->fib_FileName);
784 if ((info & (FILEINFO_PROTECTED|FILEINFO_WRITE)) != 0)
786 if (pmode != DELMODE_NONE)
788 if (
789 (pmode == DELMODE_ASK) || (pmode == DELMODE_DELETE) ||
790 (pmode == DELMODE_ALL) || (pmode == DELMODE_NO)
793 delDisplay.spath = FIB->fib_FileName;
794 delDisplay.file = NULL;
795 delDisplay.type = 1;
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);
801 unprotect = TRUE;
806 else unprotect = TRUE;
808 if (unprotect)
810 del = TRUE;
816 dm = dmode;
817 om = omode;
818 pm = pmode;
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))
833 quit = FALSE;
835 else
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);
846 if (len>0)
849 fe = AllocPooled(pool, sizeof(struct FileEntry) + len);
850 if (fe)
852 strcpy(fe->name, FIB->fib_FileName);
853 if (fel)
855 fel->next = fe;
856 fel = fe;
858 else
860 fef = fe;
861 fel = fe;
867 if (dname) freeString(pool, dname);
869 else
871 if (dHook)
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;
879 display.actlen = 0;
881 quit = CallHook(dHook, (Object *) &display, NULL);
884 overwrite = TRUE;
886 if (((flags & ACTION_COPY) != 0) && dest)
888 dpath = combinePath(pool, dest, FIB->fib_FileName);
889 if (dpath)
891 info = GetFileInfo(dpath);
892 if (info != -1)
894 overwrite = FALSE;
895 if (delHook && (omode != DELMODE_NONE))
897 if (
898 (omode == DELMODE_ASK) || (omode == DELMODE_DELETE) ||
899 (omode == DELMODE_ALL) || (omode == DELMODE_NO)
902 delDisplay.spath = dest;
903 delDisplay.file = FIB->fib_FileName;
904 delDisplay.type = 2;
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)
913 if (
914 (pmode == DELMODE_ASK) || (pmode == DELMODE_DELETE) ||
915 (pmode == DELMODE_ALL) || (pmode == DELMODE_NO)
918 delDisplay.spath = dest;
919 delDisplay.file = FIB->fib_FileName;
920 delDisplay.type = 1;
921 delDisplay.filelen = 0;
922 if (pmode != DELMODE_ALL) pmode = CallHook(delHook, (Object *) &delDisplay, NULL);
923 if ((pmode == DELMODE_ALL) || (pmode == DELMODE_DELETE))
925 overwrite = TRUE;
926 SetProtection(dpath, 0);
931 else overwrite = TRUE;
937 if (dpath) freeString(pool, dpath);
940 failure = FALSE;
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)
949 if (delHook)
951 delDisplay.spath = source;
952 delDisplay.file = FIB->fib_FileName;
953 delDisplay.type = 3;
954 delDisplay.filelen = 0;
955 if (CallHook(delHook, (Object *) &delDisplay, NULL) == ACCESS_SKIP)
956 quit = FALSE; else quit = TRUE;
958 else quit = FALSE;
961 if (!quit && delHook && (dmode != DELMODE_NONE) && ((flags & ACTION_DELETE) !=0))
963 if (
964 (dmode == DELMODE_ASK) || (dmode == DELMODE_DELETE) ||
965 (dmode == DELMODE_ALL) || (dmode == DELMODE_NO)
968 delDisplay.spath = source;
969 delDisplay.file = FIB->fib_FileName;
970 delDisplay.type = 0;
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);
977 unprotect = FALSE;
978 if ((info & (FILEINFO_PROTECTED|FILEINFO_WRITE)) != 0)
980 if (pmode != DELMODE_NONE)
982 if (
983 (pmode == DELMODE_ASK) || (pmode == DELMODE_DELETE) ||
984 (pmode == DELMODE_ALL) || (pmode == DELMODE_NO)
987 delDisplay.spath = source;
988 delDisplay.file = FIB->fib_FileName;
989 delDisplay.type = 1;
990 delDisplay.filelen = 0;
991 if (pmode != DELMODE_ALL) pmode = CallHook(delHook, (Object *) &delDisplay, NULL);
992 if ((pmode == DELMODE_ALL) || (pmode == DELMODE_DELETE))
994 unprotect = TRUE;
995 SetProtection(FIB->fib_FileName, 0);
1000 else unprotect = TRUE;
1002 if (unprotect)
1004 if (FIB->fib_FileName)
1006 len = strlen(FIB->fib_FileName);
1007 if (len>0)
1010 fe = AllocPooled(pool, sizeof(struct FileEntry) + len);
1011 if (fe)
1013 strcpy(fe->name, FIB->fib_FileName);
1014 if (fel)
1016 fel->next = fe;
1017 fel = fe;
1019 else
1021 fef = fe;
1022 fel = fe;
1034 else
1036 DosError=IoErr();
1037 if (DosError!=ERROR_NO_MORE_ENTRIES) Success=TRUE;
1040 while (Success && !quit);
1043 while (fef)
1045 len = strlen(fef->name);
1046 if (len > 0)
1048 deleteFile(fef->name);
1050 fe = fef->next;
1051 FreePooled(pool, fef, sizeof(struct FileEntry) + len);
1052 fef = fe;
1055 CurrentDir(cDir);
1056 UnLock(NewLock);
1058 FreeDosObject (DOS_FIB,(APTR) FIB2);
1060 FreeDosObject (DOS_FIB,(APTR) FIB);
1063 return quit;
1067 ///CopyContent()
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;
1075 //LONG len;
1076 LONG Success2, prot;
1077 BPTR nLock, nDir;
1078 APTR pool;
1079 BOOL created = FALSE;
1080 BOOL dir = TRUE;
1081 BOOL back = FALSE;
1082 BOOL deletesrc, unprotectsrc;
1083 LONG info;
1084 UWORD dmode = DELMODE_ASK;
1085 UWORD pmode = DELMODE_ASK;
1086 UWORD omode = DELMODE_ASK;
1088 if (p == NULL)
1090 pool = CreatePool(MEMF_CLEAR|MEMF_ANY, POOLSIZE, POOLSIZE);
1092 else pool = p;
1094 if (pool == NULL) return FALSE;
1096 infoname = AllocPooled(pool, strlen(s)+6);
1097 display.userdata = userdata;
1098 delDisplay.userdata = userdata;
1100 if (infoname)
1102 strncpy (infoname, s, strlen(s));
1103 strcat(infoname,".info");
1106 if (d) destinfo = AllocPooled(pool, strlen(d)+6); else destinfo = NULL;
1108 if (destinfo)
1110 strncpy (destinfo, d, strlen(d));
1111 strcat(destinfo,".info");
1114 destname = FilePart(s);
1116 info = GetFileInfo(s);
1118 if (info == -1)
1120 freeString(pool, infoname);
1121 freeString(pool, destinfo);
1122 if (p == NULL) DeletePool(pool);
1123 return TRUE;
1126 if ((info & FILEINFO_DIR) != 0) dir = TRUE; else dir = FALSE;
1128 dest = NULL;
1130 if ((flags & ACTION_COPY) !=0 ) dest = allocString(pool, d);
1132 if (makeparentdir && dir && dest)
1134 if (destname)
1136 if (strlen(destname)>0)
1138 freeString(pool, dest);
1139 dest = NULL;
1140 FIB = (struct FileInfoBlock*) AllocDosObject(DOS_FIB,DummyTags);
1141 if (FIB)
1143 dest = combinePath(pool, d, destname);
1144 if (dest)
1146 nLock = Lock(dest, ACCESS_READ);
1147 if (nLock)
1149 Success2 = Examine(nLock,FIB);
1150 if (Success2) if (FIB->fib_DirEntryType>0) created = TRUE;
1151 UnLock(nLock);
1153 if (!created)
1155 nDir = CreateDir(dest);
1156 if (nDir)
1158 created = TRUE;
1159 UnLock(nDir);
1160 prot = GetProtectionInfo(s);
1161 comment = GetCommentInfo(pool, s);
1162 if (comment) SetComment(dest, comment);
1163 SetProtection(dest, prot);
1164 freeString(pool, comment);
1167 if (!created)
1169 freeString(pool, dest);
1170 dest = NULL;
1171 created = FALSE;
1174 FreeDosObject (DOS_FIB,(APTR) FIB);
1180 path = NULL;
1182 deletesrc = FALSE;
1183 unprotectsrc = TRUE;
1184 if (delHook && ((flags & ACTION_DELETE) != 0) && ((makeparentdir && dir) || !dir))
1186 if (dir)
1188 delDisplay.spath = s;
1189 delDisplay.file = NULL;
1191 else
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))
1202 deletesrc = TRUE;
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;
1218 if (dest)
1220 if (delHook && !dir)
1222 dpath = combinePath(pool, d, FilePart(s));
1223 if (dpath)
1225 info = GetFileInfo(dpath);
1226 if (info != -1)
1228 if (delHook && (omode != DELMODE_NONE))
1230 if (
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))
1243 if (
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);
1268 if (dir)
1270 if (dest || ((flags & ACTION_DELETE) != 0))
1272 if (
1273 ((dmode == DELMODE_NONE) || (dmode == DELMODE_NO)) &&
1274 (flags & (ACTION_DELETE|ACTION_COPY)) == ACTION_DELETE
1277 back = FALSE;
1279 else
1281 back = actionDir(
1282 pool, flags, s, dest, FALSE, dmode, pmode, omode, displayHook, delHook, userdata
1286 else back = TRUE;
1288 else
1290 if (flags == ACTION_DELETE) back = FALSE;
1291 else
1293 STRPTR path = allocPath(pool, s);
1294 display.file = FilePart(s);
1295 display.filelen = 0;
1296 display.totallen = 0;
1297 display.actlen = 0;
1299 if (path) display.spath = path; else display.spath = s;
1300 display.dpath = d;
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)
1318 deleteFile(s);
1319 if (infoname) deleteFile(infoname);
1323 freeString(pool, infoname);
1324 freeString(pool, destinfo);
1325 freeString(pool, dest);
1327 if (p == NULL)
1328 DeletePool(pool);
1329 return !back;