add casts to zune macros to silence some warnings
[tangerine.git] / workbench / system / Wanderer / filesystems.c
blob47cad5973c9ef23cbeb62810528a1684c168e149
1 #include "filesystems.h"
3 struct TagItem DummyTags[] = { TAG_DONE, };
5 /* define some nonglobal data that can be used by the display hook */
7 void strcrem(char *s, char *d, char c)
9 while (*s) {
10 if (*s != c) *d++= *s;
11 *s++;
13 *d = 0;
16 WORD AskChoiceNew(char *title, char *strg, char *gadgets, UWORD sel, BOOL centered)
19 Object *app, *win;
20 Object *button, *bObject, *selObject;
21 LONG back, old;
22 BOOL running = TRUE;
23 ULONG signals;
24 ULONG id;
25 char Buffer[64], Buffer1[64];
27 back = 0;
29 app = ApplicationObject,
31 MUIA_Application_Title, (IPTR)"Requester",
32 MUIA_Application_Base, (IPTR)"WANDERER_REQ",
34 SubWindow, (IPTR)(win = WindowObject,
35 MUIA_Window_Title, title,
36 MUIA_Window_Activate, TRUE,
37 MUIA_Window_DepthGadget, TRUE,
38 MUIA_Window_SizeGadget, FALSE,
39 MUIA_Window_AppWindow, FALSE,
40 MUIA_Window_CloseGadget, FALSE,
41 MUIA_Window_Borderless, FALSE,
42 MUIA_Window_TopEdge, MUIV_Window_TopEdge_Moused,
43 MUIA_Window_LeftEdge, MUIV_Window_LeftEdge_Moused,
45 WindowContents, (IPTR)VGroup,
46 Child, (IPTR)TextObject,
47 TextFrame,
48 InnerSpacing(12,12),
49 MUIA_Background, MUII_TextBack,
50 MUIA_Text_PreParse, (IPTR)"\33c",
51 MUIA_Text_Contents, (IPTR)strg,
52 End,
53 Child, (IPTR)(bObject = HGroup,End),
54 End,
55 End),
56 End;
59 if (app)
61 old = 0;
62 back = 11;
63 selObject = NULL;
65 while (old != -1)
67 old = SplitName(gadgets, '|', Buffer, old, sizeof(Buffer));
68 if (old == -1) back = 10;
69 strcrem(Buffer, Buffer1, '_');
70 button = SimpleButton(Buffer1);
71 if (button)
73 if ((back-10) == sel) selObject = button;
74 set(button, MUIA_CycleChain, 1);
75 DoMethod(bObject, MUIM_Group_InitChange);
76 DoMethod(bObject, OM_ADDMEMBER, button);
77 DoMethod(bObject, MUIM_Group_ExitChange);
78 DoMethod(button,MUIM_Notify,MUIA_Pressed, FALSE, app,2,MUIM_Application_ReturnID,back);
80 back++;
83 back = -1;
85 if (centered)
87 set (win, MUIA_Window_TopEdge, MUIV_Window_TopEdge_Centered);
88 set (win, MUIA_Window_LeftEdge, MUIV_Window_LeftEdge_Centered);
90 if (selObject) set(win, MUIA_Window_ActiveObject, selObject);
91 set(win,MUIA_Window_Open,TRUE);
93 while (running)
95 id = DoMethod(app,MUIM_Application_Input,&signals);
96 switch (id)
99 case MUIV_Application_ReturnID_Quit:
100 running = FALSE;
101 break;
102 case 10:
103 running = FALSE;
104 back = 0;
105 break;
106 case 11:
107 running = FALSE;
108 back = 1;
109 break;
110 case 12:
111 running = FALSE;
112 back = 2;
113 break;
114 case 13:
115 running = FALSE;
116 back = 3;
117 break;
118 case 14:
119 running = FALSE;
120 back = 4;
121 break;
122 case 15:
123 running = FALSE;
124 back = 5;
125 break;
126 case 16:
127 running = FALSE;
128 back = 6;
129 break;
130 case 17:
131 running = FALSE;
132 back = 7;
133 break;
134 case 18:
135 running = FALSE;
136 back = 8;
137 break;
139 if (running && signals) Wait(signals);
141 set(win,MUIA_Window_Open,FALSE);
142 MUI_DisposeObject(app);
144 return back;
147 WORD AskChoice(char *title, char *strg, char *gadgets, UWORD sel)
149 return AskChoiceNew(title, strg, gadgets, sel, FALSE);
152 WORD AskChoiceCentered(char *title, char *strg, char *gadgets, UWORD sel)
154 return AskChoiceNew(title, strg, gadgets, sel, TRUE);
157 char *combinePath(APTR pool, char *path, char *file)
159 int l;
160 char *out;
161 if ((path == NULL) || (file == NULL)) return NULL;
162 if (strlen(path) == NULL) return NULL;
163 if (strlen(file) == NULL) return NULL;
165 l = strlen(path) + strlen(file) + 1;
166 if (path[strlen(path)-1] != '/') l++;
168 if (pool == NULL) out = AllocVec(l, MEMF_CLEAR);
169 else out = AllocPooled(pool, l);
171 if (out)
173 strcpy(out, path);
174 AddPart(out, file, l);
176 return out;
179 char *allocPath(APTR pool, char *str)
181 char *s0, *s1, *s;
182 int l;
184 s = NULL;
185 s0 = str;
187 s1 = PathPart(str);
188 if (s1)
190 for (l=0; s0 != s1; s0++,l++);
192 s = AllocPooled(pool, l+1);
193 if (s) strncpy(s, str, l);
195 return s;
198 void freeString(APTR pool, char *str)
200 if (str)
202 if (pool == NULL)
203 FreeVec(str);
204 else
205 FreePooled(pool, str, strlen(str)+1);
210 ** allocates memory for a string and copies them to the new buffer
212 ** inputs: str source string
213 ** return: char pointer to string or NULL
217 char *allocString(APTR pool, char *str)
219 char *b;
220 int l;
222 if (str == NULL) return NULL;
224 l = strlen(str);
226 if (pool == NULL)
227 b = (char*) AllocVec(l+1, MEMF_CLEAR);
228 else b = (char*) AllocPooled(pool, l+1);
230 if (b && (l>0)) strncpy (b, str, l);
231 return b;
234 void InfoRename(APTR pool, char *from, char *to)
236 char *frominfo, *toinfo;
238 if ((from == NULL) || (to == NULL)) return;
240 frominfo = AllocPooled(pool, strlen(from)+6);
242 if (frominfo)
244 strncpy (frominfo, from, strlen(from));
245 strcat(frominfo,".info");
246 toinfo = AllocPooled(pool, strlen(to)+6);
248 if (toinfo)
250 strncpy (toinfo, to, strlen(to));
251 strcat(toinfo,".info");
252 if (Rename(from, to)) Rename(frominfo, toinfo);
253 freeString(pool, toinfo);
255 freeString(pool, frominfo);
259 char *allocPathFromLock(APTR pool, BPTR lock)
261 char *pathb, *path;
263 path = NULL;
264 pathb = AllocPooled(pool, PATHBUFFERSIZE);
265 if (pathb)
267 if (NameFromLock(lock, pathb, PATHBUFFERSIZE))
269 path = allocString(pool, pathb);
271 FreePooled(pool, pathb, PATHBUFFERSIZE);
273 return path;
277 char *CombineString(char *format, ...) {
279 int cnt = 0, cnt1;
280 int len;
281 char *s, *s1, *str, *p;
282 char *back = NULL;
284 va_list ap;
285 s = format;
286 while ((s = strstr(s,"%s")) != NULL) {cnt++; s++; }
288 if (cnt >0)
290 len = strlen(format) - 2*cnt;
291 va_start(ap, format);
292 cnt1 = cnt;
294 while (cnt1--)
296 p = va_arg(ap, char *);
297 len += strlen(p);
299 va_end(ap);
300 len++;
301 if (len>0)
303 back = AllocVec(len, MEMF_CLEAR);
304 if (back)
306 str = back;
307 s = format;
308 va_start(ap, format);
309 while ((s1 = strstr(s, "%s")) != NULL)
311 p = va_arg(ap, char *);
312 len = s1-s;
313 strncpy(str, s, len);
314 s = s1+2;
315 str += len;
316 strncpy(str, p, strlen(p));
317 str += strlen(p);
319 if (s) strncpy(str, s, strlen(s));
320 va_end(ap);
324 return back;
327 ULONG isPathRecursive(APTR pool, char *source, char *destination)
329 BPTR srcLock, destLock;
330 ULONG back;
331 char *p1, *p2;
333 back = PATH_NOINFO;
334 srcLock = Lock(source, SHARED_LOCK);
335 if (srcLock)
337 destLock = Lock(destination, SHARED_LOCK);
338 if (destLock)
340 p1 = allocPathFromLock(pool, srcLock);
341 if (p1)
343 p2 = allocPathFromLock(pool, destLock);
344 if (p2)
346 if (strstr(p2, p1) == p2) back = PATH_RECURSIVE; else back = PATH_NONRECURSIVE;
348 freeString(pool, p2);
350 freeString(pool, p1);
352 UnLock(destLock);
354 UnLock(srcLock);
356 return back;
359 BOOL FileExists(char *name)
361 BOOL info;
362 BPTR nLock;
363 APTR win;
364 struct Task *t;
366 t = FindTask(NULL);
367 win = ((struct Process *) t)->pr_WindowPtr;
368 ((struct Process *) t)->pr_WindowPtr = (APTR) -1; //disable error requester
370 info = FALSE;
371 nLock = Lock(name, SHARED_LOCK);
372 if (nLock)
374 UnLock(nLock);
375 info = TRUE;
377 ((struct Process *) t)->pr_WindowPtr = win; //enable error requester
378 return info;
381 LONG GetFileLength(char *name)
383 LONG info = -1;
384 BPTR in;
385 APTR win;
386 struct Task *t;
388 t = FindTask(NULL);
389 win = ((struct Process *) t)->pr_WindowPtr;
390 ((struct Process *) t)->pr_WindowPtr = (APTR) -1; //disable error requester
392 in = Open(name, MODE_OLDFILE);
393 if (in) {
394 Seek(in, 0, OFFSET_END);
395 info = Seek(in, 0, OFFSET_BEGINNING);
396 Close(in);
398 ((struct Process *) t)->pr_WindowPtr = win; //enable error requester
399 return info;
402 void DisposeFileInformations(APTR pool, struct FileInfo *fi)
404 if (fi->comment) freeString(pool, fi->comment);
405 fi->comment = NULL;
408 BOOL GetFileInformations(APTR pool, char *name, struct FileInfo *fi)
410 struct FileInfoBlock *FIB;
411 LONG Success2;
412 BOOL info = FALSE;
413 BPTR nLock;
415 fi->len = 0;
416 fi->comment = NULL;
417 fi->protection = 0;
419 FIB = (struct FileInfoBlock*) AllocDosObject(DOS_FIB,DummyTags);
420 if (FIB)
422 nLock = Lock(name, ACCESS_READ);
423 if (nLock)
425 Success2 = Examine(nLock,FIB);
426 if (Success2)
428 info = TRUE;
429 fi->len = FIB->fib_Size;
430 if (strlen(FIB->fib_Comment) > 0) fi->comment = allocString(pool, FIB->fib_Comment);
431 fi->protection = FIB->fib_Protection;
433 UnLock(nLock);
435 FreeDosObject (DOS_FIB,(APTR) FIB);
437 return info;
440 LONG GetFileInfo(char *name)
442 struct FileInfoBlock *FIB;
443 LONG info,Success2;
444 BPTR nLock;
446 info = -1;
448 FIB = (struct FileInfoBlock*) AllocDosObject(DOS_FIB,DummyTags);
449 if (FIB)
451 nLock = Lock(name, ACCESS_READ);
452 if (nLock)
454 Success2 = Examine(nLock,FIB);
455 if (Success2)
457 info = 0;
458 if (FIB->fib_DirEntryType>0) info |= FILEINFO_DIR;
459 if ((FIB->fib_Protection & FIBF_DELETE) != 0) info |= FILEINFO_PROTECTED;
460 if ((FIB->fib_Protection & FIBF_WRITE) != 0) info |= FILEINFO_WRITE;
462 UnLock(nLock);
464 FreeDosObject (DOS_FIB,(APTR) FIB);
466 return info;
469 LONG GetProtectionInfo(char *name)
471 struct FileInfoBlock *FIB;
472 LONG info,Success2;
473 BPTR nLock;
475 info = 0;
477 FIB = (struct FileInfoBlock*) AllocDosObject(DOS_FIB,DummyTags);
478 if (FIB)
480 nLock = Lock(name, ACCESS_READ);
481 if (nLock)
483 Success2 = Examine(nLock,FIB);
484 if (Success2)
486 info = FIB->fib_Protection;
488 UnLock(nLock);
490 FreeDosObject (DOS_FIB,(APTR) FIB);
492 return info;
495 char *GetCommentInfo(APTR pool, char *name)
497 struct FileInfoBlock *FIB;
498 LONG Success2;
499 BPTR nLock;
500 char *info;
502 info = NULL;
504 FIB = (struct FileInfoBlock*) AllocDosObject(DOS_FIB,DummyTags);
505 if (FIB)
507 nLock = Lock(name, ACCESS_READ);
508 if (nLock)
510 Success2 = Examine(nLock,FIB);
511 if (Success2)
513 info = allocString(pool, (char*) &FIB->fib_Comment);
515 UnLock(nLock);
517 FreeDosObject (DOS_FIB,(APTR) FIB);
519 return info;
522 BOOL deleteFile(char *file) {
523 DeleteFile(file);
524 return TRUE;
527 BOOL copyFile(APTR pool, char *file, char *destpath, struct FileInfoBlock *fileinfo, struct Hook *displayHook, struct dCopyStruct *display) {
528 struct FileInfoBlock *fib;
529 char *to;
530 LONG clen, wlen;
531 LONG bufferlen = COPYLEN;
532 LONG filelen = 0;
533 BOOL quit = TRUE;
534 BPTR in, out;
535 BYTE *buffer;
536 BPTR nLock;
538 if (display != NULL) display->totallen = 0;
539 if (display != NULL) display->actlen = 0;
540 if (fileinfo)
542 filelen = fileinfo->fib_Size;
543 if (fileinfo->fib_Size <= COPYLEN) bufferlen = fileinfo->fib_Size;
544 if (bufferlen < 8192) bufferlen = 8192;
545 fib = fileinfo;
547 else
549 fib = (struct FileInfoBlock*) AllocDosObject(DOS_FIB,DummyTags);
550 if (fib)
552 nLock = Lock(file, ACCESS_READ);
553 if (nLock)
555 if (Examine(nLock,fib) == 0)
557 UnLock(nLock);
558 return TRUE;
560 UnLock(nLock);
561 filelen = fib->fib_Size;
562 if (fib->fib_Size <= COPYLEN) bufferlen = fib->fib_Size;
563 if (bufferlen < 8192) bufferlen = 8192;
566 else
568 return TRUE;
571 to = combinePath(pool, destpath, FilePart(file));
572 if (to)
574 buffer = AllocPooled(pool, bufferlen);
575 if (buffer)
577 in = Open(file, MODE_OLDFILE);
578 if (in)
580 out = Open(to, MODE_NEWFILE);
581 if (out)
583 BOOL stop = FALSE;
584 unsigned int difftime = clock();
587 clen = Read(in, buffer, bufferlen);
588 if ((clen !=0) && (clen != -1))
590 wlen = Write(out, buffer,clen);
591 if (display)
593 display->difftime = clock() - difftime;
594 if (display->difftime < 1) display->difftime = 1;
595 display->actlen = clen;
596 display->totallen += clen;
597 display->filelen = filelen;
598 if (displayHook)
600 display->flags |= ACTION_UPDATE;
601 stop = CallHook(displayHook, (Object *) display, NULL);
605 if (clen != wlen) clen = 0;
608 while ((clen !=0) && (clen != -1) && !stop);
610 quit = stop;
612 Close(out);
614 if (fib)
616 SetComment(to, fib->fib_Comment);
617 SetProtection(to, fib->fib_Protection);
618 if (fileinfo == NULL) FreeDosObject (DOS_FIB,(APTR) fib);
621 Close(in);
623 FreePooled(pool, buffer, bufferlen);
625 freeString(pool, to);
627 return quit;
630 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)
632 struct FileInfoBlock *FIB, *FIB2;
633 struct dCopyStruct display;
634 struct dCopyStruct delDisplay;
635 struct FileEntry *fe, *fef, *fel;
637 BPTR NewLock, cDir, nDir, nLock;
638 WORD dmode, pmode, omode, dm, pm, om;
639 ULONG Success, Success1, Success2, DosError, len;
640 char *dname, *comment, *dpath;
641 BOOL del, created, unprotect, failure;
642 BOOL stop, overwrite;
643 LONG info, prot;
645 if (quit) return TRUE;
647 display.userdata = userdata;
648 delDisplay.userdata = userdata;
650 dmode = delmode;
651 omode = overwritemode;
652 pmode = protectmode;
654 fef = NULL;
655 fel = NULL;
657 FIB = (struct FileInfoBlock*) AllocDosObject(DOS_FIB,DummyTags);
658 if (FIB)
660 FIB2 = (struct FileInfoBlock*) AllocDosObject(DOS_FIB,DummyTags);
661 if (FIB2)
663 NewLock = Lock(source ,ACCESS_READ);
664 if (NewLock)
666 cDir = CurrentDir(NewLock);
668 Success1=Examine(NewLock,FIB);
669 if (Success1)
671 stop = quit;
674 Success=ExNext(NewLock,FIB);
676 if ((flags & (ACTION_DELETE | ACTION_COPY)) == ACTION_DELETE)
678 if (dmode == DELMODE_NONE) Success = FALSE;
681 if (Success && Success1)
683 if (FIB->fib_DirEntryType>0)
686 dname = NULL;
688 if (((flags & ACTION_COPY) != 0) && dest)
690 dname = combinePath(pool, dest, FIB->fib_FileName);
691 if (dname)
693 created = FALSE;
694 nLock = Lock(dname, ACCESS_READ);
695 if (nLock)
697 Success2 = Examine(nLock,FIB2);
698 if (Success2) if (FIB2->fib_DirEntryType>0) created = TRUE;
699 UnLock(nLock);
701 if (!created)
703 nDir = CreateDir(dname);
704 if (nDir)
706 prot = GetProtectionInfo(FIB->fib_FileName);
707 comment = GetCommentInfo(pool, FIB->fib_FileName);
708 if (comment) SetComment(dname, comment);
709 SetProtection(dname, prot);
710 freeString(pool, comment);
712 created = TRUE;
713 UnLock(nDir);
718 unprotect = FALSE;
719 del = FALSE;
721 if (delHook && (dmode != DELMODE_NONE) && ((flags & ACTION_DELETE) != 0))
723 if ((dmode == DELMODE_ASK) || (dmode == DELMODE_DELETE) || (dmode == DELMODE_ALL) || (dmode == DELMODE_NO))
725 delDisplay.spath = FIB->fib_FileName;
726 delDisplay.file = NULL;
727 delDisplay.type = 0;
728 delDisplay.filelen = FIB->fib_Size;
729 if (dmode != DELMODE_ALL) dmode = CallHook(delHook, (Object *) &delDisplay, NULL);
730 if ((dmode == DELMODE_ALL) || (dmode == DELMODE_DELETE))
733 unprotect = FALSE;
734 info = GetFileInfo(FIB->fib_FileName);
735 if ((info & (FILEINFO_PROTECTED|FILEINFO_WRITE)) != 0)
737 if (pmode != DELMODE_NONE)
739 if (
740 (pmode == DELMODE_ASK) || (pmode == DELMODE_DELETE) ||
741 (pmode == DELMODE_ALL) || (pmode == DELMODE_NO)
744 delDisplay.spath = FIB->fib_FileName;
745 delDisplay.file = NULL;
746 delDisplay.type = 1;
747 delDisplay.filelen = 0;
748 if (pmode != DELMODE_ALL) pmode = CallHook(delHook, (Object *) &delDisplay, NULL);
749 if ((pmode == DELMODE_ALL) || (pmode == DELMODE_DELETE))
751 SetProtection(FIB->fib_FileName, 0);
752 unprotect = TRUE;
757 else unprotect = TRUE;
759 if (unprotect)
761 del = TRUE;
767 dm = dmode;
768 om = omode;
769 pm = pmode;
771 if (om == DELMODE_NO) om = DELMODE_NONE;
772 if (om == DELMODE_DELETE) om = DELMODE_ALL;
774 if (pm == DELMODE_NO) pm = DELMODE_NONE;
775 if (pm == DELMODE_DELETE) pm = DELMODE_ALL;
777 if (dm == DELMODE_NO) dm = DELMODE_NONE;
778 if (dm == DELMODE_DELETE) dm = DELMODE_ALL;
780 if (created || ((flags & ACTION_DELETE) !=0))
782 if (((dmode == DELMODE_NO) || (dmode == DELMODE_NONE)) && (flags == ACTION_DELETE))
784 quit = FALSE;
786 else
788 quit = actionDir(pool, flags, FIB->fib_FileName, dname, quit, dm, pm, om, dHook, delHook, userdata);
792 if (!quit && del && unprotect)
794 if (FIB->fib_FileName)
796 len = strlen(FIB->fib_FileName);
797 if (len>0)
800 fe = AllocPooled(pool, sizeof(struct FileEntry) + len);
801 if (fe)
803 strcpy(fe->name, FIB->fib_FileName);
804 if (fel)
806 fel->next = fe;
807 fel = fe;
809 else
811 fef = fe;
812 fel = fe;
818 if (dname) freeString(pool, dname);
820 else
822 if (dHook)
824 display.file = FIB->fib_FileName;
825 display.filelen = FIB->fib_Size;
826 display.spath = source;
827 display.dpath = dest;
828 display.flags = (flags &= ~ACTION_UPDATE);
829 display.totallen = 0;
830 display.actlen = 0;
832 quit = CallHook(dHook, (Object *) &display, NULL);
835 overwrite = TRUE;
837 if (((flags & ACTION_COPY) != 0) && dest)
839 dpath = combinePath(pool, dest, FIB->fib_FileName);
840 if (dpath)
842 info = GetFileInfo(dpath);
843 if (info != -1)
845 overwrite = FALSE;
846 if (delHook && (omode != DELMODE_NONE))
848 if (
849 (omode == DELMODE_ASK) || (omode == DELMODE_DELETE) ||
850 (omode == DELMODE_ALL) || (omode == DELMODE_NO)
853 delDisplay.spath = dest;
854 delDisplay.file = FIB->fib_FileName;
855 delDisplay.type = 2;
856 delDisplay.filelen = 0;
857 if (omode != DELMODE_ALL) omode = CallHook(delHook, (Object *) &delDisplay, NULL);
858 if ((omode == DELMODE_ALL) || (omode == DELMODE_DELETE))
860 if ((info & (FILEINFO_PROTECTED|FILEINFO_WRITE)) !=0)
862 if (pmode != DELMODE_NONE)
864 if (
865 (pmode == DELMODE_ASK) || (pmode == DELMODE_DELETE) ||
866 (pmode == DELMODE_ALL) || (pmode == DELMODE_NO)
869 delDisplay.spath = dest;
870 delDisplay.file = FIB->fib_FileName;
871 delDisplay.type = 1;
872 delDisplay.filelen = 0;
873 if (pmode != DELMODE_ALL) pmode = CallHook(delHook, (Object *) &delDisplay, NULL);
874 if ((pmode == DELMODE_ALL) || (pmode == DELMODE_DELETE))
876 overwrite = TRUE;
877 SetProtection(dpath, 0);
882 else overwrite = TRUE;
888 if (dpath) freeString(pool, dpath);
891 failure = FALSE;
892 if (!quit && ((flags & ACTION_COPY) !=0) && overwrite)
894 display.flags = (flags &= ~ACTION_UPDATE);
895 failure = copyFile(pool, FIB->fib_FileName, dest, FIB, dHook, &display);
898 if (failure && !quit)
900 if (delHook)
902 delDisplay.spath = source;
903 delDisplay.file = FIB->fib_FileName;
904 delDisplay.type = 3;
905 delDisplay.filelen = 0;
906 if (CallHook(delHook, (Object *) &delDisplay, NULL) == ACCESS_SKIP)
907 quit = FALSE; else quit = TRUE;
909 else quit = FALSE;
912 if (!quit && delHook && (dmode != DELMODE_NONE) && ((flags & ACTION_DELETE) !=0))
914 if (
915 (dmode == DELMODE_ASK) || (dmode == DELMODE_DELETE) ||
916 (dmode == DELMODE_ALL) || (dmode == DELMODE_NO)
919 delDisplay.spath = source;
920 delDisplay.file = FIB->fib_FileName;
921 delDisplay.type = 0;
922 delDisplay.filelen = FIB->fib_Size;
923 if (dmode != DELMODE_ALL) dmode = CallHook(delHook, (Object *) &delDisplay, NULL);
924 if ((dmode == DELMODE_ALL) || (dmode == DELMODE_DELETE))
927 info = GetFileInfo(FIB->fib_FileName);
928 unprotect = FALSE;
929 if ((info & (FILEINFO_PROTECTED|FILEINFO_WRITE)) != 0)
931 if (pmode != DELMODE_NONE)
933 if (
934 (pmode == DELMODE_ASK) || (pmode == DELMODE_DELETE) ||
935 (pmode == DELMODE_ALL) || (pmode == DELMODE_NO)
938 delDisplay.spath = source;
939 delDisplay.file = FIB->fib_FileName;
940 delDisplay.type = 1;
941 delDisplay.filelen = 0;
942 if (pmode != DELMODE_ALL) pmode = CallHook(delHook, (Object *) &delDisplay, NULL);
943 if ((pmode == DELMODE_ALL) || (pmode == DELMODE_DELETE))
945 unprotect = TRUE;
946 SetProtection(FIB->fib_FileName, 0);
951 else unprotect = TRUE;
953 if (unprotect)
955 if (FIB->fib_FileName)
957 len = strlen(FIB->fib_FileName);
958 if (len>0)
961 fe = AllocPooled(pool, sizeof(struct FileEntry) + len);
962 if (fe)
964 strcpy(fe->name, FIB->fib_FileName);
965 if (fel)
967 fel->next = fe;
968 fel = fe;
970 else
972 fef = fe;
973 fel = fe;
985 else
987 DosError=IoErr();
988 if (DosError!=ERROR_NO_MORE_ENTRIES) Success=TRUE;
991 while (Success && !quit);
994 while (fef)
996 len = strlen(fef->name);
997 if (len > 0)
999 deleteFile(fef->name);
1001 fe = fef->next;
1002 FreePooled(pool, fef, sizeof(struct FileEntry) + len);
1003 fef = fe;
1006 CurrentDir(cDir);
1007 UnLock(NewLock);
1009 FreeDosObject (DOS_FIB,(APTR) FIB2);
1011 FreeDosObject (DOS_FIB,(APTR) FIB);
1014 return quit;
1017 BOOL CopyContent(APTR p, char *s, char *d, BOOL makeparentdir, ULONG flags, struct Hook *displayHook, struct Hook *delHook, APTR userdata)
1020 struct FileInfoBlock *FIB;
1021 struct dCopyStruct display;
1022 struct dCopyStruct delDisplay;
1023 char *destname, *dest, *path, *comment, *dpath, *infoname, *destinfo;
1024 LONG len, Success2, prot;
1025 BPTR nLock, nDir;
1026 APTR pool;
1027 BOOL created = FALSE;
1028 BOOL dir = TRUE;
1029 BOOL back = FALSE;
1030 BOOL deletesrc, unprotectsrc;
1031 LONG info;
1032 UWORD dmode = DELMODE_ASK;
1033 UWORD pmode = DELMODE_ASK;
1034 UWORD omode = DELMODE_ASK;
1036 if (p == NULL)
1038 pool = CreatePool(MEMF_CLEAR|MEMF_ANY, POOLSIZE, POOLSIZE);
1040 else pool = p;
1042 if (pool == NULL) return FALSE;
1044 infoname = AllocPooled(pool, strlen(s)+6);
1045 display.userdata = userdata;
1046 delDisplay.userdata = userdata;
1048 if (infoname)
1050 strncpy (infoname, s, strlen(s));
1051 strcat(infoname,".info");
1054 if (d) destinfo = AllocPooled(pool, strlen(d)+6); else destinfo = NULL;
1056 if (destinfo)
1058 strncpy (destinfo, d, strlen(d));
1059 strcat(destinfo,".info");
1062 destname = FilePart(s);
1064 info = GetFileInfo(s);
1066 if (info == -1)
1068 freeString(pool, infoname);
1069 freeString(pool, destinfo);
1070 if (p == NULL) DeletePool(pool);
1071 return TRUE;
1074 if ((info & FILEINFO_DIR) != 0) dir = TRUE; else dir = FALSE;
1076 dest = NULL;
1078 if ((flags & ACTION_COPY) !=0 ) dest = allocString(pool, d);
1080 if (makeparentdir && dir && dest)
1082 if (destname)
1084 if (strlen(destname)>0)
1086 freeString(pool, dest);
1087 dest = NULL;
1088 FIB = (struct FileInfoBlock*) AllocDosObject(DOS_FIB,DummyTags);
1089 if (FIB)
1091 dest = combinePath(pool, d, destname);
1092 if (dest)
1094 nLock = Lock(dest, ACCESS_READ);
1095 if (nLock)
1097 Success2 = Examine(nLock,FIB);
1098 if (Success2) if (FIB->fib_DirEntryType>0) created = TRUE;
1099 UnLock(nLock);
1101 if (!created)
1103 nDir = CreateDir(dest);
1104 if (nDir)
1106 created = TRUE;
1107 UnLock(nDir);
1108 prot = GetProtectionInfo(s);
1109 comment = GetCommentInfo(pool, s);
1110 if (comment) SetComment(dest, comment);
1111 SetProtection(dest, prot);
1112 freeString(pool, comment);
1115 if (!created)
1117 freeString(pool, dest);
1118 dest = NULL;
1119 created = FALSE;
1122 FreeDosObject (DOS_FIB,(APTR) FIB);
1128 path = NULL;
1130 deletesrc = FALSE;
1131 unprotectsrc = TRUE;
1132 if (delHook && ((flags & ACTION_DELETE) != 0) && ((makeparentdir && dir) || !dir))
1134 if (dir)
1136 delDisplay.spath = s;
1137 delDisplay.file = NULL;
1139 else
1141 path = allocPath(pool, s);
1142 delDisplay.spath = path;
1143 delDisplay.file = FilePart(s);
1145 delDisplay.type = 0;
1147 dmode = CallHook(delHook, (Object *) &delDisplay, NULL);
1148 if ((dmode == DELMODE_ALL) || (dmode == DELMODE_DELETE))
1150 deletesrc = TRUE;
1151 if ((info & (FILEINFO_PROTECTED|FILEINFO_WRITE)) != 0)
1153 delDisplay.type = 1;
1154 unprotectsrc = FALSE;
1155 pmode = CallHook(delHook, (Object *) &delDisplay, NULL);
1156 if ((pmode == DELMODE_ALL) || (pmode == DELMODE_DELETE))
1158 SetProtection(s, 0);
1159 if (infoname) SetProtection(infoname, 0);
1160 unprotectsrc = TRUE;
1166 if (dest)
1168 if (delHook && !dir)
1170 dpath = combinePath(pool, d, FilePart(s));
1171 if (dpath)
1173 info = GetFileInfo(dpath);
1174 if (info != -1)
1176 if (delHook && (omode != DELMODE_NONE))
1178 if (
1179 (omode == DELMODE_ASK) || (omode == DELMODE_DELETE) ||
1180 (omode == DELMODE_ALL) || (omode == DELMODE_NO)
1183 delDisplay.spath = d;
1184 delDisplay.file = FilePart(s);
1185 delDisplay.type = 2;
1186 if (omode != DELMODE_ALL) omode = CallHook(delHook, (Object *) &delDisplay, NULL);
1187 if ((omode == DELMODE_ALL) || (omode == DELMODE_DELETE))
1189 if (((info & (FILEINFO_PROTECTED|FILEINFO_WRITE)) != 0) && (pmode != DELMODE_NONE))
1191 if (
1192 (pmode == DELMODE_ASK) || (pmode == DELMODE_DELETE) ||
1193 (pmode == DELMODE_ALL) || (pmode == DELMODE_NO)
1196 delDisplay.spath = d;
1197 delDisplay.file = FilePart(s);
1198 delDisplay.type = 1;
1199 if (pmode != DELMODE_ALL) pmode = CallHook(delHook, (Object *) &delDisplay, NULL);
1200 if ((pmode == DELMODE_ALL) || (pmode == DELMODE_DELETE))
1202 SetProtection(dpath, 0);
1211 freeString(pool, dpath);
1213 freeString(pool, path);
1216 if (dir)
1218 if (dest || ((flags & ACTION_DELETE) != 0))
1220 if (
1221 ((dmode == DELMODE_NONE) || (dmode == DELMODE_NO)) &&
1222 (flags & (ACTION_DELETE|ACTION_COPY)) == ACTION_DELETE
1225 back = FALSE;
1227 else
1229 back = actionDir(
1230 pool, flags, s, dest, FALSE, dmode, pmode, omode, displayHook, delHook, userdata
1234 else back = TRUE;
1236 else
1238 if (flags == ACTION_DELETE) back = FALSE;
1239 else
1241 STRPTR path = allocPath(pool, s);
1242 display.file = FilePart(s);
1243 display.filelen = 0;
1244 display.totallen = 0;
1245 display.actlen = 0;
1247 if (path) display.spath = path; else display.spath = s;
1248 display.dpath = d;
1249 display.flags = (flags &= ~ACTION_UPDATE);
1250 if (displayHook) CallHook(displayHook, (Object *) &display, NULL);
1251 back = copyFile(pool, s, d, NULL, displayHook, &display);
1252 if (path) freeString(pool, path);
1256 if (!back && destinfo && infoname)
1258 SetProtection(destinfo, 0);
1259 copyFile(pool, infoname, d, NULL, NULL, NULL);
1262 if (!back && delHook && (dmode != DELMODE_NONE) && ((flags & ACTION_DELETE) !=0))
1264 if (unprotectsrc && deletesrc)
1266 deleteFile(s);
1267 if (infoname) deleteFile(infoname);
1271 freeString(pool, infoname);
1272 freeString(pool, destinfo);
1273 freeString(pool, dest);
1275 if (p == NULL)
1276 DeletePool(pool);
1277 return !back;