Compiler warnings about misleading indentation removed.
[AROS-Contrib.git] / dopus / Program / main22.c
blob05d9601b2391ffeeb563873574f93197b59b741f
1 /*
3 Directory Opus 4
4 Original GPL release version 4.12
5 Copyright 1993-2000 Jonathan Potter
7 This program is free software; you can redistribute it and/or
8 modify it under the terms of the GNU General Public License
9 as published by the Free Software Foundation; either version 2
10 of the License, or (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21 All users of Directory Opus 4 (including versions distributed
22 under the GPL) are entitled to upgrade to the latest version of
23 Directory Opus version 5 at a reduced price. Please see
24 http://www.gpsoft.com.au for more information.
26 The release of Directory Opus 4 under the GPL in NO WAY affects
27 the existing commercial status of Directory Opus 5.
31 #include "dopus.h"
32 #ifndef __AROS__
33 #include <proto/inovamusic.h>
34 #else
35 #include "music.h"
36 #endif
37 #include "view.h"
39 int dofilefunction(function,flags,sourcedir,destdir,act,inact,rexx)
40 int function,flags;
41 char *sourcedir,*destdir;
42 int act,inact,rexx;
44 struct InfoData __aligned infodata;
45 struct FileInfoBlock __aligned fileinfo;
46 int a,b,special=0,candoicon=1,old,specflags,noshow=0,err;
47 int sourcewild=0,destwild=0,firstset=0,breakout,rexarg,protstuff[2];
48 int pt=1,okayflag,show,lastfile,flag,exist,count,data,mask=0,temp;
49 int globflag,noremove,doicons=0,total,value=0,progtype,blocksize,retval=0;
50 long long byte,bb;
51 __unused ULONG class;
52 __unused UWORD code;
53 struct Directory *file = NULL,*tempfile,*nextfile,filebuf,dummyfile;
54 char *sourcename,*destname,*oldiconname,*newiconname;
55 char *buf,*buf1,*buf2,*namebuf,*srename,*drename,*ptr,*database;
56 static char tbuf[256],titlebuf[32];
57 struct DOpusDateTime datetime;
58 struct DOpusRemember *funckey;
59 struct dopusfiletype *type;
60 struct dopusfuncpar par;
61 struct DirectoryWindow *swindow,*dwindow;
62 struct DOpusArgsList arglist;
63 struct ViewData *viewdata=NULL;
64 BPTR filelock;
65 static int entry_depth;
66 char progress_copy=0,prog_indicator=0;
67 BOOL arcfile;
69 if (act>-1) swindow=dopus_curwin[act];
70 else swindow=NULL;
71 if (inact>-1) dwindow=dopus_curwin[inact];
72 else dwindow=NULL;
74 if (destdir && (dwindow->flags & DWF_ARCHIVE))
76 dostatustext(globstring[STR_OPERATION_NOT_SUPPORTED]); //HUX
77 return 0; // XAD archive can't be modified
80 data=rexarg=0; funckey=NULL;
81 specflags=flags&~255; flags&=255;
83 if (config->iconflags&ICONFLAG_DOUNTOICONS || func_external_file[0]) doicons=1;
85 #ifndef __AROS__
86 switch (function) {
87 case FUNC_PLAYST:
88 if (!MUSICBase) return(0);
89 case FUNC_PLAY:
90 case FUNC_LOOPPLAY:
91 if (MUSICBase) FlushModule();
92 break;
94 #endif
96 /* Find the first file to work upon; if only one file specified,
97 use that */
99 if (status_flags&STATUS_GLOBALFILE) /* kludge */
100 flags=FUNCFLAGS_FILES;
102 total=-1;
104 if (func_single_entry) {
105 file=func_single_entry;
106 //D(bug("func_single_entry\n"));
107 globflag=1;
109 else if (swindow) {
110 globflag=0;
111 if (flags&FUNCFLAGS_DIRS) {
112 //D(bug("first dir\n"));
113 file=checkdirtot(swindow); /* First dir */
114 total=swindow->dirsel;
115 progtype=1;
117 if (flags&FUNCFLAGS_DEVS && !file) {
118 //D(bug("first dev\n"));
119 file=checkdevtot(swindow); /* or dev */
120 total=swindow->dirsel;
121 progtype=1;
123 if (flags&FUNCFLAGS_FILES) {
124 //D(bug("first file\n"));
125 file=checktot(swindow); /* First file */
126 total=swindow->filesel;
127 progtype=0;
129 if (flags==0 || flags&FUNCFLAGS_ANYTHING) {
130 //D(bug("first entry\n"));
131 file=checkalltot(swindow);
132 total=swindow->filesel+swindow->dirsel; /* Anything */
133 progtype=2;
135 if (!file && flags&FUNCFLAGS_ANYTHING) {
136 //D(bug("first dev2\n"));
137 file=checkdevtot(swindow);
138 total=swindow->dirsel;
139 progtype=1;
142 /* Name may be in ARexx */
144 if (rexx && (tempfile=findfile(swindow,rexx_args[0],NULL))) {
145 //D(bug("from rexx\n"));
146 ++rexarg;
147 file=tempfile;
148 func_single_entry=file;
149 strcpy(func_single_file,file->name);
150 globflag=1;
153 D(bug("dofilefunction(%ld,%lx,%s,%s,%ld,%ld,%ld)\n",function,flags,sourcedir?sourcedir:"<NULL>",destdir?destdir:"<NULL>",act,inact,rexx));
154 D(bug("\tfunc_single_entry: %lx\n",func_single_entry));
155 D(bug("\tfile: %lx\n",file));
157 if (!file) return(0); /* No files selected, return */
159 if (!(database=LAllocRemember(&funckey,3000,MEMF_CLEAR))) return(0);
160 sourcename=database; destname=database+300;
161 oldiconname=database+600; newiconname=database+900;
162 buf=database+1200; buf1=database+1500; buf2=database+1800;
163 namebuf=database+2100; srename=database+2400; drename=database+2700;
165 if (swindow) scrdata_old_offset_store=swindow->offset; /* Store directory offset for auto-scroll */
166 else scrdata_old_offset_store=-1;
168 status_justabort=count=0; namebuf[0]=0;
169 autoskip = 0;
171 /* Bump entry depth to check for recursion */
173 ++entry_depth;
175 /* Do initial setting up functions */
177 switch (function) {
178 case FUNC_READ:
179 case FUNC_HEXREAD:
180 case FUNC_ANSIREAD:
181 case FUNC_SMARTREAD:
182 if (!globflag &&
183 !(viewdata=LAllocRemember(&funckey,sizeof(struct ViewData),MEMF_CLEAR)))
184 goto endfunction;
185 case FUNC_LOOPPLAY:
186 case FUNC_SHOW:
187 total=-1;
188 case FUNC_PLAY:
189 candoicon=0;
190 break;
191 case FUNC_DELETE:
192 askeach=1;
193 if (config->deleteflags&DELETE_ASK && !globflag) {
194 /* Ask for confirmation before commencing delete */
195 displaydirgiven(act,file,0);
196 if (!(a=simplerequest(globstring[STR_REALLY_DELETE],
197 globstring[STR_DELETE],str_cancelstring,globstring[STR_ALL],NULL))) {
198 endfollow(act);
199 myabort();
200 goto endfunction;
202 if (a==2) askeach=0;
204 glob_unprotect_all=0;
205 break;
206 case FUNC_RENAME:
207 if (rexx) {
208 if (rexx_argcount<2) goto endfunction;
209 strcpy(srename,rexx_args[0]);
210 strcpy(drename,rexx_args[1]);
211 if (strchr(srename,'*')) sourcewild=1;
212 if (strchr(drename,'*')) destwild=1;
213 else {
214 strcpy(namebuf,drename);
215 firstset=1;
218 else while (file) {
219 if (file->selected) {
220 strcpy(srename,file->name); strcpy(drename,file->name);
221 displaydirgiven(act,file,0);
222 if (!(a=getrenamedata(srename,drename)) ||
223 !srename[0] || !drename[0]) {
224 endfollow(act);
225 myabort();
226 goto endfunction;
228 if (a==1) {
229 if (strchr(srename,'*')) sourcewild=1;
230 if (strchr(drename,'*')) destwild=1;
231 else {
232 strcpy(namebuf,drename);
233 firstset=1;
234 total=-1;
236 break;
239 ++value;
240 file=file->next;
242 if (!file) {
243 endfollow(act);
244 goto endfunction;
246 askeach=1;
247 break;
248 case FUNC_MOVE:
249 if (destdir[0] && (checksame(sourcedir,destdir,1)==LOCK_SAME)) goto endfunction;
250 case FUNC_MOVEAS:
251 if (!(checkdest(inact))) goto endfunction;
252 if (!(config->existflags&REPLACE_ALWAYS)) askeach=1;
253 else askeach = 0;
254 if (checksame(sourcedir,destdir,2)!=LOCK_SAME_VOLUME) progress_copy=1;
255 break;
256 case FUNC_COPY:
257 if (destdir[0] && (checksame(sourcedir,destdir,1)==LOCK_SAME)) goto endfunction;
258 // case FUNC_CLONE:
259 case FUNC_COPYAS:
260 if (!(checkdest(inact))) goto endfunction;
261 askeach = (config->existflags&REPLACE_ALWAYS) ? 0 : 1;
262 progress_copy=1;
263 if (!(specflags&FUNCFLAGS_COPYISCLONE) && config->copyflags&COPY_CHECK) {
264 old=scrdata_old_offset_store;
265 if (!globflag) {
266 a=0;
267 tempfile=file;
268 while (tempfile) {
269 if (tempfile->selected && tempfile->type>=ENTRY_DIRECTORY &&
270 tempfile->size==-1) {
271 a=1;
272 break;
274 tempfile=tempfile->next;
276 if (!a || simplerequest(globstring[STR_SIZES_NOT_KNOWN],
277 globstring[STR_YES],globstring[STR_NO],NULL)) {
278 if (status_justabort ||
279 (!(dofilefunction(FUNC_BYTE,FUNCFLAGS_BYTEISCHECKFIT,
280 sourcedir,destdir,act,inact,0)) &&
281 !(simplerequest(globstring[STR_ENTRIES_MAY_NOT_FIT],
282 globstring[STR_CONTINUE],str_cancelstring,NULL)))) {
283 myabort();
284 goto endfunction;
286 D(bug("main22.c: dos_global_files = %ld\n",dos_global_files));
287 total += dos_global_files;
290 scrdata_old_offset_store=old;
292 break;
293 case FUNC_HUNT:
294 if (rexx && rexx_argcount>0) strcpy(str_hunt_name,rexx_args[rexarg]);
295 else if (!(whatsit(globstring[STR_ENTER_HUNT_PATTERN],80,str_hunt_name,NULL)) ||
296 !str_hunt_name[0]) {
297 myabort();
298 goto endfunction;
300 LParsePatternI(str_hunt_name,str_hunt_name_parsed);
301 CopyMem(str_hunt_name_parsed,buf2,170);
302 candoicon=0;
303 break;
304 case FUNC_PRINT:
305 if (globflag) {
306 StrCombine(sourcename,sourcedir,file->name,256);
307 arglist.single_file=sourcename;
308 arglist.file_list=NULL;
309 arglist.last_select=NULL;
311 else {
312 arglist.single_file=NULL;
313 arglist.file_window=act;
314 arglist.file_list=(APTR)file;
316 dopus_print(rexx,&arglist,0,str_arexx_portname,NULL);
317 goto endfunction;
318 break;
319 case FUNC_COMMENT:
320 candoicon=0;
321 case FUNC_DATESTAMP:
322 case FUNC_PROTECT:
323 askeach=1;
324 break;
325 case FUNC_ENCRYPT:
326 if (!(checkdest(inact)) || (checksame(sourcedir,destdir,1)==LOCK_SAME))
327 goto endfunction;
328 if (!(config->existflags&REPLACE_ALWAYS)) askeach=1;
329 else askeach = 0;
330 if (rexx && rexx_argcount>0) strcpy(buf2,rexx_args[rexarg]);
331 else if (!(whatsit(globstring[STR_ENTER_PASSWORD],20,buf2,NULL)) ||
332 !buf2[0]) {
333 myabort();
334 goto endfunction;
336 if (buf2[0]=='-') {
337 data=0;
338 strcpy(buf2,&buf2[1]);
340 else data=1;
341 candoicon=0;
342 progress_copy=1;
343 break;
344 case FUNC_SEARCH:
345 if (rexx && rexx_argcount>0) strcpy(str_search_string,rexx_args[rexarg]);
346 else {
347 if (!(get_search_data(str_search_string,&search_flags,Window,scr_font[FONT_REQUEST]))) {
348 myabort();
349 goto endfunction;
351 // if (Window) ActivateWindow(Window);
354 candoicon=0;
355 askeach=1;
356 break;
357 case FUNC_RUN:
358 candoicon=0;
359 break;
360 case FUNC_ADDICON:
361 askeach=1;
362 candoicon=0;
363 break;
364 case FUNC_ICONINFO:
365 candoicon=0;
366 total=-1;
367 break;
368 case FUNC_AUTO:
369 case FUNC_AUTO2:
370 case FUNC_AUTO3:
371 case FUNC_AUTO4:
372 dostatustext(globstring[STR_INTERROGATING_FILES]);
373 candoicon=0;
374 total=-1;
375 break;
376 case FUNC_BYTE:
377 candoicon=0;
378 special=2;
379 count=1;
380 main_proc->pr_WindowPtr=(APTR)-1;
381 if (destdir && (filelock=Lock(destdir,ACCESS_READ))) {
382 Info(filelock,&infodata);
383 UnLock(filelock);
384 blocksize=infodata.id_BytesPerBlock;
386 else blocksize=512;
387 //D(bug("infodata: %lx\tdestdir: %s\tblocksize: %ld\n",&infodata,destdir,blocksize));
388 if (config->errorflags&ERROR_ENABLE_DOS) main_proc->pr_WindowPtr=(APTR)Window;
389 total=-1;
390 dos_global_files = 0;
391 break;
394 if (!(config->dynamicflags&UPDATE_PROGRESSIND_COPY)) progress_copy=0;
396 endnotifies();
398 if (config->dynamicflags&UPDATE_PROGRESSINDICATOR &&
399 (progress_copy || total>1)) {
400 char *title=NULL;
401 int x;
403 for (x=0;;x++) {
404 if (!commandlist[x].name) break;
405 if (commandlist[x].function==function &&
406 !(commandlist[x].flags&RCL_SYNONYM)) {
407 title=commandlist[x].name;
408 break;
412 if (title)
414 switch (function)
416 case FUNC_SEARCH:
417 case FUNC_HUNT:
418 StrCombine(titlebuf,title,": ",32);
419 StrConcat(titlebuf,(function==FUNC_SEARCH)?str_search_string:str_hunt_name,32);
420 break;
421 default:
422 StrCombine(titlebuf,title,"...",32);
425 else strcpy(titlebuf,"Directory Opus");
427 D(bug("main22.c: total = %ld, dos_global_files = %ld\n",total, dos_global_files));
428 /*if (total>1)*/ dotaskmsg(hotkeymsg_port,PROGRESS_OPEN,(total>1)?value:1,(total>1)?total:1,titlebuf,progress_copy|((swindow->dirsel&&(!dos_global_files))?0x80:0x00));
429 // else dotaskmsg(hotkeymsg_port,PROGRESS_OPEN,1,1,titlebuf,progress_copy);
430 prog_indicator=1;
433 while (file) {
434 if (status_haveaborted) {
435 myabort();
436 break;
438 nextfile=file->next;
440 if ((!file->selected && !globflag) ||
441 ((file->type <= ENTRY_FILE) && str_filter_parsed[0] && (LMatchPatternI(str_filter_parsed,file->name)==FALSE)))
443 file=nextfile;
444 continue;
447 if (doicons && candoicon && !(isicon(file->name))) {
448 StrCombine(oldiconname,file->name,".info",256);
449 StrCombine(buf1,sourcedir,oldiconname,256);
450 if (!(CheckExist(buf1,NULL))) oldiconname[0]=0;
452 else oldiconname[0]=0;
454 if (prog_indicator) {
455 if ((progtype==1 && file->type>=ENTRY_DEVICE) ||
456 (progtype==0 && file->type<=ENTRY_FILE) ||
457 (progtype==2)) ++value;
458 D(bug("main22.c: value = %ld\n",value));
459 // if (total) dotaskmsg(hotkeymsg_port,PROGRESS_INCREASE,1,0,NULL,0);
460 /*if (total>1)*/ dotaskmsg(hotkeymsg_port,PROGRESS_UPDATE,value,total,NULL,0);
461 // else dotaskmsg(hotkeymsg_port,PROGRESS_UPDATE,1,1,NULL,0);
462 if (progress_copy) dotaskmsg(hotkeymsg_port,PROGRESS_UPDATE,-2,0,file->name,1);
465 lastfile=flag=breakout=0;
467 arcfile = FALSE;
468 functionloop:
469 StrCombine(sourcename,sourcedir,file->name,256);
470 if (!special || count==0 ||
471 (special==2 && file->type>=0)) {
472 dofilename(sourcename);
473 displaydirgiven(act,file,0);
475 if (!firstset && !lastfile && !namebuf[0]) strcpy(namebuf,file->name);
476 else if (lastfile) strcpy(namebuf,BaseName(newiconname));
477 okayflag=a=0; show=-1;
479 if (func_external_file[0] || file==&dummyfile) noremove=1;
480 else noremove=0;
482 switch (function) {
483 case FUNC_AUTO:
484 case FUNC_AUTO2:
485 case FUNC_AUTO3:
486 case FUNC_AUTO4:
487 if (function==FUNC_AUTO) a=FTFUNC_AUTOFUNC1;
488 else if (function==FUNC_AUTO2) a=FTFUNC_AUTOFUNC2;
489 else if (function==FUNC_AUTO3) a=FTFUNC_AUTOFUNC3;
490 else if (function==FUNC_AUTO4) a=FTFUNC_AUTOFUNC4;
491 okayflag=1;
492 if (file->type<=ENTRY_FILE) {
493 if ((type=checkfiletype(sourcename,a,0))) {
494 char title[256];
496 par.which=type->which[a]; par.stack=type->stack[a];
497 par.key=par.qual=0;
498 par.pri=type->pri[a]; par.delay=type->delay[a];
499 status_previousabort=0;
500 if (status_iconified && status_flags&STATUS_ISINBUTTONS)
501 strcpy(func_external_file,sourcename);
502 if (type->actionstring[a][0]) {
503 do_title_string(type->actionstring[a],title,0,file->name);
504 dostatustext(title);
506 else title[0]=0;
507 dofunctionstring(type->function[a],file->name,title,&par);
508 if (status_previousabort) status_haveaborted=1;
510 else {
511 lsprintf(buf,globstring[STR_NOT_IDENTIFIED],file->name);
512 dostatustext(buf);
515 break;
517 case FUNC_BYTE:
518 if (file->type>=ENTRY_DIRECTORY &&
519 (file->size<0 || (specflags&FUNCFLAGS_BYTEISCHECKFIT &&
520 (file->userdata==0 || file->userdata2!=blocksize)))) {
521 bb = dos_global_files;
522 if ((a=recursedir(sourcename,NULL,R_GETBYTES,blocksize))==-10) {
523 myabort();
524 break;
526 dos_global_files += bb;
527 file->userdata=dos_global_blocksneeded;
528 file->userdata2=blocksize;
529 setdirsize(file,dos_global_bytecount,act);
530 refreshwindow(act,0);
531 D({char p[256]; unsigned long long s=0; ULONG f=0; strcpy(p,sourcename); getdircontentsinfo(p,&s,&f); sprintf(p,"size: %qd, files: %ld\n",s,f); bug("%s",p);})
533 if (file->type>=ENTRY_DIRECTORY) data+=file->userdata+1;
534 else {
535 a=(file->size+(blocksize-1))/blocksize;
536 data+=a+(a/72)+1;
537 //D(bug("size: %ld\tdata: %ld\n",file->size,data));
539 if (doicons && !(isicon(file->name))) {
540 StrCombine(oldiconname,file->name,".info",256);
541 bb=-1;
542 if ((file=findfile(swindow,oldiconname,NULL))) {
543 if (!file->selected) bb=file->size;
545 else {
546 StrCombine(tbuf,sourcedir,oldiconname,256);
547 if (lockandexamine(tbuf,&fileinfo)) bb=fileinfo.fib_Size;
549 if (bb>-1) {
550 a=(bb+(blocksize-1))/blocksize;
551 data+=a+(a/72)+1;
553 oldiconname[0]=0;
555 file=NULL;
556 okayflag=1;
557 break;
559 case FUNC_RUN:
560 if (file->type<=ENTRY_FILE) {
561 if (checkexec(sourcename)) {
562 if ((a=dorun(sourcename,1,0))==-1) break;
563 else if (a && a!=-2) okayflag=1;
565 else if (file->protection&FIBF_SCRIPT) {
566 struct dopusfuncpar par;
568 lsprintf(buf,"Execute \"%s\"",sourcename);
569 defaultpar(&par);
570 dofunctionstring(buf,NULL,NULL,&par);
571 okayflag=1;
574 break;
576 case FUNC_DELETE:
577 if (file->type>=ENTRY_DIRECTORY) {
578 if ((a=delfile(sourcename,file->name,globstring[STR_DELETING],
579 glob_unprotect_all,0))==-1) {
580 myabort();
581 break;
583 else if (a>0) {
584 if (a==2) glob_unprotect_all=1;
585 if (!noremove) removefile(file,swindow,act,1);
586 file=NULL;
587 okayflag=1;
590 if (DeleteFile(sourcename)) {
591 if (!noremove) removefile(file,swindow,act,1); file=NULL;
592 okayflag=1;
595 else if (a<0) {
596 if ((a=IoErr())==ERROR_DELETE_PROTECTED &&
597 config->deleteflags&DELETE_SET) {
598 if (!flag) {
599 flag=1;
600 SetProtection(sourcename,0);
601 goto functionloop;
604 else if (a==ERROR_OBJECT_NOT_FOUND) {
605 if (!noremove) removefile(file,swindow,act,1);
606 file=NULL;
607 okayflag=1;
609 else if (a==ERROR_DIRECTORY_NOT_EMPTY) {
610 if (config->deleteflags&DELETE_DIRS && askeach) {
611 lsprintf(buf2,globstring[STR_NOT_EMPTY],file->name);
612 if (!(a=simplerequest(buf2,globstring[STR_DELETE],
613 globstring[STR_LEAVE],globstring[STR_ALL],globstring[STR_ABORT],NULL))) {
614 okayflag=1;
615 break;
617 if (a==2) askeach=0;
618 else if (a==3) {
619 myabort();
620 break;
623 TackOn(sourcename,NULL,256);
624 a=recursedir(sourcename,NULL,R_DELETE,0);
625 sourcename[strlen(sourcename)-1]=0;
626 if (!a) {
627 if ((a=delfile(sourcename,file->name,globstring[STR_DELETING],
628 glob_unprotect_all,1))==-1) {
629 myabort();
630 break;
632 else if (a==1 || a==2) {
633 if (a==2) glob_unprotect_all=1;
634 if (!noremove) removefile(file,swindow,act,1);
635 file=NULL;
636 okayflag=1;
638 else {
639 setdirsize(file,dos_global_bytecount-dos_global_deletedbytes,act);
640 okayflag=1;
643 else {
644 setdirsize(file,file->size-dos_global_deletedbytes,act);
645 refreshwindow(act,0);
648 else {
649 doerror((a=IoErr()));
650 if ((a=checkerror(globstring[STR_DELETING],file->name,a))==3) {
651 myabort();
652 break;
654 if (a==1) goto functionloop;
657 show=act;
658 break;
660 if (file->type == ENTRY_DEVICE)
662 if ((!strcmp(file->comment,"<DEV>")) || (!strcmp(file->comment,"<VOL>"))) break;
664 if (config->deleteflags&DELETE_FILES && askeach && !lastfile) {
665 lsprintf(buf2,file->type==ENTRY_DEVICE?globstring[STR_QUERY_REMOVE_ASSIGN]:globstring[STR_WISH_TO_DELETE],file->name); // HUX
666 a=simplerequest(buf2,globstring[file->type==ENTRY_DEVICE?STR_REMOVE:STR_DELETE],globstring[STR_ABORT],
667 globstring[STR_ALL],globstring[STR_LEAVE],NULL);
668 if (a==3) {
669 okayflag=1;
670 break;
672 else if (a==2) askeach=0;
673 else if (a==0) {
674 myabort();
675 break;
678 if (file->type == ENTRY_DEVICE) /* remove assign */
680 char buf[FILEBUF_SIZE],*c;
682 strcpy(buf,file->name);
683 c = strchr(buf,':');
684 if (c) *c = 0;
685 a = AssignLock(buf,NULL)?1:0;
686 //D(bug("Removing assign %s\t%s\n",buf,a?"success":"failure"));
688 else if ((a=delfile(sourcename,file->name,globstring[STR_DELETING],
689 glob_unprotect_all,1))==-1) {
690 myabort();
691 break;
693 if (a) {
694 if (a==2) glob_unprotect_all=1;
695 if (!noremove) removefile(file,swindow,act,1);
696 file=NULL;
697 show=act;
698 okayflag=1;
700 break;
702 case FUNC_RENAME:
703 if (firstset || lastfile) a=1;
704 else if (!destwild) {
705 if (!(a=whatsit(globstring[STR_ENTER_NEW_NAME],FILEBUF_SIZE-2,namebuf,
706 globstring[STR_SKIP]))) {
707 myabort();
708 break;
710 if (a==2) {
711 file=NULL;
712 okayflag=1;
713 oldiconname[0]=0;
714 break;
717 else if (!sourcewild) a=getwildrename("*",drename,file->name,namebuf);
718 else if (sourcewild) a=getwildrename(srename,drename,file->name,namebuf);
719 firstset=0;
720 if (a) {
721 if (lastfile) StrCombine(destname,sourcedir,newiconname,256);
722 else {
723 /* if (doicons && oldiconname[0]) namebuf[FILEBUF_SIZE-7]=0;
724 else namebuf[FILEBUF_SIZE-2]=0; */ namebuf[FILEBUF_SIZE-1]=0;
725 StrCombine(destname,sourcedir,namebuf,256);
726 StrCombine(newiconname,namebuf,".info",256);
728 retry_rename:
729 D(bug("Rename(%s,%s)\n",sourcename,destname));
730 if (!(Rename(sourcename,destname))) {
731 if ((a=IoErr())==ERROR_OBJECT_EXISTS) {
732 if (askeach) {
733 if (!lastfile) {
734 if ((a=checkexistreplace(sourcename,destname,&file->date,destwild,1))==REPLACE_ABORT)
736 myabort();
737 break;
739 if (a==REPLACE_ALL) {
740 if (!destwild) goto functionloop; // TRY AGAIN
741 askeach=0; // REPLACE ALL
743 else if (a==REPLACE_SKIP) {
744 break;
746 else if (a==REPLACE_SKIPALL) {
747 askeach = 0;
748 autoskip = 1;
750 else if (a==REPLACE_RENAME) goto retry_rename;
753 if (autoskip) break;
754 if ((a=delfile(destname,namebuf,globstring[STR_DELETING],1,1))==-2) {
755 if (!(a=recursedir(destname,NULL,R_DELETE,0))) a=1;
756 else if (a==-10) a=-1;
758 if (a==-1) {
759 myabort();
760 break;
762 if (a) {
763 if ((tempfile=findfile(swindow,namebuf,NULL))) {
764 if (tempfile==nextfile) nextfile=tempfile->next;
765 removefile(tempfile,swindow,act,1);
767 firstset=1;
768 goto functionloop;
771 doerror(a);
772 if ((a=checkerror(globstring[STR_RENAMING],file->name,a))==3) {
773 myabort();
774 break;
776 if (a==1) goto functionloop;
778 else {
779 if (file->type>=ENTRY_DIRECTORY) {
780 StrCombine(buf,sourcedir,file->name,256); TackOn(buf,NULL,256);
781 StrCombine(buf1,sourcedir,namebuf,256); TackOn(buf1,NULL,256);
782 renamebuffers(buf,buf1);
784 if (!noremove){
785 if (act>-1 && config->sortmethod[act]==DISPLAY_NAME) {
786 CopyMem((char *)file,(char *)&filebuf,sizeof(struct Directory));
787 if (file->comment) strcpy(buf2,file->comment);
788 else buf2[0]=0;
789 removefile(file,swindow,act,0); file=NULL;
790 addfile(swindow,act,namebuf,filebuf.size,filebuf.type,&filebuf.date,
791 buf2,filebuf.protection,filebuf.subtype,1,NULL,NULL,
792 filebuf.owner_id,filebuf.group_id);
794 else strcpy(file->name,namebuf);
795 if (lastfile) refreshwindow(act,0);
797 okayflag=1;
800 else okayflag=1;
801 break;
803 case FUNC_MOVEAS:
804 if (!lastfile && !flag) {
805 if (rexx && rexx_argcount>1) strcpy(namebuf,rexx_args[1]);
806 else {
807 if (!(a=whatsit(globstring[STR_ENTER_NEW_NAME_MOVE],FILEBUF_SIZE-2,
808 namebuf,globstring[STR_SKIP]))) {
809 myabort();
810 break;
812 if (a==2) {
813 file=NULL;
814 okayflag=1;
815 oldiconname[0]=0;
816 break;
819 /* if (doicons && oldiconname[0]) namebuf[FILEBUF_SIZE-7]=0;
820 else namebuf[FILEBUF_SIZE-2]=0; */ namebuf[FILEBUF_SIZE-1]=0;
822 case FUNC_MOVE:
823 if (lastfile) strcpy(destname,newiconname);
824 else {
825 StrCombine(destname,destdir,namebuf,256);
826 StrCombine(newiconname,destname,".info",256);
828 if (checksame(destdir,sourcename,0)==LOCK_SAME) break;
829 retry_move:
830 if ((exist=CheckExist(destname,NULL))) {
831 if (askeach) {
832 if ((a=checkexistreplace(sourcename,destname,&file->date,(function==FUNC_MOVE),1))==REPLACE_ABORT) {
833 myabort();
834 break;
836 if (a==REPLACE_SKIP) break;
837 if (a==REPLACE_ALL) {
838 if (function==FUNC_MOVEAS) goto functionloop; // TRY AGAIN
839 askeach=0; // ALL
841 if (a==REPLACE_SKIPALL) {
842 askeach = 0;
843 autoskip = 1;
845 else if (a==REPLACE_RENAME) {
846 StrCombine(newiconname,destname,".info",256);
847 goto retry_move;
850 if (autoskip) break;
851 if ((a=delfile(destname,namebuf,globstring[STR_MOVING],1,1))==-1) {
852 myabort();
853 break;
855 if (!a) {
856 doerror(ERROR_OBJECT_EXISTS);
857 break;
859 if (a && (tempfile=findfile(dwindow,namebuf,NULL)))
860 removefile(tempfile,dwindow,inact,0);
862 if (!(Rename(sourcename,destname))) {
863 if ((exist<0 || file->type<=ENTRY_FILE) &&
864 (a=IoErr())!=ERROR_RENAME_ACROSS_DEVICES) {
865 doerror(a);
866 if ((a=checkerror(globstring[STR_MOVING],file->name,a))==3) {
867 myabort();
868 break;
870 if (a==1) goto functionloop;
872 else {
873 if (file->type>=ENTRY_DIRECTORY) {
874 a=recursedir(sourcename,destname,R_COPY|R_DELETE,0);
875 D(bug("recursedir returned %ld\n",a));
876 if (a==0) {
877 if (!func_external_file[0])
878 setdirsize(file,dos_global_bytecount-dos_global_deletedbytes,act);
880 else if (status_justabort || a<0) {
881 if (a!=-10) {
882 if ((a=checkerror(globstring[STR_MOVING],file->name,IoErr()))==3)
883 a=-10;
884 else if (a==1) goto functionloop;
886 if (!func_external_file[0]) {
887 setdirsize(file,file->size-dos_global_deletedbytes,act);
888 refreshwindow(act,0);
890 if (CheckExist(destname,NULL)) {
891 if (exist) {
892 if ((tempfile=findfile(dwindow,namebuf,NULL)))
893 removefile(tempfile,dwindow,inact,0);
895 addfile(dwindow,inact,namebuf,dos_global_copiedbytes,
896 file->type,&file->date,file->comment,
897 file->protection,file->subtype,1,NULL,NULL,
898 file->owner_id,file->group_id);
900 if (a==-10) myabort();
901 else status_justabort=0;
902 break;
904 if (!(tempfile=findfile(dwindow,namebuf,NULL))) {
905 addfile(dwindow,inact,namebuf,exist?-1:dos_global_copiedbytes,file->type,
906 &file->date,file->comment,file->protection,
907 file->subtype,1,NULL,NULL,file->owner_id,file->group_id);
909 else {
910 setdirsize(tempfile,exist?-1:dos_global_copiedbytes,act);
911 refreshwindow(inact,0);
913 if ((a=delfile(sourcename,file->name,globstring[STR_DELETING],1,1))==-1) {
914 myabort();
915 break;
917 if (a==1) {
918 if (!noremove) removefile(file,swindow,act,1);
919 file=NULL;
921 okayflag=1;
923 else {
924 if (!(a=copyfile(sourcename,destname,&err,/*-1,*/NULL,0))) {
925 doerror(err);
926 if ((a=checkerror(globstring[STR_MOVING],file->name,err))==3) {
927 myabort();
928 break;
930 if (a==1) goto functionloop;
932 else if (a==-1) {
933 myabort();
934 break;
936 else if (lockandexamine(destname,&fileinfo)) {
937 addfile(dwindow,inact,
938 fileinfo.fib_FileName,
939 fileinfo.fib_Size,
940 fileinfo.fib_DirEntryType,
941 &fileinfo.fib_Date,
942 fileinfo.fib_Comment,
943 fileinfo.fib_Protection,
944 file->subtype,1,NULL,NULL,
945 fileinfo.fib_OwnerUID,fileinfo.fib_OwnerGID);
946 if ((a=delfile(sourcename,file->name,globstring[STR_DELETING],1,1))==-2) {
947 if (!(a=recursedir(sourcename,NULL,R_DELETE,0))) a=1;
948 else if (a==-10) {
949 myabort();
950 break;
953 if (a==-1) {
954 myabort();
955 break;
957 if (a) {
958 if (!noremove) removefile(file,swindow,act,1);
959 file=NULL;
961 else oldiconname[0]=0;
962 okayflag=1;
965 show=act;
966 seename(inact);
969 else {
970 if (progress_copy) dotaskmsg(hotkeymsg_port,PROGRESS_UPDATE,100,100,file->name,1);
971 addfile(dwindow,inact,namebuf,file->size,file->type,&file->date,
972 file->comment,file->protection,file->subtype,1,NULL,NULL,
973 file->owner_id,file->group_id);
974 if (!noremove) removefile(file,swindow,act,1);
975 file=NULL;
976 okayflag=1;
978 break;
980 // case FUNC_CLONE: //function = FUNC_COPYAS;
981 case FUNC_COPYAS: /* If flag is set then won't ask for new name */
982 if (!lastfile && !flag) {
983 if (rexx && rexx_argcount>1) strcpy(namebuf,rexx_args[1]);
984 else {
985 if (!(a=whatsit((specflags&FUNCFLAGS_COPYISCLONE)?globstring[STR_ENTER_NEW_NAME_CLONE]:globstring[STR_ENTER_NEW_NAME],FILEBUF_SIZE-2,namebuf,
986 globstring[STR_SKIP]))) {
987 myabort();
988 break;
990 if (a==2) {
991 okayflag=1;
992 file=NULL;
993 oldiconname[0]=0;
994 break;
996 if ((Stricmp(sourcedir,destdir)==0) && (Stricmp(namebuf,file->name)==0)) {
997 okayflag=1; oldiconname[0]=0;
998 break;
1001 /* if (doicons && oldiconname[0]) namebuf[FILEBUF_SIZE-7]=0;
1002 else namebuf[FILEBUF_SIZE-2]=0; */ namebuf[FILEBUF_SIZE-1]=0;
1004 case FUNC_COPY:
1005 if (lastfile) strcpy(destname,newiconname);
1006 else {
1007 StrCombine(destname,destdir,namebuf,256);
1008 StrCombine(newiconname,destname,".info",256);
1010 arcfile = getsourcefromarc(swindow,sourcename,file->name);
1011 if (checksame(destdir,sourcename,0)==LOCK_SAME) break;
1012 retry_copy:
1013 if ((exist=CheckExist(destname,NULL))) {
1014 D(bug("askeach = %ld\n",askeach));
1015 if (askeach) {
1016 if ((a=checkexistreplace(sourcename,destname,&file->date,
1017 (function==FUNC_COPY),1))==REPLACE_ABORT) {
1018 myabort();
1019 break;
1021 if (a==REPLACE_SKIP) break;
1022 else if (a==REPLACE_ALL) {
1023 if (function!=FUNC_COPY/*==FUNC_COPYAS*/) goto functionloop; // TRY AGAIN
1024 askeach=0; // ALL
1026 else if (a==REPLACE_SKIPALL) {
1027 askeach = 0;
1028 autoskip = 1;
1030 else if (a==REPLACE_RENAME) {
1031 StrCombine(newiconname,destname,".info",256);
1032 goto retry_copy;
1035 if (autoskip) break;
1037 if (exist<0) {
1038 if ((a=delfile(destname,file->name,globstring[STR_COPYING],1,1))==-1) {
1039 myabort();
1040 break;
1042 if (!a) {
1043 doerror(ERROR_OBJECT_EXISTS);
1044 break;
1046 if (a==1 && (tempfile=findfile(dwindow,namebuf,NULL))) {
1047 if (!noremove) removefile(tempfile,dwindow,inact,(tempfile->type!=file->type));
1048 exist=0;
1051 if (file->type>=ENTRY_DIRECTORY) {
1052 a=recursedir(sourcename,destname,R_COPY,0);
1053 if (exist) {
1054 byte=-1;
1055 exist=0;
1057 else byte=dos_global_copiedbytes;
1058 if (config->copyflags&COPY_DATE) setdate(destname,&file->date);
1060 if (!a && !func_external_file[0]) {
1061 setdirsize(file,dos_global_bytecount,act);
1062 refreshwindow(act,0);
1063 filloutcopydata(file);
1065 else if (a==-1 || a==-10) {
1066 if (a==-1) {
1067 if ((a=checkerror(globstring[STR_COPYING],file->name,IoErr()))==1)
1068 goto functionloop;
1069 if (a==3) a=-10;
1071 if (CheckExist(destname,NULL)) {
1072 if (exist && (tempfile=findfile(dwindow,namebuf,NULL)))
1073 removefile(tempfile,dwindow,inact,0);
1074 addfile(dwindow,inact,namebuf,byte,file->type,&file->date,
1075 file->comment,file->protection,file->subtype,1,NULL,NULL,
1076 file->owner_id,file->group_id);
1078 if (a==-10) myabort();
1079 show=inact;
1080 break;
1082 else if (a<0) break;
1084 else {
1085 D(bug("FUNC_COPY: src=\"%s\", dst=\"%s\"\n",sourcename,destname));
1086 a=copyfile(sourcename,destname,&err,/*-1,*/NULL,0);
1087 D(bug("FUNC_COPY: a=%ld,err=%ld\n",a,err));
1088 if (a==0) {
1089 doerror(err);
1090 if ((a=checkerror(globstring[STR_COPYING],file->name,err))==3) {
1091 myabort();
1092 break;
1094 if (a==1) goto functionloop;
1095 break;
1097 else if (a==-1) {
1098 myabort();
1099 break;
1101 byte=file->size;
1103 if (exist && (tempfile=findfile(dwindow,namebuf,NULL)))
1104 removefile(tempfile,dwindow,inact,0);
1105 if (lockandexamine(destname,&fileinfo)) {
1106 if (fileinfo.fib_DirEntryType<0) byte=fileinfo.fib_Size;
1107 addfile(dwindow,inact,
1108 fileinfo.fib_FileName,
1109 byte,
1110 fileinfo.fib_DirEntryType,
1111 &fileinfo.fib_Date,
1112 fileinfo.fib_Comment,
1113 fileinfo.fib_Protection,
1114 file->subtype,1,NULL,NULL,
1115 fileinfo.fib_OwnerUID,fileinfo.fib_OwnerGID);
1116 if (config->copyflags&COPY_ARC && !(file->protection&FIBF_ARCHIVE)) {
1117 if (SetProtection(sourcename,file->protection|FIBF_ARCHIVE)) {
1118 file->protection|=FIBF_ARCHIVE;
1119 getprot(file->protection,file->protbuf);
1123 okayflag=1;
1124 show=inact;
1125 break;
1127 case FUNC_HUNT:
1128 if (file->type<=ENTRY_FILE) {
1129 okayflag=1;
1130 break;
1132 if ((a=recursedir(sourcename,NULL,R_HUNT,0))==-3) {
1133 wildselect(buf2,2,0,WILDSELECT_NAME);
1134 findfirstsel(act,-2);
1135 okayflag=breakout=noshow=1; count=-1;
1136 break;
1138 if (a>-1) {
1139 okayflag=1;
1140 if (a==0 && !func_external_file[0]) setdirsize(file,dos_global_bytecount,act);
1141 if (a>0) count+=a;
1143 else count=-1;
1144 break;
1146 case FUNC_READ:
1147 case FUNC_HEXREAD:
1148 case FUNC_ANSIREAD:
1149 case FUNC_SMARTREAD:
1150 if (file->type>=ENTRY_DEVICE) {
1151 okayflag=1;
1152 break;
1154 arcfile = getsourcefromarc(swindow,sourcename,file->name);
1155 a = viewfile(sourcename,str_arcorgname[0]?str_arcorgname:file->name,function,NULL,
1156 viewdata,(viewdata || str_arcorgname[0])?1:0,(entry_depth>1));
1157 D(bug("viewfile() returned %ld\n",a));
1158 if (a!=-2) {
1159 if (a!=-3) ++count;
1160 else if (count==0) unselect(act,file);
1161 if (file->selected) {
1162 file->selected=0;
1163 if (swindow) {
1164 --swindow->filesel; swindow->bytessel-=file->size;
1167 SetBusyPointer(Window);
1168 if (a==-1) status_justabort=1;
1169 else okayflag=1;
1171 else {
1172 if (!count && !(doerror(-1))) okayflag=1;
1174 break;
1176 case FUNC_SHOW:
1177 if (file->type>=ENTRY_DEVICE || file->size<1) {
1178 okayflag=1;
1179 file=NULL;
1180 break;
1182 arcfile = getsourcefromarc(swindow,sourcename,file->name);
1183 if (entry_depth<2 &&
1184 checkfiletypefunc(sourcename,FTFUNC_SHOW)) okayflag=1;
1185 else {
1186 if (data==0) {
1187 if (swindow && swindow->filesel>1 && config->viewbits&VIEWBITS_SHOWBLACK) {
1188 if ((blankscreen=OpenScreen((struct NewScreen *)&blank_scr)))
1189 SetRGB4(&blankscreen->ViewPort,0,0,0,0);
1190 setnullpointer(Window);
1191 pt=0;
1193 data=1;
1195 if ((a=showpic(sourcename,pt))==-1) {
1196 okayflag=1;
1197 myabort();
1198 break;
1200 else {
1201 if (a==1) okayflag=1;
1202 else file=NULL;
1205 break;
1207 case FUNC_ICONINFO:
1208 arcfile = getsourcefromarc(swindow,sourcename,file->name);
1209 if (Stricmp(file->name,".info")==0) okayflag=1;
1210 else {
1211 if ((ptr=isicon(sourcename))) *ptr=0;
1212 switch ((a=dopus_iconinfo(sourcename))) {
1213 case -1:
1214 myabort();
1215 file=NULL;
1216 break;
1217 case -2:
1218 dostatustext(globstring[STR_CANT_FIND_ICON]);
1219 file=NULL;
1220 break;
1221 case -3:
1222 dostatustext(globstring[STR_NO_CHIP_FOR_ICON]);
1223 file=NULL;
1224 break;
1225 case -4:
1226 file=NULL;
1227 status_justabort=1;
1228 break;
1229 case 1:
1230 if (act>-1) {
1231 StrCombine(buf,sourcename,".info",256);
1232 if (isicon(file->name)) {
1233 reload_file(act,sourcename);
1234 file=reload_file(act,buf);
1236 else {
1237 file=reload_file(act,sourcename);
1238 reload_file(act,buf);
1241 default:
1242 okayflag=1;
1243 show=act;
1244 break;
1246 if (ptr) *ptr='.';
1248 break;
1250 case FUNC_PLAYST:
1251 a=1;
1252 case FUNC_PLAY:
1253 case FUNC_LOOPPLAY:
1254 if (file->type>=ENTRY_DEVICE || file->size<1) {
1255 okayflag=1;
1256 file=NULL;
1257 break;
1259 arcfile = getsourcefromarc(swindow,sourcename,file->name);
1260 if (entry_depth<2 &&
1261 checkfiletypefunc(sourcename,(function==FUNC_PLAY)?FTFUNC_PLAY:FTFUNC_LOOPPLAY))
1262 okayflag=1;
1263 #ifndef __AROS__
1264 else if (a || check_is_module(sourcename)) {
1265 if ((a=playmod(sourcename)) && swindow && swindow->filesel>1) {
1266 a=-1;
1267 FOREVER {
1268 Wait(1<<Window->UserPort->mp_SigBit);
1269 while (getintuimsg()) {
1270 class=IMsg->Class; code=IMsg->Code;
1271 ReplyMsg((struct Message *)IMsg);
1272 if (class==MOUSEBUTTONS) {
1273 a=(code==SELECTDOWN);
1274 break;
1277 if (a!=-1) break;
1279 FlushModule();
1280 if (!a) myabort();
1281 else okayflag=1;
1283 else if (a) okayflag=1;
1284 else file=NULL;
1286 #endif
1287 else {
1288 a=doplay8svx(sourcename,(function==FUNC_LOOPPLAY));
1289 kill8svx();
1290 if (a==-1) {
1291 myabort();
1292 break;
1294 else {
1295 if (a==1) okayflag=1;
1296 else {
1297 handle8svxerror(a);
1298 file=NULL;
1302 break;
1304 case FUNC_ADDICON:
1305 if (strlen(file->name)>(FILEBUF_SIZE-6) || isicon(file->name)) {
1306 okayflag=1;
1307 file=NULL;
1308 break;
1310 StrCombine(buf2,file->name,".info",FILEBUF_SIZE-1);
1311 StrCombine(destname,sourcename,".info",256);
1312 if ((a=CheckExist(sourcename,NULL))==0) {
1313 doerror((a=IoErr()));
1314 if ((a=checkerror(globstring[STR_ADDING_ICON],file->name,a))==1)
1315 goto functionloop;
1316 if (a==3) {
1317 myabort();
1318 break;
1320 file=NULL;
1321 break;
1323 if (a>0) data=ICONTYPE_DRAWER;
1324 else if (checkexec(sourcename)) data=ICONTYPE_TOOL;
1325 else data=ICONTYPE_PROJECT;
1326 if (CheckExist(destname,NULL)) {
1327 if (askeach) {
1328 doerror(ERROR_OBJECT_EXISTS);
1329 if ((a=checkexistreplace(destname,destname,NULL,1,1))==REPLACE_ABORT) {
1330 myabort();
1331 break;
1333 else if (a==REPLACE_ALL) askeach=0;
1334 else if (a==REPLACE_SKIP) {
1335 file=NULL;
1336 break;
1338 else if (a==REPLACE_SKIPALL) {
1339 askeach = 0;
1340 autoskip = 1;
1341 file = NULL;
1343 else if (a==REPLACE_RENAME) {
1344 strcpy(buf2,BaseName(destname));
1347 if (autoskip) break;
1349 if ((iconwrite(data,destname))!=-1) {
1350 if (lockandexamine(destname,&fileinfo)) {
1351 addfile(swindow,act,buf2,fileinfo.fib_Size,-1,&fileinfo.fib_Date,
1352 fileinfo.fib_Comment,fileinfo.fib_Protection,0,1,NULL,NULL,
1353 fileinfo.fib_OwnerUID,fileinfo.fib_OwnerGID);
1354 show=act;
1355 okayflag=1;
1358 else {
1359 myabort();
1360 break;
1362 break;
1364 case FUNC_COMMENT:
1365 if (askeach) {
1366 if (rexx && rexx_argcount>0) strcpy(buf2,rexx_args[rexarg]);
1367 else {
1368 if (file->comment) strcpy(buf2,file->comment);
1369 else buf2[0]=0;
1370 if (!(a=whatsit(globstring[STR_ENTER_COMMENT],79,buf2,
1371 globstring[STR_ALL]))) {
1372 myabort();
1373 break;
1375 if (a==2) askeach=0;
1378 FOREVER {
1379 if (SetComment(sourcename,buf2)) break;
1380 doerror((a=IoErr()));
1381 if ((a=checkerror(globstring[STR_COMMENTING],file->name,a))==3) {
1382 myabort();
1383 break;
1385 if (a!=1) {
1386 file=NULL;
1387 break;
1390 if (status_justabort || !file) break;
1391 okayflag=1;
1392 if (file->type>=ENTRY_DIRECTORY) {
1393 if ((a=recursedir(sourcename,buf2,R_COMMENT,0))>0 && status_justabort)
1394 status_justabort=okayflag=0;
1395 else if (!a && !func_external_file[0]) setdirsize(file,dos_global_bytecount,act);
1397 if (!noremove && file->comment!=dos_copy_comment) {
1398 if (act>-1 && config->sortmethod[act]==DISPLAY_COMMENT) {
1399 CopyMem((char *)file,(char *)&filebuf,sizeof(struct Directory));
1400 removefile(file,swindow,act,0); file=NULL;
1401 addfile(swindow,act,namebuf,filebuf.size,filebuf.type,&filebuf.date,
1402 buf2,filebuf.protection,filebuf.subtype,1,NULL,NULL,
1403 filebuf.owner_id,filebuf.group_id);
1405 else {
1406 if (file->comment)
1407 LibFreePooled(dir_memory_pool,file->comment,strlen(file->comment)+1);
1408 if ((file->comment=LibAllocPooled(dir_memory_pool,strlen(buf2)+1)))
1409 strcpy(file->comment,buf2);
1412 break;
1414 case FUNC_PROTECT:
1415 if (askeach && !lastfile) {
1416 if (rexx) {
1417 data=rexx_arg_value[0];
1418 mask=rexx_arg_value[1];
1420 else {
1421 data=file->protection;
1422 if (!(a=getprotectdata(&data,&mask))) {
1423 myabort();
1424 break;
1426 if (a==2) askeach=0;
1429 temp=getnewprot(file->protection,data,mask);
1430 FOREVER {
1431 if (SetProtection(sourcename,temp)) break;
1432 doerror((a=IoErr()));
1433 if ((a=checkerror(globstring[STR_PROTECTING],file->name,a))==3) {
1434 myabort();
1435 break;
1437 if (a!=1) {
1438 file=NULL;
1439 break;
1442 if (status_justabort || !file) break;
1443 file->protection=temp;
1444 getprot(temp,file->protbuf);
1445 if (file->type>=ENTRY_DIRECTORY) {
1446 protstuff[0]=data; protstuff[1]=mask;
1447 if ((a=recursedir(sourcename,NULL,R_PROTECT,(int)protstuff)) &&
1448 status_justabort) break;
1449 if (!a && !func_external_file[0]) setdirsize(file,dos_global_bytecount,act);
1451 if (!file->selected) refreshwindow(act,0);
1452 okayflag=1;
1453 break;
1455 case FUNC_ENCRYPT:
1456 if (file->type>=ENTRY_DEVICE || file->size<1) {
1457 okayflag=1;
1458 file=NULL;
1459 break;
1461 StrCombine(destname,destdir,file->name,256);
1462 if (CheckExist(destname,NULL)) {
1463 if (askeach) {
1464 if ((a=checkexistreplace(sourcename,destname,&file->date,1,1))==REPLACE_ABORT) {
1465 myabort();
1466 break;
1468 else if (a==REPLACE_ALL) askeach=0;
1469 else if (a==REPLACE_SKIP) {
1470 file=NULL;
1471 break;
1473 else if (a==REPLACE_SKIPALL) {
1474 askeach = 0;
1475 autoskip = 1;
1476 file = NULL;
1479 else if (a==REPLACE_RENAME) {
1483 if (autoskip) break;
1484 if ((a=delfile(destname,file->name,globstring[STR_DATESTAMPING],1,1))==-1) {
1485 myabort();
1486 break;
1489 if (!CheckExist(destname,NULL)) {
1490 FOREVER {
1491 if (copyfile(sourcename,destname,&err,/*-1,*/buf2,data)) {
1492 addfile(dwindow,inact,file->name,file->size,file->type,&file->date,
1493 file->comment,file->protection,file->subtype,1,NULL,NULL,
1494 file->owner_id,file->group_id);
1495 okayflag=1; show=inact;
1496 break;
1498 doerror(err);
1499 if ((a=checkerror(globstring[STR_ENCRYPTING],file->name,err))==3) {
1500 myabort();
1501 break;
1503 if (a!=1) {
1504 file=NULL;
1505 break;
1509 else doerror(ERROR_OBJECT_EXISTS);
1510 break;
1512 case FUNC_DATESTAMP:
1513 if (askeach && !lastfile) {
1514 if (rexx && rexx_argcount>0) strcpy(buf2,rexx_args[rexarg]);
1515 else {
1516 seedate(&(file->date),buf2,0); // buf2[0]=0;
1517 if (!(a=whatsit(globstring[STR_ENTER_DATE_AND_TIME],20,buf2,
1518 globstring[STR_ALL]))) {
1519 myabort();
1520 break;
1522 if (a==2) askeach=0;
1524 if (buf2[0]) {
1525 parsedatetime(buf2,buf,buf1,&a);
1526 strtostamp(buf,buf1,&datetime.dat_Stamp);
1528 else DateStamp(&datetime.dat_Stamp);
1530 FOREVER {
1531 if ((a=setdate(sourcename,&datetime.dat_Stamp))==1) {
1532 if (!noremove) {
1533 if (act>-1 && config->sortmethod[act]==DISPLAY_DATE) {
1534 CopyMem((char *)file,(char *)&filebuf,sizeof(struct Directory));
1535 if (file->comment) {
1536 strcpy(buf2,file->comment);
1537 filebuf.comment=buf2;
1539 removefile(file,swindow,act,0);
1540 file=(struct Directory *)addfile(swindow,act,filebuf.name,filebuf.size,
1541 filebuf.type,&datetime.dat_Stamp,filebuf.comment,filebuf.protection,
1542 filebuf.subtype,1,NULL,NULL,filebuf.owner_id,filebuf.group_id);
1544 else {
1545 file->date.ds_Days=datetime.dat_Stamp.ds_Days;
1546 file->date.ds_Minute=datetime.dat_Stamp.ds_Minute;
1547 file->date.ds_Tick=datetime.dat_Stamp.ds_Tick;
1548 seedate(&file->date,file->datebuf,1);
1551 break;
1553 doerror(a);
1554 if ((a=checkerror(globstring[STR_DATESTAMPING],file->name,a))==3) {
1555 myabort();
1556 break;
1558 if (a!=1) {
1559 file=NULL;
1560 break;
1563 if (status_justabort || !file) break;
1564 if (file->type>=ENTRY_DIRECTORY) {
1565 if (!(recursedir(sourcename,NULL,R_DATESTAMP,(int)&datetime.dat_Stamp))) {
1566 okayflag=1;
1567 if (!func_external_file[0]) setdirsize(file,dos_global_bytecount,act);
1570 else okayflag=1;
1571 break;
1573 case FUNC_SEARCH:
1574 if (file->type==ENTRY_DEVICE) {
1575 if ((a=recursedir(file->name,NULL,R_SEARCH,0))==-2) {
1576 okayflag=1;
1577 count=-1; nextfile=NULL;
1578 break;
1580 if (a==-1) {
1581 nextfile=NULL;
1582 break;
1584 if (a==-10) {
1585 myabort();
1586 break;
1588 if (a>0) count+=a;
1589 okayflag=1;
1591 else {
1592 if (file->type<=ENTRY_FILE) {
1593 arcfile = getsourcefromarc(swindow,sourcename,file->name);
1594 a=filesearch(sourcename,&b,(askeach)?1:-1);
1595 count+=b;
1596 if (a==2) {
1597 okayflag=1; file=NULL;
1598 busy();
1599 if (act>-1) {
1600 if (swindow) {
1601 if (count>0) b=(swindow->filesel-count)+swindow->dirsel;
1602 else b=swindow->filesel+swindow->dirsel;
1603 if (!b) nextfile=NULL;
1606 if (nextfile && !simplerequest(globstring[STR_CONTINUE_WITH_SEARCH],
1607 globstring[STR_CONTINUE],str_cancelstring,NULL))
1608 nextfile=NULL;
1610 if (a==-1) {
1611 myabort();
1612 break;
1614 if (a) {
1615 okayflag=1;
1616 if (a==3) file=NULL;
1617 else if (a==4) {
1618 file=NULL;
1619 askeach=0;
1622 else doerror(-1);
1624 else {
1625 if (!(a=recursedir(sourcename,NULL,R_SEARCH,0))) {
1626 if (!func_external_file[0]) setdirsize(file,dos_global_bytecount,act);
1627 okayflag=1;
1629 if (a==-2) {
1630 okayflag=1; breakout=2;
1631 count=-1; nextfile=NULL;
1632 break;
1634 if (a==-1 || a==-10) {
1635 if (a==-10) {
1636 myabort();
1637 file=NULL;
1639 else nextfile=NULL;
1640 break;
1642 if (a>0) count+=a;
1645 break;
1647 if (arcfile) removetemparcfile(sourcename);
1649 if (config->dynamicflags&UPDATE_FREE && show>-1) seename(show);
1650 if (breakout==1) break;
1651 if (file && okayflag) {
1652 if (file->selected) unselect(act,file);
1653 else refreshwindow(act,0);
1655 if (status_justabort || breakout==2) break;
1657 if (doicons && !lastfile && okayflag && oldiconname[0]) {
1658 if ((file=findfile(swindow,oldiconname,NULL))) {
1659 if (file==nextfile) nextfile=file->next;
1660 lastfile=1;
1661 if (file->selected && prog_indicator) {
1662 if (progtype==0 || progtype==2) {
1663 ++value;
1664 // dotaskmsg(hotkeymsg_port,PROGRESS_UPDATE,value,total,NULL,0);
1665 dotaskmsg(hotkeymsg_port,PROGRESS_INCREASE,1,0,NULL,0);
1668 if (progress_copy) dotaskmsg(hotkeymsg_port,PROGRESS_UPDATE,-2,0,file->name,1);
1669 goto functionloop;
1671 else {
1672 StrCombine(sourcename,sourcedir,oldiconname,256);
1673 if (filloutdummy(sourcename,&dummyfile)) {
1674 dummyfile.selected=0;
1675 file=&dummyfile;
1676 lastfile=1;
1677 goto functionloop;
1682 if (globflag) break;
1683 if (!lastfile && file && file->next && file->next!=nextfile) file=file->next;
1684 else file=nextfile;
1685 namebuf[0]=0;
1688 if (prog_indicator) {
1689 dotaskmsg(hotkeymsg_port,PROGRESS_UPDATE,-1,status_justabort,NULL,0);
1690 if (progress_copy) dotaskmsg(hotkeymsg_port,PROGRESS_UPDATE,-1,status_justabort,NULL,1);
1693 switch (function) {
1694 case FUNC_HUNT:
1695 if (count==0) {
1696 okayflag=0;
1697 doerror(ERROR_OBJECT_NOT_FOUND);
1698 simplerequest(globstring[STR_COULD_NOT_FIND_FILE],globstring[STR_CONTINUE],NULL);
1700 else if (count>0) {
1701 lsprintf(buf2,globstring[STR_FOUND_MATCHING_FILES],count);
1702 dostatustext(buf2);
1703 simplerequest(buf2,globstring[STR_CONTINUE],NULL);
1705 break;
1707 case FUNC_READ:
1708 case FUNC_HEXREAD:
1709 case FUNC_ANSIREAD:
1710 case FUNC_SMARTREAD:
1711 if (act>-1) refreshwindow(act,0);
1712 if (viewdata) cleanupviewfile(viewdata);
1713 if (status_justabort) myabort();
1714 else if (!okayflag && !(doerror(-1))) okayflag=1;
1715 break;
1717 case FUNC_SHOW:
1718 if (config->viewbits&VIEWBITS_SHOWBLACK) {
1719 if (blankscreen) {
1720 CloseScreen(blankscreen);
1721 blankscreen=NULL;
1723 ClearPointer(Window);
1725 break;
1726 #ifdef _USE_SMALL_Q
1727 case FUNC_COMMENT:
1728 if (status_flags&STATUS_IANSCRAP && okayflag) {
1729 dostatustext(buf2);
1730 okayflag=0;
1732 break;
1734 case FUNC_PROTECT:
1735 if (status_flags&STATUS_IANSCRAP && okayflag) {
1736 getprot(data,buf2);
1737 dostatustext(buf2);
1738 okayflag=0;
1740 break;
1742 case FUNC_DATESTAMP:
1743 if (status_flags&STATUS_IANSCRAP && okayflag) {
1744 seedate(&datetime.dat_Stamp,buf2,0);
1745 dostatustext(buf2);
1746 okayflag=0;
1748 break;
1749 #endif
1750 case FUNC_SEARCH:
1751 if (count>-1) {
1752 if (count==0) simplerequest(globstring[STR_STRING_NOT_FOUND],
1753 globstring[STR_CONTINUE],NULL);
1754 else {
1755 lsprintf(buf2,globstring[STR_MATCHED_FILES],count);
1756 simplerequest(buf2,globstring[STR_CONTINUE],NULL);
1758 okayflag=1;
1760 break;
1762 case FUNC_BYTE:
1763 if (!status_justabort) {
1764 long long value;
1766 main_proc->pr_WindowPtr=(APTR)-1;
1767 if (!(destdir && (filelock=Lock(destdir,ACCESS_READ)))) value=0;
1768 else {
1769 Info(filelock,&infodata);
1770 if (ramdisk_lock && CompareLock(filelock,ramdisk_lock)!=LOCK_DIFFERENT)
1771 value=AvailMem(0);
1772 else value=(infodata.id_NumBlocks-infodata.id_NumBlocksUsed)*(long long)blocksize;
1773 UnLock(filelock);
1775 if (config->errorflags&ERROR_ENABLE_DOS) main_proc->pr_WindowPtr=(APTR)Window;
1776 if (specflags&FUNCFLAGS_BYTEISCHECKFIT) {
1777 double needed,percent;
1779 needed=data*blocksize;
1780 if (value<1) percent=0;
1781 else if (value>=needed || needed<1) {
1782 percent=100;
1783 retval=1;
1785 else percent=100/(needed/value);
1786 sprintf(buf,globstring[STR_CHECKFIT_STRING],data*(long long)blocksize,value,percent);
1787 dostatustext(buf);
1789 else {
1790 doselinfo(act);
1791 strcat(str_select_info,
1792 (value<=swindow->bytessel)?
1793 globstring[STR_NO_FIT]:globstring[STR_YES_FIT]);
1794 dostatustext(str_select_info);
1796 okayflag=0;
1798 break;
1801 if (okayflag && !status_justabort) okay();
1802 if (!noshow) {
1803 endfollow(act);
1804 displaydir(act); seename(act);
1806 if (inact>-1) {
1807 displaydir(inact);
1808 seename(inact);
1810 switch (function) {
1811 case FUNC_MOVEAS: if (checksame(sourcedir,destdir,2)==LOCK_SAME) break;
1812 case FUNC_DELETE:
1813 case FUNC_RENAME:
1814 case FUNC_MOVE:
1815 case FUNC_ADDICON:
1816 case FUNC_ICONINFO:
1817 update_buffer_stamp(act,1);
1818 break;
1819 case FUNC_COPYAS:
1820 if (specflags&FUNCFLAGS_COPYISCLONE) update_buffer_stamp(act,1);
1821 break;
1823 case FUNC_COMMENT:
1824 case FUNC_PROTECT:
1825 case FUNC_DATESTAMP:
1826 update_buffer_stamp(act,0);
1827 break;
1830 switch (function) {
1831 case FUNC_MOVEAS:
1832 case FUNC_COPYAS:
1833 if (checksame(sourcedir,destdir,2)==LOCK_SAME) break;
1834 case FUNC_MOVE:
1835 case FUNC_COPY:
1836 case FUNC_ENCRYPT:
1837 update_buffer_stamp(inact,1);
1838 break;
1841 switch (function) {
1842 case FUNC_SEARCH:
1843 if (count>0) rexx_return_value=count;
1844 break;
1847 startnotifies();
1849 endfunction:
1850 if (prog_indicator) dotaskmsg(hotkeymsg_port,PROGRESS_CLOSE,0,0,NULL,0);
1851 LFreeRemember(&funckey);
1852 --entry_depth;
1853 return(retval);