aboutsummaryrefslogtreecommitdiff
path: root/CPP/7zip/Archive/Wim/WimHandlerOut.cpp
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--CPP/7zip/Archive/Wim/WimHandlerOut.cpp101
1 files changed, 32 insertions, 69 deletions
diff --git a/CPP/7zip/Archive/Wim/WimHandlerOut.cpp b/CPP/7zip/Archive/Wim/WimHandlerOut.cpp
index 5d9dea2..3b2cb31 100644
--- a/CPP/7zip/Archive/Wim/WimHandlerOut.cpp
+++ b/CPP/7zip/Archive/Wim/WimHandlerOut.cpp
@@ -20,6 +20,8 @@
20#include "../../Crypto/RandGen.h" 20#include "../../Crypto/RandGen.h"
21#include "../../Crypto/Sha1Cls.h" 21#include "../../Crypto/Sha1Cls.h"
22 22
23#include "../Common/OutStreamWithSha1.h"
24
23#include "WimHandler.h" 25#include "WimHandler.h"
24 26
25using namespace NWindows; 27using namespace NWindows;
@@ -345,40 +347,6 @@ void CStreamInfo::WriteTo(Byte *p) const
345} 347}
346 348
347 349
348Z7_CLASS_IMP_NOQIB_1(
349 CInStreamWithSha1
350 , ISequentialInStream
351)
352 CMyComPtr<ISequentialInStream> _stream;
353 UInt64 _size;
354 // NCrypto::NSha1::CContext _sha;
355 CAlignedBuffer1 _sha;
356 CSha1 *Sha() { return (CSha1 *)(void *)(Byte *)_sha; }
357public:
358 CInStreamWithSha1(): _sha(sizeof(CSha1)) {}
359 void SetStream(ISequentialInStream *stream) { _stream = stream; }
360 void Init()
361 {
362 _size = 0;
363 Sha1_Init(Sha());
364 }
365 void ReleaseStream() { _stream.Release(); }
366 UInt64 GetSize() const { return _size; }
367 void Final(Byte *digest) { Sha1_Final(Sha(), digest); }
368};
369
370Z7_COM7F_IMF(CInStreamWithSha1::Read(void *data, UInt32 size, UInt32 *processedSize))
371{
372 UInt32 realProcessedSize;
373 const HRESULT result = _stream->Read(data, size, &realProcessedSize);
374 _size += realProcessedSize;
375 Sha1_Update(Sha(), (const Byte *)data, realProcessedSize);
376 if (processedSize)
377 *processedSize = realProcessedSize;
378 return result;
379}
380
381
382static void SetFileTimeToMem(Byte *p, const FILETIME &ft) 350static void SetFileTimeToMem(Byte *p, const FILETIME &ft)
383{ 351{
384 Set32(p, ft.dwLowDateTime) 352 Set32(p, ft.dwLowDateTime)
@@ -599,14 +567,14 @@ void CDb::WriteOrderList(const CDir &tree)
599 567
600static void AddTag_ToString(AString &s, const char *name, const char *value) 568static void AddTag_ToString(AString &s, const char *name, const char *value)
601{ 569{
602 s += '<'; 570 s.Add_Char('<');
603 s += name; 571 s += name;
604 s += '>'; 572 s.Add_Char('>');
605 s += value; 573 s += value;
606 s += '<'; 574 s.Add_Char('<');
607 s += '/'; 575 s.Add_Slash();
608 s += name; 576 s += name;
609 s += '>'; 577 s.Add_Char('>');
610} 578}
611 579
612 580
@@ -620,7 +588,7 @@ static void AddTagUInt64_ToString(AString &s, const char *name, UInt64 value)
620 588
621static CXmlItem &AddUniqueTag(CXmlItem &parentItem, const char *name) 589static CXmlItem &AddUniqueTag(CXmlItem &parentItem, const char *name)
622{ 590{
623 int index = parentItem.FindSubTag(name); 591 const int index = parentItem.FindSubTag(name);
624 if (index < 0) 592 if (index < 0)
625 { 593 {
626 CXmlItem &subItem = parentItem.SubItems.AddNew(); 594 CXmlItem &subItem = parentItem.SubItems.AddNew();
@@ -679,8 +647,7 @@ static void AddTag_Time(CXmlItem &parentItem, const char *name, const FILETIME &
679 647
680static void AddTag_String_IfEmpty(CXmlItem &parentItem, const char *name, const char *value) 648static void AddTag_String_IfEmpty(CXmlItem &parentItem, const char *name, const char *value)
681{ 649{
682 int index = parentItem.FindSubTag(name); 650 if (parentItem.FindSubTag(name) >= 0)
683 if (index >= 0)
684 return; 651 return;
685 CXmlItem &tag = parentItem.SubItems.AddNew(); 652 CXmlItem &tag = parentItem.SubItems.AddNew();
686 tag.IsTag = true; 653 tag.IsTag = true;
@@ -1094,7 +1061,7 @@ Z7_COM7F_IMF(CHandler::UpdateItems(ISequentialOutStream *outSeqStream, UInt32 nu
1094 { 1061 {
1095 for (;;) 1062 for (;;)
1096 { 1063 {
1097 wchar_t c = *path++; 1064 const wchar_t c = *path++;
1098 if (c == 0) 1065 if (c == 0)
1099 break; 1066 break;
1100 if (c == WCHAR_PATH_SEPARATOR || c == L'/') 1067 if (c == WCHAR_PATH_SEPARATOR || c == L'/')
@@ -1382,12 +1349,9 @@ Z7_COM7F_IMF(CHandler::UpdateItems(ISequentialOutStream *outSeqStream, UInt32 nu
1382 RINOK(callback->SetTotal(complexity)) 1349 RINOK(callback->SetTotal(complexity))
1383 UInt64 totalComplexity = complexity; 1350 UInt64 totalComplexity = complexity;
1384 1351
1385 NCompress::CCopyCoder *copyCoderSpec = new NCompress::CCopyCoder; 1352 CMyComPtr2_Create<ICompressProgressInfo, CLocalProgress> lps;
1386 CMyComPtr<ICompressCoder> copyCoder = copyCoderSpec;
1387
1388 CLocalProgress *lps = new CLocalProgress;
1389 CMyComPtr<ICompressProgressInfo> progress = lps;
1390 lps->Init(callback, true); 1353 lps->Init(callback, true);
1354 CMyComPtr2_Create<ICompressCoder, NCompress::CCopyCoder> copyCoder;
1391 1355
1392 complexity = 0; 1356 complexity = 0;
1393 1357
@@ -1419,8 +1383,7 @@ Z7_COM7F_IMF(CHandler::UpdateItems(ISequentialOutStream *outSeqStream, UInt32 nu
1419 1383
1420 UInt64 curPos = kHeaderSizeMax; 1384 UInt64 curPos = kHeaderSizeMax;
1421 1385
1422 CInStreamWithSha1 *inShaStreamSpec = new CInStreamWithSha1; 1386 CMyComPtr2_Create<ISequentialInStream, CInStreamWithSha1> inShaStream;
1423 CMyComPtr<ISequentialInStream> inShaStream = inShaStreamSpec;
1424 1387
1425 CLimitedSequentialInStream *inStreamLimitedSpec = NULL; 1388 CLimitedSequentialInStream *inStreamLimitedSpec = NULL;
1426 CMyComPtr<ISequentialInStream> inStreamLimited; 1389 CMyComPtr<ISequentialInStream> inStreamLimited;
@@ -1492,7 +1455,7 @@ Z7_COM7F_IMF(CHandler::UpdateItems(ISequentialOutStream *outSeqStream, UInt32 nu
1492 1455
1493 if (!rs.IsSolid() || rs.IsSolidSmall()) 1456 if (!rs.IsSolid() || rs.IsSolidSmall())
1494 { 1457 {
1495 const int find = AddUniqHash(&streams.Front(), sortedHashes, siOld.Hash, (int)streamIndex); 1458 const int find = AddUniqHash(streams.ConstData(), sortedHashes, siOld.Hash, (int)streamIndex);
1496 if (find != -1) 1459 if (find != -1)
1497 return E_FAIL; // two streams with same SHA-1 1460 return E_FAIL; // two streams with same SHA-1
1498 } 1461 }
@@ -1501,8 +1464,8 @@ Z7_COM7F_IMF(CHandler::UpdateItems(ISequentialOutStream *outSeqStream, UInt32 nu
1501 { 1464 {
1502 RINOK(InStream_SeekSet(_volumes[siOld.PartNumber].Stream, rs.Offset)) 1465 RINOK(InStream_SeekSet(_volumes[siOld.PartNumber].Stream, rs.Offset))
1503 inStreamLimitedSpec->Init(rs.PackSize); 1466 inStreamLimitedSpec->Init(rs.PackSize);
1504 RINOK(copyCoder->Code(inStreamLimited, outStream, NULL, NULL, progress)) 1467 RINOK(copyCoder.Interface()->Code(inStreamLimited, outStream, NULL, NULL, lps))
1505 if (copyCoderSpec->TotalSize != rs.PackSize) 1468 if (copyCoder->TotalSize != rs.PackSize)
1506 return E_FAIL; 1469 return E_FAIL;
1507 s.Resource.Offset = curPos; 1470 s.Resource.Offset = curPos;
1508 curPos += rs.PackSize; 1471 curPos += rs.PackSize;
@@ -1564,7 +1527,7 @@ Z7_COM7F_IMF(CHandler::UpdateItems(ISequentialOutStream *outSeqStream, UInt32 nu
1564 1527
1565 const CStreamInfo &siOld = _db.DataStreams[item.StreamIndex]; 1528 const CStreamInfo &siOld = _db.DataStreams[item.StreamIndex];
1566 1529
1567 const int index = AddUniqHash(&streams.Front(), sortedHashes, siOld.Hash, -1); 1530 const int index = AddUniqHash(streams.ConstData(), sortedHashes, siOld.Hash, -1);
1568 // we must have written that stream already 1531 // we must have written that stream already
1569 if (index == -1) 1532 if (index == -1)
1570 return E_FAIL; 1533 return E_FAIL;
@@ -1655,7 +1618,7 @@ Z7_COM7F_IMF(CHandler::UpdateItems(ISequentialOutStream *outSeqStream, UInt32 nu
1655 Byte hash[kHashSize]; 1618 Byte hash[kHashSize];
1656 sha1.Final(hash); 1619 sha1.Final(hash);
1657 1620
1658 int index = AddUniqHash(&streams.Front(), sortedHashes, hash, (int)streams.Size()); 1621 int index = AddUniqHash(streams.ConstData(), sortedHashes, hash, (int)streams.Size());
1659 1622
1660 if (index != -1) 1623 if (index != -1)
1661 streams[index].RefCount++; 1624 streams[index].RefCount++;
@@ -1684,13 +1647,13 @@ Z7_COM7F_IMF(CHandler::UpdateItems(ISequentialOutStream *outSeqStream, UInt32 nu
1684 } 1647 }
1685 else 1648 else
1686 { 1649 {
1687 inShaStreamSpec->SetStream(fileInStream); 1650 inShaStream->SetStream(fileInStream);
1688 1651
1689 CMyComPtr<IInStream> inSeekStream; 1652 CMyComPtr<IInStream> inSeekStream;
1690 fileInStream.QueryInterface(IID_IInStream, (void **)&inSeekStream); 1653 fileInStream.QueryInterface(IID_IInStream, (void **)&inSeekStream);
1691 1654
1692 fileInStream.Release(); 1655 fileInStream.Release();
1693 inShaStreamSpec->Init(); 1656 inShaStream->Init();
1694 UInt64 offsetBlockSize = 0; 1657 UInt64 offsetBlockSize = 0;
1695 /* 1658 /*
1696 if (useResourceCompression) 1659 if (useResourceCompression)
@@ -1711,16 +1674,16 @@ Z7_COM7F_IMF(CHandler::UpdateItems(ISequentialOutStream *outSeqStream, UInt32 nu
1711 1674
1712 if (inSeekStream /* && !sortedHashes.IsEmpty() */) 1675 if (inSeekStream /* && !sortedHashes.IsEmpty() */)
1713 { 1676 {
1714 RINOK(copyCoder->Code(inShaStream, NULL, NULL, NULL, progress)) 1677 RINOK(copyCoder.Interface()->Code(inShaStream, NULL, NULL, NULL, lps))
1715 size = copyCoderSpec->TotalSize; 1678 size = copyCoder->TotalSize;
1716 if (size == 0) 1679 if (size == 0)
1717 needWritePass = false; 1680 needWritePass = false;
1718 else 1681 else
1719 { 1682 {
1720 Byte hash[kHashSize]; 1683 Byte hash[kHashSize];
1721 inShaStreamSpec->Final(hash); 1684 inShaStream->Final(hash);
1722 1685
1723 index = AddUniqHash(&streams.Front(), sortedHashes, hash, -1); 1686 index = AddUniqHash(streams.ConstData(), sortedHashes, hash, -1);
1724 if (index != -1) 1687 if (index != -1)
1725 { 1688 {
1726 streams[index].RefCount++; 1689 streams[index].RefCount++;
@@ -1729,15 +1692,15 @@ Z7_COM7F_IMF(CHandler::UpdateItems(ISequentialOutStream *outSeqStream, UInt32 nu
1729 else 1692 else
1730 { 1693 {
1731 RINOK(InStream_SeekToBegin(inSeekStream)) 1694 RINOK(InStream_SeekToBegin(inSeekStream))
1732 inShaStreamSpec->Init(); 1695 inShaStream->Init();
1733 } 1696 }
1734 } 1697 }
1735 } 1698 }
1736 1699
1737 if (needWritePass) 1700 if (needWritePass)
1738 { 1701 {
1739 RINOK(copyCoder->Code(inShaStream, outStream, NULL, NULL, progress)) 1702 RINOK(copyCoder.Interface()->Code(inShaStream, outStream, NULL, NULL, lps))
1740 size = copyCoderSpec->TotalSize; 1703 size = copyCoder->TotalSize;
1741 } 1704 }
1742 1705
1743 if (size != 0) 1706 if (size != 0)
@@ -1746,9 +1709,9 @@ Z7_COM7F_IMF(CHandler::UpdateItems(ISequentialOutStream *outSeqStream, UInt32 nu
1746 { 1709 {
1747 Byte hash[kHashSize]; 1710 Byte hash[kHashSize];
1748 const UInt64 packSize = offsetBlockSize + size; 1711 const UInt64 packSize = offsetBlockSize + size;
1749 inShaStreamSpec->Final(hash); 1712 inShaStream->Final(hash);
1750 1713
1751 index = AddUniqHash(&streams.Front(), sortedHashes, hash, (int)streams.Size()); 1714 index = AddUniqHash(streams.ConstData(), sortedHashes, hash, (int)streams.Size());
1752 1715
1753 if (index != -1) 1716 if (index != -1)
1754 { 1717 {
@@ -1805,8 +1768,8 @@ Z7_COM7F_IMF(CHandler::UpdateItems(ISequentialOutStream *outSeqStream, UInt32 nu
1805 1768
1806 RINOK(InStream_SeekSet(_volumes[1].Stream, s.Resource.Offset)) 1769 RINOK(InStream_SeekSet(_volumes[1].Stream, s.Resource.Offset))
1807 inStreamLimitedSpec->Init(s.Resource.PackSize); 1770 inStreamLimitedSpec->Init(s.Resource.PackSize);
1808 RINOK(copyCoder->Code(inStreamLimited, outStream, NULL, NULL, progress)) 1771 RINOK(copyCoder.Interface()->Code(inStreamLimited, outStream, NULL, NULL, lps))
1809 if (copyCoderSpec->TotalSize != s.Resource.PackSize) 1772 if (copyCoder->TotalSize != s.Resource.PackSize)
1810 return E_FAIL; 1773 return E_FAIL;
1811 1774
1812 s.Resource.Offset = curPos; 1775 s.Resource.Offset = curPos;
@@ -1874,7 +1837,7 @@ Z7_COM7F_IMF(CHandler::UpdateItems(ISequentialOutStream *outSeqStream, UInt32 nu
1874 Set32((Byte *)meta, (UInt32)pos) // size of security data 1837 Set32((Byte *)meta, (UInt32)pos) // size of security data
1875 } 1838 }
1876 1839
1877 db.Hashes = &streams.Front(); 1840 db.Hashes = streams.ConstData();
1878 db.WriteTree(tree, (Byte *)meta, pos); 1841 db.WriteTree(tree, (Byte *)meta, pos);
1879 1842
1880 { 1843 {