mirror of
https://gitcode.com/gh_mirrors/re/react-native-pushy.git
synced 2025-11-01 05:43:11 +08:00
hpatch_by_file() ok
This commit is contained in:
@@ -5,10 +5,22 @@
|
|||||||
#include "HDiffPatch/file_for_patch.h"
|
#include "HDiffPatch/file_for_patch.h"
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
kHPatch_ok = 0,
|
kHPatch_ok = 0,
|
||||||
kHPatch_error_info =-1,
|
kHPatch_error_info =-1,
|
||||||
|
kHPatch_error_old_fopen =-2,
|
||||||
|
kHPatch_error_old_fread =-3,
|
||||||
|
kHPatch_error_old_fclose =-4,
|
||||||
|
kHPatch_error_pat_fopen =-5,
|
||||||
|
kHPatch_error_pat_fread =-6,
|
||||||
|
kHPatch_error_pat_fclose =-7,
|
||||||
|
kHPatch_error_new_fopen =-8,
|
||||||
|
kHPatch_error_new_fwrite =-9,
|
||||||
|
kHPatch_error_new_fclose =-10,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#define _check(v,errorType) do{ \
|
||||||
|
if (!(v)){ if (result==kHPatch_ok) result=errorType; if (!_isInClear){ goto _clear; }; } }while(0)
|
||||||
|
|
||||||
int hpatch_getInfo_by_mem(struct hpatch_singleCompressedDiffInfo* out_patinfo,
|
int hpatch_getInfo_by_mem(struct hpatch_singleCompressedDiffInfo* out_patinfo,
|
||||||
const uint8_t* pat,size_t patsize){
|
const uint8_t* pat,size_t patsize){
|
||||||
hpatch_TStreamInput patStream;
|
hpatch_TStreamInput patStream;
|
||||||
@@ -19,9 +31,10 @@ int hpatch_getInfo_by_mem(struct hpatch_singleCompressedDiffInfo* out_patinfo,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static int hpatch_by_stream(const hpatch_TStreamInput* old,const hpatch_TStreamInput* pat,
|
static int hpatch_by_stream(const hpatch_TStreamInput* old,hpatch_BOOL isLoadOldToMem,const hpatch_TStreamInput* pat,
|
||||||
const hpatch_TStreamOutput* out_new,const hpatch_singleCompressedDiffInfo* patInfo){
|
hpatch_TStreamOutput* out_new,const hpatch_singleCompressedDiffInfo* patInfo){
|
||||||
//
|
//todo:
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int hpatch_by_mem(const uint8_t* old,size_t oldsize,uint8_t* newBuf,size_t newsize,
|
int hpatch_by_mem(const uint8_t* old,size_t oldsize,uint8_t* newBuf,size_t newsize,
|
||||||
@@ -32,10 +45,36 @@ int hpatch_by_mem(const uint8_t* old,size_t oldsize,uint8_t* newBuf,size_t newsi
|
|||||||
mem_as_hStreamInput(&oldStream,old,old+oldsize);
|
mem_as_hStreamInput(&oldStream,old,old+oldsize);
|
||||||
mem_as_hStreamInput(&patStream,pat,pat+patsize);
|
mem_as_hStreamInput(&patStream,pat,pat+patsize);
|
||||||
mem_as_hStreamOutput(&newStream,newBuf,newBuf+newsize);
|
mem_as_hStreamOutput(&newStream,newBuf,newBuf+newsize);
|
||||||
return hpatch_by_stream(&oldStream,&patStream,&newStream,patInfo);
|
return hpatch_by_stream(&oldStream,hpatch_FALSE,&patStream,&newStream,patInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
int hpatch_by_file(const char* oldfile, const char* newfile, const char* patchfile){
|
int hpatch_by_file(const char* oldfile, const char* newfile, const char* patchfile){
|
||||||
//todo:
|
int result=kHPatch_ok;
|
||||||
return -1;
|
int _isInClear=hpatch_FALSE;
|
||||||
|
int patch_result;
|
||||||
|
hpatch_TFileStreamInput oldStream;
|
||||||
|
hpatch_TFileStreamInput patStream;
|
||||||
|
hpatch_TFileStreamOutput newStream;
|
||||||
|
hpatch_TFileStreamInput_init(&oldStream);
|
||||||
|
hpatch_TFileStreamInput_init(&patStream);
|
||||||
|
hpatch_TFileStreamOutput_init(&newStream);
|
||||||
|
|
||||||
|
_check(hpatch_TFileStreamInput_open(&oldStream,oldfile),kHPatch_error_old_fopen);
|
||||||
|
_check(hpatch_TFileStreamInput_open(&patStream,patchfile),kHPatch_error_pat_fopen);
|
||||||
|
_check(hpatch_TFileStreamOutput_open(&newStream,newfile,~(hpatch_StreamPos_t)0),kHPatch_error_new_fopen);
|
||||||
|
|
||||||
|
patch_result=hpatch_by_stream(&oldStream.base,hpatch_TRUE,&patStream.base,&newStream.base,0);
|
||||||
|
if (patch_result!=kHPatch_ok){
|
||||||
|
_check(!oldStream.fileError,kHPatch_error_old_fread);
|
||||||
|
_check(!patStream.fileError,kHPatch_error_pat_fread);
|
||||||
|
_check(!newStream.fileError,kHPatch_error_new_fwrite);
|
||||||
|
_check(hpatch_FALSE,patch_result);
|
||||||
|
}
|
||||||
|
|
||||||
|
_clear:
|
||||||
|
_isInClear=hpatch_TRUE;
|
||||||
|
_check(hpatch_TFileStreamInput_close(&oldStream),kHPatch_error_old_fclose);
|
||||||
|
_check(hpatch_TFileStreamInput_close(&patStream),kHPatch_error_pat_fclose);
|
||||||
|
_check(hpatch_TFileStreamOutput_close(&newStream),kHPatch_error_new_fclose);
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user