| 1 |
//--------------------------------------------------------------------------- |
| 2 |
// PatchGenerator.h |
| 3 |
//--------------------------------------------------------------------------- |
| 4 |
// -=* VPatch *=- |
| 5 |
//--------------------------------------------------------------------------- |
| 6 |
// Copyright (C) 2001-2005 Koen van de Sande / Van de Sande Productions |
| 7 |
//--------------------------------------------------------------------------- |
| 8 |
// Website: http://www.tibed.net/vpatch |
| 9 |
// |
| 10 |
// This software is provided 'as-is', without any express or implied |
| 11 |
// warranty. In no event will the authors be held liable for any damages |
| 12 |
// arising from the use of this software. |
| 13 |
// |
| 14 |
// Permission is granted to anyone to use this software for any purpose, |
| 15 |
// including commercial applications, and to alter it and redistribute it |
| 16 |
// freely, subject to the following restrictions: |
| 17 |
// |
| 18 |
// 1. The origin of this software must not be misrepresented; you must not |
| 19 |
// claim that you wrote the original software. If you use this software |
| 20 |
// in a product, an acknowledgment in the product documentation would be |
| 21 |
// appreciated but is not required. |
| 22 |
// 2. Altered source versions must be plainly marked as such, and must not be |
| 23 |
// misrepresented as being the original software. |
| 24 |
// 3. This notice may not be removed or altered from any source distribution. |
| 25 |
// |
| 26 |
// Reviewed for Unicode support by Jim Park -- 08/29/2007 |
| 27 |
|
| 28 |
#if !defined(PatchGenerator_H) |
| 29 |
#define PatchGenerator_H |
| 30 |
|
| 31 |
#include <iostream> |
| 32 |
#include <vector> |
| 33 |
#include "GlobalTypes.h" |
| 34 |
#include "ChunkedFile.h" |
| 35 |
|
| 36 |
using namespace std; |
| 37 |
|
| 38 |
typedef struct SameBlock { |
| 39 |
TFileOffset sourceOffset; |
| 40 |
TFileOffset targetOffset; |
| 41 |
TFileOffset size; |
| 42 |
} SameBlock; |
| 43 |
|
| 44 |
class PatchGenerator { |
| 45 |
protected: |
| 46 |
bistream& source; |
| 47 |
TFileOffset sourceSize; |
| 48 |
bistream& target; |
| 49 |
TFileOffset targetSize; |
| 50 |
bostream& patch; |
| 51 |
|
| 52 |
// cache |
| 53 |
unsigned char* targetCData; |
| 54 |
TFileOffset targetCDataBaseOffset; |
| 55 |
TFileOffset targetCDataSize; |
| 56 |
|
| 57 |
SameBlock* findBlock(ChunkedFile* sourceTree, |
| 58 |
TFileOffset targetFileStartOffset); |
| 59 |
// SameBlock* findBlock(ChunkedFile* sourceTree, unsigned char* targetData, TFileOffset targetStartOffset); |
| 60 |
void improveSameBlockMatch(SameBlock& match, TFileOffset currentBest = 0); |
| 61 |
public: |
| 62 |
TFileOffset blockSize; |
| 63 |
int maxMatches; |
| 64 |
bool beVerbose; |
| 65 |
|
| 66 |
// load in the source, target streams |
| 67 |
PatchGenerator(bistream& source, TFileOffset sourceSize, bistream& target, TFileOffset targetSize, bostream& patch); |
| 68 |
~PatchGenerator(); |
| 69 |
|
| 70 |
// construct the actual patch |
| 71 |
void execute(vector<SameBlock*>& sameBlocks); |
| 72 |
}; |
| 73 |
|
| 74 |
#endif // PatchGenerator_H |