Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 14 additions & 11 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,19 @@ else
CXXFLAGS += -fvisibility-inlines-hidden
endif

ifeq ($(BSD),0)
DEF_FLAGS += -D_IS_NEED_BSDIFF=0
else
DEF_FLAGS += -D_IS_NEED_BSDIFF=1
endif
ifeq ($(VCD),0)
DEF_FLAGS += -D_IS_NEED_VCDIFF=0
else
DEF_FLAGS += -D_IS_NEED_VCDIFF=1
endif

UTEST_FLAGS := $(DEF_FLAGS)

ifeq ($(BZIP2),0)
else
DEF_FLAGS += -D_CompressPlugin_bz2
Expand Down Expand Up @@ -335,16 +348,6 @@ else
DEF_FLAGS += -D_ChecksumPlugin_xxh3 -D_ChecksumPlugin_xxh128 -I$(XXH_PATH)
endif
endif
ifeq ($(BSD),0)
DEF_FLAGS += -D_IS_NEED_BSDIFF=0
else
DEF_FLAGS += -D_IS_NEED_BSDIFF=1
endif
ifeq ($(VCD),0)
DEF_FLAGS += -D_IS_NEED_VCDIFF=0
else
DEF_FLAGS += -D_IS_NEED_VCDIFF=1
endif
ifeq ($(LZMA),0)
else
DEF_FLAGS += -D_CompressPlugin_lzma -D_CompressPlugin_lzma2
Expand Down Expand Up @@ -446,7 +449,7 @@ hpatchz: $(HPATCH_OBJ)
hdiffz: libhdiffpatch.a
$(CXX) hdiffz.cpp libhdiffpatch.a $(CXXFLAGS) $(DIFF_LINK) -o hdiffz
unit_test: libhdiffpatch.a
$(CXX) ./test/unit_test.cpp libhdiffpatch.a $(DIFF_LINK) -o unit_test
$(CXX) ./test/unit_test.cpp libhdiffpatch.a $(UTEST_FLAGS) $(DIFF_LINK) -o unit_test

ifeq ($(OS),Windows_NT) # mingw?
RM := del /Q /F
Expand Down
261 changes: 133 additions & 128 deletions README.md

Large diffs are not rendered by default.

264 changes: 135 additions & 129 deletions README_cn.md

Large diffs are not rendered by default.

25 changes: 11 additions & 14 deletions bsdiff_wrapper/bspatch_wrapper.c
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ hpatch_BOOL getBsDiffInfo(hpatch_BsDiffInfo* out_diffinfo,const hpatch_TStreamIn
}
return (out_diffinfo->ctrlDataSize<diffStream->streamSize)&&
(out_diffinfo->subDataSize<diffStream->streamSize)&&
(out_diffinfo->headSize+out_diffinfo->ctrlDataSize+out_diffinfo->subDataSize<diffStream->streamSize);
(out_diffinfo->headSize+out_diffinfo->ctrlDataSize+out_diffinfo->subDataSize<=diffStream->streamSize);
}

hpatch_BOOL getBsDiffInfo_mem(hpatch_BsDiffInfo* out_diffinfo,const unsigned char* diffData,const unsigned char* diffData_end){
Expand Down Expand Up @@ -185,6 +185,11 @@ hpatch_BOOL bspatchByClip(_TOutStreamCache* outCache,const hpatch_TStreamInput*
static const hpatch_uint64_t _kUnknowMaxSize=~(hpatch_uint64_t)0;
#define _clear_return(exitValue) { result=exitValue; goto clear; }

#define _getStreamClip(_diffClip,_decompresser,_dataSize) \
getStreamClip(_diffClip,_decompresser, \
decompressPlugin?_kUnknowMaxSize:(_dataSize),decompressPlugin?(_dataSize):0, \
compressedDiff,&diffPos0,decompressPlugin,temp_cache,cacheSize)

hpatch_BOOL bspatch_with_cache(const hpatch_TStreamOutput* out_newData,
const hpatch_TStreamInput* oldData,
const hpatch_TStreamInput* compressedDiff,
Expand All @@ -202,7 +207,7 @@ hpatch_BOOL bspatch_with_cache(const hpatch_TStreamOutput* out_newData,
hpatch_StreamPos_t diffPos0;
hpatch_size_t cacheSize;
hpatch_BOOL isReadError=hpatch_FALSE;
assert(decompressPlugin!=0);
//assert(decompressPlugin!=0);
assert(out_newData!=0);
assert(out_newData->write!=0);
assert(oldData!=0);
Expand All @@ -224,24 +229,16 @@ hpatch_BOOL bspatch_with_cache(const hpatch_TStreamOutput* out_newData,

diffPos0=diffInfo.headSize;
if (diffInfo.isEndsleyBsdiff){
if (!getStreamClip(&newDataDiffClip,&decompressers[0],
_kUnknowMaxSize,compressedDiff->streamSize-diffPos0,compressedDiff,&diffPos0,
decompressPlugin,temp_cache,cacheSize)) _clear_return(_hpatch_FALSE);
if (!_getStreamClip(&newDataDiffClip,&decompressers[0],compressedDiff->streamSize-diffPos0)) _clear_return(_hpatch_FALSE);
temp_cache+=cacheSize;
_ctrlClip=&newDataDiffClip;
_subClip=&newDataDiffClip;
}else{
if (!getStreamClip(&ctrlClip,&decompressers[0],
_kUnknowMaxSize,diffInfo.ctrlDataSize,compressedDiff,&diffPos0,
decompressPlugin,temp_cache,cacheSize)) _clear_return(_hpatch_FALSE);
if (!_getStreamClip(&ctrlClip,&decompressers[0],diffInfo.ctrlDataSize)) _clear_return(_hpatch_FALSE);
temp_cache+=cacheSize;
if (!getStreamClip(&subClip,&decompressers[1],
_kUnknowMaxSize,diffInfo.subDataSize,compressedDiff,&diffPos0,
decompressPlugin,temp_cache,cacheSize)) _clear_return(_hpatch_FALSE);
if (!_getStreamClip(&subClip,&decompressers[1],diffInfo.subDataSize)) _clear_return(_hpatch_FALSE);
temp_cache+=cacheSize;
if (!getStreamClip(&newDataDiffClip,&decompressers[2],
_kUnknowMaxSize,compressedDiff->streamSize-diffPos0,compressedDiff,&diffPos0,
decompressPlugin,temp_cache,cacheSize)) _clear_return(_hpatch_FALSE);
if (!_getStreamClip(&newDataDiffClip,&decompressers[2],compressedDiff->streamSize-diffPos0)) _clear_return(_hpatch_FALSE);
temp_cache+=cacheSize;
}
assert(diffPos0==compressedDiff->streamSize);
Expand Down
1 change: 1 addition & 0 deletions builds/android_ndk_jni_mk/hpatch.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ extern "C" {
// cacheMemory:
// cacheMemory is used for file IO, different cacheMemory only affects patch speed;
// recommended 1M,8M,... if cacheMemory<0 then default 1024*1024*4;
// isChecksumNewData: 0 or 1, recommended 1; auto checksum newData when patching VCDIFF and window diffData;
int hpatchz(const char *oldFileName,const char *diffFileName,const char *outNewFileName,
int64_t cacheMemory,size_t threadNum,unsigned int isChecksumNewData) H_PATCH_EXPORT;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class HPatch{
// if need supported oldFileName or outNewFileName is directory, build .so with DIR=1 can opened;
// threadNum: 1..5, default 1; >1 opened multi-thread patching;
// now support single compressed diffData(created by hdiffz -SD) & window diffData(created by hdiffz -WD, recommended)
// isChecksumNewData: default true; checsum newData when patching VCDIFF and window diffData;
// isChecksumNewData: default true; auto checksum newData when patching VCDIFF and window diffData;
public static native int patch(String oldFileName,String diffFileName,String outNewFileName,long cacheMemory,int _threadNum,boolean isChecksumNewData);
public static final int patch(String oldFileName,String diffFileName,String outNewFileName,long cacheMemory,int _threadNum){
return patch(oldFileName,diffFileName,outNewFileName,cacheMemory,_threadNum,true);
Expand Down
4 changes: 4 additions & 0 deletions builds/vc/unitTest.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,8 @@
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="..\..\bsdiff_wrapper\bsdiff_wrapper.cpp" />
<ClCompile Include="..\..\bsdiff_wrapper\bspatch_wrapper.c" />
<ClCompile Include="..\..\dirDiffPatch\dir_diff\dir_diff_tools.cpp" />
<ClCompile Include="..\..\dirDiffPatch\dir_patch\dir_patch_tools.c" />
<ClCompile Include="..\..\dirDiffPatch\dir_patch\ref_stream.c" />
Expand Down Expand Up @@ -276,6 +278,8 @@
<ClCompile Include="..\..\libParallel\parallel_channel.cpp" />
<ClCompile Include="..\..\libParallel\parallel_import_c.c" />
<ClCompile Include="..\..\test\unit_test.cpp" />
<ClCompile Include="..\..\vcdiff_wrapper\vcdiff_wrapper.cpp" />
<ClCompile Include="..\..\vcdiff_wrapper\vcpatch_wrapper.c" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\libHDiffPatch\HPatch\patch.h" />
Expand Down
16 changes: 16 additions & 0 deletions builds/xcode/unitTest.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@
0D99CCBC2FD6CF0E005CC92A /* window_matcher.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 0D99CCB92FD6CF0E005CC92A /* window_matcher.cpp */; };
0D99CCBD2FD6CF0E005CC92A /* covers_range.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 0D99CCBA2FD6CF0E005CC92A /* covers_range.cpp */; };
0D99CCC42FE9004E005CC92A /* _hcache_window_old_mt.c in Sources */ = {isa = PBXBuildFile; fileRef = 0D99CCBF2FE8FD4D005CC92A /* _hcache_window_old_mt.c */; };
0D99CCF02FF4CE4B005CC92A /* bsdiff_wrapper.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 0D99CCEE2FF4CE4B005CC92A /* bsdiff_wrapper.cpp */; };
0D99CCF12FF4CE4B005CC92A /* bspatch_wrapper.c in Sources */ = {isa = PBXBuildFile; fileRef = 0D99CCEF2FF4CE4B005CC92A /* bspatch_wrapper.c */; };
0D99CCF42FF4CE5C005CC92A /* vcdiff_wrapper.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 0D99CCF22FF4CE5C005CC92A /* vcdiff_wrapper.cpp */; };
0D99CCF52FF4CE5C005CC92A /* vcpatch_wrapper.c in Sources */ = {isa = PBXBuildFile; fileRef = 0D99CCF32FF4CE5C005CC92A /* vcpatch_wrapper.c */; };
0DA686642E536CB4002A6651 /* _hpatch_mt.c in Sources */ = {isa = PBXBuildFile; fileRef = 0DA686352E536964002A6651 /* _hpatch_mt.c */; };
0DA686652E536CB4002A6651 /* hpatch_mt.c in Sources */ = {isa = PBXBuildFile; fileRef = 0DA686372E536964002A6651 /* hpatch_mt.c */; };
0DA686662E536CB4002A6651 /* _houtput_mt.c in Sources */ = {isa = PBXBuildFile; fileRef = 0DA686382E536964002A6651 /* _houtput_mt.c */; };
Expand Down Expand Up @@ -92,6 +96,10 @@
0D99CCBA2FD6CF0E005CC92A /* covers_range.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = covers_range.cpp; sourceTree = "<group>"; };
0D99CCBE2FE8FD3E005CC92A /* _hcache_window_old_mt.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = _hcache_window_old_mt.h; sourceTree = "<group>"; };
0D99CCBF2FE8FD4D005CC92A /* _hcache_window_old_mt.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = _hcache_window_old_mt.c; sourceTree = "<group>"; };
0D99CCEE2FF4CE4B005CC92A /* bsdiff_wrapper.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = bsdiff_wrapper.cpp; path = ../../bsdiff_wrapper/bsdiff_wrapper.cpp; sourceTree = "<group>"; };
0D99CCEF2FF4CE4B005CC92A /* bspatch_wrapper.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = bspatch_wrapper.c; path = ../../bsdiff_wrapper/bspatch_wrapper.c; sourceTree = "<group>"; };
0D99CCF22FF4CE5C005CC92A /* vcdiff_wrapper.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = vcdiff_wrapper.cpp; path = ../../vcdiff_wrapper/vcdiff_wrapper.cpp; sourceTree = "<group>"; };
0D99CCF32FF4CE5C005CC92A /* vcpatch_wrapper.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = vcpatch_wrapper.c; path = ../../vcdiff_wrapper/vcpatch_wrapper.c; sourceTree = "<group>"; };
0DA686352E536964002A6651 /* _hpatch_mt.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = _hpatch_mt.c; sourceTree = "<group>"; };
0DA686362E536964002A6651 /* _hinput_mt.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = _hinput_mt.h; sourceTree = "<group>"; };
0DA686372E536964002A6651 /* hpatch_mt.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = hpatch_mt.c; sourceTree = "<group>"; };
Expand Down Expand Up @@ -206,6 +214,10 @@
0D3D964129FD3C5E00B37681 /* hdiffpatch */ = {
isa = PBXGroup;
children = (
0D99CCF22FF4CE5C005CC92A /* vcdiff_wrapper.cpp */,
0D99CCF32FF4CE5C005CC92A /* vcpatch_wrapper.c */,
0D99CCEE2FF4CE4B005CC92A /* bsdiff_wrapper.cpp */,
0D99CCEF2FF4CE4B005CC92A /* bspatch_wrapper.c */,
0D3D964629FD3CC100B37681 /* dir_diff_tools.cpp */,
0D3D964229FD3C7F00B37681 /* file_for_patch.c */,
);
Expand Down Expand Up @@ -434,9 +446,11 @@
0D99CCC42FE9004E005CC92A /* _hcache_window_old_mt.c in Sources */,
0D99CCBD2FD6CF0E005CC92A /* covers_range.cpp in Sources */,
0DA686642E536CB4002A6651 /* _hpatch_mt.c in Sources */,
0D99CCF52FF4CE5C005CC92A /* vcpatch_wrapper.c in Sources */,
0DA686652E536CB4002A6651 /* hpatch_mt.c in Sources */,
0DA686662E536CB4002A6651 /* _houtput_mt.c in Sources */,
0DA686672E536CB4002A6651 /* _hcache_old_mt.c in Sources */,
0D99CCF12FF4CE4B005CC92A /* bspatch_wrapper.c in Sources */,
0DA686682E536CB4002A6651 /* _hinput_mt.c in Sources */,
0D99CC8F2E9A611E005CC92A /* match_block.cpp in Sources */,
0D3D963E29FD3C1000B37681 /* match_in_new.cpp in Sources */,
Expand All @@ -447,6 +461,7 @@
0D3D964029FD3C1000B37681 /* sync_make.cpp in Sources */,
D6BD9BB017578491004886DE /* bytes_rle.cpp in Sources */,
0DD93B1428F16B010097699C /* parallel_channel.cpp in Sources */,
0D99CCF42FF4CE5C005CC92A /* vcdiff_wrapper.cpp in Sources */,
0D3D963C29FD3C1000B37681 /* sync_info_client.cpp in Sources */,
0D3D964729FD3CC100B37681 /* dir_diff_tools.cpp in Sources */,
0DE343BB2DF807230000234B /* match_inplace.cpp in Sources */,
Expand All @@ -464,6 +479,7 @@
0D3D964329FD3C7F00B37681 /* file_for_patch.c in Sources */,
0D99CCBC2FD6CF0E005CC92A /* window_matcher.cpp in Sources */,
0D3D963A29FD3C1000B37681 /* sync_client.cpp in Sources */,
0D99CCF02FF4CE4B005CC92A /* bsdiff_wrapper.cpp in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
2 changes: 1 addition & 1 deletion builds/xcode_iOS_hpatchz/hpatch_objc/hpatch_objc.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
// if need supported oldFileName or outNewFileName is directory, build .so with DIR=1 can opened;
// threadNum: 1..5, default 1; >1 opened multi-thread patching;
// now support single compressed diffData(created by hdiffz -SD) & window diffData(created by hdiffz -WD, recommended)
// isChecksumNewData: default true; checsum newData when patching VCDIFF and window diffData;
// isChecksumNewData: default true; auto checksum newData when patching VCDIFF and window diffData;

+ (int)patchWithOld:(NSString *)oldFileName
withDiff:(NSString *)diffFileName
Expand Down
6 changes: 3 additions & 3 deletions dirDiffPatch/dir_patch/dir_patch.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,14 @@ static const char* kVersionType="HDIFF19";


hpatch_BOOL getDirDiffInfoByFile(TDirDiffInfo* out_info,const char* diffFileName,
hpatch_StreamPos_t diffDataOffert,hpatch_StreamPos_t diffDataSize){
hpatch_StreamPos_t diffDataOffset,hpatch_StreamPos_t diffDataSize){
hpatch_BOOL result=hpatch_TRUE;
hpatch_TFileStreamInput diffData;
hpatch_TFileStreamInput_init(&diffData);

checki(hpatch_TFileStreamInput_open(&diffData,diffFileName),"getDirDiffInfoByFile() file open");
if (diffDataOffert>0){
checki(hpatch_TFileStreamInput_setOffset(&diffData,diffDataOffert),
if (diffDataOffset>0){
checki(hpatch_TFileStreamInput_setOffset(&diffData,diffDataOffset),
"getDirDiffInfoByFile() file setOffset");
check(diffData.base.streamSize>=diffDataSize);
diffData.base.streamSize=diffDataSize;
Expand Down
2 changes: 1 addition & 1 deletion dirDiffPatch/dir_patch/dir_patch.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ typedef struct TDirDiffInfo{

hpatch_BOOL getDirDiffInfo(TDirDiffInfo* out_info,const hpatch_TStreamInput* diffFile);
hpatch_BOOL getDirDiffInfoByFile(TDirDiffInfo* out_info,const char* diffFileName,
hpatch_StreamPos_t diffDataOffert,hpatch_StreamPos_t diffDataSize);
hpatch_StreamPos_t diffDataOffset,hpatch_StreamPos_t diffDataSize);
static hpatch_inline
hpatch_BOOL getIsDirDiffFile(const char* diffFileName){
TDirDiffInfo dirDiffInfo;
Expand Down
6 changes: 3 additions & 3 deletions dirDiffPatch/dir_patch/dir_patch_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,11 @@ extern "C" {
#endif

#ifdef _WIN32
static const char kPatch_dirSeparator = '\\';
#define kPatch_dirSeparator '\\'
#else
static const char kPatch_dirSeparator = '/';
#define kPatch_dirSeparator '/'
#endif
static const char kPatch_dirSeparator_saved = '/';
#define kPatch_dirSeparator_saved '/'

static hpatch_inline //align upper
hpatch_StreamPos_t toAlignRangeSize(hpatch_StreamPos_t rangeSize,size_t kAlignSize)
Expand Down
Loading
Loading