grub2: bring back build of aros-side grub2 tools
[AROS.git] / workbench / system / Wanderer / filesystems.c
blob1fc2ed3951de321a75bb5871e32e57c48e0eb43d
1 /*
2 Copyright © 2007-2013, 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 static void strcrem(char *s, char *d, char c)
15 while (*s) {
16 if (*s != c) *d++= *s;
17 s++;
19 *d = 0;
21 ///
23 ///AskChoiceNew()
24 WORD AskChoiceNew(const char *title, const char *strg, const 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(const char *title, const char *strg, const char *gadgets, UWORD sel)
162 return AskChoiceNew(title, strg, gadgets, sel, FALSE);
166 ///AskChoiceCentered()
167 WORD AskChoiceCentered(const char *title, const char *strg, const char *gadgets, UWORD sel)
169 return AskChoiceNew(title, strg, gadgets, sel, TRUE);
173 ///combinePath()
174 static 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 = AllocVecPooled(pool, l);
188 if (out)
190 strcpy(out, path);
191 AddPart(out, file, l);
193 return out;
197 ///allocPath()
198 static 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 = AllocVecPooled(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 FreeVecPooled(pool, str);
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 static 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*) AllocVecPooled(pool, l+1);
252 if (b && (l>0)) strncpy (b, str, l);
253 return b;
257 ///CombineString()
258 char *CombineString(char *format, ...)
260 int cnt = 0, cnt1;
261 int len;
262 char *s, *s1, *str, *p;
263 char *back = NULL;
265 va_list ap;
266 s = format;
267 while ((s = strstr(s,"%s")) != NULL) {cnt++; s++; }
269 if (cnt >0)
271 len = strlen(format) - 2*cnt;
272 va_start(ap, format);
273 cnt1 = cnt;
275 while (cnt1--)
277 p = va_arg(ap, char *);
278 len += strlen(p);
280 va_end(ap);
281 len++;
282 if (len>0)
284 back = AllocVec(len, MEMF_CLEAR);
285 if (back)
287 str = back;
288 s = format;
289 va_start(ap, format);
290 while ((s1 = strstr(s, "%s")) != NULL)
292 p = va_arg(ap, char *);
293 len = s1-s;
294 strncpy(str, s, len);
295 s = s1+2;
296 str += len;
297 strncpy(str, p, strlen(p));
298 str += strlen(p);
300 if (s) strncpy(str, s, strlen(s));
301 va_end(ap);
305 return back;
309 ///GetFileInfo()
310 static LONG GetFileInfo(char *name)
312 struct FileInfoBlock *FIB;
313 LONG info,Success2;
314 BPTR nLock;
316 info = -1;
318 FIB = (struct FileInfoBlock*) AllocDosObject(DOS_FIB,DummyTags);
319 if (FIB)
321 nLock = Lock(name, ACCESS_READ);
322 if (nLock)
324 Success2 = Examine(nLock,FIB);
325 if (Success2)
327 info = 0;
328 if (FIB->fib_DirEntryType>0) info |= FILEINFO_DIR;
329 if ((FIB->fib_Protection & FIBF_DELETE) != 0) info |= FILEINFO_PROTECTED;
330 if ((FIB->fib_Protection & FIBF_WRITE) != 0) info |= FILEINFO_WRITE;
332 UnLock(nLock);
334 FreeDosObject (DOS_FIB,(APTR) FIB);
336 return info;
340 ///GetProtectionInfo()
341 static LONG GetProtectionInfo(char *name)
343 struct FileInfoBlock *FIB;
344 LONG info,Success2;
345 BPTR nLock;
347 info = 0;
349 FIB = (struct FileInfoBlock*) AllocDosObject(DOS_FIB,DummyTags);
350 if (FIB)
352 nLock = Lock(name, ACCESS_READ);
353 if (nLock)
355 Success2 = Examine(nLock,FIB);
356 if (Success2)
358 info = FIB->fib_Protection;
360 UnLock(nLock);
362 FreeDosObject (DOS_FIB,(APTR) FIB);
364 return info;
368 ///GetCommentInfo()
369 static char *GetCommentInfo(APTR pool, char *name)
371 struct FileInfoBlock *FIB;
372 LONG Success2;
373 BPTR nLock;
374 char *info;
376 info = NULL;
378 FIB = (struct FileInfoBlock*) AllocDosObject(DOS_FIB,DummyTags);
379 if (FIB)
381 nLock = Lock(name, ACCESS_READ);
382 if (nLock)
384 Success2 = Examine(nLock,FIB);
385 if (Success2)
387 info = allocString(pool, (char*) &FIB->fib_Comment);
389 UnLock(nLock);
391 FreeDosObject (DOS_FIB,(APTR) FIB);
393 return info;
397 ///deleteFile()
398 static BOOL deleteFile(char *file)
400 DeleteFile(file);
401 return TRUE;
405 ///copyFile()
406 static BOOL copyFile(APTR pool, char *file, char *destpath,
407 struct FileInfoBlock *fileinfo, struct Hook *displayHook,
408 struct dCopyStruct *display)
410 struct FileInfoBlock *fib;
411 char *to;
412 LONG clen, wlen;
413 LONG bufferlen = COPYLEN;
414 LONG filelen = 0;
415 BOOL quit = TRUE;
416 BPTR in, out;
417 BYTE *buffer;
418 BPTR nLock;
420 if (display != NULL) display->totallen = 0;
421 if (display != NULL) display->actlen = 0;
422 if (fileinfo)
424 filelen = fileinfo->fib_Size;
425 if (fileinfo->fib_Size <= COPYLEN) bufferlen = fileinfo->fib_Size;
426 if (bufferlen < 8192) bufferlen = 8192;
427 fib = fileinfo;
429 else
431 fib = (struct FileInfoBlock*) AllocDosObject(DOS_FIB,DummyTags);
432 if (fib)
434 nLock = Lock(file, ACCESS_READ);
435 if (nLock)
437 if (Examine(nLock,fib) == 0)
439 UnLock(nLock);
440 return TRUE;
442 UnLock(nLock);
443 filelen = fib->fib_Size;
444 if (fib->fib_Size <= COPYLEN) bufferlen = fib->fib_Size;
445 if (bufferlen < 8192) bufferlen = 8192;
448 else
450 return TRUE;
453 to = combinePath(pool, destpath, FilePart(file));
454 if (to)
456 buffer = AllocVecPooled(pool, bufferlen);
457 if (buffer)
459 in = Open(file, MODE_OLDFILE);
460 if (in)
462 out = Open(to, MODE_NEWFILE);
463 if (out)
465 BOOL stop = FALSE;
466 unsigned int difftime = clock();
469 clen = Read(in, buffer, bufferlen);
470 if ((clen !=0) && (clen != -1))
472 wlen = Write(out, buffer,clen);
473 if (display)
475 display->difftime = clock() - difftime;
476 if (display->difftime < 1) display->difftime = 1;
477 display->actlen = clen;
478 display->totallen += clen;
479 display->filelen = filelen;
480 if (displayHook)
482 display->flags |= ACTION_UPDATE;
483 stop = CallHook(displayHook, (Object *) display, NULL);
487 if (clen != wlen) clen = 0;
490 while ((clen !=0) && (clen != -1) && !stop);
492 quit = stop;
494 Close(out);
496 if (fib)
498 SetComment(to, fib->fib_Comment);
499 SetProtection(to, fib->fib_Protection);
502 Close(in);
504 FreeVecPooled(pool, buffer);
506 freeString(pool, to);
508 if (fileinfo == NULL) FreeDosObject(DOS_FIB,(APTR) fib);
510 return quit;
514 static VOID handleUnprotect(LONG info, char * spath, char * file, char * target, struct Hook * askHook, WORD * pmode, BOOL * unprotect)
516 struct dCopyStruct askDisplay;
518 if ((info & (FILEINFO_PROTECTED|FILEINFO_WRITE)) != 0)
520 if (*pmode != OPMODE_NONE)
522 if (
523 (*pmode == OPMODE_ASK) || (*pmode == OPMODE_YES) ||
524 (*pmode == OPMODE_ALL) || (*pmode == OPMODE_NO)
527 askDisplay.spath = spath;
528 askDisplay.file = file;
529 askDisplay.type = 1;
530 askDisplay.filelen = 0;
531 if (*pmode != OPMODE_ALL) *pmode = CallHook(askHook, (Object *) &askDisplay, NULL);
532 if ((*pmode == OPMODE_ALL) || (*pmode == OPMODE_YES))
534 SetProtection(target, 0);
535 *unprotect = TRUE;
540 else *unprotect = TRUE;
543 #define dmode (opModes->deletemode)
544 #define pmode (opModes->protectmode)
545 #define omode (opModes->overwritemode)
546 ///actionDir()
547 static BOOL actionDir(APTR pool, ULONG flags, char *source, char *dest,
548 BOOL quit, struct Hook *dHook, struct OpModes * opModes, APTR userdata)
550 struct FileInfoBlock *FIB, *FIB2;
551 struct dCopyStruct display;
552 struct dCopyStruct askDisplay;
553 struct FileEntry *fe, *fef, *fel;
555 BPTR NewLock, cDir, nDir, nLock;
556 ULONG Success, Success1, Success2, DosError, len;
557 char *dname, *comment, *dpath;
558 BOOL del, created, unprotect, failure;
559 BOOL overwrite;
560 LONG info, prot;
562 if (quit) return TRUE;
564 created = FALSE;
566 display.userdata = userdata;
567 askDisplay.userdata = userdata;
569 fef = NULL;
570 fel = NULL;
572 FIB = (struct FileInfoBlock*) AllocDosObject(DOS_FIB,DummyTags);
573 if (FIB)
575 FIB2 = (struct FileInfoBlock*) AllocDosObject(DOS_FIB,DummyTags);
576 if (FIB2)
578 NewLock = Lock(source ,ACCESS_READ);
579 if (NewLock)
581 cDir = CurrentDir(NewLock);
583 Success1=Examine(NewLock,FIB);
584 if (Success1)
588 /* For each entry in directory ... */
589 Success=ExNext(NewLock,FIB);
591 /* If OPMODE_NONE, stop all actions */
592 if ((flags & (ACTION_DELETE | ACTION_COPY)) == ACTION_DELETE)
594 if (dmode == OPMODE_NONE) Success = FALSE;
597 if (Success && Success1)
599 if (FIB->fib_DirEntryType>0)
601 /* The entry is a directory */
602 dname = NULL;
604 /* If copying, check if the destination directory exists and create if needed */
605 if (((flags & ACTION_COPY) != 0) && dest)
607 dname = combinePath(pool, dest, FIB->fib_FileName);
608 if (dname)
610 created = FALSE;
611 nLock = Lock(dname, ACCESS_READ);
612 if (nLock)
614 Success2 = Examine(nLock,FIB2);
615 if (Success2) if (FIB2->fib_DirEntryType>0) created = TRUE;
616 UnLock(nLock);
618 if (!created)
620 nDir = CreateDir(dname);
621 if (nDir)
623 prot = GetProtectionInfo(FIB->fib_FileName);
624 comment = GetCommentInfo(pool, FIB->fib_FileName);
625 if (comment) SetComment(dname, comment);
626 SetProtection(dname, prot);
627 freeString(pool, comment);
629 created = TRUE;
630 UnLock(nDir);
635 unprotect = FALSE;
636 del = FALSE;
638 /* If deleting, ask for confirmation and ask to unprotect */
639 if (opModes && (dmode != OPMODE_NONE) && ((flags & ACTION_DELETE) != 0))
641 if ((dmode == OPMODE_ASK) || (dmode == OPMODE_YES) || (dmode == OPMODE_ALL) || (dmode == OPMODE_NO))
643 askDisplay.spath = FIB->fib_FileName;
644 askDisplay.file = NULL;
645 askDisplay.type = 0;
646 askDisplay.filelen = FIB->fib_Size;
647 if (dmode != OPMODE_ALL) dmode = CallHook(opModes->askhook, (Object *) &askDisplay, NULL);
648 if ((dmode == OPMODE_ALL) || (dmode == OPMODE_YES))
651 unprotect = FALSE;
652 info = GetFileInfo(FIB->fib_FileName);
654 handleUnprotect(info, FIB->fib_FileName, NULL, FIB->fib_FileName, opModes->askhook, &pmode, &unprotect);
656 if (unprotect)
658 del = TRUE;
664 /* If directory was created or we are deleting, trawl deeper and repeat actions */
665 if (created || ((flags & ACTION_DELETE) !=0))
667 if (((dmode == OPMODE_NO) || (dmode == OPMODE_NONE)) && (flags == ACTION_DELETE))
669 quit = FALSE;
671 else
673 quit = actionDir(pool, flags, FIB->fib_FileName, dname, quit, dHook, opModes, userdata);
677 /* If deleting and all actions succeeded in deeper directory, add the directory to "to be deleted" list */
678 if (!quit && del && unprotect)
680 if (FIB->fib_FileName)
682 len = strlen(FIB->fib_FileName);
683 if (len>0)
686 fe = AllocVecPooled(pool, sizeof(struct FileEntry) + len);
687 if (fe)
689 strcpy(fe->name, FIB->fib_FileName);
690 if (fel)
692 fel->next = fe;
693 fel = fe;
695 else
697 fef = fe;
698 fel = fe;
704 freeString(pool, dname);
706 else
708 /* The entry is a file */
709 if (dHook)
711 display.file = FIB->fib_FileName;
712 display.filelen = FIB->fib_Size;
713 display.spath = source;
714 display.dpath = dest;
715 display.flags = (flags &= ~ACTION_UPDATE);
716 display.totallen = 0;
717 display.actlen = 0;
719 quit = CallHook(dHook, (Object *) &display, NULL);
722 overwrite = TRUE;
724 /* If copying, ask for overwrite destinatin and ask for unprotect destination */
725 if (((flags & ACTION_COPY) != 0) && dest)
727 dpath = combinePath(pool, dest, FIB->fib_FileName);
728 if (dpath)
730 info = GetFileInfo(dpath);
731 if (info != -1)
733 overwrite = FALSE;
734 if (opModes && (omode != OPMODE_NONE))
736 if (
737 (omode == OPMODE_ASK) || (omode == OPMODE_YES) ||
738 (omode == OPMODE_ALL) || (omode == OPMODE_NO)
741 askDisplay.spath = dest;
742 askDisplay.file = FIB->fib_FileName;
743 askDisplay.type = 2;
744 askDisplay.filelen = 0;
745 if (omode != OPMODE_ALL) omode = CallHook(opModes->askhook, (Object *) &askDisplay, NULL);
746 if ((omode == OPMODE_ALL) || (omode == OPMODE_YES))
748 handleUnprotect(info, dest, FIB->fib_FileName, dpath, opModes->askhook, &pmode, &overwrite);
753 freeString(pool, dpath);
757 /* Copy the file */
758 failure = FALSE;
759 if (!quit && ((flags & ACTION_COPY) !=0) && overwrite)
761 display.flags = (flags &= ~ACTION_UPDATE);
762 failure = copyFile(pool, FIB->fib_FileName, dest, FIB, dHook, &display);
765 /* If failed, ask if process should continue */
766 if (failure && !quit)
768 if (opModes)
770 askDisplay.spath = source;
771 askDisplay.file = FIB->fib_FileName;
772 askDisplay.type = 3;
773 askDisplay.filelen = 0;
774 if (CallHook(opModes->askhook, (Object *) &askDisplay, NULL) == ACCESS_SKIP)
775 quit = FALSE; else quit = TRUE;
777 else quit = FALSE;
780 /* If deleting ask for confirmation and ask to unprotect */
781 if (!quit && opModes && (dmode != OPMODE_NONE) && ((flags & ACTION_DELETE) !=0))
783 if (
784 (dmode == OPMODE_ASK) || (dmode == OPMODE_YES) ||
785 (dmode == OPMODE_ALL) || (dmode == OPMODE_NO)
788 askDisplay.spath = source;
789 askDisplay.file = FIB->fib_FileName;
790 askDisplay.type = 0;
791 askDisplay.filelen = FIB->fib_Size;
792 if (dmode != OPMODE_ALL) dmode = CallHook(opModes->askhook, (Object *) &askDisplay, NULL);
793 if ((dmode == OPMODE_ALL) || (dmode == OPMODE_YES))
796 info = GetFileInfo(FIB->fib_FileName);
797 unprotect = FALSE;
799 handleUnprotect(info, source, FIB->fib_FileName, FIB->fib_FileName, opModes->askhook, &pmode, &unprotect);
801 /* If file ready to be deleted, add it to "to be deleted" list */
802 if (unprotect)
804 if (FIB->fib_FileName)
806 len = strlen(FIB->fib_FileName);
807 if (len>0)
810 fe = AllocVecPooled(pool, sizeof(struct FileEntry) + len);
811 if (fe)
813 strcpy(fe->name, FIB->fib_FileName);
814 if (fel)
816 fel->next = fe;
817 fel = fe;
819 else
821 fef = fe;
822 fel = fe;
834 else
836 DosError=IoErr();
837 /* Is this the end of entries in directory ? */
838 if (DosError!=ERROR_NO_MORE_ENTRIES) Success=TRUE;
841 while (Success && !quit);
844 /* Delete all directories and files which were put on the "to be deleted" list */
845 while (fef)
847 len = strlen(fef->name);
848 if (len > 0)
850 deleteFile(fef->name);
852 fe = fef->next;
853 FreeVecPooled(pool, fef);
854 fef = fe;
857 CurrentDir(cDir);
858 UnLock(NewLock);
860 FreeDosObject (DOS_FIB,(APTR) FIB2);
862 FreeDosObject (DOS_FIB,(APTR) FIB);
865 return quit;
868 #undef dmode
869 #undef pmode
870 #undef omode
872 ///CopyContent()
873 BOOL CopyContent(APTR p, char *s, char *d, BOOL makeparentdir, ULONG flags, struct Hook *displayHook, struct OpModes *opModes, APTR userdata)
876 struct FileInfoBlock *FIB;
877 struct dCopyStruct display;
878 struct dCopyStruct askDisplay;
879 char *destname, *dest, *path, *comment, *dpath, *infoname, *destinfo;
880 //LONG len;
881 LONG Success2, prot;
882 BPTR nLock, nDir;
883 APTR pool;
884 BOOL created = FALSE;
885 BOOL dir = TRUE;
886 BOOL back = FALSE;
887 BOOL deletesrc, unprotectsrc;
888 LONG info;
890 if (p == NULL)
892 pool = CreatePool(MEMF_CLEAR|MEMF_ANY, POOLSIZE, POOLSIZE);
894 else pool = p;
896 if (pool == NULL) return FALSE;
898 infoname = AllocVecPooled(pool, strlen(s)+6);
899 display.userdata = userdata;
900 askDisplay.userdata = userdata;
902 if (infoname)
904 strncpy (infoname, s, strlen(s));
905 strcat(infoname,".info");
908 if (d) destinfo = AllocVecPooled(pool, strlen(d)+6); else destinfo = NULL;
910 if (destinfo)
912 strncpy (destinfo, d, strlen(d));
913 strcat(destinfo,".info");
916 destname = FilePart(s);
918 info = GetFileInfo(s);
920 if (info == -1)
922 freeString(pool, infoname);
923 freeString(pool, destinfo);
924 if (p == NULL) DeletePool(pool);
925 return TRUE;
928 if ((info & FILEINFO_DIR) != 0) dir = TRUE; else dir = FALSE;
930 dest = NULL;
932 if ((flags & ACTION_COPY) !=0 ) dest = allocString(pool, d);
934 /* If copying a directory, create target directory */
935 if (makeparentdir && dir && dest)
937 if (destname)
939 if (strlen(destname)>0)
941 freeString(pool, dest);
942 dest = NULL;
943 FIB = (struct FileInfoBlock*) AllocDosObject(DOS_FIB,DummyTags);
944 if (FIB)
946 dest = combinePath(pool, d, destname);
947 if (dest)
949 nLock = Lock(dest, ACCESS_READ);
950 if (nLock)
952 Success2 = Examine(nLock,FIB);
953 if (Success2) if (FIB->fib_DirEntryType>0) created = TRUE;
954 UnLock(nLock);
956 if (!created)
958 nDir = CreateDir(dest);
959 if (nDir)
961 created = TRUE;
962 UnLock(nDir);
963 prot = GetProtectionInfo(s);
964 comment = GetCommentInfo(pool, s);
965 if (comment) SetComment(dest, comment);
966 SetProtection(dest, prot);
967 freeString(pool, comment);
970 if (!created)
972 freeString(pool, dest);
973 dest = NULL;
974 created = FALSE;
977 FreeDosObject (DOS_FIB,(APTR) FIB);
983 path = NULL;
985 deletesrc = FALSE;
986 unprotectsrc = TRUE;
987 /* If deleting ask for confirmation, ask to unprotect */
988 if (opModes && (opModes->deletemode != OPMODE_NONE) && ((flags & ACTION_DELETE) != 0) && ((makeparentdir && dir) || !dir))
990 if (dir)
992 askDisplay.spath = s;
993 askDisplay.file = NULL;
995 else
997 path = allocPath(pool, s);
998 askDisplay.spath = path;
999 askDisplay.file = FilePart(s);
1001 askDisplay.type = 0;
1003 if (opModes->deletemode != OPMODE_ALL) opModes->deletemode = CallHook(opModes->askhook, (Object *) &askDisplay, NULL);
1004 if ((opModes->deletemode == OPMODE_ALL) || (opModes->deletemode == OPMODE_YES))
1006 deletesrc = TRUE;
1007 if ((info & (FILEINFO_PROTECTED|FILEINFO_WRITE)) != 0)
1009 askDisplay.type = 1;
1010 unprotectsrc = FALSE;
1011 opModes->protectmode = CallHook(opModes->askhook, (Object *) &askDisplay, NULL);
1012 if ((opModes->protectmode == OPMODE_ALL) || (opModes->protectmode == OPMODE_YES))
1014 SetProtection(s, 0);
1015 if (infoname) SetProtection(infoname, 0);
1016 unprotectsrc = TRUE;
1022 /* If copying ask to overwrite, ask to unprotect */
1023 if (dest)
1025 if (opModes && !dir)
1027 dpath = combinePath(pool, d, FilePart(s));
1028 if (dpath)
1030 info = GetFileInfo(dpath);
1031 if (info != -1)
1033 if (opModes && (opModes->overwritemode != OPMODE_NONE))
1035 if (
1036 (opModes->overwritemode == OPMODE_ASK) || (opModes->overwritemode == OPMODE_YES) ||
1037 (opModes->overwritemode == OPMODE_ALL) || (opModes->overwritemode == OPMODE_NO)
1040 askDisplay.spath = d;
1041 askDisplay.file = FilePart(s);
1042 askDisplay.type = 2;
1043 if (opModes->overwritemode != OPMODE_ALL) opModes->overwritemode = CallHook(opModes->askhook, (Object *) &askDisplay, NULL);
1044 if ((opModes->overwritemode == OPMODE_ALL) || (opModes->overwritemode == OPMODE_YES))
1046 if (((info & (FILEINFO_PROTECTED|FILEINFO_WRITE)) != 0) && (opModes->protectmode != OPMODE_NONE))
1048 if (
1049 (opModes->protectmode == OPMODE_ASK) || (opModes->protectmode == OPMODE_YES) ||
1050 (opModes->protectmode == OPMODE_ALL) || (opModes->protectmode == OPMODE_NO)
1053 askDisplay.spath = d;
1054 askDisplay.file = FilePart(s);
1055 askDisplay.type = 1;
1056 if (opModes->protectmode != OPMODE_ALL) opModes->protectmode = CallHook(opModes->askhook, (Object *) &askDisplay, NULL);
1057 if ((opModes->protectmode == OPMODE_ALL) || (opModes->protectmode == OPMODE_YES))
1059 SetProtection(dpath, 0);
1067 freeString(pool, dpath);
1071 freeString(pool, path);
1073 if (dir)
1075 if (dest || ((flags & ACTION_DELETE) != 0))
1077 if (
1078 ((opModes->deletemode == OPMODE_NONE) || (opModes->deletemode == OPMODE_NO)) &&
1079 (flags & (ACTION_DELETE|ACTION_COPY)) == ACTION_DELETE
1082 back = FALSE;
1084 else
1086 back = actionDir(pool, flags, s, dest, FALSE, displayHook, opModes, userdata);
1089 else back = TRUE;
1091 else
1093 if (flags == ACTION_DELETE) back = FALSE;
1094 else
1096 STRPTR path = allocPath(pool, s);
1097 display.file = FilePart(s);
1098 display.filelen = 0;
1099 display.totallen = 0;
1100 display.actlen = 0;
1102 if (path) display.spath = path; else display.spath = s;
1103 display.dpath = d;
1104 display.flags = (flags &= ~ACTION_UPDATE);
1105 if (displayHook) CallHook(displayHook, (Object *) &display, NULL);
1106 back = copyFile(pool, s, d, NULL, displayHook, &display);
1107 freeString(pool, path);
1111 if (!back && destinfo && infoname)
1113 SetProtection(destinfo, 0);
1114 copyFile(pool, infoname, d, NULL, NULL, NULL);
1117 if (!back && opModes && (opModes->deletemode != OPMODE_NONE) && ((flags & ACTION_DELETE) !=0))
1119 if (unprotectsrc && deletesrc)
1121 deleteFile(s);
1122 if (infoname) deleteFile(infoname);
1126 freeString(pool, infoname);
1127 freeString(pool, destinfo);
1128 freeString(pool, dest);
1130 if (p == NULL)
1131 DeletePool(pool);
1132 return !back;