home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
DOS/V Power Report 2000 March
/
VPR0003A.BIN
/
OLS
/
UNRAR32005
/
unrar32005.lzh
/
src
/
arcinfo.cxx
next >
Wrap
C/C++ Source or Header
|
1998-03-23
|
3KB
|
139 lines
/*
* Copyright (c) 1998 T. Kamei (kamei@jsdlab.co.jp)
*
* Permission to use, copy, modify, and distribute this software
* and its documentation for any purpose is hereby granted provided
* that the above copyright notice and this permission notice appear
* in all copies of the software and related documentation.
*
* NO WARRANTY
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY WARRANTIES;
* WITHOUT EVEN THE IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS
* FOR A PARTICULAR PURPOSE.
*/
#include "comm-arc.h"
#include "unrarapi.h"
#include "util.h"
#include "arcinfo.h"
arcinfo *arcinfo::a_chain;
arcinfo *
arcinfo::find (HARC harc)
{
for (arcinfo *p = a_chain; p; p = p->a_next)
if ((arcinfo *)harc == p)
return p;
return 0;
}
void
arcinfo::cleanup ()
{
while (a_chain)
delete a_chain;
}
arcinfo::arcinfo ()
: a_hunrar (0)
{
a_prev = 0;
a_next = a_chain;
if (a_next)
a_next->a_prev = this;
a_chain = this;
}
arcinfo::~arcinfo ()
{
if (a_prev)
a_prev->a_next = a_next;
else
a_chain = a_next;
if (a_next)
a_next->a_prev = a_prev;
close ();
}
int
arcinfo::open (const char *path, DWORD mode)
{
WIN32_FIND_DATA fd;
HANDLE h = FindFirstFile (path, &fd);
if (!h)
return 0;
FindClose (h);
strcpy (a_arcpath, path);
a_mode = mode;
a_arcsize = fd.nFileSizeLow;
FILETIME lt;
FileTimeToLocalFileTime (&fd.ftLastWriteTime, <);
if (!FileTimeToDosDateTime (<, &a_arcdate, &a_arctime))
a_arcdate = a_arctime = WORD (-1);
a_sfx = file_executable_p (path) ? SFX_WIN32_UNKNOWN : 0;
a_orig_sz = 0;
a_comp_sz = 0;
a_first_time = 1;
a_valid = 0;
a_eof = 0;
rarOpenArchiveData oad (path, RAR_OM_LIST);
a_hunrar = rarOpenArchive (&oad);
return int (a_hunrar);
}
int
arcinfo::close ()
{
if (!a_hunrar)
return 0;
int e = rarCloseArchive (a_hunrar);
if (e)
return e;
a_hunrar = 0;
return 0;
}
int
arcinfo::findnext (INDIVIDUALINFO *vinfo, int skip)
{
do
{
if (a_eof
|| (skip && rarProcessFile (a_hunrar, RAR_SKIP, 0, 0))
|| rarReadHeader (a_hunrar, &a_hd))
{
a_eof = 1;
a_valid = 0;
return -1;
}
skip = 1;
if (a_hd.Flags & FRAR_NEXTVOL)
a_eof = 1;
}
while (!a_glob.match (a_hd.FileName, a_mode & M_CHECK_ALL_PATH));
a_orig_sz += a_hd.UnpSize;
a_comp_sz += a_hd.PackSize;
a_valid = 1;
if (vinfo)
{
vinfo->dwOriginalSize = a_hd.UnpSize;
vinfo->dwCompressedSize = a_hd.PackSize;
vinfo->dwCRC = a_hd.FileCRC;
vinfo->uFlag = 0;
vinfo->uOSType = os_type (a_hd.HostOS);
vinfo->wRatio = calc_ratio (a_hd.PackSize, a_hd.UnpSize);
vinfo->wDate = HIWORD (a_hd.FileTime);
vinfo->wTime = LOWORD (a_hd.FileTime);
strcpy (vinfo->szFileName, a_hd.FileName);
strcpy (vinfo->szAttribute, attr_string (a_hd.FileAttr));
strcpy (vinfo->szMode, method_string (a_hd.Method));
}
return 0;
}