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.
33 #include <proto/xadmaster.h>
38 int readarchive(struct DirectoryWindow
*dir
,int win
)
43 struct xadFileInfo
*xfi
;
45 unsigned char arcname
[256], arcdir
[256], buf
[FILEBUF_SIZE
], *c
;
49 D(bug("readarchive: %s\n",dir
->directory
)); //Delay(100);
50 strcpy(arcname
, dir
->directory
);
51 if ((len
= strlen(arcname
))) if (arcname
[len
-1] == '/') arcname
[len
-1] = 0;
52 //D(bug("arcname: %s\n",arcname));
53 while(!(lock
= Lock(arcname
, ACCESS_READ
)))
55 c
= FilePart(arcname
);
56 if (c
== arcname
) return 0;
57 if (c
> arcname
) *(c
-1) = 0;
58 //D(bug("arcname2: %s\n",arcname));
59 strcpy(arcdir
,dir
->directory
+(IPTR
)c
-(IPTR
)arcname
);
62 //D(bug("arcdir: %s\n",arcdir));
66 dostatustext(globstring
[STR_OPENING_ARCHIVE
]);//HUX
67 if ((dir
->arcname
= AllocVec(strlen(arcname
)+1, MEMF_ANY
)))
69 strcpy(dir
->arcname
,arcname
);
70 if ((dir
->xai
= xadAllocObjectA(XADOBJ_ARCHIVEINFO
, NULL
)))
74 ti
[0].ti_Tag
= XAD_INFILENAME
;
75 ti
[0].ti_Data
= (Tag
)arcname
;
76 ti
[1].ti_Tag
= TAG_END
;
78 D(bug("Allocated dir->xai: %lx\nOpening the archive...\n",dir
->xai
));
79 if(!(xadGetInfoA(dir
->xai
, ti
)))
82 if (dir
->xai
->xai_DiskInfo
)
84 struct xadArchiveInfo
*xai2
;
87 if ((xai2
= xadAllocObjectA(XADOBJ_ARCHIVEINFO
, NULL
)))
89 struct TagItem ti2
[2];
91 ti2
[0].ti_Tag
= XAD_ENTRYNUMBER
;
92 ti2
[0].ti_Data
= dir
->xai
->xai_DiskInfo
->xdi_EntryNumber
;
93 ti2
[1].ti_Tag
= TAG_MORE
;
94 ti2
[1].ti_Data
= (IPTR
)ti
;
96 D(bug("Allocated dir->xai2: %lx\n",xai2
));
97 if(!(err
=xadGetDiskInfo(xai2
, XAD_NOEMPTYERROR
, 1, XAD_INDISKARCHIVE
, (IPTR
)ti2
, TAG_DONE
)))
99 D(bug("xai2 initialized\n"));
100 if (xai2
->xai_FileInfo
)
102 xadFreeInfo(dir
->xai
);
103 xadFreeObjectA(dir
->xai
, NULL
);
106 else xadFreeInfo(xai2
);
108 D(bug("err = %lx\n",err
));
109 xadFreeObjectA(xai2
, NULL
);
112 dir
->flags
|= DWF_ARCHIVE
;
117 xadFreeObjectA(dir
->xai
, NULL
);
119 FreeVec(dir
->arcname
);
126 FreeVec(dir
->arcname
);
133 else D(bug("dir->xai present: %lx\n",dir
->xai
));
134 D(bug("archive: %s\tarcdir: %s\n",arcname
,arcdir
));
135 if ((xfi
= dir
->xai
->xai_FileInfo
))
137 //D(bug("xfi = %lx\n",xfi));
140 //D(bug("Object: %s\n",xfi->xfi_FileName));
141 // if ((len == 0) || (strncmp(arcdir,xfi->xfi_FileName,len) != 0))
144 c
= xfi
->xfi_FileName
;
145 //D(bug("arcdir: %s (%ld)\n",arcdir,len));
146 // for (i = 0; ToLower(arcdir[i]) == ToLower(xfi->xfi_FileName[i]); i++) c++;
150 c1
= ToLower(arcdir
[i
]);
151 c2
= ToLower(xfi
->xfi_FileName
[i
]);
162 for (i
= 0; *c
&& (*c
!= '/') && (i
< (FILEBUF_SIZE
-1)); i
++, c
++) buf
[i
] = *c
;
165 //D(bug("dir cut: %s\n",buf));
166 if(!(findfile(dir
,buf
,NULL
)))
168 D(bug("readarchive/add: %s\n",buf
));
169 if (*c
== '/') type
= ST_USERDIR
;
172 if ((xfi
->xfi_Flags
& XADFIF_DIRECTORY
)==XADFIF_DIRECTORY
) type
= ST_USERDIR
;
174 xadConvertDates(XAD_DATEXADDATE
, (Tag
)&xfi
->xfi_Date
, XAD_GETDATEDATESTAMP
, (Tag
)&ds
, TAG_END
);
176 addfile(dir
, win
, buf
,
177 (type
> 0) ? -1LL : xfi
->xfi_Size
,
179 &ds
, xfi
->xfi_Comment
, xfi
->xfi_Protection
, 0,
180 FALSE
, NULL
, NULL
, xfi
->xfi_OwnerUID
, xfi
->xfi_OwnerGID
);
184 xfi
= xfi
-> xfi_Next
;
186 dostatustext(globstring
[STR_OKAY_TITLE
]); //HUX
187 // dostatustext("OK");
194 void freearchive(struct DirectoryWindow
*dir
)
199 D(bug("Freeing dir->xai: %lx\n",dir
->xai
));
200 xadFreeInfo(dir
->xai
);
201 if (dir
->arcname
) FreeVec(dir
->arcname
);
203 xadFreeObject(dir
->xai
, TAG_END
);
205 dir
->arcpassword
[0]=0;
210 BOOL
getsourcefromarc(struct DirectoryWindow
*dir
, char *buf
, char *file
)
213 D(bug("getsourcefromarc(%s,%s)\n",buf
?buf
:"<NULL>",file
?file
:"<NULL>"));
214 if (dir
&& (dir
->flags
& DWF_ARCHIVE
))
216 char srcdir
[256], tempname
[FILEBUF_SIZE
];
219 if (unarcfiledir(dir
,srcdir
,tempname
,file
))
221 AddPart(srcdir
,tempname
,256);
230 BOOL
unarcfiledir(const struct DirectoryWindow
*dir
, const char *path
, char *namebuf
, const char *file
)
237 struct xadFileInfo
*xfi
;
238 char arcname
[256], arcdir
[256], *c
;
239 int err
=XADERR_UNKNOWN
;
241 if (dir
->xai
->xai_Flags
& XADAIF_CRYPTED
)
243 D(bug("Encrypted archive!\n"));
244 if (dir
->arcpassword
[0] == 0) whatsit(globstring
[STR_ENTER_PASSWORD
],32,dir
->arcpassword
,NULL
);
247 strcpy(arcname
,dir
->arcname
);
248 D(bug("unarcfiledir: arcname = %s\n",arcname
));
250 c
= strstr(dir
->directory
,FilePart(arcname
));
251 if (c
) for (; c
&& (*c
!= '/'); c
++);
253 strcpy(arcdir
,c
?c
:"");
255 D(bug("unarcfiledir: arcdir = %s\n",arcdir
));
262 //D(bug("Get dir: %s\n",dir->directory));
263 strcpy(arcname, dir->directory);
264 if (i = strlen(arcname)) if (arcname[i-1] == '/') arcname[i-1] = 0;
265 while(!(lock = Lock(arcname, ACCESS_READ)))
267 c = FilePart(arcname);
268 if (c > arcname) *(c-1) = 0;
269 strcpy(arcdir,dir->directory+(int)c-(int)arcname);
274 AddPart(arcdir
,file
,256);
275 strcpy(namebuf
,"dopustmp");
276 lsprintf(arcname
,"%04lx",GetUniqueID());
277 strcat(namebuf
,arcname
);
278 c
= strchr(file
,'.');
279 if (c
) strcat(namebuf
,c
);
280 strcpy(arcname
,path
);
281 strcat(arcname
,namebuf
);
282 for (xfi
= dir
->xai
->xai_FileInfo
; xfi
; xfi
= xfi
->xfi_Next
)
283 if (LStrCmpI(xfi
->xfi_FileName
,arcdir
) == 0)
286 if (xfi
) while(err
!= XADERR_OK
)
288 err
= xadFileUnArc(dir
->xai
,XAD_ENTRYNUMBER
, xfi
->xfi_EntryNumber
,
289 XAD_OUTFILENAME
, (IPTR
)arcname
,
290 dir
->arcpassword
[0]?XAD_PASSWORD
:TAG_IGNORE
, dir
->arcpassword
,
298 xadConvertDates(XAD_DATEXADDATE
, (Tag
)&xfi
->xfi_Date
, XAD_GETDATEDATESTAMP
, (Tag
)&ds
, TAG_END
);
299 SetFileDate(arcname
,&ds
);
300 SetProtection(arcname
,xfi
->xfi_Protection
);
301 if (xfi
->xfi_Comment
) SetComment(arcname
,xfi
->xfi_Comment
);
303 strcpy(str_arcorgname
,file
);
304 D(bug("str_arcorgname set\n"));
307 case XADERR_PASSWORD
:
308 if (!(whatsit(globstring
[STR_ENTER_PASSWORD
],32,dir
->arcpassword
,NULL
)))
312 D(bug("XADERR: %ld\n",err
);)
322 void removetemparcfile(const char *name
)
324 if (str_arcorgname
[0])
326 D(bug("removetemparcfile(%s)\n",name
));
329 D(bug("str_arcorgname cleared\n"));
333 void arcfillfib(struct FileInfoBlock
*fib
, struct Directory
*entry
)
335 if (entry
== NULL
) return;
336 D(bug("arcfillfib: %s (%s)\n",entry
->name
?entry
->name
:"<NULL>",entry
->comment
?entry
->comment
:"<NULL>"));
337 fib
->fib_DirEntryType
= entry
->/*sub*/type
;
338 strcpy(fib
->fib_FileName
,entry
->name
);
339 fib
->fib_Protection
= entry
->protection
;
340 fib
->fib_Size
= (int)entry
->size
;
341 fib
->fib_Date
= entry
->date
;
342 if (entry
->comment
) strcpy(fib
->fib_Comment
,entry
->comment
);
343 else fib
->fib_Comment
[0] = 0;
344 fib
->fib_OwnerUID
= entry
->owner_id
;
345 fib
->fib_OwnerGID
= entry
->group_id
;