Moved DejaVue fonts to contrib. They are only needed by applications
[AROS-Contrib.git] / dopus / Program / archive.c
blob07a46054a7418ae91d7bde193c1d5f07ab32bd2c
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/xadmaster.h>
34 #endif
36 #define EXALL_NUM 2
38 int readarchive(struct DirectoryWindow *dir,int win)
40 #ifndef __AROS__
41 BPTR lock;
42 long len, i;
43 struct xadFileInfo *xfi;
44 struct DateStamp ds;
45 unsigned char arcname[256], arcdir[256], buf[FILEBUF_SIZE], *c;
46 int type;
48 strcpy(arcdir,"");
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);
61 len = strlen(arcdir);
62 //D(bug("arcdir: %s\n",arcdir));
63 UnLock(lock);
64 if (! dir->xai)
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)))
72 struct TagItem ti[2];
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)))
81 D(bug("done\n"));
82 if (dir->xai->xai_DiskInfo)
84 struct xadArchiveInfo *xai2;
85 int err;
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);
104 dir->xai = xai2;
106 else xadFreeInfo(xai2);
108 D(bug("err = %lx\n",err));
109 xadFreeObjectA(xai2, NULL);
112 dir->flags |= DWF_ARCHIVE;
114 else
116 D(bug("failed\n"));
117 xadFreeObjectA(dir->xai, NULL);
118 dir->xai = NULL;
119 FreeVec(dir->arcname);
120 dir->arcname = NULL;
121 return(0);
124 else
126 FreeVec(dir->arcname);
127 dir->arcname = NULL;
128 return(0);
131 else return(0);
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));
138 while (xfi)
140 //D(bug("Object: %s\n",xfi->xfi_FileName));
141 // if ((len == 0) || (strncmp(arcdir,xfi->xfi_FileName,len) != 0))
143 UBYTE c1,c2;
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++;
147 i=0;
150 c1 = ToLower(arcdir[i]);
151 c2 = ToLower(xfi->xfi_FileName[i]);
152 if (c1 == c2)
154 c++;
155 i++;
158 while (c1==c2);
160 if (i >= len)
162 for (i = 0; *c && (*c != '/') && (i < (FILEBUF_SIZE-1)); i++, c++) buf[i] = *c;
163 buf[i] = 0;
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;
170 else type = ST_FILE;
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,
178 type,
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");
188 return(1);
190 #endif
191 return(0);
194 void freearchive(struct DirectoryWindow *dir)
196 #ifndef __AROS__
197 if (dir->xai)
199 D(bug("Freeing dir->xai: %lx\n",dir->xai));
200 xadFreeInfo(dir->xai);
201 if (dir->arcname) FreeVec(dir->arcname);
202 dir->arcname = NULL;
203 xadFreeObject(dir->xai, TAG_END);
204 dir->xai = NULL;
205 dir->arcpassword[0]=0;
207 #endif
210 BOOL getsourcefromarc(struct DirectoryWindow *dir, char *buf, char *file)
212 #ifndef __AROS__
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];
218 strcpy(srcdir,"T:");
219 if (unarcfiledir(dir,srcdir,tempname,file))
221 AddPart(srcdir,tempname,256);
222 strcpy(buf,srcdir);
223 return TRUE;
226 #endif
227 return FALSE;
230 BOOL unarcfiledir(const struct DirectoryWindow *dir, const char *path, char *namebuf, const char *file)
232 #ifndef __AROS__
233 if (dir->xai)
235 if (dir->arcname)
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++);
252 if (c) c++;
253 strcpy(arcdir,c?c:"");
255 D(bug("unarcfiledir: arcdir = %s\n",arcdir));
257 else
259 BPTR lock;
261 strcpy(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);
271 UnLock(lock);
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)
284 break;
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,
291 TAG_END);
292 switch (err)
294 case XADERR_OK:
296 struct DateStamp ds;
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"));
305 return TRUE;
307 case XADERR_PASSWORD:
308 if (!(whatsit(globstring[STR_ENTER_PASSWORD],32,dir->arcpassword,NULL)))
309 return FALSE;
310 break;
311 default:
312 D(bug("XADERR: %ld\n",err);)
313 err = XADERR_OK;
318 #endif
319 return FALSE;
322 void removetemparcfile(const char *name)
324 if (str_arcorgname[0])
326 D(bug("removetemparcfile(%s)\n",name));
327 DeleteFile(name);
328 str_arcorgname[0]=0;
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;