1 // UpdateProduce.cpp
2 
3 #include "StdAfx.h"
4 
5 #include "UpdateProduce.h"
6 
7 using namespace NUpdateArchive;
8 
9 static const char *kUpdateActionSetCollision = "Internal collision in update action set";
10 
UpdateProduce(const CRecordVector<CUpdatePair> & updatePairs,const CActionSet & actionSet,CRecordVector<CUpdatePair2> & operationChain,IUpdateProduceCallback * callback)11 void UpdateProduce(
12     const CRecordVector<CUpdatePair> &updatePairs,
13     const CActionSet &actionSet,
14     CRecordVector<CUpdatePair2> &operationChain,
15     IUpdateProduceCallback *callback)
16 {
17   FOR_VECTOR (i, updatePairs)
18   {
19     const CUpdatePair &pair = updatePairs[i];
20 
21     CUpdatePair2 up2;
22     up2.DirIndex = pair.DirIndex;
23     up2.ArcIndex = pair.ArcIndex;
24     up2.NewData = up2.NewProps = true;
25     up2.UseArcProps = false;
26 
27     switch (actionSet.StateActions[pair.State])
28     {
29       case NPairAction::kIgnore:
30         /*
31         if (pair.State != NPairState::kOnlyOnDisk)
32           IgnoreArchiveItem(m_ArchiveItems[pair.ArcIndex]);
33         // cout << "deleting";
34         */
35         if (callback)
36           callback->ShowDeleteFile(pair.ArcIndex);
37         continue;
38 
39       case NPairAction::kCopy:
40         if (pair.State == NPairState::kOnlyOnDisk)
41           throw kUpdateActionSetCollision;
42         if (pair.State == NPairState::kOnlyInArchive)
43         {
44           if (pair.HostIndex >= 0)
45           {
46             /*
47               ignore alt stream if
48                 1) no such alt stream in Disk
49                 2) there is Host file in disk
50             */
51             if (updatePairs[pair.HostIndex].DirIndex >= 0)
52               continue;
53           }
54         }
55         up2.NewData = up2.NewProps = false;
56         up2.UseArcProps = true;
57         break;
58 
59       case NPairAction::kCompress:
60         if (pair.State == NPairState::kOnlyInArchive ||
61             pair.State == NPairState::kNotMasked)
62           throw kUpdateActionSetCollision;
63         break;
64 
65       case NPairAction::kCompressAsAnti:
66         up2.IsAnti = true;
67         up2.UseArcProps = (pair.ArcIndex >= 0);
68         break;
69     }
70     operationChain.Add(up2);
71   }
72   operationChain.ReserveDown();
73 }
74