home *** CD-ROM | disk | FTP | other *** search
/ DOS/V Power Report 2000 March / VPR0003A.BIN / OLS / UNRAR32005 / unrar32005.lzh / src / arcinfo.cxx next >
C/C++ Source or Header  |  1998-03-23  |  3KB  |  139 lines

  1. /*
  2.  *   Copyright (c) 1998 T. Kamei (kamei@jsdlab.co.jp)
  3.  *
  4.  *   Permission to use, copy, modify, and distribute this software
  5.  * and its documentation for any purpose is hereby granted provided
  6.  * that the above copyright notice and this permission notice appear
  7.  * in all copies of the software and related documentation.
  8.  *
  9.  *                          NO WARRANTY
  10.  *
  11.  *   THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY WARRANTIES;
  12.  * WITHOUT EVEN THE IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS
  13.  * FOR A PARTICULAR PURPOSE.
  14.  */
  15.  
  16. #include "comm-arc.h"
  17. #include "unrarapi.h"
  18. #include "util.h"
  19. #include "arcinfo.h"
  20.  
  21. arcinfo *arcinfo::a_chain;
  22.  
  23. arcinfo *
  24. arcinfo::find (HARC harc)
  25. {
  26.   for (arcinfo *p = a_chain; p; p = p->a_next)
  27.     if ((arcinfo *)harc == p)
  28.       return p;
  29.   return 0;
  30. }
  31.  
  32. void
  33. arcinfo::cleanup ()
  34. {
  35.   while (a_chain)
  36.     delete a_chain;
  37. }
  38.  
  39. arcinfo::arcinfo ()
  40.      : a_hunrar (0)
  41. {
  42.   a_prev = 0;
  43.   a_next = a_chain;
  44.   if (a_next)
  45.     a_next->a_prev = this;
  46.   a_chain = this;
  47. }
  48.  
  49. arcinfo::~arcinfo ()
  50. {
  51.   if (a_prev)
  52.     a_prev->a_next = a_next;
  53.   else
  54.     a_chain = a_next;
  55.   if (a_next)
  56.     a_next->a_prev = a_prev;
  57.   close ();
  58. }
  59.  
  60. int
  61. arcinfo::open (const char *path, DWORD mode)
  62. {
  63.   WIN32_FIND_DATA fd;
  64.   HANDLE h = FindFirstFile (path, &fd);
  65.   if (!h)
  66.     return 0;
  67.   FindClose (h);
  68.   strcpy (a_arcpath, path);
  69.   a_mode = mode;
  70.   a_arcsize = fd.nFileSizeLow;
  71.   FILETIME lt;
  72.   FileTimeToLocalFileTime (&fd.ftLastWriteTime, <);
  73.   if (!FileTimeToDosDateTime (<, &a_arcdate, &a_arctime))
  74.     a_arcdate = a_arctime = WORD (-1);
  75.   a_sfx = file_executable_p (path) ? SFX_WIN32_UNKNOWN : 0;
  76.  
  77.   a_orig_sz = 0;
  78.   a_comp_sz = 0;
  79.   a_first_time = 1;
  80.   a_valid = 0;
  81.   a_eof = 0;
  82.  
  83.   rarOpenArchiveData oad (path, RAR_OM_LIST);
  84.   a_hunrar = rarOpenArchive (&oad);
  85.   return int (a_hunrar);
  86. }
  87.  
  88. int
  89. arcinfo::close ()
  90. {
  91.   if (!a_hunrar)
  92.     return 0;
  93.   int e = rarCloseArchive (a_hunrar);
  94.   if (e)
  95.     return e;
  96.   a_hunrar = 0;
  97.   return 0;
  98. }
  99.  
  100. int
  101. arcinfo::findnext (INDIVIDUALINFO *vinfo, int skip)
  102. {
  103.   do
  104.     {
  105.       if (a_eof
  106.           || (skip && rarProcessFile (a_hunrar, RAR_SKIP, 0, 0))
  107.           || rarReadHeader (a_hunrar, &a_hd))
  108.         {
  109.           a_eof = 1;
  110.           a_valid = 0;
  111.           return -1;
  112.         }
  113.       skip = 1;
  114.       if (a_hd.Flags & FRAR_NEXTVOL)
  115.         a_eof = 1;
  116.     }
  117.   while (!a_glob.match (a_hd.FileName, a_mode & M_CHECK_ALL_PATH));
  118.  
  119.   a_orig_sz += a_hd.UnpSize;
  120.   a_comp_sz += a_hd.PackSize;
  121.   a_valid = 1;
  122.  
  123.   if (vinfo)
  124.     {
  125.       vinfo->dwOriginalSize = a_hd.UnpSize;
  126.       vinfo->dwCompressedSize = a_hd.PackSize;
  127.       vinfo->dwCRC = a_hd.FileCRC;
  128.       vinfo->uFlag = 0;
  129.       vinfo->uOSType = os_type (a_hd.HostOS);
  130.       vinfo->wRatio = calc_ratio (a_hd.PackSize, a_hd.UnpSize);
  131.       vinfo->wDate = HIWORD (a_hd.FileTime);
  132.       vinfo->wTime = LOWORD (a_hd.FileTime);
  133.       strcpy (vinfo->szFileName, a_hd.FileName);
  134.       strcpy (vinfo->szAttribute, attr_string (a_hd.FileAttr));
  135.       strcpy (vinfo->szMode, method_string (a_hd.Method));
  136.     }
  137.   return 0;
  138. }
  139.