misc/libphysfs/lzma/C/Archive/7z/7zItem.c
changeset 12213 bb5522e88ab2
equal deleted inserted replaced
12212:ea891871f481 12213:bb5522e88ab2
       
     1 /* 7zItem.c */
       
     2 
       
     3 #include "7zItem.h"
       
     4 #include "7zAlloc.h"
       
     5 
       
     6 void SzCoderInfoInit(CCoderInfo *coder)
       
     7 {
       
     8   SzByteBufferInit(&coder->Properties);
       
     9 }
       
    10 
       
    11 void SzCoderInfoFree(CCoderInfo *coder, void (*freeFunc)(void *p))
       
    12 {
       
    13   SzByteBufferFree(&coder->Properties, freeFunc);
       
    14   SzCoderInfoInit(coder);
       
    15 }
       
    16 
       
    17 void SzFolderInit(CFolder *folder)
       
    18 {
       
    19   folder->NumCoders = 0;
       
    20   folder->Coders = 0;
       
    21   folder->NumBindPairs = 0;
       
    22   folder->BindPairs = 0;
       
    23   folder->NumPackStreams = 0;
       
    24   folder->PackStreams = 0;
       
    25   folder->UnPackSizes = 0;
       
    26   folder->UnPackCRCDefined = 0;
       
    27   folder->UnPackCRC = 0;
       
    28   folder->NumUnPackStreams = 0;
       
    29 }
       
    30 
       
    31 void SzFolderFree(CFolder *folder, void (*freeFunc)(void *p))
       
    32 {
       
    33   UInt32 i;
       
    34   for (i = 0; i < folder->NumCoders; i++)
       
    35     SzCoderInfoFree(&folder->Coders[i], freeFunc);
       
    36   freeFunc(folder->Coders);
       
    37   freeFunc(folder->BindPairs);
       
    38   freeFunc(folder->PackStreams);
       
    39   freeFunc(folder->UnPackSizes);
       
    40   SzFolderInit(folder);
       
    41 }
       
    42 
       
    43 UInt32 SzFolderGetNumOutStreams(CFolder *folder)
       
    44 {
       
    45   UInt32 result = 0;
       
    46   UInt32 i;
       
    47   for (i = 0; i < folder->NumCoders; i++)
       
    48     result += folder->Coders[i].NumOutStreams;
       
    49   return result;
       
    50 }
       
    51 
       
    52 int SzFolderFindBindPairForInStream(CFolder *folder, UInt32 inStreamIndex)
       
    53 {
       
    54   UInt32 i;
       
    55   for(i = 0; i < folder->NumBindPairs; i++)
       
    56     if (folder->BindPairs[i].InIndex == inStreamIndex)
       
    57       return i;
       
    58   return -1;
       
    59 }
       
    60 
       
    61 
       
    62 int SzFolderFindBindPairForOutStream(CFolder *folder, UInt32 outStreamIndex)
       
    63 {
       
    64   UInt32 i;
       
    65   for(i = 0; i < folder->NumBindPairs; i++)
       
    66     if (folder->BindPairs[i].OutIndex == outStreamIndex)
       
    67       return i;
       
    68   return -1;
       
    69 }
       
    70 
       
    71 CFileSize SzFolderGetUnPackSize(CFolder *folder)
       
    72 { 
       
    73   int i = (int)SzFolderGetNumOutStreams(folder);
       
    74   if (i == 0)
       
    75     return 0;
       
    76   for (i--; i >= 0; i--)
       
    77     if (SzFolderFindBindPairForOutStream(folder, i) < 0)
       
    78       return folder->UnPackSizes[i];
       
    79   /* throw 1; */
       
    80   return 0;
       
    81 }
       
    82 
       
    83 /*
       
    84 int FindPackStreamArrayIndex(int inStreamIndex) const
       
    85 {
       
    86   for(int i = 0; i < PackStreams.Size(); i++)
       
    87   if (PackStreams[i] == inStreamIndex)
       
    88     return i;
       
    89   return -1;
       
    90 }
       
    91 */
       
    92 
       
    93 void SzFileInit(CFileItem *fileItem)
       
    94 {
       
    95   fileItem->IsFileCRCDefined = 0;
       
    96   fileItem->HasStream = 1;
       
    97   fileItem->IsDirectory = 0;
       
    98   fileItem->IsAnti = 0;
       
    99   fileItem->IsLastWriteTimeDefined = 0;
       
   100   fileItem->Name = 0;
       
   101 }
       
   102 
       
   103 void SzFileFree(CFileItem *fileItem, void (*freeFunc)(void *p))
       
   104 {
       
   105   freeFunc(fileItem->Name);
       
   106   SzFileInit(fileItem);
       
   107 }
       
   108 
       
   109 void SzArchiveDatabaseInit(CArchiveDatabase *db)
       
   110 {
       
   111   db->NumPackStreams = 0;
       
   112   db->PackSizes = 0;
       
   113   db->PackCRCsDefined = 0;
       
   114   db->PackCRCs = 0;
       
   115   db->NumFolders = 0;
       
   116   db->Folders = 0;
       
   117   db->NumFiles = 0;
       
   118   db->Files = 0;
       
   119 }
       
   120 
       
   121 void SzArchiveDatabaseFree(CArchiveDatabase *db, void (*freeFunc)(void *))
       
   122 {
       
   123   UInt32 i;
       
   124   for (i = 0; i < db->NumFolders; i++)
       
   125     SzFolderFree(&db->Folders[i], freeFunc);
       
   126   for (i = 0; i < db->NumFiles; i++)
       
   127     SzFileFree(&db->Files[i], freeFunc);
       
   128   freeFunc(db->PackSizes);
       
   129   freeFunc(db->PackCRCsDefined);
       
   130   freeFunc(db->PackCRCs);
       
   131   freeFunc(db->Folders);
       
   132   freeFunc(db->Files);
       
   133   SzArchiveDatabaseInit(db);
       
   134 }