forked from sisong/HDiffPatch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
hdiffz.cpp
1798 lines (1709 loc) · 81.3 KB
/
hdiffz.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//hdiffz.cpp
// diff tool
//
/*
The MIT License (MIT)
Copyright (c) 2012-2021 HouSisong
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:
The above copyright notice and this permission notice shall be
included in all copies of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
*/
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include "libHDiffPatch/HDiff/diff.h"
#include "libHDiffPatch/HDiff/match_block.h"
#include "libHDiffPatch/HPatch/patch.h"
#include "_clock_for_demo.h"
#include "_atosize.h"
#include "file_for_patch.h"
#include "libHDiffPatch/HDiff/private_diff/mem_buf.h"
#include "hdiffz_import_patch.h"
#include "_dir_ignore.h"
#include "dirDiffPatch/dir_diff/dir_diff.h"
#ifndef _IS_NEED_MAIN
# define _IS_NEED_MAIN 1
#endif
#ifndef _IS_NEED_BSDIFF
# define _IS_NEED_BSDIFF 1
#endif
#ifndef _IS_NEED_DEFAULT_CompressPlugin
# define _IS_NEED_DEFAULT_CompressPlugin 1
#endif
#if (_IS_NEED_ALL_CompressPlugin)
# undef _IS_NEED_DEFAULT_CompressPlugin
# define _IS_NEED_DEFAULT_CompressPlugin 1
#endif
#if (_IS_NEED_DEFAULT_CompressPlugin)
//===== select needs decompress plugins or change to your plugin=====
# define _CompressPlugin_zlib // memory requires less
# define _CompressPlugin_bz2
# define _CompressPlugin_lzma // better compresser
# define _CompressPlugin_lzma2 // better compresser
# define _CompressPlugin_zstd // better compresser / faster decompresser
#endif
#if (_IS_NEED_ALL_CompressPlugin)
//===== select needs decompress plugins or change to your plugin=====
# define _CompressPlugin_lz4 // faster compresser / faster decompresser
# define _CompressPlugin_lz4hc // faster decompresser
# define _CompressPlugin_brotli// better compresser / faster decompresser
# define _CompressPlugin_lzham // better compresser / decompress faster than lzma2
# define _CompressPlugin_tuz // decompress requires tiny code(.text) & ram
#endif
#if (_IS_NEED_BSDIFF)
# include "bsdiff_wrapper/bsdiff_wrapper.h"
# include "bsdiff_wrapper/bspatch_wrapper.h"
# ifndef _CompressPlugin_bz2
# define _CompressPlugin_bz2 //bsdiff need bz2
# endif
#endif
#include "compress_plugin_demo.h"
#include "decompress_plugin_demo.h"
#if (_IS_NEED_DIR_DIFF_PATCH)
#ifndef _IS_NEED_DEFAULT_ChecksumPlugin
# define _IS_NEED_DEFAULT_ChecksumPlugin 1
#endif
#if (_IS_NEED_ALL_ChecksumPlugin)
# undef _IS_NEED_DEFAULT_ChecksumPlugin
# define _IS_NEED_DEFAULT_ChecksumPlugin 1
#endif
#if (_IS_NEED_DEFAULT_ChecksumPlugin)
//===== select needs checksum plugins or change to your plugin=====
# define _ChecksumPlugin_crc32 // 32 bit effective //need zlib
# define _ChecksumPlugin_fadler64 // ? 63 bit effective
#endif
#if (_IS_NEED_ALL_ChecksumPlugin)
//===== select needs checksum plugins or change to your plugin=====
# define _ChecksumPlugin_adler32 // ? 29 bit effective
# define _ChecksumPlugin_adler64 // ? 30 bit effective
# define _ChecksumPlugin_fadler32 // ~ 32 bit effective
# define _ChecksumPlugin_fadler128// ? 81 bit effective
# define _ChecksumPlugin_md5 // 128 bit
# define _ChecksumPlugin_blake3 // 256 bit
#endif
#include "checksum_plugin_demo.h"
#endif
static void printVersion(){
printf("HDiffPatch::hdiffz v" HDIFFPATCH_VERSION_STRING "\n");
}
static void printHelpInfo(){
printf(" -h (or -?)\n"
" output usage info.\n");
}
static void printUsage(){
printVersion();
printf("\n");
printf("diff usage: hdiffz [options] oldPath newPath outDiffFile\n"
"test usage: hdiffz -t oldPath newPath testDiffFile\n"
"resave usage: hdiffz [-c-...] diffFile outDiffFile\n"
#if (_IS_NEED_DIR_DIFF_PATCH)
"get manifest: hdiffz [-g#...] [-C-checksumType] inputPath -M#outManifestTxtFile\n"
"manifest diff: hdiffz [options] -M-old#oldManifestFile -M-new#newManifestFile\n"
" oldPath newPath outDiffFile\n"
" oldPath newPath inputPath can be file or directory(folder),\n"
#endif
" oldPath can empty, and input parameter \"\"\n"
"memory options:\n"
" -m[-matchScore]\n"
" DEFAULT; all file load into Memory; best diffFileSize;\n"
" requires (newFileSize+ oldFileSize*5(or *9 when oldFileSize>=2GB))+O(1)\n"
" bytes of memory;\n"
" matchScore>=0, DEFAULT -m-6, recommended bin: 0--4 text: 4--9 etc...\n"
" -s[-matchBlockSize]\n"
" all file load as Stream; fast;\n"
" requires O(oldFileSize*16/matchBlockSize+matchBlockSize*5"
#if (_IS_USED_MULTITHREAD)
"*parallelThreadNumber"
#endif
")bytes of memory;\n"
" matchBlockSize>=4, DEFAULT -s-64, recommended 16,32,48,1k,64k,1m etc...\n"
"special options:\n"
" -block-fastMatchBlockSize \n"
" must run with -m;\n"
" set block match befor slow byte-by-byte match, DEFAULT -block-4k;\n"
" if set -block-0, means don't use block match;\n"
" fastMatchBlockSize>=4, recommended 256,1k,64k,1m etc...\n"
" if newData similar to oldData then diff speed++ & diff memory--,\n"
" but small possibility outDiffFile's size+\n"
" -cache \n"
" must run with -m;\n"
" set is use a big cache for slow match, DEFAULT false;\n"
" if newData not similar to oldData then diff speed++,\n"
" big cache max used O(oldFileSize) memory, and build slow(diff speed--)\n"
" -SD[-stepSize]\n"
" create single compressed diffData, only need one decompress buffer\n"
" when patch, and support step by step patching when step by step downloading!\n"
" stepSize>=" _HDIFFPATCH_EXPAND_AND_QUOTE(hpatch_kStreamCacheSize) ", DEFAULT -SD-256k, recommended 64k,2m etc...\n"
#if (_IS_NEED_BSDIFF)
" -BSD \n"
" create diffFile compatible with bsdiff, unsupport input directory(folder).\n"
#endif
#if (_IS_USED_MULTITHREAD)
" -p-parallelThreadNumber\n"
" if parallelThreadNumber>1 then open multi-thread Parallel mode;\n"
" DEFAULT -p-4; requires more memory!\n"
#endif
" -c-compressType[-compressLevel]\n"
" set outDiffFile Compress type, DEFAULT uncompress;\n"
" for resave diffFile,recompress diffFile to outDiffFile by new set;\n"
" support compress type & level & dict:\n"
#ifdef _CompressPlugin_zlib
" -c-zlib[-{1..9}[-dictBits]] DEFAULT level 9\n"
" dictBits can 9--15, DEFAULT 15.\n"
# if (_IS_USED_MULTITHREAD)
" support run by multi-thread parallel, fast!\n"
# endif
#endif
#ifdef _CompressPlugin_bz2
" -c-bzip2[-{1..9}] (or -bz2) DEFAULT level 9\n"
# if (_IS_USED_MULTITHREAD)
" -c-pbzip2[-{1..9}] (or -pbz2) DEFAULT level 8\n"
" support run by multi-thread parallel, fast!\n"
" WARNING: code not compatible with it compressed by -c-bzip2!\n"
" and code size may be larger than if it compressed by -c-bzip2.\n"
# endif
#endif
#ifdef _CompressPlugin_lzma
" -c-lzma[-{0..9}[-dictSize]] DEFAULT level 7\n"
" dictSize can like 4096 or 4k or 4m or 128m etc..., DEFAULT 8m\n"
# if (_IS_USED_MULTITHREAD)
" support run by 2-thread parallel.\n"
# endif
#endif
#ifdef _CompressPlugin_lzma2
" -c-lzma2[-{0..9}[-dictSize]] DEFAULT level 7\n"
" dictSize can like 4096 or 4k or 4m or 128m etc..., DEFAULT 8m\n"
# if (_IS_USED_MULTITHREAD)
" support run by multi-thread parallel, fast!\n"
# endif
" WARNING: code not compatible with it compressed by -c-lzma!\n"
#endif
#ifdef _CompressPlugin_lz4
" -c-lz4[-{1..50}] DEFAULT level 50 (as lz4 acceleration 1)\n"
#endif
#ifdef _CompressPlugin_lz4hc
" -c-lz4hc[-{3..12}] DEFAULT level 11\n"
#endif
#ifdef _CompressPlugin_zstd
" -c-zstd[-{0..22}[-dictBits]] DEFAULT level 20\n"
" dictBits can 10--31, DEFAULT 23.\n"
# if (_IS_USED_MULTITHREAD)
" support run by multi-thread parallel, fast!\n"
# endif
#endif
#ifdef _CompressPlugin_brotli
" -c-brotli[-{0..11}[-dictBits]] DEFAULT level 9\n"
" dictBits can 10--30, DEFAULT 23.\n"
#endif
#ifdef _CompressPlugin_lzham
" -c-lzham[-{0..5}[-dictBits]] DEFAULT level 4\n"
" dictBits can 15--29, DEFAULT 23.\n"
# if (_IS_USED_MULTITHREAD)
" support run by multi-thread parallel, fast!\n"
# endif
#endif
#ifdef _CompressPlugin_tuz
" -c-tuz[-dictSize] (or -tinyuz)\n"
" 1<=dictSize<=" _HDIFFPATCH_EXPAND_AND_QUOTE(tuz_kMaxOfDictSize) ", can like 510,1k,4k,64k,1m,16m ..., DEFAULT 8m\n"
#endif
#if (_IS_NEED_DIR_DIFF_PATCH)
" -C-checksumType\n"
" set outDiffFile Checksum type for directory diff, DEFAULT "
#ifdef _ChecksumPlugin_fadler64
"-C-fadler64;\n"
#else
# ifdef _ChecksumPlugin_crc32
"-C-crc32;\n"
# else
"no checksum;\n"
# endif
" (if need checksum for diff between two files, add -D)\n"
#endif
" support checksum type:\n"
" -C-no no checksum\n"
#ifdef _ChecksumPlugin_crc32
# ifdef _ChecksumPlugin_fadler64
" -C-crc32\n"
# else
" -C-crc32 DEFAULT\n"
# endif
#endif
#ifdef _ChecksumPlugin_adler32
" -C-adler32\n"
#endif
#ifdef _ChecksumPlugin_adler64
" -C-adler64\n"
#endif
#ifdef _ChecksumPlugin_fadler32
" -C-fadler32\n"
#endif
#ifdef _ChecksumPlugin_fadler64
" -C-fadler64 DEFAULT\n"
#endif
#ifdef _ChecksumPlugin_fadler128
" -C-fadler128\n"
#endif
#ifdef _ChecksumPlugin_md5
" -C-md5\n"
#endif
#ifdef _ChecksumPlugin_blake3
" -C-blake3\n"
#endif
" -n-maxOpenFileNumber\n"
" limit Number of open files at same time when stream directory diff;\n"
" maxOpenFileNumber>=8, DEFAULT -n-48, the best limit value by different\n"
" operating system.\n"
" -g#ignorePath[#ignorePath#...]\n"
" set iGnore path list when Directory Diff; ignore path list such as:\n"
" #.DS_Store#desktop.ini#*thumbs*.db#.git*#.svn/#cache_*/00*11/*.tmp\n"
" # means separator between names; (if char # in name, need write #: )\n"
" * means can match any chars in name; (if char * in name, need write *: );\n"
" / at the end of name means must match directory;\n"
" -g-old#ignorePath[#ignorePath#...]\n"
" set iGnore path list in oldPath when Directory Diff;\n"
" if oldFile can be changed, need add it in old ignore list;\n"
" -g-new#ignorePath[#ignorePath#...]\n"
" set iGnore path list in newPath when Directory Diff;\n"
" in general, new ignore list should is empty;\n"
" -M#outManifestTxtFile\n"
" create a Manifest file for inputPath; it is a text file, saved infos of\n"
" all files and directoriy list in inputPath; this file while be used in \n"
" manifest diff, support re-checksum data by manifest diff;\n"
" can be used to protect historical versions be modified!\n"
" -M-old#oldManifestFile\n"
" oldManifestFile is created from oldPath; if no oldPath not need -M-old;\n"
" -M-new#newManifestFile\n"
" newManifestFile is created from newPath;\n"
" -D force run Directory diff between two files; DEFAULT (no -D) run \n"
" directory diff need oldPath or newPath is directory.\n"
#endif //_IS_NEED_DIR_DIFF_PATCH
" -d Diff only, do't run patch check, DEFAULT run patch check.\n"
" -t Test only, run patch check, patch(oldPath,testDiffFile)==newPath ? \n"
" -f Force overwrite, ignore write path already exists;\n"
" DEFAULT (no -f) not overwrite and then return error;\n"
" if used -f and write path is exist directory, will always return error.\n"
" --patch\n"
" swap to hpatchz mode.\n"
" -v output Version info.\n"
);
printHelpInfo();
printf("\n");
}
typedef enum THDiffResult {
HDIFF_SUCCESS=0,
HDIFF_OPTIONS_ERROR,
HDIFF_OPENREAD_ERROR,
HDIFF_OPENWRITE_ERROR,
HDIFF_FILECLOSE_ERROR,
HDIFF_MEM_ERROR, // 5
HDIFF_DIFF_ERROR,
HDIFF_PATCH_ERROR,
HDIFF_RESAVE_FILEREAD_ERROR,
//HDIFF_RESAVE_OPENWRITE_ERROR = HDIFF_OPENWRITE_ERROR
HDIFF_RESAVE_DIFFINFO_ERROR,
HDIFF_RESAVE_COMPRESSTYPE_ERROR, // 10
HDIFF_RESAVE_ERROR,
HDIFF_RESAVE_CHECKSUMTYPE_ERROR,
HDIFF_PATHTYPE_ERROR, //adding begin v3.0
HDIFF_TEMPPATH_ERROR,
HDIFF_DELETEPATH_ERROR, // 15
HDIFF_RENAMEPATH_ERROR,
DIRDIFF_DIFF_ERROR=101,
DIRDIFF_PATCH_ERROR,
MANIFEST_CREATE_ERROR,
MANIFEST_TEST_ERROR,
} THDiffResult;
#define HDIFF_RESAVE_OPENWRITE_ERROR HDIFF_OPENWRITE_ERROR
int hdiff_cmd_line(int argc,const char * argv[]);
struct TDiffSets:public THDiffSets{
hpatch_BOOL isDoDiff;
hpatch_BOOL isDoPatchCheck;
#if (_IS_NEED_BSDIFF)
hpatch_BOOL isBsDiff;
#endif
};
#if (_IS_NEED_DIR_DIFF_PATCH)
int hdiff_dir(const char* oldPath,const char* newPath,const char* outDiffFileName,
const hdiff_TCompress* compressPlugin,hpatch_TChecksum* checksumPlugin,
hpatch_BOOL oldIsDir, hpatch_BOOL newIsDir,
const TDiffSets& diffSets,size_t kMaxOpenFileNumber,
const std::vector<std::string>& ignorePathListBase,const std::vector<std::string>& ignoreOldPathList,
const std::vector<std::string>& ignoreNewPathList,
const std::string& oldManifestFileName,const std::string& newManifestFileName);
int create_manifest(const char* inputPath,const char* outManifestFileName,
hpatch_TChecksum* checksumPlugin,const std::vector<std::string>& ignorePathList);
#endif
int hdiff(const char* oldFileName,const char* newFileName,const char* outDiffFileName,
const hdiff_TCompress* compressPlugin,const TDiffSets& diffSets);
int hdiff_resave(const char* diffFileName,const char* outDiffFileName,
const hdiff_TCompress* compressPlugin);
#define _checkPatchMode(_argc,_argv) \
if (isSwapToPatchMode(_argc,_argv)){ \
printf("hdiffz swap to hpatchz mode.\n\n"); \
return hpatch_cmd_line(_argc,_argv); \
}
#if (_IS_NEED_MAIN)
# if (_IS_USED_WIN32_UTF8_WAPI)
int wmain(int argc,wchar_t* argv_w[]){
hdiff_private::TAutoMem _mem(hpatch_kPathMaxSize*4);
char** argv_utf8=(char**)_mem.data();
if (!_wFileNames_to_utf8((const wchar_t**)argv_w,argc,argv_utf8,_mem.size()))
return HDIFF_OPTIONS_ERROR;
SetDefaultStringLocale();
_checkPatchMode(argc,(const char**)argv_utf8);
return hdiff_cmd_line(argc,(const char**)argv_utf8);
}
# else
int main(int argc,char* argv[]){
_checkPatchMode(argc,(const char**)argv);
return hdiff_cmd_line(argc,(const char**)argv);
}
# endif
#endif
static hpatch_BOOL _getIsCompressedDiffFile(const char* diffFileName){
hpatch_TFileStreamInput diffData;
hpatch_TFileStreamInput_init(&diffData);
if (!hpatch_TFileStreamInput_open(&diffData,diffFileName)) return hpatch_FALSE;
hpatch_compressedDiffInfo diffInfo;
hpatch_BOOL result=getCompressedDiffInfo(&diffInfo,&diffData.base);
if (!hpatch_TFileStreamInput_close(&diffData)) return hpatch_FALSE;
return result;
}
static hpatch_BOOL _getIsSingleStreamDiffFile(const char* diffFileName){
hpatch_TFileStreamInput diffData;
hpatch_TFileStreamInput_init(&diffData);
if (!hpatch_TFileStreamInput_open(&diffData,diffFileName)) return hpatch_FALSE;
hpatch_singleCompressedDiffInfo diffInfo;
hpatch_BOOL result=getSingleCompressedDiffInfo(&diffInfo,&diffData.base,0);
if (!hpatch_TFileStreamInput_close(&diffData)) return hpatch_FALSE;
return result;
}
#if (_IS_NEED_BSDIFF)
static hpatch_BOOL _getIsBsDiffFile(const char* diffFileName){
hpatch_TFileStreamInput diffData;
hpatch_TFileStreamInput_init(&diffData);
if (!hpatch_TFileStreamInput_open(&diffData,diffFileName)) return hpatch_FALSE;
hpatch_BsDiffInfo diffInfo;
hpatch_BOOL result=getBsDiffInfo(&diffInfo,&diffData.base);
if (!hpatch_TFileStreamInput_close(&diffData)) return hpatch_FALSE;
return result;
}
#endif
#define _try_rt_dec(dec) { if (dec.is_can_open(compressType)) return &dec; }
static hpatch_TDecompress* __find_decompressPlugin(const char* compressType){
#ifdef _CompressPlugin_zlib
_try_rt_dec(zlibDecompressPlugin);
#endif
#ifdef _CompressPlugin_bz2
_try_rt_dec(bz2DecompressPlugin);
#endif
#ifdef _CompressPlugin_lzma
_try_rt_dec(lzmaDecompressPlugin);
#endif
#ifdef _CompressPlugin_lzma2
_try_rt_dec(lzma2DecompressPlugin);
#endif
#if (defined(_CompressPlugin_lz4) || (defined(_CompressPlugin_lz4hc)))
_try_rt_dec(lz4DecompressPlugin);
#endif
#ifdef _CompressPlugin_zstd
_try_rt_dec(zstdDecompressPlugin);
#endif
#ifdef _CompressPlugin_brotli
_try_rt_dec(brotliDecompressPlugin);
#endif
#ifdef _CompressPlugin_lzham
_try_rt_dec(lzhamDecompressPlugin);
#endif
#ifdef _CompressPlugin_tuz
_try_rt_dec(tuzDecompressPlugin);
#endif
return 0;
}
static hpatch_BOOL findDecompress(hpatch_TDecompress** out_decompressPlugin,const char* compressType){
*out_decompressPlugin=0;
if (strlen(compressType)==0) return hpatch_TRUE;
*out_decompressPlugin=__find_decompressPlugin(compressType);
return 0!=(*out_decompressPlugin);
}
#if (_IS_NEED_DIR_DIFF_PATCH)
static inline hpatch_BOOL _trySetChecksum(hpatch_TChecksum** out_checksumPlugin,const char* checksumType,
hpatch_TChecksum* testChecksumPlugin){
assert(0==*out_checksumPlugin);
if (0!=strcmp(checksumType,testChecksumPlugin->checksumType())) return hpatch_FALSE;
*out_checksumPlugin=testChecksumPlugin;
return hpatch_TRUE;
}
#define __setChecksum(_checksumPlugin) \
if (_trySetChecksum(out_checksumPlugin,checksumType,_checksumPlugin)) return hpatch_TRUE;
static hpatch_BOOL findChecksum(hpatch_TChecksum** out_checksumPlugin,const char* checksumType){
*out_checksumPlugin=0;
if (strlen(checksumType)==0) return hpatch_TRUE;
#ifdef _ChecksumPlugin_crc32
__setChecksum(&crc32ChecksumPlugin);
#endif
#ifdef _ChecksumPlugin_adler32
__setChecksum(&adler32ChecksumPlugin);
#endif
#ifdef _ChecksumPlugin_adler64
__setChecksum(&adler64ChecksumPlugin);
#endif
#ifdef _ChecksumPlugin_fadler32
__setChecksum(&fadler32ChecksumPlugin);
#endif
#ifdef _ChecksumPlugin_fadler64
__setChecksum(&fadler64ChecksumPlugin);
#endif
#ifdef _ChecksumPlugin_fadler128
__setChecksum(&fadler128ChecksumPlugin);
#endif
#ifdef _ChecksumPlugin_md5
__setChecksum(&md5ChecksumPlugin);
#endif
#ifdef _ChecksumPlugin_blake3
__setChecksum(&blake3ChecksumPlugin);
#endif
return hpatch_FALSE;
}
static hpatch_BOOL _getOptChecksum(hpatch_TChecksum** out_checksumPlugin,
const char* checksumType,const char* kNoChecksum){
assert(0==*out_checksumPlugin);
if (0==strcmp(checksumType,kNoChecksum))
return hpatch_TRUE;
else
return findChecksum(out_checksumPlugin,checksumType);
}
#endif //_IS_NEED_DIR_DIFF_PATCH
static bool _tryGetCompressSet(const char** isMatchedType,const char* ptype,const char* ptypeEnd,
const char* cmpType,const char* cmpType2=0,
size_t* compressLevel=0,size_t levelMin=0,size_t levelMax=0,size_t levelDefault=0,
size_t* dictSize=0,size_t dictSizeMin=0,size_t dictSizeMax=0,size_t dictSizeDefault=0){
assert (0==(*isMatchedType));
const size_t ctypeLen=strlen(cmpType);
const size_t ctype2Len=(cmpType2!=0)?strlen(cmpType2):0;
if ( ((ctypeLen==(size_t)(ptypeEnd-ptype))&&(0==strncmp(ptype,cmpType,ctypeLen)))
|| ((cmpType2!=0)&&(ctype2Len==(size_t)(ptypeEnd-ptype))&&(0==strncmp(ptype,cmpType2,ctype2Len))) )
*isMatchedType=cmpType; //ok
else
return true;//type mismatch
if ((compressLevel)&&(ptypeEnd[0]=='-')){
const char* plevel=ptypeEnd+1;
const char* plevelEnd=findUntilEnd(plevel,'-');
if (!kmg_to_size(plevel,plevelEnd-plevel,compressLevel)) return false; //error
if (*compressLevel<levelMin) *compressLevel=levelMin;
else if (*compressLevel>levelMax) *compressLevel=levelMax;
if ((dictSize)&&(plevelEnd[0]=='-')){
const char* pdictSize=plevelEnd+1;
const char* pdictSizeEnd=findUntilEnd(pdictSize,'-');
if (!kmg_to_size(pdictSize,pdictSizeEnd-pdictSize,dictSize)) return false; //error
if (*dictSize<dictSizeMin) *dictSize=dictSizeMin;
else if (*dictSize>dictSizeMax) *dictSize=dictSizeMax;
}else{
if (plevelEnd[0]!='\0') return false; //error
if (dictSize) *dictSize=dictSizeDefault;
}
}else{
if (ptypeEnd[0]!='\0') return false; //error
if (compressLevel) *compressLevel=levelDefault;
if (dictSize) *dictSize=dictSizeDefault;
}
return true;
}
#define _options_check(value,errorInfo){ \
if (!(value)) { LOG_ERR("options " errorInfo " ERROR!\n\n"); printHelpInfo(); return HDIFF_OPTIONS_ERROR; } }
#define __getCompressSet(_tryGet_code,_errTag) \
if (isMatchedType==0){ \
_options_check(_tryGet_code,_errTag); \
if (isMatchedType)
static int _checkSetCompress(hdiff_TCompress** out_compressPlugin,
const char* ptype,const char* ptypeEnd){
const char* isMatchedType=0;
size_t compressLevel=0;
#if (defined _CompressPlugin_lzma)||(defined _CompressPlugin_lzma2)||(defined _CompressPlugin_tuz)
size_t dictSize=0;
const size_t defaultDictSize=(1<<20)*8; //8m
#endif
#if (defined _CompressPlugin_zlib)||(defined _CompressPlugin_zstd)||(defined _CompressPlugin_brotli)||(defined _CompressPlugin_lzham)
size_t dictBits=0;
const size_t defaultDictBits=20+3; //8m
const size_t defaultDictBits_zlib=15; //32k
#endif
#ifdef _CompressPlugin_zlib
__getCompressSet(_tryGetCompressSet(&isMatchedType,ptype,ptypeEnd,"zlib","pzlib",
&compressLevel,1,9,9, &dictBits,9,15,defaultDictBits_zlib),"-c-zlib-?"){
# if (!_IS_USED_MULTITHREAD)
static TCompressPlugin_zlib _zlibCompressPlugin=zlibCompressPlugin;
_zlibCompressPlugin.compress_level=(int)compressLevel;
_zlibCompressPlugin.windowBits=(signed char)(-dictBits);
*out_compressPlugin=&_zlibCompressPlugin.base; }}
# else
static TCompressPlugin_pzlib _pzlibCompressPlugin=pzlibCompressPlugin;
_pzlibCompressPlugin.base.compress_level=(int)compressLevel;
_pzlibCompressPlugin.base.windowBits=(signed char)(-dictBits);
*out_compressPlugin=&_pzlibCompressPlugin.base.base; }}
# endif // _IS_USED_MULTITHREAD
#endif
#ifdef _CompressPlugin_bz2
__getCompressSet(_tryGetCompressSet(&isMatchedType,ptype,ptypeEnd,"bzip2","bz2",
&compressLevel,1,9,9),"-c-bzip2-?"){
static TCompressPlugin_bz2 _bz2CompressPlugin=bz2CompressPlugin;
_bz2CompressPlugin.compress_level=(int)compressLevel;
*out_compressPlugin=&_bz2CompressPlugin.base; }}
# if (_IS_USED_MULTITHREAD)
//pbzip2
__getCompressSet(_tryGetCompressSet(&isMatchedType,ptype,ptypeEnd,"pbzip2","pbz2",
&compressLevel,1,9,8),"-c-pbzip2-?"){
static TCompressPlugin_pbz2 _pbz2CompressPlugin=pbz2CompressPlugin;
_pbz2CompressPlugin.base.compress_level=(int)compressLevel;
*out_compressPlugin=&_pbz2CompressPlugin.base.base; }}
# endif // _IS_USED_MULTITHREAD
#endif
#ifdef _CompressPlugin_lzma
__getCompressSet(_tryGetCompressSet(&isMatchedType,ptype,ptypeEnd,"lzma",0,
&compressLevel,0,9,7, &dictSize,1<<12,
(sizeof(size_t)<=4)?(1<<27):((size_t)3<<29),defaultDictSize),"-c-lzma-?"){
static TCompressPlugin_lzma _lzmaCompressPlugin=lzmaCompressPlugin;
_lzmaCompressPlugin.compress_level=(int)compressLevel;
_lzmaCompressPlugin.dict_size=(int)dictSize;
*out_compressPlugin=&_lzmaCompressPlugin.base; }}
#endif
#ifdef _CompressPlugin_lzma2
__getCompressSet(_tryGetCompressSet(&isMatchedType,ptype,ptypeEnd,"lzma2",0,
&compressLevel,0,9,7, &dictSize,1<<12,
(sizeof(size_t)<=4)?(1<<27):((size_t)3<<29),defaultDictSize),"-c-lzma2-?"){
static TCompressPlugin_lzma2 _lzma2CompressPlugin=lzma2CompressPlugin;
_lzma2CompressPlugin.compress_level=(int)compressLevel;
_lzma2CompressPlugin.dict_size=(int)dictSize;
*out_compressPlugin=&_lzma2CompressPlugin.base; }}
#endif
#ifdef _CompressPlugin_lz4
__getCompressSet(_tryGetCompressSet(&isMatchedType,ptype,ptypeEnd,"lz4",0,
&compressLevel,1,50,50),"-c-lz4-?"){
static TCompressPlugin_lz4 _lz4CompressPlugin=lz4CompressPlugin;
_lz4CompressPlugin.compress_level=(int)compressLevel;
*out_compressPlugin=&_lz4CompressPlugin.base; }}
#endif
#ifdef _CompressPlugin_lz4hc
__getCompressSet(_tryGetCompressSet(&isMatchedType,ptype,ptypeEnd,"lz4hc",0,
&compressLevel,3,12,11),"-c-lz4hc-?"){
static TCompressPlugin_lz4hc _lz4hcCompressPlugin=lz4hcCompressPlugin;
_lz4hcCompressPlugin.compress_level=(int)compressLevel;
*out_compressPlugin=&_lz4hcCompressPlugin.base; }}
#endif
#ifdef _CompressPlugin_zstd
__getCompressSet(_tryGetCompressSet(&isMatchedType,ptype,ptypeEnd,"zstd",0,
&compressLevel,0,22,20, &dictBits,10,
_ZSTD_WINDOWLOG_MAX,defaultDictBits),"-c-zstd-?"){
static TCompressPlugin_zstd _zstdCompressPlugin=zstdCompressPlugin;
_zstdCompressPlugin.compress_level=(int)compressLevel;
_zstdCompressPlugin.dict_bits = (int)dictBits;
*out_compressPlugin=&_zstdCompressPlugin.base; }}
#endif
#ifdef _CompressPlugin_brotli
__getCompressSet(_tryGetCompressSet(&isMatchedType,ptype,ptypeEnd,"brotli",0,
&compressLevel,0,11,9, &dictBits,10,
30,defaultDictBits),"-c-brotli-?"){
static TCompressPlugin_brotli _brotliCompressPlugin=brotliCompressPlugin;
_brotliCompressPlugin.compress_level=(int)compressLevel;
_brotliCompressPlugin.dict_bits = (int)dictBits;
*out_compressPlugin=&_brotliCompressPlugin.base; }}
#endif
#ifdef _CompressPlugin_lzham
__getCompressSet(_tryGetCompressSet(&isMatchedType,ptype,ptypeEnd,"lzham",0,
&compressLevel,0,5,4, &dictBits,15,
(sizeof(size_t)<=4)?26:29,defaultDictBits),"-c-lzham-?"){
static TCompressPlugin_lzham _lzhamCompressPlugin=lzhamCompressPlugin;
_lzhamCompressPlugin.compress_level=(int)compressLevel;
_lzhamCompressPlugin.dict_bits = (int)dictBits;
*out_compressPlugin=&_lzhamCompressPlugin.base; }}
#endif
#ifdef _CompressPlugin_tuz
__getCompressSet(_tryGetCompressSet(&isMatchedType,
ptype,ptypeEnd,"tuz","tinyuz",
&dictSize,1,tuz_kMaxOfDictSize,defaultDictSize),"-c-tuz-?"){
static TCompressPlugin_tuz _tuzCompressPlugin=tuzCompressPlugin;
_tuzCompressPlugin.props.dictSize=(tuz_size_t)dictSize;
*out_compressPlugin=&_tuzCompressPlugin.base; }}
#endif
_options_check((*out_compressPlugin!=0),"-c-?");
return HDIFF_SUCCESS;
}
#define _return_check(value,exitCode,errorInfo){ \
if (!(value)) { LOG_ERR(errorInfo " ERROR!\n"); return exitCode; } }
#define _kNULL_VALUE ((hpatch_BOOL)(-1))
#define _kNULL_SIZE (~(size_t)0)
#define _THREAD_NUMBER_NULL 0
#define _THREAD_NUMBER_MIN 1
#define _THREAD_NUMBER_DEFUALT kDefaultCompressThreadNumber
#define _THREAD_NUMBER_MAX (1<<8)
int hdiff_cmd_line(int argc, const char * argv[]){
TDiffSets diffSets;
memset(&diffSets,0,sizeof(diffSets));
#if (_IS_NEED_BSDIFF)
diffSets.isBsDiff =_kNULL_VALUE;
#endif
diffSets.isDoDiff =_kNULL_VALUE;
diffSets.isDoPatchCheck=_kNULL_VALUE;
diffSets.isDiffInMem =_kNULL_VALUE;
diffSets.isSingleCompressedDiff =_kNULL_VALUE;
diffSets.isUseBigCacheMatch =_kNULL_VALUE;
diffSets.matchBlockSize=_kNULL_SIZE;
diffSets.threadNum=_THREAD_NUMBER_NULL;
hpatch_BOOL isForceOverwrite=_kNULL_VALUE;
hpatch_BOOL isOutputHelp=_kNULL_VALUE;
hpatch_BOOL isOutputVersion=_kNULL_VALUE;
hpatch_BOOL isOldPathInputEmpty=_kNULL_VALUE;
hdiff_TCompress* compressPlugin=0;
#if (_IS_NEED_DIR_DIFF_PATCH)
hpatch_BOOL isForceRunDirDiff=_kNULL_VALUE;
size_t kMaxOpenFileNumber=_kNULL_SIZE; //only used in dir diff by stream
hpatch_BOOL isSetChecksum=_kNULL_VALUE;
hpatch_TChecksum* checksumPlugin=0;
std::string manifestOut;
std::string manifestOld;
std::string manifestNew;
std::vector<std::string> ignorePathList;
std::vector<std::string> ignoreOldPathList;
std::vector<std::string> ignoreNewPathList;
#endif
std::vector<const char *> arg_values;
if (argc<=1){
printUsage();
return HDIFF_OPTIONS_ERROR;
}
for (int i=1; i<argc; ++i) {
const char* op=argv[i];
_options_check(op!=0,"?");
if (op[0]!='-'){
hpatch_BOOL isEmpty=(strlen(op)==0);
if (isEmpty){
if (isOldPathInputEmpty==_kNULL_VALUE)
isOldPathInputEmpty=hpatch_TRUE;
else
_options_check(!isEmpty,"?"); //error return
}else{
if (isOldPathInputEmpty==_kNULL_VALUE)
isOldPathInputEmpty=hpatch_FALSE;
}
arg_values.push_back(op); //path:file or directory
continue;
}
switch (op[1]) {
case 'm':{ //diff in memory
_options_check((diffSets.isDiffInMem==_kNULL_VALUE)&&((op[2]=='-')||(op[2]=='\0')),"-m");
diffSets.isDiffInMem=hpatch_TRUE;
if (op[2]=='-'){
const char* pnum=op+3;
_options_check(kmg_to_size(pnum,strlen(pnum),&diffSets.matchScore),"-m-?");
_options_check((0<=(int)diffSets.matchScore)&&(diffSets.matchScore==(size_t)(int)diffSets.matchScore),"-m-?");
}else{
diffSets.matchScore=kMinSingleMatchScore_default;
}
} break;
case 's':{
_options_check((diffSets.isDiffInMem==_kNULL_VALUE),"-s");
_options_check((diffSets.matchBlockSize==_kNULL_SIZE),"-block must run with -m");
diffSets.isDiffInMem=hpatch_FALSE; //diff by stream
if (op[2]=='-'){
const char* pnum=op+3;
_options_check(kmg_to_size(pnum,strlen(pnum),&diffSets.matchBlockSize),"-s-?");
_options_check((kMatchBlockSize_min<=diffSets.matchBlockSize)
&&(diffSets.matchBlockSize!=_kNULL_SIZE),"-s-?");
}else{
diffSets.matchBlockSize=kMatchBlockSize_default;
}
} break;
case 'S':{
_options_check((diffSets.isSingleCompressedDiff==_kNULL_VALUE)
&&(op[2]=='D')&&((op[3]=='\0')||(op[3]=='-')),"-SD");
diffSets.isSingleCompressedDiff=hpatch_TRUE;
if (op[3]=='-'){
const char* pnum=op+4;
_options_check(kmg_to_size(pnum,strlen(pnum),&diffSets.patchStepMemSize),"-SD-?");
_options_check((diffSets.patchStepMemSize>=hpatch_kStreamCacheSize),"-SD-?");
}else{
diffSets.patchStepMemSize=kDefaultPatchStepMemSize;
}
} break;
#if (_IS_NEED_BSDIFF)
case 'B':{
_options_check((diffSets.isBsDiff==_kNULL_VALUE)
&&(op[2]=='S')&&(op[3]=='D')&&(op[4]=='\0'),"-BSD");
diffSets.isBsDiff=hpatch_TRUE;
} break;
#endif
case '?':
case 'h':{
_options_check((isOutputHelp==_kNULL_VALUE)&&(op[2]=='\0'),"-h");
isOutputHelp=hpatch_TRUE;
} break;
case 'v':{
_options_check((isOutputVersion==_kNULL_VALUE)&&(op[2]=='\0'),"-v");
isOutputVersion=hpatch_TRUE;
} break;
case 't':{
_options_check((diffSets.isDoDiff==_kNULL_VALUE)&&(diffSets.isDoPatchCheck==_kNULL_VALUE)&&(op[2]=='\0'),"-t -d?");
diffSets.isDoDiff=hpatch_FALSE;
diffSets.isDoPatchCheck=hpatch_TRUE; //only test diffFile
} break;
case 'd':{
_options_check((diffSets.isDoDiff==_kNULL_VALUE)&&(diffSets.isDoPatchCheck==_kNULL_VALUE)&&(op[2]=='\0'),"-t -d?");
diffSets.isDoDiff=hpatch_TRUE; //only diff
diffSets.isDoPatchCheck=hpatch_FALSE;
} break;
case 'f':{
_options_check((isForceOverwrite==_kNULL_VALUE)&&(op[2]=='\0'),"-f");
isForceOverwrite=hpatch_TRUE;
} break;
#if (_IS_USED_MULTITHREAD)
case 'p':{
_options_check((diffSets.threadNum==_THREAD_NUMBER_NULL)&&(op[2]=='-'),"-p-?");
const char* pnum=op+3;
_options_check(a_to_size(pnum,strlen(pnum),&diffSets.threadNum),"-p-?");
_options_check(diffSets.threadNum>=_THREAD_NUMBER_MIN,"-p-?");
} break;
#endif
case 'b':{
_options_check((diffSets.matchBlockSize==_kNULL_SIZE)&&
(op[2]=='l')&&(op[3]=='o')&&(op[4]=='c')&&(op[5]=='k')&&
((op[6]=='\0')||(op[6]=='-')),"-block?");
if (op[6]=='-'){
const char* pnum=op+7;
_options_check(kmg_to_size(pnum,strlen(pnum),&diffSets.matchBlockSize),"-block-?");
if (diffSets.matchBlockSize!=0)
_options_check((kMatchBlockSize_min<=diffSets.matchBlockSize)
&&(diffSets.matchBlockSize!=_kNULL_SIZE),"-block-?");
}else{
diffSets.matchBlockSize=kDefaultFastMatchBlockSize;
}
} break;
case 'c':{
if (op[2]=='-'){
_options_check((compressPlugin==0),"-c-");
const char* ptype=op+3;
const char* ptypeEnd=findUntilEnd(ptype,'-');
int result=_checkSetCompress(&compressPlugin,ptype,ptypeEnd);
if (HDIFF_SUCCESS!=result)
return result;
}else if (op[2]=='a'){
_options_check((diffSets.isUseBigCacheMatch==_kNULL_VALUE)&&
(op[3]=='c')&&(op[4]=='h')&&(op[5]=='e')&&(op[6]=='\0'),"-cache?");
diffSets.isUseBigCacheMatch=hpatch_TRUE; //use big cache for match
}else{
_options_check(false,"-c?");
}
} break;
#if (_IS_NEED_DIR_DIFF_PATCH)
case 'C':{
_options_check((isSetChecksum==_kNULL_VALUE)&&(checksumPlugin==0)&&(op[2]=='-'),"-C");
const char* ptype=op+3;
isSetChecksum=hpatch_TRUE;
_options_check(_getOptChecksum(&checksumPlugin,ptype,"no"),"-C-?");
} break;
case 'n':{
_options_check((kMaxOpenFileNumber==_kNULL_SIZE)&&(op[2]=='-'),"-n")
const char* pnum=op+3;
_options_check(kmg_to_size(pnum,strlen(pnum),&kMaxOpenFileNumber),"-n-?");
_options_check((kMaxOpenFileNumber!=_kNULL_SIZE),"-n-?");
} break;
case 'g':{
if (op[2]=='#'){ //-g#
const char* plist=op+3;
_options_check(_getIgnorePathSetList(ignorePathList,plist),"-g#?");
}else if (op[2]=='-'){
const char* plist=op+7;
if ((op[3]=='o')&&(op[4]=='l')&&(op[5]=='d')&&(op[6]=='#')){
_options_check(_getIgnorePathSetList(ignoreOldPathList,plist),"-g-old#?");
}else if ((op[3]=='n')&&(op[4]=='e')&&(op[5]=='w')&&(op[6]=='#')){
_options_check(_getIgnorePathSetList(ignoreNewPathList,plist),"-g-new#?");
}else{
_options_check(hpatch_FALSE,"-g-?");
}
}else{
_options_check(hpatch_FALSE,"-g?");
}
} break;
case 'M':{
if (op[2]=='#'){ //-M#
const char* plist=op+3;
_options_check(manifestOut.empty()&&manifestOld.empty()&&manifestNew.empty(),"-M#");
manifestOut=plist;
}else if (op[2]=='-'){
const char* plist=op+7;
if ((op[3]=='o')&&(op[4]=='l')&&(op[5]=='d')&&(op[6]=='#')){
_options_check(manifestOut.empty()&&manifestOld.empty(),"-M-old#");
manifestOld=plist;
}else if ((op[3]=='n')&&(op[4]=='e')&&(op[5]=='w')&&(op[6]=='#')){
_options_check(manifestOut.empty()&&manifestNew.empty(),"-M-new#");
manifestNew=plist;
}else{
_options_check(hpatch_FALSE,"-M-?");
}
}else{
_options_check(hpatch_FALSE,"-M?");
}
} break;
case 'D':{
_options_check((isForceRunDirDiff==_kNULL_VALUE)&&(op[2]=='\0'),"-D");
isForceRunDirDiff=hpatch_TRUE; //force run DirDiff
} break;
#endif
default: {
_options_check(hpatch_FALSE,"-?");
} break;
}//switch
}
if (isOutputHelp==_kNULL_VALUE)
isOutputHelp=hpatch_FALSE;
if (isOutputVersion==_kNULL_VALUE)
isOutputVersion=hpatch_FALSE;
if (isForceOverwrite==_kNULL_VALUE)
isForceOverwrite=hpatch_FALSE;
if (isOutputHelp||isOutputVersion){
if (isOutputHelp)
printUsage();//with version
else
printVersion();
if (arg_values.empty())
return 0; //ok
}
if (diffSets.isSingleCompressedDiff==_kNULL_VALUE)
diffSets.isSingleCompressedDiff=hpatch_FALSE;
#if (_IS_NEED_BSDIFF)
if (diffSets.isBsDiff==_kNULL_VALUE)
diffSets.isBsDiff=hpatch_FALSE;
if (diffSets.isBsDiff){
_options_check(!diffSets.isSingleCompressedDiff,"-SD -BSD can only set one");
if (compressPlugin!=0){
_options_check(0==strcmp(compressPlugin->compressType(),"bz2"),"bsdiff must run with -c-bz2");
}else{
static TCompressPlugin_bz2 _bz2CompressPlugin=bz2CompressPlugin;
compressPlugin=&_bz2CompressPlugin.base;
}
}
#endif
#if (_IS_NEED_DIR_DIFF_PATCH)
if (kMaxOpenFileNumber==_kNULL_SIZE)
kMaxOpenFileNumber=kMaxOpenFileNumber_default_diff;
if (kMaxOpenFileNumber<kMaxOpenFileNumber_default_min)
kMaxOpenFileNumber=kMaxOpenFileNumber_default_min;
#endif
if (diffSets.isDiffInMem&&(diffSets.matchBlockSize==_kNULL_SIZE))
diffSets.matchBlockSize=kDefaultFastMatchBlockSize;
if (diffSets.threadNum==_THREAD_NUMBER_NULL)
diffSets.threadNum=_THREAD_NUMBER_DEFUALT;
else if (diffSets.threadNum>_THREAD_NUMBER_MAX)
diffSets.threadNum=_THREAD_NUMBER_MAX;
if (compressPlugin!=0){
compressPlugin->setParallelThreadNumber(compressPlugin,(int)diffSets.threadNum);
}
if (isOldPathInputEmpty==_kNULL_VALUE)
isOldPathInputEmpty=hpatch_FALSE;
_options_check((arg_values.size()==1)||(arg_values.size()==2)||(arg_values.size()==3),"input count");
if (arg_values.size()==3){ //diff
if (diffSets.isDiffInMem==_kNULL_VALUE){
diffSets.isDiffInMem=hpatch_TRUE;
diffSets.matchScore=kMinSingleMatchScore_default;
}
if (diffSets.isDoDiff==_kNULL_VALUE)
diffSets.isDoDiff=hpatch_TRUE;
if (diffSets.isDoPatchCheck==_kNULL_VALUE)
diffSets.isDoPatchCheck=hpatch_TRUE;
assert(diffSets.isDoDiff||diffSets.isDoPatchCheck);
if (diffSets.isUseBigCacheMatch==_kNULL_VALUE)
diffSets.isUseBigCacheMatch=hpatch_FALSE;
if (diffSets.isDoDiff&&(!diffSets.isDiffInMem)){
_options_check(!diffSets.isUseBigCacheMatch, "-cache must run with -m");
}
#if (_IS_NEED_DIR_DIFF_PATCH)
if (isForceRunDirDiff==_kNULL_VALUE)
isForceRunDirDiff=hpatch_FALSE;
if (isSetChecksum==_kNULL_VALUE)
isSetChecksum=hpatch_FALSE;
if ((!manifestOld.empty())||(!manifestNew.empty())){
isForceRunDirDiff=hpatch_TRUE;
_options_check(manifestOut.empty()&&(!manifestNew.empty()),"-M?");
if (isOldPathInputEmpty){
_options_check(manifestOld.empty(),"-M?");
}else{
_options_check(!manifestOld.empty(),"-M?");
}
_options_check(ignorePathList.empty()&&ignoreOldPathList.empty()