Skip to content

Commit

Permalink
为了简化checksum,输出流允许支持输入,文件流修改为输入输出流
Browse files Browse the repository at this point in the history
  • Loading branch information
sisong committed Jan 18, 2019
1 parent d30f689 commit 7093cc6
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 28 deletions.
17 changes: 10 additions & 7 deletions file_for_patch.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,21 +78,22 @@ hpatch_BOOL TFileStreamInput_close(TFileStreamInput* self){
size_t writeLen;
TFileStreamOutput* self=(TFileStreamOutput*)stream->streamImport;
assert(data<=data_end);
assert(self->m_offset==0);
writeLen=(size_t)(data_end-data);
if (writeLen==0) return hpatch_TRUE;
if ((writeLen>self->base.streamSize)
||(writeToPos>self->base.streamSize-writeLen)) _fileError_return;
if (writeToPos!=self->out_pos){
if (writeToPos!=self->m_pos){
if (self->is_random_out){
if (!_import_fileSeek64(self->m_file,writeToPos,SEEK_SET)) _fileError_return;
self->out_pos=writeToPos;
self->m_pos=writeToPos;
}else{
_fileError_return;
}
}
if (!_import_fileWrite(self->m_file,data,data+writeLen)) _fileError_return;
self->out_pos=writeToPos+writeLen;
self->out_length=(self->out_length>=self->out_pos)?self->out_length:self->out_pos;
self->m_pos=writeToPos+writeLen;
self->out_length=(self->out_length>=self->m_pos)?self->out_length:self->m_pos;
return hpatch_TRUE;
}
hpatch_BOOL TFileStreamOutput_open(TFileStreamOutput* self,const char* fileName_utf8,
Expand All @@ -104,10 +105,12 @@ hpatch_BOOL TFileStreamOutput_open(TFileStreamOutput* self,const char* fileName_
self->base.streamImport=self;
self->base.streamSize=max_file_length;
self->base.write=_write_file;
self->out_pos=0;
self->out_length=0;
self->is_random_out=hpatch_FALSE;
*(void**)(&self->base.read_writed)=_read_file; //TFileStreamOutput is A TFileStreamInput !
self->m_pos=0;
self->m_offset=0;
self->fileError=hpatch_FALSE;
self->is_random_out=hpatch_FALSE;
self->out_length=0;
return hpatch_TRUE;
}

Expand Down
17 changes: 10 additions & 7 deletions file_for_patch.h
Original file line number Diff line number Diff line change
Expand Up @@ -157,10 +157,10 @@ static hpatch_BOOL _wFileNames_to_utf8(const wchar_t** fileNames_w,size_t fileCo

#if (_IS_USE_WIN32_UTF8_WAPI)
# define _kFileReadMode L"rb"
# define _kFileWriteMode L"wb"
# define _kFileWriteMode L"wb+"
#else
# define _kFileReadMode "rb"
# define _kFileWriteMode "wb"
# define _kFileWriteMode "wb+"
#endif

#if (_IS_USE_WIN32_UTF8_WAPI)
Expand Down Expand Up @@ -263,9 +263,10 @@ int printStdErrPath_utf8(const char* pathTxt_utf8){

typedef struct TFileStreamInput{
hpatch_TStreamInput base;
const void* _null_write;
hpatch_FileHandle m_file;
hpatch_StreamPos_t m_fpos;
size_t m_offset;
hpatch_StreamPos_t m_offset;
hpatch_BOOL fileError;
} TFileStreamInput;

Expand All @@ -277,13 +278,15 @@ hpatch_BOOL TFileStreamInput_open(TFileStreamInput* self,const char* fileName_ut
void TFileStreamInput_setOffset(TFileStreamInput* self,size_t offset);
hpatch_BOOL TFileStreamInput_close(TFileStreamInput* self);

typedef struct TFileStreamOutput{
hpatch_TStreamOutput base;
typedef struct TFileStreamOutput{ //is TFileStreamInput !
hpatch_TStreamOutput base; //is hpatch_TStreamInput + write
hpatch_FileHandle m_file;
hpatch_StreamPos_t out_pos;
hpatch_StreamPos_t out_length;
hpatch_StreamPos_t m_pos;
hpatch_StreamPos_t m_offset; //now not used
hpatch_BOOL fileError;
//
hpatch_BOOL is_random_out;
hpatch_StreamPos_t out_length;
} TFileStreamOutput;

hpatch_inline
Expand Down
29 changes: 15 additions & 14 deletions libHDiffPatch/HPatch/patch_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,35 +75,37 @@ typedef int hpatch_BOOL;
typedef void* hpatch_TStreamOutputHandle;

typedef struct hpatch_TStreamInput{
void* streamImport;
hpatch_StreamPos_t streamSize; //stream size,max readable range;
void* streamImport;
hpatch_StreamPos_t streamSize; //stream size,max readable range;
//read() must read (out_data_end-out_data), otherwise error return hpatch_FALSE
hpatch_BOOL (*read)(const struct hpatch_TStreamInput* stream,hpatch_StreamPos_t readFromPos,
unsigned char* out_data,unsigned char* out_data_end);
hpatch_BOOL (*read)(const struct hpatch_TStreamInput* stream,hpatch_StreamPos_t readFromPos,
unsigned char* out_data,unsigned char* out_data_end);
} hpatch_TStreamInput;

typedef struct hpatch_TStreamOutput{
void* streamImport;
hpatch_StreamPos_t streamSize; //stream size,max writable range; not is write pos!
void* streamImport;
hpatch_StreamPos_t streamSize; //stream size,max writable range; not is write pos!
//read_writed for ReadWriteIO, can null!
hpatch_BOOL (*read_writed)(const struct hpatch_TStreamOutput* stream,hpatch_StreamPos_t readFromPos,
unsigned char* out_data,unsigned char* out_data_end);
//write() must wrote (out_data_end-out_data), otherwise error return hpatch_FALSE
hpatch_BOOL (*write)(const struct hpatch_TStreamOutput* stream,hpatch_StreamPos_t writeToPos,
const unsigned char* data,const unsigned char* data_end);
hpatch_BOOL (*write)(const struct hpatch_TStreamOutput* stream,hpatch_StreamPos_t writeToPos,
const unsigned char* data,const unsigned char* data_end);
} hpatch_TStreamOutput;


#define hpatch_kMaxCompressTypeLength 256
#define hpatch_kMaxPluginTypeLength 259

typedef struct hpatch_compressedDiffInfo{
hpatch_StreamPos_t newDataSize;
hpatch_StreamPos_t oldDataSize;
int compressedCount;//need open hpatch_decompressHandle number
char compressType[hpatch_kMaxCompressTypeLength+1]; //ascii cstring
char compressType[hpatch_kMaxPluginTypeLength+1]; //ascii cstring
} hpatch_compressedDiffInfo;

typedef void* hpatch_decompressHandle;
typedef struct hpatch_TDecompress{
hpatch_BOOL (*is_can_open)(const struct hpatch_TDecompress* decompressPlugin,
const hpatch_compressedDiffInfo* compressedDiffInfo);
hpatch_BOOL (*is_can_open)(const char* compresseType);
//error return 0.
hpatch_decompressHandle (*open)(struct hpatch_TDecompress* decompressPlugin,
hpatch_StreamPos_t dataSize,
Expand All @@ -113,8 +115,7 @@ typedef int hpatch_BOOL;
hpatch_BOOL (*close)(struct hpatch_TDecompress* decompressPlugin,
hpatch_decompressHandle decompressHandle);
//decompress_part() must out (out_part_data_end-out_part_data), otherwise error return hpatch_FALSE
hpatch_BOOL (*decompress_part)(const struct hpatch_TDecompress* decompressPlugin,
hpatch_decompressHandle decompressHandle,
hpatch_BOOL (*decompress_part)(hpatch_decompressHandle decompressHandle,
unsigned char* out_part_data,unsigned char* out_part_data_end);
} hpatch_TDecompress;

Expand Down

0 comments on commit 7093cc6

Please sign in to comment.