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.
32 #include <proto/asyncio.h>
35 //struct Library *AsyncIOBase;
37 int copyfile(src
,dst
,err
,/*size,*/password
,encryptstate
)
43 struct FileInfoBlock __aligned cfinfo
;
45 int length
,suc
,readsize
,size_read
,size_write
,size_total
,ret
=0,buffer_size
,size
;
46 int prog
= (config
->dynamicflags
&UPDATE_PROGRESSIND_COPY
);
47 BPTR out
,inhandle
,outhandle
;
48 struct AsyncFile
*infile
;
50 struct AsyncFile *outfile;
52 struct DateStamp ds
,*dsp
;
66 for (a
=0;password
[a
];a
++) encrypt
*=password
[a
];
70 suc
=lockandexamine(src
,&cfinfo
);
77 if (!(size
=cfinfo
.fib_Size
)) {
78 if (!(out
=Open(dst
,MODE_NEWFILE
))) goto failed
;
80 if (config
->copyflags
©_DATE
) setdate(dst
,&(cfinfo
.fib_Date
));
81 if (config
->copyflags
©_PROT
) SetProtection(dst
,cfinfo
.fib_Protection
&((config
->copyflags
©_COPYARC
)?~0:~FIBF_ARCHIVE
));
82 if (config
->copyflags
©_NOTE
) SetComment(dst
,cfinfo
.fib_Comment
);
83 SetOwner(dst
,(cfinfo
.fib_OwnerUID
<<16)|cfinfo
.fib_OwnerGID
);
87 if (size
<=COPY_BUF_SIZE
) {
88 dotaskmsg(hotkeymsg_port
,PROGRESS_UPDATE
,100,100,NULL
,1);
91 else dotaskmsg(hotkeymsg_port
,PROGRESS_UPDATE
,0,100,NULL
,1);
93 infile
= OpenAsync(src
,MODE_READ
,ASYNC_READ_SIZE
);
94 if (!infile
&& (!(inhandle
=Open(src
,MODE_OLDFILE
)))) goto failed
;
96 if (!(outhandle
=Open(dst
,MODE_NEWFILE
))) goto failed
;
98 if (size
>(64*1024)) buffer_size
=size
/2;
99 else buffer_size
=size
;
100 if (buffer_size
>(128*1024)) buffer_size
=128*1024;
102 while (buffer_size
>0) {
103 if ((buffer
=AllocMem(buffer_size
,MEMF_ANY
))) break;
106 if (!buffer
) goto failed
;
108 size_read
=size_write
=0;
112 readsize
=(size
>buffer_size
)?buffer_size
:size
;
113 if (infile
) length
=ReadAsync(infile
,buffer
,readsize
);
114 else length
=Read(inhandle
,buffer
,readsize
);
120 dotaskmsg(hotkeymsg_port
,PROGRESS_UPDATE
,size_read
+size_write
,size_total
,NULL
,1);
122 if (status_haveaborted
) {
132 for (a
=0;a
<length
;a
++) {
138 for (a
=0;a
<length
;a
++) {
148 if ((WriteAsync(outfile,buffer,length))==-1) goto failed;
152 if ((Write(outhandle
,buffer
,length
))==-1) goto failed
;
157 dotaskmsg(hotkeymsg_port
,PROGRESS_UPDATE
,size_read
+size_write
,size_total
,NULL
,1);
159 if (status_haveaborted
) {
165 if (infile
) CloseAsync(infile
);
166 else /*if (inhandle)*/ Close(inhandle
);
168 if (outfile) CloseAsync(outfile);
170 /*if (outhandle)*/ Close(outhandle
);
172 FreeMem(buffer
,buffer_size
);
174 if (config
->copyflags
©_DATE
) {
175 setdate(dst
,&(cfinfo
.fib_Date
));
176 dsp
=&cfinfo
.fib_Date
;
182 copy_datestamp(dsp
,&dos_copy_date
);
184 if (config
->copyflags
©_PROT
)
185 SetProtection(dst
,cfinfo
.fib_Protection
&((config
->copyflags
©_COPYARC
)?~0:~FIBF_ARCHIVE
));
186 dos_copy_protection
=cfinfo
.fib_Protection
;
188 if (config
->copyflags
©_NOTE
) {
189 SetComment(dst
,cfinfo
.fib_Comment
);
190 strcpy(dos_copy_comment
,cfinfo
.fib_Comment
);
192 else dos_copy_comment
[0]=0;
198 if (buffer
) FreeMem(buffer
,buffer_size
);
199 if (infile
) CloseAsync(infile
);
200 if (inhandle
) Close(inhandle
);
201 if (/* outfile || */ outhandle
) {
203 if (outfile) CloseAsync(outfile);
212 struct Directory
*checktot(dir
)
213 struct DirectoryWindow
*dir
;
215 struct Directory
*first
;
217 if (!dir
) return(NULL
);
218 first
=dir
->firstentry
;
220 if (first
->selected
&& first
->type
<=ENTRY_FILE
) break;
226 struct Directory
*checkdirtot(dir
)
227 struct DirectoryWindow
*dir
;
229 struct Directory
*first
;
231 if (!dir
) return(NULL
);
232 first
=dir
->firstentry
;
234 if (first
->selected
&& ENTRYTYPE(first
->type
)==ENTRY_DIRECTORY
) break;
240 struct Directory
*checkdevtot(dir
)
241 struct DirectoryWindow
*dir
;
243 struct Directory
*first
;
245 if (!dir
) return(NULL
);
246 first
=dir
->firstentry
;
248 if (first
->selected
&& first
->type
==ENTRY_DEVICE
) break;
254 struct Directory
*checkalltot(dir
)
255 struct DirectoryWindow
*dir
;
257 struct Directory
*first
;
259 if (!dir
) return(NULL
);
260 first
=dir
->firstentry
;
262 if (first
->selected
&& first
->type
!=ENTRY_DEVICE
&& first
->type
!=ENTRY_CUSTOM
) break;
268 /* Enforcer HIT: with ARexx script sameselect.dopus */
270 struct Directory
*findfile(dir
,name
,count
)
271 struct DirectoryWindow
*dir
;
275 struct Directory
*find
;
279 LParsePatternI(name,parsebuf);
282 D(bug("findfile(%s)\n",name
?name
:"<NULL>"));
284 if (str_arcorgname
[0]) name
=str_arcorgname
; /* required for double-click */
286 find
=dir
->firstentry
;
290 if (find->name && (LMatchPatternI(parsebuf,find->name))) return(find);
292 if (find
->name
&& !(Stricmp(name
,find
->name
))) return(find
);
295 if (count
) ++(*count
);
301 int delfile(name
,nam
,errs
,unprotect
,errcheck
)
302 char *name
,*nam
,*errs
;
303 int unprotect
,errcheck
;
305 int suc
,a
,err
,try=0,recplus
=0;
306 char buf
[300],buf2
[100];
309 suc
=DeleteFile(name
);
311 if ((err
=IoErr())==ERROR_OBJECT_NOT_FOUND
) suc
=1;
313 if (err
==ERROR_DIRECTORY_NOT_EMPTY
) return(-2);
314 else if (err
==ERROR_DELETE_PROTECTED
&& try==0) {
315 if (!(config
->deleteflags
&DELETE_SET
)) {
317 doerror(ERROR_DELETE_PROTECTED
);
318 geterrorstring(buf2
,ERROR_DELETE_PROTECTED
);
319 lsprintf(buf
,globstring
[STR_ERROR_OCCURED
],globstring
[STR_DELETING
],nam
,buf2
);
320 strcat(buf
,globstring
[STR_SELECT_UNPROTECT
]);
321 if (!(a
=simplerequest(buf
,globstring
[STR_UNPROTECT
],
322 globstring
[STR_ABORT
],globstring
[STR_UNPROTECT_ALL
],globstring
[STR_SKIP
],NULL
)))
329 SetProtection(name
,0);
332 else if (!errcheck
) return(-2);
334 if ((a
=checkerror(errs
,nam
,err
))==3) return(-1);
345 int getwildrename(sname
,dname
,name
,newn
)
346 char *sname
,*dname
,*name
,*newn
;
348 // char sfirst[FILEBUF_SIZE],slast[FILEBUF_SIZE],dfirst[FILEBUF_SIZE],dlast[FILEBUF_SIZE],foon[FILEBUF_SIZE];
349 int a
,b
,c
/*,flen,llen,d*/;
351 char *spat
= sname
, *dpat
= dname
, *sn
= name
, *dn
= newn
;
354 D(bug("getwildrename(%s,%s,%s,)\n",sname
,dname
,name
));
355 /* check if filename matches source pattern */
363 if (*spat
) for (c1
=ToLower(*spat
); c1
!= ToLower(*sn
); sn
++);
382 D(bug("getwildrename(): <%smatch>, %ld asterisks in source pattern\n",a
?"":"no ",b
));
384 /* count asterisks in destination pattern */
385 for(c
= 0; *dpat
; dpat
++) if (*dpat
== '*') c
++;
386 D(bug("getwildrename(): %ld asterisks in destination pattern\n",c
));
388 if (a
&& (b
== c
)) // try to build destination filename
394 while (*spat
|| *dpat
|| *sn
)
396 // skip to wildcard part of filename
399 for (; *spat
&& (*spat
!= '*'); spat
++, sn
++);
402 // copy replacement text
405 for (; *dpat
&& (*dpat
!= '*'); *dn
++ = *dpat
++);
408 // copy wildcard part of source filename
409 if (*sn
) for (c1
=ToLower(*spat
); c1
!= ToLower(*sn
); sn
++) if (*spat
!= '*') *dn
++ = *sn
;
411 D(bug("getwildrename(): spat = %s, dpat = %s, sn = %s, destination name: %s\n",spat
,dpat
,sn
,newn
));
416 b=strlen(sname); sfirst[0]=slast[0]=0;
419 strcpy(sfirst,sname); sfirst[(flen=a)]=0;
420 strcpy(slast,(char *)&sname[a+1]);
427 strcpy(dfirst,dname); dfirst[a]=0;
428 strcpy(dlast,(char *)&dname[a+1]);
431 a=strlen(sfirst); b=strlen(slast);
432 if ((!a || (Strnicmp(name,sfirst,flen))==0) &&
433 (!b || ((d=strlen(name))>=llen && (Stricmp(&name[(d-llen)+1],slast))==0))) {
435 CopyMem((char *)&name[a],foon,c);
437 strcpy(newn,dfirst); strcat(newn,foon); strcat(newn,dlast);
438 D(bug("getwildrename(): newname = %s\n",newn));
439 if (newn[0]!=0) return(1);
445 void filloutcopydata(dir
)
446 struct Directory
*dir
;
448 dos_copy_date
.ds_Days
=dir
->date
.ds_Days
;
449 dos_copy_date
.ds_Minute
=dir
->date
.ds_Minute
;
450 dos_copy_date
.ds_Tick
=dir
->date
.ds_Tick
;
451 dos_copy_protection
=dir
->protection
;
452 if (dir
->comment
) strcpy(dos_copy_comment
,dir
->comment
);
453 else dos_copy_comment
[0]=0;
456 void filloutcopydatafile(fil
)
459 struct FileInfoBlock __aligned fileinfo
;
461 if (lockandexamine(fil
,&fileinfo
)) {
462 dos_copy_date
.ds_Days
=fileinfo
.fib_Date
.ds_Days
;
463 dos_copy_date
.ds_Minute
=fileinfo
.fib_Date
.ds_Minute
;
464 dos_copy_date
.ds_Tick
=fileinfo
.fib_Date
.ds_Tick
;
465 dos_copy_protection
=fileinfo
.fib_Protection
;
466 strcpy(dos_copy_comment
,fileinfo
.fib_Comment
);
470 void update_buffer_stamp(win
,true)
473 struct FileInfoBlock __aligned fib
;
475 struct DirectoryWindow
*dirwin
;
477 if (win
==-1 || !(config
->dirflags
&DIRFLAGS_REREADOLD
)) return;
479 dirwin
=dopus_curwin
[win
];
480 strcpy(dirbuf
,str_pathbuffer
[win
]);
483 if (lockandexamine(dirbuf
,&fib
))
484 copy_datestamp(&fib
.fib_Date
,&dirwin
->dirstamp
);
485 if (!(doparent(dirbuf
)) ||
486 !(dirwin
=findbuffer(dirbuf
,win
,0,1))) break;
489 if (!(dirwin
=dirwin
->next
) ||
490 dirwin
==dopus_curwin
[win
]) break;
491 if (Strnicmp(dirwin
->directory
,dirbuf
,strlen(dirbuf
))==0) {
492 dirwin
->dirstamp
.ds_Days
=0;
493 dirwin
->dirstamp
.ds_Minute
=0;
494 dirwin
->dirstamp
.ds_Tick
=0;
500 int check_key_press(func
,code
,qual
)
501 struct dopusfunction
*func
;
504 if (!func
->function
||
505 !func
->function
[0] ||
506 (func
->key
==0xff && func
->qual
==0) ||
508 func
->qual
!=qual
) return(0);
509 if (func
->key
==0xff || func
->key
==code
) return(1);