Lots of compiler warnings removed.
[AROS-Contrib.git] / dopus / Program / main22.c
blob15114063cf9fe3fe7ea53e968d61711941007407
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); file=NULL;
586 okayflag=1;
589 if (DeleteFile(sourcename)) {
590 if (!noremove) removefile(file,swindow,act,1); file=NULL;
591 okayflag=1;
594 else if (a<0) {
595 if ((a=IoErr())==ERROR_DELETE_PROTECTED &&
596 config->deleteflags&DELETE_SET) {
597 if (!flag) {
598 flag=1;
599 SetProtection(sourcename,0);
600 goto functionloop;
603 else if (a==ERROR_OBJECT_NOT_FOUND) {
604 if (!noremove) removefile(file,swindow,act,1);
605 file=NULL;
606 okayflag=1;
608 else if (a==ERROR_DIRECTORY_NOT_EMPTY) {
609 if (config->deleteflags&DELETE_DIRS && askeach) {
610 lsprintf(buf2,globstring[STR_NOT_EMPTY],file->name);
611 if (!(a=simplerequest(buf2,globstring[STR_DELETE],
612 globstring[STR_LEAVE],globstring[STR_ALL],globstring[STR_ABORT],NULL))) {
613 okayflag=1;
614 break;
616 if (a==2) askeach=0;
617 else if (a==3) {
618 myabort();
619 break;
622 TackOn(sourcename,NULL,256);
623 a=recursedir(sourcename,NULL,R_DELETE,0);
624 sourcename[strlen(sourcename)-1]=0;
625 if (!a) {
626 if ((a=delfile(sourcename,file->name,globstring[STR_DELETING],
627 glob_unprotect_all,1))==-1) {
628 myabort();
629 break;
631 else if (a==1 || a==2) {
632 if (a==2) glob_unprotect_all=1;
633 if (!noremove) removefile(file,swindow,act,1); file=NULL;
634 okayflag=1;
636 else {
637 setdirsize(file,dos_global_bytecount-dos_global_deletedbytes,act);
638 okayflag=1;
641 else {
642 setdirsize(file,file->size-dos_global_deletedbytes,act);
643 refreshwindow(act,0);
646 else {
647 doerror((a=IoErr()));
648 if ((a=checkerror(globstring[STR_DELETING],file->name,a))==3) {
649 myabort();
650 break;
652 if (a==1) goto functionloop;
655 show=act;
656 break;
658 if (file->type == ENTRY_DEVICE)
660 if ((!strcmp(file->comment,"<DEV>")) || (!strcmp(file->comment,"<VOL>"))) break;
662 if (config->deleteflags&DELETE_FILES && askeach && !lastfile) {
663 lsprintf(buf2,file->type==ENTRY_DEVICE?globstring[STR_QUERY_REMOVE_ASSIGN]:globstring[STR_WISH_TO_DELETE],file->name); // HUX
664 a=simplerequest(buf2,globstring[file->type==ENTRY_DEVICE?STR_REMOVE:STR_DELETE],globstring[STR_ABORT],
665 globstring[STR_ALL],globstring[STR_LEAVE],NULL);
666 if (a==3) {
667 okayflag=1;
668 break;
670 else if (a==2) askeach=0;
671 else if (a==0) {
672 myabort();
673 break;
676 if (file->type == ENTRY_DEVICE) /* remove assign */
678 char buf[FILEBUF_SIZE],*c;
680 strcpy(buf,file->name);
681 c = strchr(buf,':');
682 if (c) *c = 0;
683 a = AssignLock(buf,NULL)?1:0;
684 //D(bug("Removing assign %s\t%s\n",buf,a?"success":"failure"));
686 else if ((a=delfile(sourcename,file->name,globstring[STR_DELETING],
687 glob_unprotect_all,1))==-1) {
688 myabort();
689 break;
691 if (a) {
692 if (a==2) glob_unprotect_all=1;
693 if (!noremove) removefile(file,swindow,act,1); file=NULL;
694 show=act;
695 okayflag=1;
697 break;
699 case FUNC_RENAME:
700 if (firstset || lastfile) a=1;
701 else if (!destwild) {
702 if (!(a=whatsit(globstring[STR_ENTER_NEW_NAME],FILEBUF_SIZE-2,namebuf,
703 globstring[STR_SKIP]))) {
704 myabort();
705 break;
707 if (a==2) {
708 file=NULL;
709 okayflag=1;
710 oldiconname[0]=0;
711 break;
714 else if (!sourcewild) a=getwildrename("*",drename,file->name,namebuf);
715 else if (sourcewild) a=getwildrename(srename,drename,file->name,namebuf);
716 firstset=0;
717 if (a) {
718 if (lastfile) StrCombine(destname,sourcedir,newiconname,256);
719 else {
720 /* if (doicons && oldiconname[0]) namebuf[FILEBUF_SIZE-7]=0;
721 else namebuf[FILEBUF_SIZE-2]=0; */ namebuf[FILEBUF_SIZE-1]=0;
722 StrCombine(destname,sourcedir,namebuf,256);
723 StrCombine(newiconname,namebuf,".info",256);
725 retry_rename:
726 D(bug("Rename(%s,%s)\n",sourcename,destname));
727 if (!(Rename(sourcename,destname))) {
728 if ((a=IoErr())==ERROR_OBJECT_EXISTS) {
729 if (askeach) {
730 if (!lastfile) {
731 if ((a=checkexistreplace(sourcename,destname,&file->date,destwild,1))==REPLACE_ABORT)
733 myabort();
734 break;
736 if (a==REPLACE_ALL) {
737 if (!destwild) goto functionloop; // TRY AGAIN
738 askeach=0; // REPLACE ALL
740 else if (a==REPLACE_SKIP) {
741 break;
743 else if (a==REPLACE_SKIPALL) {
744 askeach = 0;
745 autoskip = 1;
747 else if (a==REPLACE_RENAME) goto retry_rename;
750 if (autoskip) break;
751 if ((a=delfile(destname,namebuf,globstring[STR_DELETING],1,1))==-2) {
752 if (!(a=recursedir(destname,NULL,R_DELETE,0))) a=1;
753 else if (a==-10) a=-1;
755 if (a==-1) {
756 myabort();
757 break;
759 if (a) {
760 if ((tempfile=findfile(swindow,namebuf,NULL))) {
761 if (tempfile==nextfile) nextfile=tempfile->next;
762 removefile(tempfile,swindow,act,1);
764 firstset=1;
765 goto functionloop;
768 doerror(a);
769 if ((a=checkerror(globstring[STR_RENAMING],file->name,a))==3) {
770 myabort();
771 break;
773 if (a==1) goto functionloop;
775 else {
776 if (file->type>=ENTRY_DIRECTORY) {
777 StrCombine(buf,sourcedir,file->name,256); TackOn(buf,NULL,256);
778 StrCombine(buf1,sourcedir,namebuf,256); TackOn(buf1,NULL,256);
779 renamebuffers(buf,buf1);
781 if (!noremove){
782 if (act>-1 && config->sortmethod[act]==DISPLAY_NAME) {
783 CopyMem((char *)file,(char *)&filebuf,sizeof(struct Directory));
784 if (file->comment) strcpy(buf2,file->comment);
785 else buf2[0]=0;
786 removefile(file,swindow,act,0); file=NULL;
787 addfile(swindow,act,namebuf,filebuf.size,filebuf.type,&filebuf.date,
788 buf2,filebuf.protection,filebuf.subtype,1,NULL,NULL,
789 filebuf.owner_id,filebuf.group_id);
791 else strcpy(file->name,namebuf);
792 if (lastfile) refreshwindow(act,0);
794 okayflag=1;
797 else okayflag=1;
798 break;
800 case FUNC_MOVEAS:
801 if (!lastfile && !flag) {
802 if (rexx && rexx_argcount>1) strcpy(namebuf,rexx_args[1]);
803 else {
804 if (!(a=whatsit(globstring[STR_ENTER_NEW_NAME_MOVE],FILEBUF_SIZE-2,
805 namebuf,globstring[STR_SKIP]))) {
806 myabort();
807 break;
809 if (a==2) {
810 file=NULL;
811 okayflag=1;
812 oldiconname[0]=0;
813 break;
816 /* if (doicons && oldiconname[0]) namebuf[FILEBUF_SIZE-7]=0;
817 else namebuf[FILEBUF_SIZE-2]=0; */ namebuf[FILEBUF_SIZE-1]=0;
819 case FUNC_MOVE:
820 if (lastfile) strcpy(destname,newiconname);
821 else {
822 StrCombine(destname,destdir,namebuf,256);
823 StrCombine(newiconname,destname,".info",256);
825 if (checksame(destdir,sourcename,0)==LOCK_SAME) break;
826 retry_move:
827 if ((exist=CheckExist(destname,NULL))) {
828 if (askeach) {
829 if ((a=checkexistreplace(sourcename,destname,&file->date,(function==FUNC_MOVE),1))==REPLACE_ABORT) {
830 myabort();
831 break;
833 if (a==REPLACE_SKIP) break;
834 if (a==REPLACE_ALL) {
835 if (function==FUNC_MOVEAS) goto functionloop; // TRY AGAIN
836 askeach=0; // ALL
838 if (a==REPLACE_SKIPALL) {
839 askeach = 0;
840 autoskip = 1;
842 else if (a==REPLACE_RENAME) {
843 StrCombine(newiconname,destname,".info",256);
844 goto retry_move;
847 if (autoskip) break;
848 if ((a=delfile(destname,namebuf,globstring[STR_MOVING],1,1))==-1) {
849 myabort();
850 break;
852 if (!a) {
853 doerror(ERROR_OBJECT_EXISTS);
854 break;
856 if (a && (tempfile=findfile(dwindow,namebuf,NULL)))
857 removefile(tempfile,dwindow,inact,0);
859 if (!(Rename(sourcename,destname))) {
860 if ((exist<0 || file->type<=ENTRY_FILE) &&
861 (a=IoErr())!=ERROR_RENAME_ACROSS_DEVICES) {
862 doerror(a);
863 if ((a=checkerror(globstring[STR_MOVING],file->name,a))==3) {
864 myabort();
865 break;
867 if (a==1) goto functionloop;
869 else {
870 if (file->type>=ENTRY_DIRECTORY) {
871 a=recursedir(sourcename,destname,R_COPY|R_DELETE,0);
872 D(bug("recursedir returned %ld\n",a));
873 if (a==0) {
874 if (!func_external_file[0])
875 setdirsize(file,dos_global_bytecount-dos_global_deletedbytes,act);
877 else if (status_justabort || a<0) {
878 if (a!=-10) {
879 if ((a=checkerror(globstring[STR_MOVING],file->name,IoErr()))==3)
880 a=-10;
881 else if (a==1) goto functionloop;
883 if (!func_external_file[0]) {
884 setdirsize(file,file->size-dos_global_deletedbytes,act);
885 refreshwindow(act,0);
887 if (CheckExist(destname,NULL)) {
888 if (exist) {
889 if ((tempfile=findfile(dwindow,namebuf,NULL)))
890 removefile(tempfile,dwindow,inact,0);
892 addfile(dwindow,inact,namebuf,dos_global_copiedbytes,
893 file->type,&file->date,file->comment,
894 file->protection,file->subtype,1,NULL,NULL,
895 file->owner_id,file->group_id);
897 if (a==-10) myabort();
898 else status_justabort=0;
899 break;
901 if (!(tempfile=findfile(dwindow,namebuf,NULL))) {
902 addfile(dwindow,inact,namebuf,exist?-1:dos_global_copiedbytes,file->type,
903 &file->date,file->comment,file->protection,
904 file->subtype,1,NULL,NULL,file->owner_id,file->group_id);
906 else {
907 setdirsize(tempfile,exist?-1:dos_global_copiedbytes,act);
908 refreshwindow(inact,0);
910 if ((a=delfile(sourcename,file->name,globstring[STR_DELETING],1,1))==-1) {
911 myabort();
912 break;
914 if (a==1) {
915 if (!noremove) removefile(file,swindow,act,1);
916 file=NULL;
918 okayflag=1;
920 else {
921 if (!(a=copyfile(sourcename,destname,&err,/*-1,*/NULL,0))) {
922 doerror(err);
923 if ((a=checkerror(globstring[STR_MOVING],file->name,err))==3) {
924 myabort();
925 break;
927 if (a==1) goto functionloop;
929 else if (a==-1) {
930 myabort();
931 break;
933 else if (lockandexamine(destname,&fileinfo)) {
934 addfile(dwindow,inact,
935 fileinfo.fib_FileName,
936 fileinfo.fib_Size,
937 fileinfo.fib_DirEntryType,
938 &fileinfo.fib_Date,
939 fileinfo.fib_Comment,
940 fileinfo.fib_Protection,
941 file->subtype,1,NULL,NULL,
942 fileinfo.fib_OwnerUID,fileinfo.fib_OwnerGID);
943 if ((a=delfile(sourcename,file->name,globstring[STR_DELETING],1,1))==-2) {
944 if (!(a=recursedir(sourcename,NULL,R_DELETE,0))) a=1;
945 else if (a==-10) {
946 myabort();
947 break;
950 if (a==-1) {
951 myabort();
952 break;
954 if (a) {
955 if (!noremove) removefile(file,swindow,act,1); file=NULL;
957 else oldiconname[0]=0;
958 okayflag=1;
961 show=act;
962 seename(inact);
965 else {
966 if (progress_copy) dotaskmsg(hotkeymsg_port,PROGRESS_UPDATE,100,100,file->name,1);
967 addfile(dwindow,inact,namebuf,file->size,file->type,&file->date,
968 file->comment,file->protection,file->subtype,1,NULL,NULL,
969 file->owner_id,file->group_id);
970 if (!noremove) removefile(file,swindow,act,1); file=NULL;
971 okayflag=1;
973 break;
975 // case FUNC_CLONE: //function = FUNC_COPYAS;
976 case FUNC_COPYAS: /* If flag is set then won't ask for new name */
977 if (!lastfile && !flag) {
978 if (rexx && rexx_argcount>1) strcpy(namebuf,rexx_args[1]);
979 else {
980 if (!(a=whatsit((specflags&FUNCFLAGS_COPYISCLONE)?globstring[STR_ENTER_NEW_NAME_CLONE]:globstring[STR_ENTER_NEW_NAME],FILEBUF_SIZE-2,namebuf,
981 globstring[STR_SKIP]))) {
982 myabort();
983 break;
985 if (a==2) {
986 okayflag=1;
987 file=NULL;
988 oldiconname[0]=0;
989 break;
991 if ((Stricmp(sourcedir,destdir)==0) && (Stricmp(namebuf,file->name)==0)) {
992 okayflag=1; oldiconname[0]=0;
993 break;
996 /* if (doicons && oldiconname[0]) namebuf[FILEBUF_SIZE-7]=0;
997 else namebuf[FILEBUF_SIZE-2]=0; */ namebuf[FILEBUF_SIZE-1]=0;
999 case FUNC_COPY:
1000 if (lastfile) strcpy(destname,newiconname);
1001 else {
1002 StrCombine(destname,destdir,namebuf,256);
1003 StrCombine(newiconname,destname,".info",256);
1005 arcfile = getsourcefromarc(swindow,sourcename,file->name);
1006 if (checksame(destdir,sourcename,0)==LOCK_SAME) break;
1007 retry_copy:
1008 if ((exist=CheckExist(destname,NULL))) {
1009 D(bug("askeach = %ld\n",askeach));
1010 if (askeach) {
1011 if ((a=checkexistreplace(sourcename,destname,&file->date,
1012 (function==FUNC_COPY),1))==REPLACE_ABORT) {
1013 myabort();
1014 break;
1016 if (a==REPLACE_SKIP) break;
1017 else if (a==REPLACE_ALL) {
1018 if (function!=FUNC_COPY/*==FUNC_COPYAS*/) goto functionloop; // TRY AGAIN
1019 askeach=0; // ALL
1021 else if (a==REPLACE_SKIPALL) {
1022 askeach = 0;
1023 autoskip = 1;
1025 else if (a==REPLACE_RENAME) {
1026 StrCombine(newiconname,destname,".info",256);
1027 goto retry_copy;
1030 if (autoskip) break;
1032 if (exist<0) {
1033 if ((a=delfile(destname,file->name,globstring[STR_COPYING],1,1))==-1) {
1034 myabort();
1035 break;
1037 if (!a) {
1038 doerror(ERROR_OBJECT_EXISTS);
1039 break;
1041 if (a==1 && (tempfile=findfile(dwindow,namebuf,NULL))) {
1042 if (!noremove) removefile(tempfile,dwindow,inact,(tempfile->type!=file->type));
1043 exist=0;
1046 if (file->type>=ENTRY_DIRECTORY) {
1047 a=recursedir(sourcename,destname,R_COPY,0);
1048 if (exist) {
1049 byte=-1;
1050 exist=0;
1052 else byte=dos_global_copiedbytes;
1053 if (config->copyflags&COPY_DATE) setdate(destname,&file->date);
1055 if (!a && !func_external_file[0]) {
1056 setdirsize(file,dos_global_bytecount,act);
1057 refreshwindow(act,0);
1058 filloutcopydata(file);
1060 else if (a==-1 || a==-10) {
1061 if (a==-1) {
1062 if ((a=checkerror(globstring[STR_COPYING],file->name,IoErr()))==1)
1063 goto functionloop;
1064 if (a==3) a=-10;
1066 if (CheckExist(destname,NULL)) {
1067 if (exist && (tempfile=findfile(dwindow,namebuf,NULL)))
1068 removefile(tempfile,dwindow,inact,0);
1069 addfile(dwindow,inact,namebuf,byte,file->type,&file->date,
1070 file->comment,file->protection,file->subtype,1,NULL,NULL,
1071 file->owner_id,file->group_id);
1073 if (a==-10) myabort();
1074 show=inact;
1075 break;
1077 else if (a<0) break;
1079 else {
1080 D(bug("FUNC_COPY: src=\"%s\", dst=\"%s\"\n",sourcename,destname));
1081 a=copyfile(sourcename,destname,&err,/*-1,*/NULL,0);
1082 D(bug("FUNC_COPY: a=%ld,err=%ld\n",a,err));
1083 if (a==0) {
1084 doerror(err);
1085 if ((a=checkerror(globstring[STR_COPYING],file->name,err))==3) {
1086 myabort();
1087 break;
1089 if (a==1) goto functionloop;
1090 break;
1092 else if (a==-1) {
1093 myabort();
1094 break;
1096 byte=file->size;
1098 if (exist && (tempfile=findfile(dwindow,namebuf,NULL)))
1099 removefile(tempfile,dwindow,inact,0);
1100 if (lockandexamine(destname,&fileinfo)) {
1101 if (fileinfo.fib_DirEntryType<0) byte=fileinfo.fib_Size;
1102 addfile(dwindow,inact,
1103 fileinfo.fib_FileName,
1104 byte,
1105 fileinfo.fib_DirEntryType,
1106 &fileinfo.fib_Date,
1107 fileinfo.fib_Comment,
1108 fileinfo.fib_Protection,
1109 file->subtype,1,NULL,NULL,
1110 fileinfo.fib_OwnerUID,fileinfo.fib_OwnerGID);
1111 if (config->copyflags&COPY_ARC && !(file->protection&FIBF_ARCHIVE)) {
1112 if (SetProtection(sourcename,file->protection|FIBF_ARCHIVE)) {
1113 file->protection|=FIBF_ARCHIVE;
1114 getprot(file->protection,file->protbuf);
1118 okayflag=1;
1119 show=inact;
1120 break;
1122 case FUNC_HUNT:
1123 if (file->type<=ENTRY_FILE) {
1124 okayflag=1;
1125 break;
1127 if ((a=recursedir(sourcename,NULL,R_HUNT,0))==-3) {
1128 wildselect(buf2,2,0,WILDSELECT_NAME);
1129 findfirstsel(act,-2);
1130 okayflag=breakout=noshow=1; count=-1;
1131 break;
1133 if (a>-1) {
1134 okayflag=1;
1135 if (a==0 && !func_external_file[0]) setdirsize(file,dos_global_bytecount,act);
1136 if (a>0) count+=a;
1138 else count=-1;
1139 break;
1141 case FUNC_READ:
1142 case FUNC_HEXREAD:
1143 case FUNC_ANSIREAD:
1144 case FUNC_SMARTREAD:
1145 if (file->type>=ENTRY_DEVICE) {
1146 okayflag=1;
1147 break;
1149 arcfile = getsourcefromarc(swindow,sourcename,file->name);
1150 a = viewfile(sourcename,str_arcorgname[0]?str_arcorgname:file->name,function,NULL,
1151 viewdata,(viewdata || str_arcorgname[0])?1:0,(entry_depth>1));
1152 D(bug("viewfile() returned %ld\n",a));
1153 if (a!=-2) {
1154 if (a!=-3) ++count;
1155 else if (count==0) unselect(act,file);
1156 if (file->selected) {
1157 file->selected=0;
1158 if (swindow) {
1159 --swindow->filesel; swindow->bytessel-=file->size;
1162 SetBusyPointer(Window);
1163 if (a==-1) status_justabort=1;
1164 else okayflag=1;
1166 else {
1167 if (!count && !(doerror(-1))) okayflag=1;
1169 break;
1171 case FUNC_SHOW:
1172 if (file->type>=ENTRY_DEVICE || file->size<1) {
1173 okayflag=1;
1174 file=NULL;
1175 break;
1177 arcfile = getsourcefromarc(swindow,sourcename,file->name);
1178 if (entry_depth<2 &&
1179 checkfiletypefunc(sourcename,FTFUNC_SHOW)) okayflag=1;
1180 else {
1181 if (data==0) {
1182 if (swindow && swindow->filesel>1 && config->viewbits&VIEWBITS_SHOWBLACK) {
1183 if ((blankscreen=OpenScreen((struct NewScreen *)&blank_scr)))
1184 SetRGB4(&blankscreen->ViewPort,0,0,0,0);
1185 setnullpointer(Window);
1186 pt=0;
1188 data=1;
1190 if ((a=showpic(sourcename,pt))==-1) {
1191 okayflag=1;
1192 myabort();
1193 break;
1195 else {
1196 if (a==1) okayflag=1;
1197 else file=NULL;
1200 break;
1202 case FUNC_ICONINFO:
1203 arcfile = getsourcefromarc(swindow,sourcename,file->name);
1204 if (Stricmp(file->name,".info")==0) okayflag=1;
1205 else {
1206 if ((ptr=isicon(sourcename))) *ptr=0;
1207 switch ((a=dopus_iconinfo(sourcename))) {
1208 case -1:
1209 myabort();
1210 file=NULL;
1211 break;
1212 case -2:
1213 dostatustext(globstring[STR_CANT_FIND_ICON]);
1214 file=NULL;
1215 break;
1216 case -3:
1217 dostatustext(globstring[STR_NO_CHIP_FOR_ICON]);
1218 file=NULL;
1219 break;
1220 case -4:
1221 file=NULL;
1222 status_justabort=1;
1223 break;
1224 case 1:
1225 if (act>-1) {
1226 StrCombine(buf,sourcename,".info",256);
1227 if (isicon(file->name)) {
1228 reload_file(act,sourcename);
1229 file=reload_file(act,buf);
1231 else {
1232 file=reload_file(act,sourcename);
1233 reload_file(act,buf);
1236 default:
1237 okayflag=1;
1238 show=act;
1239 break;
1241 if (ptr) *ptr='.';
1243 break;
1245 case FUNC_PLAYST:
1246 a=1;
1247 case FUNC_PLAY:
1248 case FUNC_LOOPPLAY:
1249 if (file->type>=ENTRY_DEVICE || file->size<1) {
1250 okayflag=1;
1251 file=NULL;
1252 break;
1254 arcfile = getsourcefromarc(swindow,sourcename,file->name);
1255 if (entry_depth<2 &&
1256 checkfiletypefunc(sourcename,(function==FUNC_PLAY)?FTFUNC_PLAY:FTFUNC_LOOPPLAY))
1257 okayflag=1;
1258 #ifndef __AROS__
1259 else if (a || check_is_module(sourcename)) {
1260 if ((a=playmod(sourcename)) && swindow && swindow->filesel>1) {
1261 a=-1;
1262 FOREVER {
1263 Wait(1<<Window->UserPort->mp_SigBit);
1264 while (getintuimsg()) {
1265 class=IMsg->Class; code=IMsg->Code;
1266 ReplyMsg((struct Message *)IMsg);
1267 if (class==MOUSEBUTTONS) {
1268 a=(code==SELECTDOWN);
1269 break;
1272 if (a!=-1) break;
1274 FlushModule();
1275 if (!a) myabort();
1276 else okayflag=1;
1278 else if (a) okayflag=1;
1279 else file=NULL;
1281 #endif
1282 else {
1283 a=doplay8svx(sourcename,(function==FUNC_LOOPPLAY));
1284 kill8svx();
1285 if (a==-1) {
1286 myabort();
1287 break;
1289 else {
1290 if (a==1) okayflag=1;
1291 else {
1292 handle8svxerror(a);
1293 file=NULL;
1297 break;
1299 case FUNC_ADDICON:
1300 if (strlen(file->name)>(FILEBUF_SIZE-6) || isicon(file->name)) {
1301 okayflag=1;
1302 file=NULL;
1303 break;
1305 StrCombine(buf2,file->name,".info",FILEBUF_SIZE-1);
1306 StrCombine(destname,sourcename,".info",256);
1307 if ((a=CheckExist(sourcename,NULL))==0) {
1308 doerror((a=IoErr()));
1309 if ((a=checkerror(globstring[STR_ADDING_ICON],file->name,a))==1)
1310 goto functionloop;
1311 if (a==3) {
1312 myabort();
1313 break;
1315 file=NULL;
1316 break;
1318 if (a>0) data=ICONTYPE_DRAWER;
1319 else if (checkexec(sourcename)) data=ICONTYPE_TOOL;
1320 else data=ICONTYPE_PROJECT;
1321 if (CheckExist(destname,NULL)) {
1322 if (askeach) {
1323 doerror(ERROR_OBJECT_EXISTS);
1324 if ((a=checkexistreplace(destname,destname,NULL,1,1))==REPLACE_ABORT) {
1325 myabort();
1326 break;
1328 else if (a==REPLACE_ALL) askeach=0;
1329 else if (a==REPLACE_SKIP) {
1330 file=NULL;
1331 break;
1333 else if (a==REPLACE_SKIPALL) {
1334 askeach = 0;
1335 autoskip = 1;
1336 file = NULL;
1338 else if (a==REPLACE_RENAME) {
1339 strcpy(buf2,BaseName(destname));
1342 if (autoskip) break;
1344 if ((iconwrite(data,destname))!=-1) {
1345 if (lockandexamine(destname,&fileinfo)) {
1346 addfile(swindow,act,buf2,fileinfo.fib_Size,-1,&fileinfo.fib_Date,
1347 fileinfo.fib_Comment,fileinfo.fib_Protection,0,1,NULL,NULL,
1348 fileinfo.fib_OwnerUID,fileinfo.fib_OwnerGID);
1349 show=act;
1350 okayflag=1;
1353 else {
1354 myabort();
1355 break;
1357 break;
1359 case FUNC_COMMENT:
1360 if (askeach) {
1361 if (rexx && rexx_argcount>0) strcpy(buf2,rexx_args[rexarg]);
1362 else {
1363 if (file->comment) strcpy(buf2,file->comment);
1364 else buf2[0]=0;
1365 if (!(a=whatsit(globstring[STR_ENTER_COMMENT],79,buf2,
1366 globstring[STR_ALL]))) {
1367 myabort();
1368 break;
1370 if (a==2) askeach=0;
1373 FOREVER {
1374 if (SetComment(sourcename,buf2)) break;
1375 doerror((a=IoErr()));
1376 if ((a=checkerror(globstring[STR_COMMENTING],file->name,a))==3) {
1377 myabort();
1378 break;
1380 if (a!=1) {
1381 file=NULL;
1382 break;
1385 if (status_justabort || !file) break;
1386 okayflag=1;
1387 if (file->type>=ENTRY_DIRECTORY) {
1388 if ((a=recursedir(sourcename,buf2,R_COMMENT,0))>0 && status_justabort)
1389 status_justabort=okayflag=0;
1390 else if (!a && !func_external_file[0]) setdirsize(file,dos_global_bytecount,act);
1392 if (!noremove && file->comment!=dos_copy_comment) {
1393 if (act>-1 && config->sortmethod[act]==DISPLAY_COMMENT) {
1394 CopyMem((char *)file,(char *)&filebuf,sizeof(struct Directory));
1395 removefile(file,swindow,act,0); file=NULL;
1396 addfile(swindow,act,namebuf,filebuf.size,filebuf.type,&filebuf.date,
1397 buf2,filebuf.protection,filebuf.subtype,1,NULL,NULL,
1398 filebuf.owner_id,filebuf.group_id);
1400 else {
1401 if (file->comment)
1402 LibFreePooled(dir_memory_pool,file->comment,strlen(file->comment)+1);
1403 if ((file->comment=LibAllocPooled(dir_memory_pool,strlen(buf2)+1)))
1404 strcpy(file->comment,buf2);
1407 break;
1409 case FUNC_PROTECT:
1410 if (askeach && !lastfile) {
1411 if (rexx) {
1412 data=rexx_arg_value[0];
1413 mask=rexx_arg_value[1];
1415 else {
1416 data=file->protection;
1417 if (!(a=getprotectdata(&data,&mask))) {
1418 myabort();
1419 break;
1421 if (a==2) askeach=0;
1424 temp=getnewprot(file->protection,data,mask);
1425 FOREVER {
1426 if (SetProtection(sourcename,temp)) break;
1427 doerror((a=IoErr()));
1428 if ((a=checkerror(globstring[STR_PROTECTING],file->name,a))==3) {
1429 myabort();
1430 break;
1432 if (a!=1) {
1433 file=NULL;
1434 break;
1437 if (status_justabort || !file) break;
1438 file->protection=temp;
1439 getprot(temp,file->protbuf);
1440 if (file->type>=ENTRY_DIRECTORY) {
1441 protstuff[0]=data; protstuff[1]=mask;
1442 if ((a=recursedir(sourcename,NULL,R_PROTECT,(int)protstuff)) &&
1443 status_justabort) break;
1444 if (!a && !func_external_file[0]) setdirsize(file,dos_global_bytecount,act);
1446 if (!file->selected) refreshwindow(act,0);
1447 okayflag=1;
1448 break;
1450 case FUNC_ENCRYPT:
1451 if (file->type>=ENTRY_DEVICE || file->size<1) {
1452 okayflag=1;
1453 file=NULL;
1454 break;
1456 StrCombine(destname,destdir,file->name,256);
1457 if (CheckExist(destname,NULL)) {
1458 if (askeach) {
1459 if ((a=checkexistreplace(sourcename,destname,&file->date,1,1))==REPLACE_ABORT) {
1460 myabort();
1461 break;
1463 else if (a==REPLACE_ALL) askeach=0;
1464 else if (a==REPLACE_SKIP) {
1465 file=NULL;
1466 break;
1468 else if (a==REPLACE_SKIPALL) {
1469 askeach = 0;
1470 autoskip = 1;
1471 file = NULL;
1474 else if (a==REPLACE_RENAME) {
1478 if (autoskip) break;
1479 if ((a=delfile(destname,file->name,globstring[STR_DATESTAMPING],1,1))==-1) {
1480 myabort();
1481 break;
1484 if (!CheckExist(destname,NULL)) {
1485 FOREVER {
1486 if (copyfile(sourcename,destname,&err,/*-1,*/buf2,data)) {
1487 addfile(dwindow,inact,file->name,file->size,file->type,&file->date,
1488 file->comment,file->protection,file->subtype,1,NULL,NULL,
1489 file->owner_id,file->group_id);
1490 okayflag=1; show=inact;
1491 break;
1493 doerror(err);
1494 if ((a=checkerror(globstring[STR_ENCRYPTING],file->name,err))==3) {
1495 myabort();
1496 break;
1498 if (a!=1) {
1499 file=NULL;
1500 break;
1504 else doerror(ERROR_OBJECT_EXISTS);
1505 break;
1507 case FUNC_DATESTAMP:
1508 if (askeach && !lastfile) {
1509 if (rexx && rexx_argcount>0) strcpy(buf2,rexx_args[rexarg]);
1510 else {
1511 seedate(&(file->date),buf2,0); // buf2[0]=0;
1512 if (!(a=whatsit(globstring[STR_ENTER_DATE_AND_TIME],20,buf2,
1513 globstring[STR_ALL]))) {
1514 myabort();
1515 break;
1517 if (a==2) askeach=0;
1519 if (buf2[0]) {
1520 parsedatetime(buf2,buf,buf1,&a);
1521 strtostamp(buf,buf1,&datetime.dat_Stamp);
1523 else DateStamp(&datetime.dat_Stamp);
1525 FOREVER {
1526 if ((a=setdate(sourcename,&datetime.dat_Stamp))==1) {
1527 if (!noremove) {
1528 if (act>-1 && config->sortmethod[act]==DISPLAY_DATE) {
1529 CopyMem((char *)file,(char *)&filebuf,sizeof(struct Directory));
1530 if (file->comment) {
1531 strcpy(buf2,file->comment);
1532 filebuf.comment=buf2;
1534 removefile(file,swindow,act,0);
1535 file=(struct Directory *)addfile(swindow,act,filebuf.name,filebuf.size,
1536 filebuf.type,&datetime.dat_Stamp,filebuf.comment,filebuf.protection,
1537 filebuf.subtype,1,NULL,NULL,filebuf.owner_id,filebuf.group_id);
1539 else {
1540 file->date.ds_Days=datetime.dat_Stamp.ds_Days;
1541 file->date.ds_Minute=datetime.dat_Stamp.ds_Minute;
1542 file->date.ds_Tick=datetime.dat_Stamp.ds_Tick;
1543 seedate(&file->date,file->datebuf,1);
1546 break;
1548 doerror(a);
1549 if ((a=checkerror(globstring[STR_DATESTAMPING],file->name,a))==3) {
1550 myabort();
1551 break;
1553 if (a!=1) {
1554 file=NULL;
1555 break;
1558 if (status_justabort || !file) break;
1559 if (file->type>=ENTRY_DIRECTORY) {
1560 if (!(recursedir(sourcename,NULL,R_DATESTAMP,(int)&datetime.dat_Stamp))) {
1561 okayflag=1;
1562 if (!func_external_file[0]) setdirsize(file,dos_global_bytecount,act);
1565 else okayflag=1;
1566 break;
1568 case FUNC_SEARCH:
1569 if (file->type==ENTRY_DEVICE) {
1570 if ((a=recursedir(file->name,NULL,R_SEARCH,0))==-2) {
1571 okayflag=1;
1572 count=-1; nextfile=NULL;
1573 break;
1575 if (a==-1) {
1576 nextfile=NULL;
1577 break;
1579 if (a==-10) {
1580 myabort();
1581 break;
1583 if (a>0) count+=a;
1584 okayflag=1;
1586 else {
1587 if (file->type<=ENTRY_FILE) {
1588 arcfile = getsourcefromarc(swindow,sourcename,file->name);
1589 a=filesearch(sourcename,&b,(askeach)?1:-1);
1590 count+=b;
1591 if (a==2) {
1592 okayflag=1; file=NULL;
1593 busy();
1594 if (act>-1) {
1595 if (swindow) {
1596 if (count>0) b=(swindow->filesel-count)+swindow->dirsel;
1597 else b=swindow->filesel+swindow->dirsel;
1598 if (!b) nextfile=NULL;
1601 if (nextfile && !simplerequest(globstring[STR_CONTINUE_WITH_SEARCH],
1602 globstring[STR_CONTINUE],str_cancelstring,NULL))
1603 nextfile=NULL;
1605 if (a==-1) {
1606 myabort();
1607 break;
1609 if (a) {
1610 okayflag=1;
1611 if (a==3) file=NULL;
1612 else if (a==4) {
1613 file=NULL;
1614 askeach=0;
1617 else doerror(-1);
1619 else {
1620 if (!(a=recursedir(sourcename,NULL,R_SEARCH,0))) {
1621 if (!func_external_file[0]) setdirsize(file,dos_global_bytecount,act);
1622 okayflag=1;
1624 if (a==-2) {
1625 okayflag=1; breakout=2;
1626 count=-1; nextfile=NULL;
1627 break;
1629 if (a==-1 || a==-10) {
1630 if (a==-10) {
1631 myabort();
1632 file=NULL;
1634 else nextfile=NULL;
1635 break;
1637 if (a>0) count+=a;
1640 break;
1642 if (arcfile) removetemparcfile(sourcename);
1644 if (config->dynamicflags&UPDATE_FREE && show>-1) seename(show);
1645 if (breakout==1) break;
1646 if (file && okayflag) {
1647 if (file->selected) unselect(act,file);
1648 else refreshwindow(act,0);
1650 if (status_justabort || breakout==2) break;
1652 if (doicons && !lastfile && okayflag && oldiconname[0]) {
1653 if ((file=findfile(swindow,oldiconname,NULL))) {
1654 if (file==nextfile) nextfile=file->next;
1655 lastfile=1;
1656 if (file->selected && prog_indicator) {
1657 if (progtype==0 || progtype==2) {
1658 ++value;
1659 // dotaskmsg(hotkeymsg_port,PROGRESS_UPDATE,value,total,NULL,0);
1660 dotaskmsg(hotkeymsg_port,PROGRESS_INCREASE,1,0,NULL,0);
1663 if (progress_copy) dotaskmsg(hotkeymsg_port,PROGRESS_UPDATE,-2,0,file->name,1);
1664 goto functionloop;
1666 else {
1667 StrCombine(sourcename,sourcedir,oldiconname,256);
1668 if (filloutdummy(sourcename,&dummyfile)) {
1669 dummyfile.selected=0;
1670 file=&dummyfile;
1671 lastfile=1;
1672 goto functionloop;
1677 if (globflag) break;
1678 if (!lastfile && file && file->next && file->next!=nextfile) file=file->next;
1679 else file=nextfile;
1680 namebuf[0]=0;
1683 if (prog_indicator) {
1684 dotaskmsg(hotkeymsg_port,PROGRESS_UPDATE,-1,status_justabort,NULL,0);
1685 if (progress_copy) dotaskmsg(hotkeymsg_port,PROGRESS_UPDATE,-1,status_justabort,NULL,1);
1688 switch (function) {
1689 case FUNC_HUNT:
1690 if (count==0) {
1691 okayflag=0;
1692 doerror(ERROR_OBJECT_NOT_FOUND);
1693 simplerequest(globstring[STR_COULD_NOT_FIND_FILE],globstring[STR_CONTINUE],NULL);
1695 else if (count>0) {
1696 lsprintf(buf2,globstring[STR_FOUND_MATCHING_FILES],count);
1697 dostatustext(buf2);
1698 simplerequest(buf2,globstring[STR_CONTINUE],NULL);
1700 break;
1702 case FUNC_READ:
1703 case FUNC_HEXREAD:
1704 case FUNC_ANSIREAD:
1705 case FUNC_SMARTREAD:
1706 if (act>-1) refreshwindow(act,0);
1707 if (viewdata) cleanupviewfile(viewdata);
1708 if (status_justabort) myabort();
1709 else if (!okayflag && !(doerror(-1))) okayflag=1;
1710 break;
1712 case FUNC_SHOW:
1713 if (config->viewbits&VIEWBITS_SHOWBLACK) {
1714 if (blankscreen) {
1715 CloseScreen(blankscreen);
1716 blankscreen=NULL;
1718 ClearPointer(Window);
1720 break;
1721 #ifdef _USE_SMALL_Q
1722 case FUNC_COMMENT:
1723 if (status_flags&STATUS_IANSCRAP && okayflag) {
1724 dostatustext(buf2);
1725 okayflag=0;
1727 break;
1729 case FUNC_PROTECT:
1730 if (status_flags&STATUS_IANSCRAP && okayflag) {
1731 getprot(data,buf2);
1732 dostatustext(buf2);
1733 okayflag=0;
1735 break;
1737 case FUNC_DATESTAMP:
1738 if (status_flags&STATUS_IANSCRAP && okayflag) {
1739 seedate(&datetime.dat_Stamp,buf2,0);
1740 dostatustext(buf2);
1741 okayflag=0;
1743 break;
1744 #endif
1745 case FUNC_SEARCH:
1746 if (count>-1) {
1747 if (count==0) simplerequest(globstring[STR_STRING_NOT_FOUND],
1748 globstring[STR_CONTINUE],NULL);
1749 else {
1750 lsprintf(buf2,globstring[STR_MATCHED_FILES],count);
1751 simplerequest(buf2,globstring[STR_CONTINUE],NULL);
1753 okayflag=1;
1755 break;
1757 case FUNC_BYTE:
1758 if (!status_justabort) {
1759 long long value;
1761 main_proc->pr_WindowPtr=(APTR)-1;
1762 if (!(destdir && (filelock=Lock(destdir,ACCESS_READ)))) value=0;
1763 else {
1764 Info(filelock,&infodata);
1765 if (ramdisk_lock && CompareLock(filelock,ramdisk_lock)!=LOCK_DIFFERENT)
1766 value=AvailMem(0);
1767 else value=(infodata.id_NumBlocks-infodata.id_NumBlocksUsed)*(long long)blocksize;
1768 UnLock(filelock);
1770 if (config->errorflags&ERROR_ENABLE_DOS) main_proc->pr_WindowPtr=(APTR)Window;
1771 if (specflags&FUNCFLAGS_BYTEISCHECKFIT) {
1772 double needed,percent;
1774 needed=data*blocksize;
1775 if (value<1) percent=0;
1776 else if (value>=needed || needed<1) {
1777 percent=100;
1778 retval=1;
1780 else percent=100/(needed/value);
1781 sprintf(buf,globstring[STR_CHECKFIT_STRING],data*(long long)blocksize,value,percent);
1782 dostatustext(buf);
1784 else {
1785 doselinfo(act);
1786 strcat(str_select_info,
1787 (value<=swindow->bytessel)?
1788 globstring[STR_NO_FIT]:globstring[STR_YES_FIT]);
1789 dostatustext(str_select_info);
1791 okayflag=0;
1793 break;
1796 if (okayflag && !status_justabort) okay();
1797 if (!noshow) {
1798 endfollow(act);
1799 displaydir(act); seename(act);
1801 if (inact>-1) {
1802 displaydir(inact);
1803 seename(inact);
1805 switch (function) {
1806 case FUNC_MOVEAS: if (checksame(sourcedir,destdir,2)==LOCK_SAME) break;
1807 case FUNC_DELETE:
1808 case FUNC_RENAME:
1809 case FUNC_MOVE:
1810 case FUNC_ADDICON:
1811 case FUNC_ICONINFO:
1812 update_buffer_stamp(act,1);
1813 break;
1814 case FUNC_COPYAS:
1815 if (specflags&FUNCFLAGS_COPYISCLONE) update_buffer_stamp(act,1);
1816 break;
1818 case FUNC_COMMENT:
1819 case FUNC_PROTECT:
1820 case FUNC_DATESTAMP:
1821 update_buffer_stamp(act,0);
1822 break;
1825 switch (function) {
1826 case FUNC_MOVEAS:
1827 case FUNC_COPYAS:
1828 if (checksame(sourcedir,destdir,2)==LOCK_SAME) break;
1829 case FUNC_MOVE:
1830 case FUNC_COPY:
1831 case FUNC_ENCRYPT:
1832 update_buffer_stamp(inact,1);
1833 break;
1836 switch (function) {
1837 case FUNC_SEARCH:
1838 if (count>0) rexx_return_value=count;
1839 break;
1842 startnotifies();
1844 endfunction:
1845 if (prog_indicator) dotaskmsg(hotkeymsg_port,PROGRESS_CLOSE,0,0,NULL,0);
1846 LFreeRemember(&funckey);
1847 --entry_depth;
1848 return(retval);