7zItem.c 2.9 KB

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