├── .gitignore
├── ApkPatchLibrary
├── .cproject
├── .externalToolBuilders
│ └── NDK_Builder__.launch
├── .gitignore
├── AndroidManifest.xml
├── jni
│ ├── Android.mk
│ ├── bzip2
│ │ ├── blocksort.c
│ │ ├── bzip2.c
│ │ ├── bzip2recover.c
│ │ ├── bzlib.c
│ │ ├── bzlib.h
│ │ ├── bzlib_private.h
│ │ ├── compress.c
│ │ ├── crctable.c
│ │ ├── decompress.c
│ │ ├── huffman.c
│ │ ├── randtable.c
│ │ └── readMe.txt
│ ├── com_jph_utils_PatchUtils.c
│ └── com_jph_utils_PatchUtils.h
├── libs
│ └── armeabi
│ │ └── libApkPatchLibrary.so
├── lint.xml
├── obj
│ └── local
│ │ └── armeabi
│ │ ├── libApkPatchLibrary.so
│ │ └── objs
│ │ └── ApkPatchLibrary
│ │ ├── com_cundong_utils_PatchUtils.o
│ │ ├── com_cundong_utils_PatchUtils.o.d
│ │ ├── com_jph_utils_PatchUtils.o
│ │ └── com_jph_utils_PatchUtils.o.d
├── proguard-project.txt
├── project.properties
├── res
│ ├── drawable-hdpi
│ │ └── ic_launcher.png
│ ├── drawable-mdpi
│ │ └── ic_launcher.png
│ ├── drawable-xhdpi
│ │ └── ic_launcher.png
│ ├── values-v11
│ │ └── styles.xml
│ ├── values-v14
│ │ └── styles.xml
│ └── values
│ │ ├── strings.xml
│ │ └── styles.xml
└── src
│ └── com
│ └── jph
│ └── utils
│ └── PatchUtils.java
├── IncrementalUpdate-Android
├── .gitignore
├── .idea
│ └── vcs.xml
├── app
│ ├── .gitignore
│ ├── build.gradle
│ ├── proguard-rules.pro
│ └── src
│ │ └── main
│ │ ├── AndroidManifest.xml
│ │ ├── java
│ │ └── com
│ │ │ └── jph
│ │ │ ├── iu
│ │ │ └── activity
│ │ │ │ ├── ApkUtils.java
│ │ │ │ ├── Constants.java
│ │ │ │ ├── MainActivity.java
│ │ │ │ └── SignUtils.java
│ │ │ └── utils
│ │ │ └── PatchUtils.java
│ │ ├── jniLibs
│ │ └── armeabi
│ │ │ └── libApkPatchLibrary.so
│ │ └── res
│ │ ├── layout
│ │ └── activity_main.xml
│ │ ├── mipmap-hdpi
│ │ └── ic_launcher.png
│ │ ├── mipmap-mdpi
│ │ └── ic_launcher.png
│ │ ├── mipmap-xhdpi
│ │ └── ic_launcher.png
│ │ ├── mipmap-xxhdpi
│ │ └── ic_launcher.png
│ │ ├── mipmap-xxxhdpi
│ │ └── ic_launcher.png
│ │ ├── values-w820dp
│ │ └── dimens.xml
│ │ └── values
│ │ ├── colors.xml
│ │ ├── dimens.xml
│ │ ├── strings.xml
│ │ └── styles.xml
├── build.gradle
├── gradle.properties
├── gradle
│ └── wrapper
│ │ ├── gradle-wrapper.jar
│ │ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
└── settings.gradle
├── IncrementalUpdate-web
├── .classpath
├── .project
├── .settings
│ ├── .jsdtscope
│ ├── org.eclipse.core.resources.prefs
│ ├── org.eclipse.jdt.core.prefs
│ ├── org.eclipse.wst.common.component
│ ├── org.eclipse.wst.common.project.facet.core.xml
│ ├── org.eclipse.wst.jsdt.ui.superType.container
│ └── org.eclipse.wst.jsdt.ui.superType.name
├── WebContent
│ ├── ApplyPatch.jsp
│ ├── GenPatch.jsp
│ ├── META-INF
│ │ └── MANIFEST.MF
│ └── WEB-INF
│ │ ├── lib
│ │ ├── bsdiff.exe
│ │ └── bspatch.exe
│ │ └── web.xml
└── src
│ └── com
│ └── jph
│ └── iu
│ └── server
│ ├── servlet
│ ├── ApplyPatch.java
│ └── GenPatch.java
│ └── util
│ └── PatchFile.java
├── LICENSE
├── PatchUtil-cs
├── .vs
│ └── PatchUtil
│ │ └── v14
│ │ └── .suo
├── PatchUtil.sln
└── PatchUtil
│ ├── App.config
│ ├── Main.Designer.cs
│ ├── Main.cs
│ ├── Main.resx
│ ├── PatchUtil.csproj
│ ├── Program.cs
│ ├── Properties
│ ├── AssemblyInfo.cs
│ ├── Resources.Designer.cs
│ ├── Resources.resx
│ ├── Settings.Designer.cs
│ └── Settings.settings
│ ├── lib
│ ├── bsdiff.exe
│ └── bspatch.exe
│ └── obj
│ └── Debug
│ ├── DesignTimeResolveAssemblyReferences.cache
│ ├── DesignTimeResolveAssemblyReferencesInput.cache
│ ├── PatchUtil.csproj.FileListAbsolute.txt
│ ├── PatchUtil.csproj.GenerateResource.Cache
│ ├── PatchUtil.csprojResolveAssemblyReference.cache
│ ├── TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs
│ ├── TemporaryGeneratedFile_5937a670-0e60-4077-877b-f7221da3dda1.cs
│ ├── TemporaryGeneratedFile_E7A71F73-0F8D-4B9B-B56E-8E70B10BC5D3.cs
│ ├── WindowsFormsApplication2.Main.resources
│ ├── WindowsFormsApplication2.Properties.Resources.resources
│ ├── WindowsFormsApplication2.csproj.FileListAbsolute.txt
│ ├── WindowsFormsApplication2.csproj.GenerateResource.Cache
│ ├── WindowsFormsApplication2.csprojResolveAssemblyReference.cache
│ ├── WindowsFormsApplication2.exe
│ └── WindowsFormsApplication2.pdb
└── README.md
/.gitignore:
--------------------------------------------------------------------------------
1 | # Built application files
2 | *.apk
3 | *.ap_
4 |
5 | # Files for the Dalvik VM
6 | *.dex
7 |
8 | # Java class files
9 | *.class
10 |
11 | # Generated files
12 | bin/
13 | gen/
14 |
15 | # Gradle files
16 | .gradle/
17 | build/
18 |
19 | # Local configuration file (sdk path, etc)
20 | local.properties
21 |
22 | # Proguard folder generated by Eclipse
23 | proguard/
24 |
25 | # Log Files
26 | *.log
27 |
28 | # Android Studio Navigation editor temp files
29 | .navigation/
30 |
31 | # Android Studio captures folder
32 | captures/
33 |
--------------------------------------------------------------------------------
/ApkPatchLibrary/.cproject:
--------------------------------------------------------------------------------
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 |
--------------------------------------------------------------------------------
/ApkPatchLibrary/.externalToolBuilders/NDK_Builder__.launch:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/ApkPatchLibrary/.gitignore:
--------------------------------------------------------------------------------
1 | # built application files
2 | *.ap_
3 |
4 | # files for the dex VM
5 | *.dex
6 |
7 | # Java class files
8 | *.class
9 |
10 | # generated files
11 | bin/
12 | gen/
13 |
14 | # Local configuration file (sdk path, etc)
15 | local.properties
16 |
17 | # Proguard folder generated by Eclipse
18 | proguard/
19 |
20 | # Ignore gradle files
21 | .gradle/
22 | build/
23 |
24 | # Eclipse project files
25 | .classpath
26 | .project
27 | .settings/
28 |
29 | # Intellij project files
30 | *.iml
31 | *.ipr
32 | *.iws
33 | .idea/
34 |
35 | # Mac system files
36 | .DS_Store
37 |
--------------------------------------------------------------------------------
/ApkPatchLibrary/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
5 |
6 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/ApkPatchLibrary/jni/Android.mk:
--------------------------------------------------------------------------------
1 | LOCAL_PATH := $(call my-dir)
2 |
3 | include $(CLEAR_VARS)
4 |
5 | LOCAL_MODULE := ApkPatchLibrary
6 | LOCAL_SRC_FILES := com_jph_utils_PatchUtils.c
7 |
8 | LOCAL_LDLIBS := -lz -llog
9 |
10 | include $(BUILD_SHARED_LIBRARY)
--------------------------------------------------------------------------------
/ApkPatchLibrary/jni/bzip2/bzip2recover.c:
--------------------------------------------------------------------------------
1 | /*-----------------------------------------------------------*/
2 | /*--- Block recoverer program for bzip2 ---*/
3 | /*--- bzip2recover.c ---*/
4 | /*-----------------------------------------------------------*/
5 |
6 | /* ------------------------------------------------------------------
7 | This file is part of bzip2/libbzip2, a program and library for
8 | lossless, block-sorting data compression.
9 |
10 | bzip2/libbzip2 version 1.0.6 of 6 September 2010
11 | Copyright (C) 1996-2010 Julian Seward
12 |
13 | Please read the WARNING, DISCLAIMER and PATENTS sections in the
14 | README file.
15 |
16 | This program is released under the terms of the license contained
17 | in the file LICENSE.
18 | ------------------------------------------------------------------ */
19 |
20 | /* This program is a complete hack and should be rewritten properly.
21 | It isn't very complicated. */
22 |
23 | #include
24 | #include
25 | #include
26 | #include
27 |
28 |
29 | /* This program records bit locations in the file to be recovered.
30 | That means that if 64-bit ints are not supported, we will not
31 | be able to recover .bz2 files over 512MB (2^32 bits) long.
32 | On GNU supported platforms, we take advantage of the 64-bit
33 | int support to circumvent this problem. Ditto MSVC.
34 |
35 | This change occurred in version 1.0.2; all prior versions have
36 | the 512MB limitation.
37 | */
38 | #ifdef __GNUC__
39 | typedef unsigned long long int MaybeUInt64;
40 | # define MaybeUInt64_FMT "%Lu"
41 | #else
42 | #ifdef _MSC_VER
43 | typedef unsigned __int64 MaybeUInt64;
44 | # define MaybeUInt64_FMT "%I64u"
45 | #else
46 | typedef unsigned int MaybeUInt64;
47 | # define MaybeUInt64_FMT "%u"
48 | #endif
49 | #endif
50 |
51 | typedef unsigned int UInt32;
52 | typedef int Int32;
53 | typedef unsigned char UChar;
54 | typedef char Char;
55 | typedef unsigned char Bool;
56 | #define True ((Bool)1)
57 | #define False ((Bool)0)
58 |
59 |
60 | #define BZ_MAX_FILENAME 2000
61 |
62 | Char inFileName[BZ_MAX_FILENAME];
63 | Char outFileName[BZ_MAX_FILENAME];
64 | Char progName[BZ_MAX_FILENAME];
65 |
66 | MaybeUInt64 bytesOut = 0;
67 | MaybeUInt64 bytesIn = 0;
68 |
69 |
70 | /*---------------------------------------------------*/
71 | /*--- Header bytes ---*/
72 | /*---------------------------------------------------*/
73 |
74 | #define BZ_HDR_B 0x42 /* 'B' */
75 | #define BZ_HDR_Z 0x5a /* 'Z' */
76 | #define BZ_HDR_h 0x68 /* 'h' */
77 | #define BZ_HDR_0 0x30 /* '0' */
78 |
79 |
80 | /*---------------------------------------------------*/
81 | /*--- I/O errors ---*/
82 | /*---------------------------------------------------*/
83 |
84 | /*---------------------------------------------*/
85 | static void readError ( void )
86 | {
87 | fprintf ( stderr,
88 | "%s: I/O error reading `%s', possible reason follows.\n",
89 | progName, inFileName );
90 | perror ( progName );
91 | fprintf ( stderr, "%s: warning: output file(s) may be incomplete.\n",
92 | progName );
93 | exit ( 1 );
94 | }
95 |
96 |
97 | /*---------------------------------------------*/
98 | static void writeError ( void )
99 | {
100 | fprintf ( stderr,
101 | "%s: I/O error reading `%s', possible reason follows.\n",
102 | progName, inFileName );
103 | perror ( progName );
104 | fprintf ( stderr, "%s: warning: output file(s) may be incomplete.\n",
105 | progName );
106 | exit ( 1 );
107 | }
108 |
109 |
110 | /*---------------------------------------------*/
111 | static void mallocFail ( Int32 n )
112 | {
113 | fprintf ( stderr,
114 | "%s: malloc failed on request for %d bytes.\n",
115 | progName, n );
116 | fprintf ( stderr, "%s: warning: output file(s) may be incomplete.\n",
117 | progName );
118 | exit ( 1 );
119 | }
120 |
121 |
122 | /*---------------------------------------------*/
123 | static void tooManyBlocks ( Int32 max_handled_blocks )
124 | {
125 | fprintf ( stderr,
126 | "%s: `%s' appears to contain more than %d blocks\n",
127 | progName, inFileName, max_handled_blocks );
128 | fprintf ( stderr,
129 | "%s: and cannot be handled. To fix, increase\n",
130 | progName );
131 | fprintf ( stderr,
132 | "%s: BZ_MAX_HANDLED_BLOCKS in bzip2recover.c, and recompile.\n",
133 | progName );
134 | exit ( 1 );
135 | }
136 |
137 |
138 |
139 | /*---------------------------------------------------*/
140 | /*--- Bit stream I/O ---*/
141 | /*---------------------------------------------------*/
142 |
143 | typedef
144 | struct {
145 | FILE* handle;
146 | Int32 buffer;
147 | Int32 buffLive;
148 | Char mode;
149 | }
150 | BitStream;
151 |
152 |
153 | /*---------------------------------------------*/
154 | static BitStream* bsOpenReadStream ( FILE* stream )
155 | {
156 | BitStream *bs = malloc ( sizeof(BitStream) );
157 | if (bs == NULL) mallocFail ( sizeof(BitStream) );
158 | bs->handle = stream;
159 | bs->buffer = 0;
160 | bs->buffLive = 0;
161 | bs->mode = 'r';
162 | return bs;
163 | }
164 |
165 |
166 | /*---------------------------------------------*/
167 | static BitStream* bsOpenWriteStream ( FILE* stream )
168 | {
169 | BitStream *bs = malloc ( sizeof(BitStream) );
170 | if (bs == NULL) mallocFail ( sizeof(BitStream) );
171 | bs->handle = stream;
172 | bs->buffer = 0;
173 | bs->buffLive = 0;
174 | bs->mode = 'w';
175 | return bs;
176 | }
177 |
178 |
179 | /*---------------------------------------------*/
180 | static void bsPutBit ( BitStream* bs, Int32 bit )
181 | {
182 | if (bs->buffLive == 8) {
183 | Int32 retVal = putc ( (UChar) bs->buffer, bs->handle );
184 | if (retVal == EOF) writeError();
185 | bytesOut++;
186 | bs->buffLive = 1;
187 | bs->buffer = bit & 0x1;
188 | } else {
189 | bs->buffer = ( (bs->buffer << 1) | (bit & 0x1) );
190 | bs->buffLive++;
191 | };
192 | }
193 |
194 |
195 | /*---------------------------------------------*/
196 | /*--
197 | Returns 0 or 1, or 2 to indicate EOF.
198 | --*/
199 | static Int32 bsGetBit ( BitStream* bs )
200 | {
201 | if (bs->buffLive > 0) {
202 | bs->buffLive --;
203 | return ( ((bs->buffer) >> (bs->buffLive)) & 0x1 );
204 | } else {
205 | Int32 retVal = getc ( bs->handle );
206 | if ( retVal == EOF ) {
207 | if (errno != 0) readError();
208 | return 2;
209 | }
210 | bs->buffLive = 7;
211 | bs->buffer = retVal;
212 | return ( ((bs->buffer) >> 7) & 0x1 );
213 | }
214 | }
215 |
216 |
217 | /*---------------------------------------------*/
218 | static void bsClose ( BitStream* bs )
219 | {
220 | Int32 retVal;
221 |
222 | if ( bs->mode == 'w' ) {
223 | while ( bs->buffLive < 8 ) {
224 | bs->buffLive++;
225 | bs->buffer <<= 1;
226 | };
227 | retVal = putc ( (UChar) (bs->buffer), bs->handle );
228 | if (retVal == EOF) writeError();
229 | bytesOut++;
230 | retVal = fflush ( bs->handle );
231 | if (retVal == EOF) writeError();
232 | }
233 | retVal = fclose ( bs->handle );
234 | if (retVal == EOF) {
235 | if (bs->mode == 'w') writeError(); else readError();
236 | }
237 | free ( bs );
238 | }
239 |
240 |
241 | /*---------------------------------------------*/
242 | static void bsPutUChar ( BitStream* bs, UChar c )
243 | {
244 | Int32 i;
245 | for (i = 7; i >= 0; i--)
246 | bsPutBit ( bs, (((UInt32) c) >> i) & 0x1 );
247 | }
248 |
249 |
250 | /*---------------------------------------------*/
251 | static void bsPutUInt32 ( BitStream* bs, UInt32 c )
252 | {
253 | Int32 i;
254 |
255 | for (i = 31; i >= 0; i--)
256 | bsPutBit ( bs, (c >> i) & 0x1 );
257 | }
258 |
259 |
260 | /*---------------------------------------------*/
261 | static Bool endsInBz2 ( Char* name )
262 | {
263 | Int32 n = strlen ( name );
264 | if (n <= 4) return False;
265 | return
266 | (name[n-4] == '.' &&
267 | name[n-3] == 'b' &&
268 | name[n-2] == 'z' &&
269 | name[n-1] == '2');
270 | }
271 |
272 |
273 | /*---------------------------------------------------*/
274 | /*--- ---*/
275 | /*---------------------------------------------------*/
276 |
277 | /* This logic isn't really right when it comes to Cygwin. */
278 | #ifdef _WIN32
279 | # define BZ_SPLIT_SYM '\\' /* path splitter on Windows platform */
280 | #else
281 | # define BZ_SPLIT_SYM '/' /* path splitter on Unix platform */
282 | #endif
283 |
284 | #define BLOCK_HEADER_HI 0x00003141UL
285 | #define BLOCK_HEADER_LO 0x59265359UL
286 |
287 | #define BLOCK_ENDMARK_HI 0x00001772UL
288 | #define BLOCK_ENDMARK_LO 0x45385090UL
289 |
290 | /* Increase if necessary. However, a .bz2 file with > 50000 blocks
291 | would have an uncompressed size of at least 40GB, so the chances
292 | are low you'll need to up this.
293 | */
294 | #define BZ_MAX_HANDLED_BLOCKS 50000
295 |
296 | MaybeUInt64 bStart [BZ_MAX_HANDLED_BLOCKS];
297 | MaybeUInt64 bEnd [BZ_MAX_HANDLED_BLOCKS];
298 | MaybeUInt64 rbStart[BZ_MAX_HANDLED_BLOCKS];
299 | MaybeUInt64 rbEnd [BZ_MAX_HANDLED_BLOCKS];
300 |
301 |
302 | /*-----------------------------------------------------------*/
303 | /*--- end bzip2recover.c ---*/
304 | /*-----------------------------------------------------------*/
305 |
--------------------------------------------------------------------------------
/ApkPatchLibrary/jni/bzip2/bzlib.h:
--------------------------------------------------------------------------------
1 |
2 | /*-------------------------------------------------------------*/
3 | /*--- Public header file for the library. ---*/
4 | /*--- bzlib.h ---*/
5 | /*-------------------------------------------------------------*/
6 |
7 | /* ------------------------------------------------------------------
8 | This file is part of bzip2/libbzip2, a program and library for
9 | lossless, block-sorting data compression.
10 |
11 | bzip2/libbzip2 version 1.0.6 of 6 September 2010
12 | Copyright (C) 1996-2010 Julian Seward
13 |
14 | Please read the WARNING, DISCLAIMER and PATENTS sections in the
15 | README file.
16 |
17 | This program is released under the terms of the license contained
18 | in the file LICENSE.
19 | ------------------------------------------------------------------ */
20 |
21 |
22 | #ifndef _BZLIB_H
23 | #define _BZLIB_H
24 |
25 | #ifdef __cplusplus
26 | extern "C" {
27 | #endif
28 |
29 | #define BZ_RUN 0
30 | #define BZ_FLUSH 1
31 | #define BZ_FINISH 2
32 |
33 | #define BZ_OK 0
34 | #define BZ_RUN_OK 1
35 | #define BZ_FLUSH_OK 2
36 | #define BZ_FINISH_OK 3
37 | #define BZ_STREAM_END 4
38 | #define BZ_SEQUENCE_ERROR (-1)
39 | #define BZ_PARAM_ERROR (-2)
40 | #define BZ_MEM_ERROR (-3)
41 | #define BZ_DATA_ERROR (-4)
42 | #define BZ_DATA_ERROR_MAGIC (-5)
43 | #define BZ_IO_ERROR (-6)
44 | #define BZ_UNEXPECTED_EOF (-7)
45 | #define BZ_OUTBUFF_FULL (-8)
46 | #define BZ_CONFIG_ERROR (-9)
47 |
48 | typedef
49 | struct {
50 | char *next_in;
51 | unsigned int avail_in;
52 | unsigned int total_in_lo32;
53 | unsigned int total_in_hi32;
54 |
55 | char *next_out;
56 | unsigned int avail_out;
57 | unsigned int total_out_lo32;
58 | unsigned int total_out_hi32;
59 |
60 | void *state;
61 |
62 | void *(*bzalloc)(void *,int,int);
63 | void (*bzfree)(void *,void *);
64 | void *opaque;
65 | }
66 | bz_stream;
67 |
68 |
69 | #ifndef BZ_IMPORT
70 | #define BZ_EXPORT
71 | #endif
72 |
73 | #ifndef BZ_NO_STDIO
74 | /* Need a definitition for FILE */
75 | #include
76 | #endif
77 |
78 | #ifdef _WIN32
79 | # include
80 | # ifdef small
81 | /* windows.h define small to char */
82 | # undef small
83 | # endif
84 | # ifdef BZ_EXPORT
85 | # define BZ_API(func) WINAPI func
86 | # define BZ_EXTERN extern
87 | # else
88 | /* import windows dll dynamically */
89 | # define BZ_API(func) (WINAPI * func)
90 | # define BZ_EXTERN
91 | # endif
92 | #else
93 | # define BZ_API(func) func
94 | # define BZ_EXTERN extern
95 | #endif
96 |
97 |
98 | /*-- Core (low-level) library functions --*/
99 |
100 | BZ_EXTERN int BZ_API(BZ2_bzCompressInit) (
101 | bz_stream* strm,
102 | int blockSize100k,
103 | int verbosity,
104 | int workFactor
105 | );
106 |
107 | BZ_EXTERN int BZ_API(BZ2_bzCompress) (
108 | bz_stream* strm,
109 | int action
110 | );
111 |
112 | BZ_EXTERN int BZ_API(BZ2_bzCompressEnd) (
113 | bz_stream* strm
114 | );
115 |
116 | BZ_EXTERN int BZ_API(BZ2_bzDecompressInit) (
117 | bz_stream *strm,
118 | int verbosity,
119 | int small
120 | );
121 |
122 | BZ_EXTERN int BZ_API(BZ2_bzDecompress) (
123 | bz_stream* strm
124 | );
125 |
126 | BZ_EXTERN int BZ_API(BZ2_bzDecompressEnd) (
127 | bz_stream *strm
128 | );
129 |
130 |
131 |
132 | /*-- High(er) level library functions --*/
133 |
134 | #ifndef BZ_NO_STDIO
135 | #define BZ_MAX_UNUSED 5000
136 |
137 | typedef void BZFILE;
138 |
139 | BZ_EXTERN BZFILE* BZ_API(BZ2_bzReadOpen) (
140 | int* bzerror,
141 | FILE* f,
142 | int verbosity,
143 | int small,
144 | void* unused,
145 | int nUnused
146 | );
147 |
148 | BZ_EXTERN void BZ_API(BZ2_bzReadClose) (
149 | int* bzerror,
150 | BZFILE* b
151 | );
152 |
153 | BZ_EXTERN void BZ_API(BZ2_bzReadGetUnused) (
154 | int* bzerror,
155 | BZFILE* b,
156 | void** unused,
157 | int* nUnused
158 | );
159 |
160 | BZ_EXTERN int BZ_API(BZ2_bzRead) (
161 | int* bzerror,
162 | BZFILE* b,
163 | void* buf,
164 | int len
165 | );
166 |
167 | BZ_EXTERN BZFILE* BZ_API(BZ2_bzWriteOpen) (
168 | int* bzerror,
169 | FILE* f,
170 | int blockSize100k,
171 | int verbosity,
172 | int workFactor
173 | );
174 |
175 | BZ_EXTERN void BZ_API(BZ2_bzWrite) (
176 | int* bzerror,
177 | BZFILE* b,
178 | void* buf,
179 | int len
180 | );
181 |
182 | BZ_EXTERN void BZ_API(BZ2_bzWriteClose) (
183 | int* bzerror,
184 | BZFILE* b,
185 | int abandon,
186 | unsigned int* nbytes_in,
187 | unsigned int* nbytes_out
188 | );
189 |
190 | BZ_EXTERN void BZ_API(BZ2_bzWriteClose64) (
191 | int* bzerror,
192 | BZFILE* b,
193 | int abandon,
194 | unsigned int* nbytes_in_lo32,
195 | unsigned int* nbytes_in_hi32,
196 | unsigned int* nbytes_out_lo32,
197 | unsigned int* nbytes_out_hi32
198 | );
199 | #endif
200 |
201 |
202 | /*-- Utility functions --*/
203 |
204 | BZ_EXTERN int BZ_API(BZ2_bzBuffToBuffCompress) (
205 | char* dest,
206 | unsigned int* destLen,
207 | char* source,
208 | unsigned int sourceLen,
209 | int blockSize100k,
210 | int verbosity,
211 | int workFactor
212 | );
213 |
214 | BZ_EXTERN int BZ_API(BZ2_bzBuffToBuffDecompress) (
215 | char* dest,
216 | unsigned int* destLen,
217 | char* source,
218 | unsigned int sourceLen,
219 | int small,
220 | int verbosity
221 | );
222 |
223 |
224 | /*--
225 | Code contributed by Yoshioka Tsuneo (tsuneo@rr.iij4u.or.jp)
226 | to support better zlib compatibility.
227 | This code is not _officially_ part of libbzip2 (yet);
228 | I haven't tested it, documented it, or considered the
229 | threading-safeness of it.
230 | If this code breaks, please contact both Yoshioka and me.
231 | --*/
232 |
233 | BZ_EXTERN const char * BZ_API(BZ2_bzlibVersion) (
234 | void
235 | );
236 |
237 | #ifndef BZ_NO_STDIO
238 | BZ_EXTERN BZFILE * BZ_API(BZ2_bzopen) (
239 | const char *path,
240 | const char *mode
241 | );
242 |
243 | BZ_EXTERN BZFILE * BZ_API(BZ2_bzdopen) (
244 | int fd,
245 | const char *mode
246 | );
247 |
248 | BZ_EXTERN int BZ_API(BZ2_bzread) (
249 | BZFILE* b,
250 | void* buf,
251 | int len
252 | );
253 |
254 | BZ_EXTERN int BZ_API(BZ2_bzwrite) (
255 | BZFILE* b,
256 | void* buf,
257 | int len
258 | );
259 |
260 | BZ_EXTERN int BZ_API(BZ2_bzflush) (
261 | BZFILE* b
262 | );
263 |
264 | BZ_EXTERN void BZ_API(BZ2_bzclose) (
265 | BZFILE* b
266 | );
267 |
268 | BZ_EXTERN const char * BZ_API(BZ2_bzerror) (
269 | BZFILE *b,
270 | int *errnum
271 | );
272 | #endif
273 |
274 | #ifdef __cplusplus
275 | }
276 | #endif
277 |
278 | #endif
279 |
280 | /*-------------------------------------------------------------*/
281 | /*--- end bzlib.h ---*/
282 | /*-------------------------------------------------------------*/
283 |
--------------------------------------------------------------------------------
/ApkPatchLibrary/jni/bzip2/bzlib_private.h:
--------------------------------------------------------------------------------
1 |
2 | /*-------------------------------------------------------------*/
3 | /*--- Private header file for the library. ---*/
4 | /*--- bzlib_private.h ---*/
5 | /*-------------------------------------------------------------*/
6 |
7 | /* ------------------------------------------------------------------
8 | This file is part of bzip2/libbzip2, a program and library for
9 | lossless, block-sorting data compression.
10 |
11 | bzip2/libbzip2 version 1.0.6 of 6 September 2010
12 | Copyright (C) 1996-2010 Julian Seward
13 |
14 | Please read the WARNING, DISCLAIMER and PATENTS sections in the
15 | README file.
16 |
17 | This program is released under the terms of the license contained
18 | in the file LICENSE.
19 | ------------------------------------------------------------------ */
20 |
21 |
22 | #ifndef _BZLIB_PRIVATE_H
23 | #define _BZLIB_PRIVATE_H
24 |
25 | #include
26 |
27 | #ifndef BZ_NO_STDIO
28 | #include
29 | #include
30 | #include
31 | #endif
32 |
33 | #include "bzlib.h"
34 |
35 |
36 |
37 | /*-- General stuff. --*/
38 |
39 | #define BZ_VERSION "1.0.6, 6-Sept-2010"
40 |
41 | typedef char Char;
42 | typedef unsigned char Bool;
43 | typedef unsigned char UChar;
44 | typedef int Int32;
45 | typedef unsigned int UInt32;
46 | typedef short Int16;
47 | typedef unsigned short UInt16;
48 |
49 | #define True ((Bool)1)
50 | #define False ((Bool)0)
51 |
52 | #ifndef __GNUC__
53 | #define __inline__ /* */
54 | #endif
55 |
56 | #ifndef BZ_NO_STDIO
57 |
58 | extern void BZ2_bz__AssertH__fail ( int errcode );
59 | #define AssertH(cond,errcode) \
60 | { if (!(cond)) BZ2_bz__AssertH__fail ( errcode ); }
61 |
62 | #if BZ_DEBUG
63 | #define AssertD(cond,msg) \
64 | { if (!(cond)) { \
65 | fprintf ( stderr, \
66 | "\n\nlibbzip2(debug build): internal error\n\t%s\n", msg );\
67 | exit(1); \
68 | }}
69 | #else
70 | #define AssertD(cond,msg) /* */
71 | #endif
72 |
73 | #define VPrintf0(zf) \
74 | fprintf(stderr,zf)
75 | #define VPrintf1(zf,za1) \
76 | fprintf(stderr,zf,za1)
77 | #define VPrintf2(zf,za1,za2) \
78 | fprintf(stderr,zf,za1,za2)
79 | #define VPrintf3(zf,za1,za2,za3) \
80 | fprintf(stderr,zf,za1,za2,za3)
81 | #define VPrintf4(zf,za1,za2,za3,za4) \
82 | fprintf(stderr,zf,za1,za2,za3,za4)
83 | #define VPrintf5(zf,za1,za2,za3,za4,za5) \
84 | fprintf(stderr,zf,za1,za2,za3,za4,za5)
85 |
86 | #else
87 |
88 | extern void bz_internal_error ( int errcode );
89 | #define AssertH(cond,errcode) \
90 | { if (!(cond)) bz_internal_error ( errcode ); }
91 | #define AssertD(cond,msg) do { } while (0)
92 | #define VPrintf0(zf) do { } while (0)
93 | #define VPrintf1(zf,za1) do { } while (0)
94 | #define VPrintf2(zf,za1,za2) do { } while (0)
95 | #define VPrintf3(zf,za1,za2,za3) do { } while (0)
96 | #define VPrintf4(zf,za1,za2,za3,za4) do { } while (0)
97 | #define VPrintf5(zf,za1,za2,za3,za4,za5) do { } while (0)
98 |
99 | #endif
100 |
101 |
102 | #define BZALLOC(nnn) (strm->bzalloc)(strm->opaque,(nnn),1)
103 | #define BZFREE(ppp) (strm->bzfree)(strm->opaque,(ppp))
104 |
105 |
106 | /*-- Header bytes. --*/
107 |
108 | #define BZ_HDR_B 0x42 /* 'B' */
109 | #define BZ_HDR_Z 0x5a /* 'Z' */
110 | #define BZ_HDR_h 0x68 /* 'h' */
111 | #define BZ_HDR_0 0x30 /* '0' */
112 |
113 | /*-- Constants for the back end. --*/
114 |
115 | #define BZ_MAX_ALPHA_SIZE 258
116 | #define BZ_MAX_CODE_LEN 23
117 |
118 | #define BZ_RUNA 0
119 | #define BZ_RUNB 1
120 |
121 | #define BZ_N_GROUPS 6
122 | #define BZ_G_SIZE 50
123 | #define BZ_N_ITERS 4
124 |
125 | #define BZ_MAX_SELECTORS (2 + (900000 / BZ_G_SIZE))
126 |
127 |
128 |
129 | /*-- Stuff for randomising repetitive blocks. --*/
130 |
131 | extern Int32 BZ2_rNums[512];
132 |
133 | #define BZ_RAND_DECLS \
134 | Int32 rNToGo; \
135 | Int32 rTPos \
136 |
137 | #define BZ_RAND_INIT_MASK \
138 | s->rNToGo = 0; \
139 | s->rTPos = 0 \
140 |
141 | #define BZ_RAND_MASK ((s->rNToGo == 1) ? 1 : 0)
142 |
143 | #define BZ_RAND_UPD_MASK \
144 | if (s->rNToGo == 0) { \
145 | s->rNToGo = BZ2_rNums[s->rTPos]; \
146 | s->rTPos++; \
147 | if (s->rTPos == 512) s->rTPos = 0; \
148 | } \
149 | s->rNToGo--;
150 |
151 |
152 |
153 | /*-- Stuff for doing CRCs. --*/
154 |
155 | extern UInt32 BZ2_crc32Table[256];
156 |
157 | #define BZ_INITIALISE_CRC(crcVar) \
158 | { \
159 | crcVar = 0xffffffffL; \
160 | }
161 |
162 | #define BZ_FINALISE_CRC(crcVar) \
163 | { \
164 | crcVar = ~(crcVar); \
165 | }
166 |
167 | #define BZ_UPDATE_CRC(crcVar,cha) \
168 | { \
169 | crcVar = (crcVar << 8) ^ \
170 | BZ2_crc32Table[(crcVar >> 24) ^ \
171 | ((UChar)cha)]; \
172 | }
173 |
174 |
175 |
176 | /*-- States and modes for compression. --*/
177 |
178 | #define BZ_M_IDLE 1
179 | #define BZ_M_RUNNING 2
180 | #define BZ_M_FLUSHING 3
181 | #define BZ_M_FINISHING 4
182 |
183 | #define BZ_S_OUTPUT 1
184 | #define BZ_S_INPUT 2
185 |
186 | #define BZ_N_RADIX 2
187 | #define BZ_N_QSORT 12
188 | #define BZ_N_SHELL 18
189 | #define BZ_N_OVERSHOOT (BZ_N_RADIX + BZ_N_QSORT + BZ_N_SHELL + 2)
190 |
191 |
192 |
193 |
194 | /*-- Structure holding all the compression-side stuff. --*/
195 |
196 | typedef
197 | struct {
198 | /* pointer back to the struct bz_stream */
199 | bz_stream* strm;
200 |
201 | /* mode this stream is in, and whether inputting */
202 | /* or outputting data */
203 | Int32 mode;
204 | Int32 state;
205 |
206 | /* remembers avail_in when flush/finish requested */
207 | UInt32 avail_in_expect;
208 |
209 | /* for doing the block sorting */
210 | UInt32* arr1;
211 | UInt32* arr2;
212 | UInt32* ftab;
213 | Int32 origPtr;
214 |
215 | /* aliases for arr1 and arr2 */
216 | UInt32* ptr;
217 | UChar* block;
218 | UInt16* mtfv;
219 | UChar* zbits;
220 |
221 | /* for deciding when to use the fallback sorting algorithm */
222 | Int32 workFactor;
223 |
224 | /* run-length-encoding of the input */
225 | UInt32 state_in_ch;
226 | Int32 state_in_len;
227 | BZ_RAND_DECLS;
228 |
229 | /* input and output limits and current posns */
230 | Int32 nblock;
231 | Int32 nblockMAX;
232 | Int32 numZ;
233 | Int32 state_out_pos;
234 |
235 | /* map of bytes used in block */
236 | Int32 nInUse;
237 | Bool inUse[256];
238 | UChar unseqToSeq[256];
239 |
240 | /* the buffer for bit stream creation */
241 | UInt32 bsBuff;
242 | Int32 bsLive;
243 |
244 | /* block and combined CRCs */
245 | UInt32 blockCRC;
246 | UInt32 combinedCRC;
247 |
248 | /* misc administratium */
249 | Int32 verbosity;
250 | Int32 blockNo;
251 | Int32 blockSize100k;
252 |
253 | /* stuff for coding the MTF values */
254 | Int32 nMTF;
255 | Int32 mtfFreq [BZ_MAX_ALPHA_SIZE];
256 | UChar selector [BZ_MAX_SELECTORS];
257 | UChar selectorMtf[BZ_MAX_SELECTORS];
258 |
259 | UChar len [BZ_N_GROUPS][BZ_MAX_ALPHA_SIZE];
260 | Int32 code [BZ_N_GROUPS][BZ_MAX_ALPHA_SIZE];
261 | Int32 rfreq [BZ_N_GROUPS][BZ_MAX_ALPHA_SIZE];
262 | /* second dimension: only 3 needed; 4 makes index calculations faster */
263 | UInt32 len_pack[BZ_MAX_ALPHA_SIZE][4];
264 |
265 | }
266 | EState;
267 |
268 |
269 |
270 | /*-- externs for compression. --*/
271 |
272 | extern void
273 | BZ2_blockSort ( EState* );
274 |
275 | extern void
276 | BZ2_compressBlock ( EState*, Bool );
277 |
278 | extern void
279 | BZ2_bsInitWrite ( EState* );
280 |
281 | extern void
282 | BZ2_hbAssignCodes ( Int32*, UChar*, Int32, Int32, Int32 );
283 |
284 | extern void
285 | BZ2_hbMakeCodeLengths ( UChar*, Int32*, Int32, Int32 );
286 |
287 |
288 |
289 | /*-- states for decompression. --*/
290 |
291 | #define BZ_X_IDLE 1
292 | #define BZ_X_OUTPUT 2
293 |
294 | #define BZ_X_MAGIC_1 10
295 | #define BZ_X_MAGIC_2 11
296 | #define BZ_X_MAGIC_3 12
297 | #define BZ_X_MAGIC_4 13
298 | #define BZ_X_BLKHDR_1 14
299 | #define BZ_X_BLKHDR_2 15
300 | #define BZ_X_BLKHDR_3 16
301 | #define BZ_X_BLKHDR_4 17
302 | #define BZ_X_BLKHDR_5 18
303 | #define BZ_X_BLKHDR_6 19
304 | #define BZ_X_BCRC_1 20
305 | #define BZ_X_BCRC_2 21
306 | #define BZ_X_BCRC_3 22
307 | #define BZ_X_BCRC_4 23
308 | #define BZ_X_RANDBIT 24
309 | #define BZ_X_ORIGPTR_1 25
310 | #define BZ_X_ORIGPTR_2 26
311 | #define BZ_X_ORIGPTR_3 27
312 | #define BZ_X_MAPPING_1 28
313 | #define BZ_X_MAPPING_2 29
314 | #define BZ_X_SELECTOR_1 30
315 | #define BZ_X_SELECTOR_2 31
316 | #define BZ_X_SELECTOR_3 32
317 | #define BZ_X_CODING_1 33
318 | #define BZ_X_CODING_2 34
319 | #define BZ_X_CODING_3 35
320 | #define BZ_X_MTF_1 36
321 | #define BZ_X_MTF_2 37
322 | #define BZ_X_MTF_3 38
323 | #define BZ_X_MTF_4 39
324 | #define BZ_X_MTF_5 40
325 | #define BZ_X_MTF_6 41
326 | #define BZ_X_ENDHDR_2 42
327 | #define BZ_X_ENDHDR_3 43
328 | #define BZ_X_ENDHDR_4 44
329 | #define BZ_X_ENDHDR_5 45
330 | #define BZ_X_ENDHDR_6 46
331 | #define BZ_X_CCRC_1 47
332 | #define BZ_X_CCRC_2 48
333 | #define BZ_X_CCRC_3 49
334 | #define BZ_X_CCRC_4 50
335 |
336 |
337 |
338 | /*-- Constants for the fast MTF decoder. --*/
339 |
340 | #define MTFA_SIZE 4096
341 | #define MTFL_SIZE 16
342 |
343 |
344 |
345 | /*-- Structure holding all the decompression-side stuff. --*/
346 |
347 | typedef
348 | struct {
349 | /* pointer back to the struct bz_stream */
350 | bz_stream* strm;
351 |
352 | /* state indicator for this stream */
353 | Int32 state;
354 |
355 | /* for doing the final run-length decoding */
356 | UChar state_out_ch;
357 | Int32 state_out_len;
358 | Bool blockRandomised;
359 | BZ_RAND_DECLS;
360 |
361 | /* the buffer for bit stream reading */
362 | UInt32 bsBuff;
363 | Int32 bsLive;
364 |
365 | /* misc administratium */
366 | Int32 blockSize100k;
367 | Bool smallDecompress;
368 | Int32 currBlockNo;
369 | Int32 verbosity;
370 |
371 | /* for undoing the Burrows-Wheeler transform */
372 | Int32 origPtr;
373 | UInt32 tPos;
374 | Int32 k0;
375 | Int32 unzftab[256];
376 | Int32 nblock_used;
377 | Int32 cftab[257];
378 | Int32 cftabCopy[257];
379 |
380 | /* for undoing the Burrows-Wheeler transform (FAST) */
381 | UInt32 *tt;
382 |
383 | /* for undoing the Burrows-Wheeler transform (SMALL) */
384 | UInt16 *ll16;
385 | UChar *ll4;
386 |
387 | /* stored and calculated CRCs */
388 | UInt32 storedBlockCRC;
389 | UInt32 storedCombinedCRC;
390 | UInt32 calculatedBlockCRC;
391 | UInt32 calculatedCombinedCRC;
392 |
393 | /* map of bytes used in block */
394 | Int32 nInUse;
395 | Bool inUse[256];
396 | Bool inUse16[16];
397 | UChar seqToUnseq[256];
398 |
399 | /* for decoding the MTF values */
400 | UChar mtfa [MTFA_SIZE];
401 | Int32 mtfbase[256 / MTFL_SIZE];
402 | UChar selector [BZ_MAX_SELECTORS];
403 | UChar selectorMtf[BZ_MAX_SELECTORS];
404 | UChar len [BZ_N_GROUPS][BZ_MAX_ALPHA_SIZE];
405 |
406 | Int32 limit [BZ_N_GROUPS][BZ_MAX_ALPHA_SIZE];
407 | Int32 base [BZ_N_GROUPS][BZ_MAX_ALPHA_SIZE];
408 | Int32 perm [BZ_N_GROUPS][BZ_MAX_ALPHA_SIZE];
409 | Int32 minLens[BZ_N_GROUPS];
410 |
411 | /* save area for scalars in the main decompress code */
412 | Int32 save_i;
413 | Int32 save_j;
414 | Int32 save_t;
415 | Int32 save_alphaSize;
416 | Int32 save_nGroups;
417 | Int32 save_nSelectors;
418 | Int32 save_EOB;
419 | Int32 save_groupNo;
420 | Int32 save_groupPos;
421 | Int32 save_nextSym;
422 | Int32 save_nblockMAX;
423 | Int32 save_nblock;
424 | Int32 save_es;
425 | Int32 save_N;
426 | Int32 save_curr;
427 | Int32 save_zt;
428 | Int32 save_zn;
429 | Int32 save_zvec;
430 | Int32 save_zj;
431 | Int32 save_gSel;
432 | Int32 save_gMinlen;
433 | Int32* save_gLimit;
434 | Int32* save_gBase;
435 | Int32* save_gPerm;
436 |
437 | }
438 | DState;
439 |
440 |
441 |
442 | /*-- Macros for decompression. --*/
443 |
444 | #define BZ_GET_FAST(cccc) \
445 | /* c_tPos is unsigned, hence test < 0 is pointless. */ \
446 | if (s->tPos >= (UInt32)100000 * (UInt32)s->blockSize100k) return True; \
447 | s->tPos = s->tt[s->tPos]; \
448 | cccc = (UChar)(s->tPos & 0xff); \
449 | s->tPos >>= 8;
450 |
451 | #define BZ_GET_FAST_C(cccc) \
452 | /* c_tPos is unsigned, hence test < 0 is pointless. */ \
453 | if (c_tPos >= (UInt32)100000 * (UInt32)ro_blockSize100k) return True; \
454 | c_tPos = c_tt[c_tPos]; \
455 | cccc = (UChar)(c_tPos & 0xff); \
456 | c_tPos >>= 8;
457 |
458 | #define SET_LL4(i,n) \
459 | { if (((i) & 0x1) == 0) \
460 | s->ll4[(i) >> 1] = (s->ll4[(i) >> 1] & 0xf0) | (n); else \
461 | s->ll4[(i) >> 1] = (s->ll4[(i) >> 1] & 0x0f) | ((n) << 4); \
462 | }
463 |
464 | #define GET_LL4(i) \
465 | ((((UInt32)(s->ll4[(i) >> 1])) >> (((i) << 2) & 0x4)) & 0xF)
466 |
467 | #define SET_LL(i,n) \
468 | { s->ll16[i] = (UInt16)(n & 0x0000ffff); \
469 | SET_LL4(i, n >> 16); \
470 | }
471 |
472 | #define GET_LL(i) \
473 | (((UInt32)s->ll16[i]) | (GET_LL4(i) << 16))
474 |
475 | #define BZ_GET_SMALL(cccc) \
476 | /* c_tPos is unsigned, hence test < 0 is pointless. */ \
477 | if (s->tPos >= (UInt32)100000 * (UInt32)s->blockSize100k) return True; \
478 | cccc = BZ2_indexIntoF ( s->tPos, s->cftab ); \
479 | s->tPos = GET_LL(s->tPos);
480 |
481 |
482 | /*-- externs for decompression. --*/
483 |
484 | extern Int32
485 | BZ2_indexIntoF ( Int32, Int32* );
486 |
487 | extern Int32
488 | BZ2_decompress ( DState* );
489 |
490 | extern void
491 | BZ2_hbCreateDecodeTables ( Int32*, Int32*, Int32*, UChar*,
492 | Int32, Int32, Int32 );
493 |
494 |
495 | #endif
496 |
497 |
498 | /*-- BZ_NO_STDIO seems to make NULL disappear on some platforms. --*/
499 |
500 | #ifdef BZ_NO_STDIO
501 | #ifndef NULL
502 | #define NULL 0
503 | #endif
504 | #endif
505 |
506 |
507 | /*-------------------------------------------------------------*/
508 | /*--- end bzlib_private.h ---*/
509 | /*-------------------------------------------------------------*/
510 |
--------------------------------------------------------------------------------
/ApkPatchLibrary/jni/bzip2/crctable.c:
--------------------------------------------------------------------------------
1 |
2 | /*-------------------------------------------------------------*/
3 | /*--- Table for doing CRCs ---*/
4 | /*--- crctable.c ---*/
5 | /*-------------------------------------------------------------*/
6 |
7 | /* ------------------------------------------------------------------
8 | This file is part of bzip2/libbzip2, a program and library for
9 | lossless, block-sorting data compression.
10 |
11 | bzip2/libbzip2 version 1.0.6 of 6 September 2010
12 | Copyright (C) 1996-2010 Julian Seward
13 |
14 | Please read the WARNING, DISCLAIMER and PATENTS sections in the
15 | README file.
16 |
17 | This program is released under the terms of the license contained
18 | in the file LICENSE.
19 | ------------------------------------------------------------------ */
20 |
21 |
22 | #include "bzlib_private.h"
23 |
24 | /*--
25 | I think this is an implementation of the AUTODIN-II,
26 | Ethernet & FDDI 32-bit CRC standard. Vaguely derived
27 | from code by Rob Warnock, in Section 51 of the
28 | comp.compression FAQ.
29 | --*/
30 |
31 | UInt32 BZ2_crc32Table[256] = {
32 |
33 | /*-- Ugly, innit? --*/
34 |
35 | 0x00000000L, 0x04c11db7L, 0x09823b6eL, 0x0d4326d9L,
36 | 0x130476dcL, 0x17c56b6bL, 0x1a864db2L, 0x1e475005L,
37 | 0x2608edb8L, 0x22c9f00fL, 0x2f8ad6d6L, 0x2b4bcb61L,
38 | 0x350c9b64L, 0x31cd86d3L, 0x3c8ea00aL, 0x384fbdbdL,
39 | 0x4c11db70L, 0x48d0c6c7L, 0x4593e01eL, 0x4152fda9L,
40 | 0x5f15adacL, 0x5bd4b01bL, 0x569796c2L, 0x52568b75L,
41 | 0x6a1936c8L, 0x6ed82b7fL, 0x639b0da6L, 0x675a1011L,
42 | 0x791d4014L, 0x7ddc5da3L, 0x709f7b7aL, 0x745e66cdL,
43 | 0x9823b6e0L, 0x9ce2ab57L, 0x91a18d8eL, 0x95609039L,
44 | 0x8b27c03cL, 0x8fe6dd8bL, 0x82a5fb52L, 0x8664e6e5L,
45 | 0xbe2b5b58L, 0xbaea46efL, 0xb7a96036L, 0xb3687d81L,
46 | 0xad2f2d84L, 0xa9ee3033L, 0xa4ad16eaL, 0xa06c0b5dL,
47 | 0xd4326d90L, 0xd0f37027L, 0xddb056feL, 0xd9714b49L,
48 | 0xc7361b4cL, 0xc3f706fbL, 0xceb42022L, 0xca753d95L,
49 | 0xf23a8028L, 0xf6fb9d9fL, 0xfbb8bb46L, 0xff79a6f1L,
50 | 0xe13ef6f4L, 0xe5ffeb43L, 0xe8bccd9aL, 0xec7dd02dL,
51 | 0x34867077L, 0x30476dc0L, 0x3d044b19L, 0x39c556aeL,
52 | 0x278206abL, 0x23431b1cL, 0x2e003dc5L, 0x2ac12072L,
53 | 0x128e9dcfL, 0x164f8078L, 0x1b0ca6a1L, 0x1fcdbb16L,
54 | 0x018aeb13L, 0x054bf6a4L, 0x0808d07dL, 0x0cc9cdcaL,
55 | 0x7897ab07L, 0x7c56b6b0L, 0x71159069L, 0x75d48ddeL,
56 | 0x6b93dddbL, 0x6f52c06cL, 0x6211e6b5L, 0x66d0fb02L,
57 | 0x5e9f46bfL, 0x5a5e5b08L, 0x571d7dd1L, 0x53dc6066L,
58 | 0x4d9b3063L, 0x495a2dd4L, 0x44190b0dL, 0x40d816baL,
59 | 0xaca5c697L, 0xa864db20L, 0xa527fdf9L, 0xa1e6e04eL,
60 | 0xbfa1b04bL, 0xbb60adfcL, 0xb6238b25L, 0xb2e29692L,
61 | 0x8aad2b2fL, 0x8e6c3698L, 0x832f1041L, 0x87ee0df6L,
62 | 0x99a95df3L, 0x9d684044L, 0x902b669dL, 0x94ea7b2aL,
63 | 0xe0b41de7L, 0xe4750050L, 0xe9362689L, 0xedf73b3eL,
64 | 0xf3b06b3bL, 0xf771768cL, 0xfa325055L, 0xfef34de2L,
65 | 0xc6bcf05fL, 0xc27dede8L, 0xcf3ecb31L, 0xcbffd686L,
66 | 0xd5b88683L, 0xd1799b34L, 0xdc3abdedL, 0xd8fba05aL,
67 | 0x690ce0eeL, 0x6dcdfd59L, 0x608edb80L, 0x644fc637L,
68 | 0x7a089632L, 0x7ec98b85L, 0x738aad5cL, 0x774bb0ebL,
69 | 0x4f040d56L, 0x4bc510e1L, 0x46863638L, 0x42472b8fL,
70 | 0x5c007b8aL, 0x58c1663dL, 0x558240e4L, 0x51435d53L,
71 | 0x251d3b9eL, 0x21dc2629L, 0x2c9f00f0L, 0x285e1d47L,
72 | 0x36194d42L, 0x32d850f5L, 0x3f9b762cL, 0x3b5a6b9bL,
73 | 0x0315d626L, 0x07d4cb91L, 0x0a97ed48L, 0x0e56f0ffL,
74 | 0x1011a0faL, 0x14d0bd4dL, 0x19939b94L, 0x1d528623L,
75 | 0xf12f560eL, 0xf5ee4bb9L, 0xf8ad6d60L, 0xfc6c70d7L,
76 | 0xe22b20d2L, 0xe6ea3d65L, 0xeba91bbcL, 0xef68060bL,
77 | 0xd727bbb6L, 0xd3e6a601L, 0xdea580d8L, 0xda649d6fL,
78 | 0xc423cd6aL, 0xc0e2d0ddL, 0xcda1f604L, 0xc960ebb3L,
79 | 0xbd3e8d7eL, 0xb9ff90c9L, 0xb4bcb610L, 0xb07daba7L,
80 | 0xae3afba2L, 0xaafbe615L, 0xa7b8c0ccL, 0xa379dd7bL,
81 | 0x9b3660c6L, 0x9ff77d71L, 0x92b45ba8L, 0x9675461fL,
82 | 0x8832161aL, 0x8cf30badL, 0x81b02d74L, 0x857130c3L,
83 | 0x5d8a9099L, 0x594b8d2eL, 0x5408abf7L, 0x50c9b640L,
84 | 0x4e8ee645L, 0x4a4ffbf2L, 0x470cdd2bL, 0x43cdc09cL,
85 | 0x7b827d21L, 0x7f436096L, 0x7200464fL, 0x76c15bf8L,
86 | 0x68860bfdL, 0x6c47164aL, 0x61043093L, 0x65c52d24L,
87 | 0x119b4be9L, 0x155a565eL, 0x18197087L, 0x1cd86d30L,
88 | 0x029f3d35L, 0x065e2082L, 0x0b1d065bL, 0x0fdc1becL,
89 | 0x3793a651L, 0x3352bbe6L, 0x3e119d3fL, 0x3ad08088L,
90 | 0x2497d08dL, 0x2056cd3aL, 0x2d15ebe3L, 0x29d4f654L,
91 | 0xc5a92679L, 0xc1683bceL, 0xcc2b1d17L, 0xc8ea00a0L,
92 | 0xd6ad50a5L, 0xd26c4d12L, 0xdf2f6bcbL, 0xdbee767cL,
93 | 0xe3a1cbc1L, 0xe760d676L, 0xea23f0afL, 0xeee2ed18L,
94 | 0xf0a5bd1dL, 0xf464a0aaL, 0xf9278673L, 0xfde69bc4L,
95 | 0x89b8fd09L, 0x8d79e0beL, 0x803ac667L, 0x84fbdbd0L,
96 | 0x9abc8bd5L, 0x9e7d9662L, 0x933eb0bbL, 0x97ffad0cL,
97 | 0xafb010b1L, 0xab710d06L, 0xa6322bdfL, 0xa2f33668L,
98 | 0xbcb4666dL, 0xb8757bdaL, 0xb5365d03L, 0xb1f740b4L
99 | };
100 |
101 |
102 | /*-------------------------------------------------------------*/
103 | /*--- end crctable.c ---*/
104 | /*-------------------------------------------------------------*/
105 |
--------------------------------------------------------------------------------
/ApkPatchLibrary/jni/bzip2/huffman.c:
--------------------------------------------------------------------------------
1 |
2 | /*-------------------------------------------------------------*/
3 | /*--- Huffman coding low-level stuff ---*/
4 | /*--- huffman.c ---*/
5 | /*-------------------------------------------------------------*/
6 |
7 | /* ------------------------------------------------------------------
8 | This file is part of bzip2/libbzip2, a program and library for
9 | lossless, block-sorting data compression.
10 |
11 | bzip2/libbzip2 version 1.0.6 of 6 September 2010
12 | Copyright (C) 1996-2010 Julian Seward
13 |
14 | Please read the WARNING, DISCLAIMER and PATENTS sections in the
15 | README file.
16 |
17 | This program is released under the terms of the license contained
18 | in the file LICENSE.
19 | ------------------------------------------------------------------ */
20 |
21 |
22 | #include "bzlib_private.h"
23 |
24 | /*---------------------------------------------------*/
25 | #define WEIGHTOF(zz0) ((zz0) & 0xffffff00)
26 | #define DEPTHOF(zz1) ((zz1) & 0x000000ff)
27 | #define MYMAX(zz2,zz3) ((zz2) > (zz3) ? (zz2) : (zz3))
28 |
29 | #define ADDWEIGHTS(zw1,zw2) \
30 | (WEIGHTOF(zw1)+WEIGHTOF(zw2)) | \
31 | (1 + MYMAX(DEPTHOF(zw1),DEPTHOF(zw2)))
32 |
33 | #define UPHEAP(z) \
34 | { \
35 | Int32 zz, tmp; \
36 | zz = z; tmp = heap[zz]; \
37 | while (weight[tmp] < weight[heap[zz >> 1]]) { \
38 | heap[zz] = heap[zz >> 1]; \
39 | zz >>= 1; \
40 | } \
41 | heap[zz] = tmp; \
42 | }
43 |
44 | #define DOWNHEAP(z) \
45 | { \
46 | Int32 zz, yy, tmp; \
47 | zz = z; tmp = heap[zz]; \
48 | while (True) { \
49 | yy = zz << 1; \
50 | if (yy > nHeap) break; \
51 | if (yy < nHeap && \
52 | weight[heap[yy+1]] < weight[heap[yy]]) \
53 | yy++; \
54 | if (weight[tmp] < weight[heap[yy]]) break; \
55 | heap[zz] = heap[yy]; \
56 | zz = yy; \
57 | } \
58 | heap[zz] = tmp; \
59 | }
60 |
61 |
62 | /*---------------------------------------------------*/
63 | void BZ2_hbMakeCodeLengths ( UChar *len,
64 | Int32 *freq,
65 | Int32 alphaSize,
66 | Int32 maxLen )
67 | {
68 | /*--
69 | Nodes and heap entries run from 1. Entry 0
70 | for both the heap and nodes is a sentinel.
71 | --*/
72 | Int32 nNodes, nHeap, n1, n2, i, j, k;
73 | Bool tooLong;
74 |
75 | Int32 heap [ BZ_MAX_ALPHA_SIZE + 2 ];
76 | Int32 weight [ BZ_MAX_ALPHA_SIZE * 2 ];
77 | Int32 parent [ BZ_MAX_ALPHA_SIZE * 2 ];
78 |
79 | for (i = 0; i < alphaSize; i++)
80 | weight[i+1] = (freq[i] == 0 ? 1 : freq[i]) << 8;
81 |
82 | while (True) {
83 |
84 | nNodes = alphaSize;
85 | nHeap = 0;
86 |
87 | heap[0] = 0;
88 | weight[0] = 0;
89 | parent[0] = -2;
90 |
91 | for (i = 1; i <= alphaSize; i++) {
92 | parent[i] = -1;
93 | nHeap++;
94 | heap[nHeap] = i;
95 | UPHEAP(nHeap);
96 | }
97 |
98 | AssertH( nHeap < (BZ_MAX_ALPHA_SIZE+2), 2001 );
99 |
100 | while (nHeap > 1) {
101 | n1 = heap[1]; heap[1] = heap[nHeap]; nHeap--; DOWNHEAP(1);
102 | n2 = heap[1]; heap[1] = heap[nHeap]; nHeap--; DOWNHEAP(1);
103 | nNodes++;
104 | parent[n1] = parent[n2] = nNodes;
105 | weight[nNodes] = ADDWEIGHTS(weight[n1], weight[n2]);
106 | parent[nNodes] = -1;
107 | nHeap++;
108 | heap[nHeap] = nNodes;
109 | UPHEAP(nHeap);
110 | }
111 |
112 | AssertH( nNodes < (BZ_MAX_ALPHA_SIZE * 2), 2002 );
113 |
114 | tooLong = False;
115 | for (i = 1; i <= alphaSize; i++) {
116 | j = 0;
117 | k = i;
118 | while (parent[k] >= 0) { k = parent[k]; j++; }
119 | len[i-1] = j;
120 | if (j > maxLen) tooLong = True;
121 | }
122 |
123 | if (! tooLong) break;
124 |
125 | /* 17 Oct 04: keep-going condition for the following loop used
126 | to be 'i < alphaSize', which missed the last element,
127 | theoretically leading to the possibility of the compressor
128 | looping. However, this count-scaling step is only needed if
129 | one of the generated Huffman code words is longer than
130 | maxLen, which up to and including version 1.0.2 was 20 bits,
131 | which is extremely unlikely. In version 1.0.3 maxLen was
132 | changed to 17 bits, which has minimal effect on compression
133 | ratio, but does mean this scaling step is used from time to
134 | time, enough to verify that it works.
135 |
136 | This means that bzip2-1.0.3 and later will only produce
137 | Huffman codes with a maximum length of 17 bits. However, in
138 | order to preserve backwards compatibility with bitstreams
139 | produced by versions pre-1.0.3, the decompressor must still
140 | handle lengths of up to 20. */
141 |
142 | for (i = 1; i <= alphaSize; i++) {
143 | j = weight[i] >> 8;
144 | j = 1 + (j / 2);
145 | weight[i] = j << 8;
146 | }
147 | }
148 | }
149 |
150 |
151 | /*---------------------------------------------------*/
152 | void BZ2_hbAssignCodes ( Int32 *code,
153 | UChar *length,
154 | Int32 minLen,
155 | Int32 maxLen,
156 | Int32 alphaSize )
157 | {
158 | Int32 n, vec, i;
159 |
160 | vec = 0;
161 | for (n = minLen; n <= maxLen; n++) {
162 | for (i = 0; i < alphaSize; i++)
163 | if (length[i] == n) { code[i] = vec; vec++; };
164 | vec <<= 1;
165 | }
166 | }
167 |
168 |
169 | /*---------------------------------------------------*/
170 | void BZ2_hbCreateDecodeTables ( Int32 *limit,
171 | Int32 *base,
172 | Int32 *perm,
173 | UChar *length,
174 | Int32 minLen,
175 | Int32 maxLen,
176 | Int32 alphaSize )
177 | {
178 | Int32 pp, i, j, vec;
179 |
180 | pp = 0;
181 | for (i = minLen; i <= maxLen; i++)
182 | for (j = 0; j < alphaSize; j++)
183 | if (length[j] == i) { perm[pp] = j; pp++; };
184 |
185 | for (i = 0; i < BZ_MAX_CODE_LEN; i++) base[i] = 0;
186 | for (i = 0; i < alphaSize; i++) base[length[i]+1]++;
187 |
188 | for (i = 1; i < BZ_MAX_CODE_LEN; i++) base[i] += base[i-1];
189 |
190 | for (i = 0; i < BZ_MAX_CODE_LEN; i++) limit[i] = 0;
191 | vec = 0;
192 |
193 | for (i = minLen; i <= maxLen; i++) {
194 | vec += (base[i+1] - base[i]);
195 | limit[i] = vec-1;
196 | vec <<= 1;
197 | }
198 | for (i = minLen + 1; i <= maxLen; i++)
199 | base[i] = ((limit[i-1] + 1) << 1) - base[i];
200 | }
201 |
202 |
203 | /*-------------------------------------------------------------*/
204 | /*--- end huffman.c ---*/
205 | /*-------------------------------------------------------------*/
206 |
--------------------------------------------------------------------------------
/ApkPatchLibrary/jni/bzip2/randtable.c:
--------------------------------------------------------------------------------
1 |
2 | /*-------------------------------------------------------------*/
3 | /*--- Table for randomising repetitive blocks ---*/
4 | /*--- randtable.c ---*/
5 | /*-------------------------------------------------------------*/
6 |
7 | /* ------------------------------------------------------------------
8 | This file is part of bzip2/libbzip2, a program and library for
9 | lossless, block-sorting data compression.
10 |
11 | bzip2/libbzip2 version 1.0.6 of 6 September 2010
12 | Copyright (C) 1996-2010 Julian Seward
13 |
14 | Please read the WARNING, DISCLAIMER and PATENTS sections in the
15 | README file.
16 |
17 | This program is released under the terms of the license contained
18 | in the file LICENSE.
19 | ------------------------------------------------------------------ */
20 |
21 |
22 | #include "bzlib_private.h"
23 |
24 |
25 | /*---------------------------------------------*/
26 | Int32 BZ2_rNums[512] = {
27 | 619, 720, 127, 481, 931, 816, 813, 233, 566, 247,
28 | 985, 724, 205, 454, 863, 491, 741, 242, 949, 214,
29 | 733, 859, 335, 708, 621, 574, 73, 654, 730, 472,
30 | 419, 436, 278, 496, 867, 210, 399, 680, 480, 51,
31 | 878, 465, 811, 169, 869, 675, 611, 697, 867, 561,
32 | 862, 687, 507, 283, 482, 129, 807, 591, 733, 623,
33 | 150, 238, 59, 379, 684, 877, 625, 169, 643, 105,
34 | 170, 607, 520, 932, 727, 476, 693, 425, 174, 647,
35 | 73, 122, 335, 530, 442, 853, 695, 249, 445, 515,
36 | 909, 545, 703, 919, 874, 474, 882, 500, 594, 612,
37 | 641, 801, 220, 162, 819, 984, 589, 513, 495, 799,
38 | 161, 604, 958, 533, 221, 400, 386, 867, 600, 782,
39 | 382, 596, 414, 171, 516, 375, 682, 485, 911, 276,
40 | 98, 553, 163, 354, 666, 933, 424, 341, 533, 870,
41 | 227, 730, 475, 186, 263, 647, 537, 686, 600, 224,
42 | 469, 68, 770, 919, 190, 373, 294, 822, 808, 206,
43 | 184, 943, 795, 384, 383, 461, 404, 758, 839, 887,
44 | 715, 67, 618, 276, 204, 918, 873, 777, 604, 560,
45 | 951, 160, 578, 722, 79, 804, 96, 409, 713, 940,
46 | 652, 934, 970, 447, 318, 353, 859, 672, 112, 785,
47 | 645, 863, 803, 350, 139, 93, 354, 99, 820, 908,
48 | 609, 772, 154, 274, 580, 184, 79, 626, 630, 742,
49 | 653, 282, 762, 623, 680, 81, 927, 626, 789, 125,
50 | 411, 521, 938, 300, 821, 78, 343, 175, 128, 250,
51 | 170, 774, 972, 275, 999, 639, 495, 78, 352, 126,
52 | 857, 956, 358, 619, 580, 124, 737, 594, 701, 612,
53 | 669, 112, 134, 694, 363, 992, 809, 743, 168, 974,
54 | 944, 375, 748, 52, 600, 747, 642, 182, 862, 81,
55 | 344, 805, 988, 739, 511, 655, 814, 334, 249, 515,
56 | 897, 955, 664, 981, 649, 113, 974, 459, 893, 228,
57 | 433, 837, 553, 268, 926, 240, 102, 654, 459, 51,
58 | 686, 754, 806, 760, 493, 403, 415, 394, 687, 700,
59 | 946, 670, 656, 610, 738, 392, 760, 799, 887, 653,
60 | 978, 321, 576, 617, 626, 502, 894, 679, 243, 440,
61 | 680, 879, 194, 572, 640, 724, 926, 56, 204, 700,
62 | 707, 151, 457, 449, 797, 195, 791, 558, 945, 679,
63 | 297, 59, 87, 824, 713, 663, 412, 693, 342, 606,
64 | 134, 108, 571, 364, 631, 212, 174, 643, 304, 329,
65 | 343, 97, 430, 751, 497, 314, 983, 374, 822, 928,
66 | 140, 206, 73, 263, 980, 736, 876, 478, 430, 305,
67 | 170, 514, 364, 692, 829, 82, 855, 953, 676, 246,
68 | 369, 970, 294, 750, 807, 827, 150, 790, 288, 923,
69 | 804, 378, 215, 828, 592, 281, 565, 555, 710, 82,
70 | 896, 831, 547, 261, 524, 462, 293, 465, 502, 56,
71 | 661, 821, 976, 991, 658, 869, 905, 758, 745, 193,
72 | 768, 550, 608, 933, 378, 286, 215, 979, 792, 961,
73 | 61, 688, 793, 644, 986, 403, 106, 366, 905, 644,
74 | 372, 567, 466, 434, 645, 210, 389, 550, 919, 135,
75 | 780, 773, 635, 389, 707, 100, 626, 958, 165, 504,
76 | 920, 176, 193, 713, 857, 265, 203, 50, 668, 108,
77 | 645, 990, 626, 197, 510, 357, 358, 850, 858, 364,
78 | 936, 638
79 | };
80 |
81 |
82 | /*-------------------------------------------------------------*/
83 | /*--- end randtable.c ---*/
84 | /*-------------------------------------------------------------*/
85 |
--------------------------------------------------------------------------------
/ApkPatchLibrary/jni/bzip2/readMe.txt:
--------------------------------------------------------------------------------
1 | bzip2包中文件来来自:
2 | http://www.bzip.org/downloads.html
--------------------------------------------------------------------------------
/ApkPatchLibrary/jni/com_jph_utils_PatchUtils.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 | #include
5 | #include
6 | #include
7 | #include
8 | #include
9 |
10 | #include "bzip2/bzlib.c"
11 | #include "bzip2/crctable.c"
12 | #include "bzip2/compress.c"
13 | #include "bzip2/decompress.c"
14 | #include "bzip2/randtable.c"
15 | #include "bzip2/blocksort.c"
16 | #include "bzip2/huffman.c"
17 |
18 | #include "com_jph_utils_PatchUtils.h"
19 |
20 | static off_t offtin(u_char *buf) {
21 | off_t y;
22 |
23 | y = buf[7] & 0x7F;
24 | y = y * 256;
25 | y += buf[6];
26 | y = y * 256;
27 | y += buf[5];
28 | y = y * 256;
29 | y += buf[4];
30 | y = y * 256;
31 | y += buf[3];
32 | y = y * 256;
33 | y += buf[2];
34 | y = y * 256;
35 | y += buf[1];
36 | y = y * 256;
37 | y += buf[0];
38 |
39 | if (buf[7] & 0x80)
40 | y = -y;
41 |
42 | return y;
43 | }
44 |
45 | int applypatch(int argc, char * argv[]) {
46 | FILE * f, *cpf, *dpf, *epf;
47 | BZFILE * cpfbz2, *dpfbz2, *epfbz2;
48 | int cbz2err, dbz2err, ebz2err;
49 | int fd;
50 | ssize_t oldsize, newsize;
51 | ssize_t bzctrllen, bzdatalen;
52 | u_char header[32], buf[8];
53 | u_char *old, *new;
54 | off_t oldpos, newpos;
55 | off_t ctrl[3];
56 | off_t lenread;
57 | off_t i;
58 |
59 | if (argc != 4)
60 | errx(1, "usage: %s oldfile newfile patchfile\n", argv[0]);
61 |
62 | /* Open patch file */
63 | if ((f = fopen(argv[3], "r")) == NULL)
64 | err(1, "fopen(%s)", argv[3]);
65 |
66 | /*
67 | File format:
68 | 0 8 "BSDIFF40"
69 | 8 8 X
70 | 16 8 Y
71 | 24 8 sizeof(newfile)
72 | 32 X bzip2(control block)
73 | 32+X Y bzip2(diff block)
74 | 32+X+Y ??? bzip2(extra block)
75 | with control block a set of triples (x,y,z) meaning "add x bytes
76 | from oldfile to x bytes from the diff block; copy y bytes from the
77 | extra block; seek forwards in oldfile by z bytes".
78 | */
79 |
80 | /* Read header */
81 | if (fread(header, 1, 32, f) < 32) {
82 | if (feof(f))
83 | errx(1, "Corrupt patch\n");
84 | err(1, "fread(%s)", argv[3]);
85 | }
86 |
87 | /* Check for appropriate magic */
88 | if (memcmp(header, "BSDIFF40", 8) != 0)
89 | errx(1, "Corrupt patch\n");
90 |
91 | /* Read lengths from header */
92 | bzctrllen = offtin(header + 8);
93 | bzdatalen = offtin(header + 16);
94 | newsize = offtin(header + 24);
95 | if ((bzctrllen < 0) || (bzdatalen < 0) || (newsize < 0))
96 | errx(1, "Corrupt patch\n");
97 |
98 | /* Close patch file and re-open it via libbzip2 at the right places */
99 | if (fclose(f))
100 | err(1, "fclose(%s)", argv[3]);
101 | if ((cpf = fopen(argv[3], "r")) == NULL)
102 | err(1, "fopen(%s)", argv[3]);
103 | if (fseeko(cpf, 32, SEEK_SET))
104 | err(1, "fseeko(%s, %lld)", argv[3], (long long) 32);
105 | if ((cpfbz2 = BZ2_bzReadOpen(&cbz2err, cpf, 0, 0, NULL, 0)) == NULL)
106 | errx(1, "BZ2_bzReadOpen, bz2err = %d", cbz2err);
107 | if ((dpf = fopen(argv[3], "r")) == NULL)
108 | err(1, "fopen(%s)", argv[3]);
109 | if (fseeko(dpf, 32 + bzctrllen, SEEK_SET))
110 | err(1, "fseeko(%s, %lld)", argv[3], (long long) (32 + bzctrllen));
111 | if ((dpfbz2 = BZ2_bzReadOpen(&dbz2err, dpf, 0, 0, NULL, 0)) == NULL)
112 | errx(1, "BZ2_bzReadOpen, bz2err = %d", dbz2err);
113 | if ((epf = fopen(argv[3], "r")) == NULL)
114 | err(1, "fopen(%s)", argv[3]);
115 | if (fseeko(epf, 32 + bzctrllen + bzdatalen, SEEK_SET))
116 | err(1, "fseeko(%s, %lld)", argv[3],
117 | (long long) (32 + bzctrllen + bzdatalen));
118 | if ((epfbz2 = BZ2_bzReadOpen(&ebz2err, epf, 0, 0, NULL, 0)) == NULL)
119 | errx(1, "BZ2_bzReadOpen, bz2err = %d", ebz2err);
120 |
121 | if (((fd = open(argv[1], O_RDONLY, 0)) < 0)
122 | || ((oldsize = lseek(fd, 0, SEEK_END)) == -1)
123 | || ((old = malloc(oldsize + 1)) == NULL)
124 | || (lseek(fd, 0, SEEK_SET) != 0)
125 | || (read(fd, old, oldsize) != oldsize) || (close(fd) == -1))
126 | err(1, "%s", argv[1]);
127 | if ((new = malloc(newsize + 1)) == NULL)
128 | err(1, NULL);
129 |
130 | oldpos = 0;
131 | newpos = 0;
132 | while (newpos < newsize) {
133 | /* Read control data */
134 | for (i = 0; i <= 2; i++) {
135 | lenread = BZ2_bzRead(&cbz2err, cpfbz2, buf, 8);
136 | if ((lenread < 8)
137 | || ((cbz2err != BZ_OK) && (cbz2err != BZ_STREAM_END)))
138 | errx(1, "Corrupt patch\n");
139 | ctrl[i] = offtin(buf);
140 | };
141 |
142 | /* Sanity-check */
143 | if (newpos + ctrl[0] > newsize)
144 | errx(1, "Corrupt patch\n");
145 |
146 | /* Read diff string */
147 | lenread = BZ2_bzRead(&dbz2err, dpfbz2, new + newpos, ctrl[0]);
148 | if ((lenread < ctrl[0])
149 | || ((dbz2err != BZ_OK) && (dbz2err != BZ_STREAM_END)))
150 | errx(1, "Corrupt patch\n");
151 |
152 | /* Add old data to diff string */
153 | for (i = 0; i < ctrl[0]; i++)
154 | if ((oldpos + i >= 0) && (oldpos + i < oldsize))
155 | new[newpos + i] += old[oldpos + i];
156 |
157 | /* Adjust pointers */
158 | newpos += ctrl[0];
159 | oldpos += ctrl[0];
160 |
161 | /* Sanity-check */
162 | if (newpos + ctrl[1] > newsize)
163 | errx(1, "Corrupt patch\n");
164 |
165 | /* Read extra string */
166 | lenread = BZ2_bzRead(&ebz2err, epfbz2, new + newpos, ctrl[1]);
167 | if ((lenread < ctrl[1])
168 | || ((ebz2err != BZ_OK) && (ebz2err != BZ_STREAM_END)))
169 | errx(1, "Corrupt patch\n");
170 |
171 | /* Adjust pointers */
172 | newpos += ctrl[1];
173 | oldpos += ctrl[2];
174 | };
175 |
176 | /* Clean up the bzip2 reads */
177 | BZ2_bzReadClose(&cbz2err, cpfbz2);
178 | BZ2_bzReadClose(&dbz2err, dpfbz2);
179 | BZ2_bzReadClose(&ebz2err, epfbz2);
180 | if (fclose(cpf) || fclose(dpf) || fclose(epf))
181 | err(1, "fclose(%s)", argv[3]);
182 |
183 | /* Write the new file */
184 | if (((fd = open(argv[2], O_CREAT | O_TRUNC | O_WRONLY, 0666)) < 0)
185 | || (write(fd, new, newsize) != newsize) || (close(fd) == -1))
186 | err(1, "%s", argv[2]);
187 |
188 | free(new);
189 | free(old);
190 |
191 | return 0;
192 | }
193 |
194 | /*
195 | * Class: com_jph_utils_PatchUtils
196 | * Method: patch
197 | * Signature: (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)I
198 | */
199 | JNIEXPORT jint JNICALL Java_com_jph_utils_PatchUtils_patch(JNIEnv *env,
200 | jobject obj, jstring old, jstring new, jstring patch) {
201 |
202 | char * ch[4];
203 | ch[0] = "bspatch";
204 | ch[1] = (char*) ((*env)->GetStringUTFChars(env, old, 0));
205 | ch[2] = (char*) ((*env)->GetStringUTFChars(env, new, 0));
206 | ch[3] = (char*) ((*env)->GetStringUTFChars(env, patch, 0));
207 |
208 | __android_log_print(ANDROID_LOG_INFO, "ApkPatchLibrary", "old = %s ", ch[1]);
209 | __android_log_print(ANDROID_LOG_INFO, "ApkPatchLibrary", "new = %s ", ch[2]);
210 | __android_log_print(ANDROID_LOG_INFO, "ApkPatchLibrary", "patch = %s ", ch[3]);
211 |
212 | int ret = applypatch(4, ch);
213 |
214 | __android_log_print(ANDROID_LOG_INFO, "ApkPatchLibrary", "applypatch result = %d ", ret);
215 |
216 | (*env)->ReleaseStringUTFChars(env, old, ch[1]);
217 | (*env)->ReleaseStringUTFChars(env, new, ch[2]);
218 | (*env)->ReleaseStringUTFChars(env, patch, ch[3]);
219 |
220 | return ret;
221 | }
222 |
--------------------------------------------------------------------------------
/ApkPatchLibrary/jni/com_jph_utils_PatchUtils.h:
--------------------------------------------------------------------------------
1 | /* DO NOT EDIT THIS FILE - it is machine generated */
2 | #include
3 | /* Header for class com_jph_utils_PatchUtils */
4 |
5 | #ifndef _Included_com_jph_utils_PatchUtils
6 | #define _Included_com_jph_utils_PatchUtils
7 | #ifdef __cplusplus
8 | extern "C" {
9 | #endif
10 | /*
11 | * Class: com_jph_utils_PatchUtils
12 | * Method: patch
13 | * Signature: (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)I
14 | */
15 | JNIEXPORT jint JNICALL Java_com_jph_utils_PatchUtils_patch
16 | (JNIEnv *, jclass, jstring, jstring, jstring);
17 |
18 | #ifdef __cplusplus
19 | }
20 | #endif
21 | #endif
22 |
--------------------------------------------------------------------------------
/ApkPatchLibrary/libs/armeabi/libApkPatchLibrary.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/crazycodeboy/IncrementalUpdate/ad8d310c71ba319a0d1e14968865142978830816/ApkPatchLibrary/libs/armeabi/libApkPatchLibrary.so
--------------------------------------------------------------------------------
/ApkPatchLibrary/lint.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/ApkPatchLibrary/obj/local/armeabi/libApkPatchLibrary.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/crazycodeboy/IncrementalUpdate/ad8d310c71ba319a0d1e14968865142978830816/ApkPatchLibrary/obj/local/armeabi/libApkPatchLibrary.so
--------------------------------------------------------------------------------
/ApkPatchLibrary/obj/local/armeabi/objs/ApkPatchLibrary/com_cundong_utils_PatchUtils.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/crazycodeboy/IncrementalUpdate/ad8d310c71ba319a0d1e14968865142978830816/ApkPatchLibrary/obj/local/armeabi/objs/ApkPatchLibrary/com_cundong_utils_PatchUtils.o
--------------------------------------------------------------------------------
/ApkPatchLibrary/obj/local/armeabi/objs/ApkPatchLibrary/com_cundong_utils_PatchUtils.o.d:
--------------------------------------------------------------------------------
1 | C:/Users/Penn/Desktop/lib/ApkPatchLibrary/obj/local/armeabi/objs/ApkPatchLibrary/com_cundong_utils_PatchUtils.o: \
2 | C:/Users/Penn/Desktop/lib/ApkPatchLibrary/jni/com_cundong_utils_PatchUtils.c \
3 | C:/Users/Penn/Desktop/lib/ApkPatchLibrary/jni/bzip2/bzlib.c \
4 | C:/Users/Penn/Desktop/lib/ApkPatchLibrary/jni/bzip2/bzlib_private.h \
5 | C:/Users/Penn/Desktop/lib/ApkPatchLibrary/jni/bzip2/bzlib.h \
6 | C:/Users/Penn/Desktop/lib/ApkPatchLibrary/jni/bzip2/crctable.c \
7 | C:/Users/Penn/Desktop/lib/ApkPatchLibrary/jni/bzip2/compress.c \
8 | C:/Users/Penn/Desktop/lib/ApkPatchLibrary/jni/bzip2/decompress.c \
9 | C:/Users/Penn/Desktop/lib/ApkPatchLibrary/jni/bzip2/randtable.c \
10 | C:/Users/Penn/Desktop/lib/ApkPatchLibrary/jni/bzip2/blocksort.c \
11 | C:/Users/Penn/Desktop/lib/ApkPatchLibrary/jni/bzip2/huffman.c \
12 | C:/Users/Penn/Desktop/lib/ApkPatchLibrary/jni/com_cundong_utils_PatchUtils.h
13 |
14 | C:/Users/Penn/Desktop/lib/ApkPatchLibrary/jni/bzip2/bzlib.c:
15 |
16 | C:/Users/Penn/Desktop/lib/ApkPatchLibrary/jni/bzip2/bzlib_private.h:
17 |
18 | C:/Users/Penn/Desktop/lib/ApkPatchLibrary/jni/bzip2/bzlib.h:
19 |
20 | C:/Users/Penn/Desktop/lib/ApkPatchLibrary/jni/bzip2/crctable.c:
21 |
22 | C:/Users/Penn/Desktop/lib/ApkPatchLibrary/jni/bzip2/compress.c:
23 |
24 | C:/Users/Penn/Desktop/lib/ApkPatchLibrary/jni/bzip2/decompress.c:
25 |
26 | C:/Users/Penn/Desktop/lib/ApkPatchLibrary/jni/bzip2/randtable.c:
27 |
28 | C:/Users/Penn/Desktop/lib/ApkPatchLibrary/jni/bzip2/blocksort.c:
29 |
30 | C:/Users/Penn/Desktop/lib/ApkPatchLibrary/jni/bzip2/huffman.c:
31 |
32 | C:/Users/Penn/Desktop/lib/ApkPatchLibrary/jni/com_cundong_utils_PatchUtils.h:
33 |
--------------------------------------------------------------------------------
/ApkPatchLibrary/obj/local/armeabi/objs/ApkPatchLibrary/com_jph_utils_PatchUtils.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/crazycodeboy/IncrementalUpdate/ad8d310c71ba319a0d1e14968865142978830816/ApkPatchLibrary/obj/local/armeabi/objs/ApkPatchLibrary/com_jph_utils_PatchUtils.o
--------------------------------------------------------------------------------
/ApkPatchLibrary/obj/local/armeabi/objs/ApkPatchLibrary/com_jph_utils_PatchUtils.o.d:
--------------------------------------------------------------------------------
1 | E:/JiaPengHui/workplace/GitRepository/IncrementalUpdate/ApkPatchLibrary/obj/local/armeabi/objs/ApkPatchLibrary/com_jph_utils_PatchUtils.o: \
2 | E:/JiaPengHui/workplace/GitRepository/IncrementalUpdate/ApkPatchLibrary/jni/com_jph_utils_PatchUtils.c \
3 | E:/JiaPengHui/workplace/GitRepository/IncrementalUpdate/ApkPatchLibrary/jni/bzip2/bzlib.c \
4 | E:/JiaPengHui/workplace/GitRepository/IncrementalUpdate/ApkPatchLibrary/jni/bzip2/bzlib_private.h \
5 | E:/JiaPengHui/workplace/GitRepository/IncrementalUpdate/ApkPatchLibrary/jni/bzip2/bzlib.h \
6 | E:/JiaPengHui/workplace/GitRepository/IncrementalUpdate/ApkPatchLibrary/jni/bzip2/crctable.c \
7 | E:/JiaPengHui/workplace/GitRepository/IncrementalUpdate/ApkPatchLibrary/jni/bzip2/compress.c \
8 | E:/JiaPengHui/workplace/GitRepository/IncrementalUpdate/ApkPatchLibrary/jni/bzip2/decompress.c \
9 | E:/JiaPengHui/workplace/GitRepository/IncrementalUpdate/ApkPatchLibrary/jni/bzip2/randtable.c \
10 | E:/JiaPengHui/workplace/GitRepository/IncrementalUpdate/ApkPatchLibrary/jni/bzip2/blocksort.c \
11 | E:/JiaPengHui/workplace/GitRepository/IncrementalUpdate/ApkPatchLibrary/jni/bzip2/huffman.c \
12 | E:/JiaPengHui/workplace/GitRepository/IncrementalUpdate/ApkPatchLibrary/jni/com_jph_utils_PatchUtils.h
13 |
14 | E:/JiaPengHui/workplace/GitRepository/IncrementalUpdate/ApkPatchLibrary/jni/bzip2/bzlib.c:
15 |
16 | E:/JiaPengHui/workplace/GitRepository/IncrementalUpdate/ApkPatchLibrary/jni/bzip2/bzlib_private.h:
17 |
18 | E:/JiaPengHui/workplace/GitRepository/IncrementalUpdate/ApkPatchLibrary/jni/bzip2/bzlib.h:
19 |
20 | E:/JiaPengHui/workplace/GitRepository/IncrementalUpdate/ApkPatchLibrary/jni/bzip2/crctable.c:
21 |
22 | E:/JiaPengHui/workplace/GitRepository/IncrementalUpdate/ApkPatchLibrary/jni/bzip2/compress.c:
23 |
24 | E:/JiaPengHui/workplace/GitRepository/IncrementalUpdate/ApkPatchLibrary/jni/bzip2/decompress.c:
25 |
26 | E:/JiaPengHui/workplace/GitRepository/IncrementalUpdate/ApkPatchLibrary/jni/bzip2/randtable.c:
27 |
28 | E:/JiaPengHui/workplace/GitRepository/IncrementalUpdate/ApkPatchLibrary/jni/bzip2/blocksort.c:
29 |
30 | E:/JiaPengHui/workplace/GitRepository/IncrementalUpdate/ApkPatchLibrary/jni/bzip2/huffman.c:
31 |
32 | E:/JiaPengHui/workplace/GitRepository/IncrementalUpdate/ApkPatchLibrary/jni/com_jph_utils_PatchUtils.h:
33 |
--------------------------------------------------------------------------------
/ApkPatchLibrary/proguard-project.txt:
--------------------------------------------------------------------------------
1 | # To enable ProGuard in your project, edit project.properties
2 | # to define the proguard.config property as described in that file.
3 | #
4 | # Add project specific ProGuard rules here.
5 | # By default, the flags in this file are appended to flags specified
6 | # in ${sdk.dir}/tools/proguard/proguard-android.txt
7 | # You can edit the include path and order by changing the ProGuard
8 | # include property in project.properties.
9 | #
10 | # For more details, see
11 | # http://developer.android.com/guide/developing/tools/proguard.html
12 |
13 | # Add any project specific keep options here:
14 |
15 | # If your project uses WebView with JS, uncomment the following
16 | # and specify the fully qualified class name to the JavaScript interface
17 | # class:
18 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
19 | # public *;
20 | #}
21 |
--------------------------------------------------------------------------------
/ApkPatchLibrary/project.properties:
--------------------------------------------------------------------------------
1 | # This file is automatically generated by Android Tools.
2 | # Do not modify this file -- YOUR CHANGES WILL BE ERASED!
3 | #
4 | # This file must be checked in Version Control Systems.
5 | #
6 | # To customize properties used by the Ant build system edit
7 | # "ant.properties", and override values to adapt the script to your
8 | # project structure.
9 | #
10 | # To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home):
11 | #proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
12 |
13 | # Project target.
14 | target=android-23
15 | android.library=true
--------------------------------------------------------------------------------
/ApkPatchLibrary/res/drawable-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/crazycodeboy/IncrementalUpdate/ad8d310c71ba319a0d1e14968865142978830816/ApkPatchLibrary/res/drawable-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/ApkPatchLibrary/res/drawable-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/crazycodeboy/IncrementalUpdate/ad8d310c71ba319a0d1e14968865142978830816/ApkPatchLibrary/res/drawable-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/ApkPatchLibrary/res/drawable-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/crazycodeboy/IncrementalUpdate/ad8d310c71ba319a0d1e14968865142978830816/ApkPatchLibrary/res/drawable-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/ApkPatchLibrary/res/values-v11/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
7 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/ApkPatchLibrary/res/values-v14/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
8 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/ApkPatchLibrary/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | ApkPatchLibrary
4 |
5 |
6 |
--------------------------------------------------------------------------------
/ApkPatchLibrary/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
7 |
14 |
15 |
16 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/ApkPatchLibrary/src/com/jph/utils/PatchUtils.java:
--------------------------------------------------------------------------------
1 | package com.jph.utils;
2 |
3 |
4 | /**
5 | * APK Patch工具类
6 | * @author Penn
7 | *
8 | */
9 | public class PatchUtils {
10 |
11 | /**
12 | * native方法 使用路径为oldApkPath的apk与路径为patchPath的补丁包,合成新的apk,并存储于newApkPath
13 | *
14 | * 返回:0,说明操作成功
15 | *
16 | * @param oldApkPath 示例:/sdcard/old.apk
17 | * @param newApkPath 示例:/sdcard/new.apk
18 | * @param patchPath 示例:/sdcard/xx.patch
19 | * @return
20 | */
21 | public static native int patch(String oldApkPath, String newApkPath,
22 | String patchPath);
23 | }
--------------------------------------------------------------------------------
/IncrementalUpdate-Android/.gitignore:
--------------------------------------------------------------------------------
1 | # Created by .ignore support plugin (hsz.mobi)
2 | ### Android template
3 | # Built application files
4 | *.apk
5 | *.ap_
6 |
7 | # Files for the Dalvik VM
8 | *.dex
9 |
10 | # Java class files
11 | *.class
12 |
13 | # Generated files
14 | bin/
15 | gen/
16 |
17 | # Gradle files
18 | .gradle/
19 | build/
20 | /*/build/
21 |
22 | # Local configuration file (sdk path, etc)
23 | local.properties
24 |
25 | # Proguard folder generated by Eclipse
26 | proguard/
27 |
28 | # Log Files
29 | *.log
30 |
31 |
32 | ### JetBrains template
33 | # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion
34 |
35 | *.iml
36 |
37 | ## Directory-based project format:
38 | .idea/
39 | # if you remove the above rule, at least ignore the following:
40 |
41 | # User-specific stuff:
42 | # .idea/workspace.xml
43 | # .idea/tasks.xml
44 | # .idea/dictionaries
45 |
46 | # Sensitive or high-churn files:
47 | # .idea/dataSources.ids
48 | # .idea/dataSources.xml
49 | # .idea/sqlDataSources.xml
50 | # .idea/dynamic.xml
51 | # .idea/uiDesigner.xml
52 |
53 | # Gradle:
54 | # .idea/gradle.xml
55 | # .idea/libraries
56 |
57 | # Mongo Explorer plugin:
58 | # .idea/mongoSettings.xml
59 |
60 | ## File-based project format:
61 | *.ipr
62 | *.iws
63 |
64 | ## Plugin-specific files:
65 |
66 | # IntelliJ
67 | /out/
68 |
69 | # mpeltonen/sbt-idea plugin
70 | .idea_modules/
71 |
72 | # JIRA plugin
73 | atlassian-ide-plugin.xml
74 |
75 | # Crashlytics plugin (for Android Studio and IntelliJ)
76 | com_crashlytics_export_strings.xml
77 | crashlytics.properties
78 | crashlytics-build.properties
79 |
80 |
81 | ### Gradle template
82 | .gradle
83 |
84 | # Ignore Gradle GUI config
85 | gradle-app.setting
86 |
87 | # Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored)
88 | !gradle-wrapper.jar
89 |
90 |
91 |
--------------------------------------------------------------------------------
/IncrementalUpdate-Android/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/IncrementalUpdate-Android/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/IncrementalUpdate-Android/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 23
5 | buildToolsVersion "23.0.2"
6 |
7 | defaultConfig {
8 | applicationId "com.jph.iu.incrementalupdate_android"
9 | minSdkVersion 9
10 | targetSdkVersion 23
11 | versionCode 1
12 | versionName "1.0"
13 | }
14 | buildTypes {
15 | release {
16 | minifyEnabled false
17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
18 | }
19 | }
20 | }
21 |
22 | dependencies {
23 | compile fileTree(dir: 'libs', include: ['*.jar'])
24 | testCompile 'junit:junit:4.12'
25 | compile 'com.android.support:appcompat-v7:23.3.0'
26 | }
27 |
--------------------------------------------------------------------------------
/IncrementalUpdate-Android/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in D:\android-sdk\sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/IncrementalUpdate-Android/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
8 |
9 |
15 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/IncrementalUpdate-Android/app/src/main/java/com/jph/iu/activity/ApkUtils.java:
--------------------------------------------------------------------------------
1 | package com.jph.iu.activity;
2 |
3 | import android.content.Context;
4 | import android.content.Intent;
5 | import android.content.pm.ApplicationInfo;
6 | import android.content.pm.PackageInfo;
7 | import android.content.pm.PackageManager;
8 | import android.content.pm.PackageManager.NameNotFoundException;
9 | import android.net.Uri;
10 | import android.text.TextUtils;
11 |
12 | import java.util.Iterator;
13 | import java.util.List;
14 |
15 | /**
16 | * Apk工具类 *
17 | * @author jph
18 | */
19 | public class ApkUtils {
20 |
21 | /**
22 | * 获取已安装apk的PackageInfo
23 | *
24 | * @param context
25 | * @param packageName
26 | * @return
27 | */
28 | public static PackageInfo getInstalledApkPackageInfo(Context context, String packageName) {
29 | PackageManager pm = context.getPackageManager();
30 | List apps = pm.getInstalledPackages(PackageManager.GET_SIGNATURES);
31 |
32 | Iterator it = apps.iterator();
33 | while (it.hasNext()) {
34 | PackageInfo packageinfo = it.next();
35 | String thisName = packageinfo.packageName;
36 | if (thisName.equals(packageName)) {
37 | return packageinfo;
38 | }
39 | }
40 |
41 | return null;
42 | }
43 |
44 | /**
45 | * 判断apk是否已安装
46 | *
47 | * @param context
48 | * @param packageName
49 | * @return
50 | */
51 | public static boolean isInstalled(Context context, String packageName) {
52 | PackageManager pm = context.getPackageManager();
53 | boolean installed = false;
54 | try {
55 | pm.getPackageInfo(packageName, PackageManager.GET_ACTIVITIES);
56 | installed = true;
57 | } catch (Exception e) {
58 | e.printStackTrace();
59 | }
60 |
61 | return installed;
62 | }
63 |
64 | /**
65 | * 获取已安装Apk文件的源Apk文件
66 | * 如:/data/app/com.sina.weibo-1.apk
67 | *
68 | * @param context
69 | * @param packageName
70 | * @return
71 | */
72 | public static String getSourceApkPath(Context context, String packageName) {
73 | if (TextUtils.isEmpty(packageName))
74 | return null;
75 |
76 | try {
77 | ApplicationInfo appInfo = context.getPackageManager().getApplicationInfo(packageName, 0);
78 | return appInfo.sourceDir;
79 | } catch (NameNotFoundException e) {
80 | e.printStackTrace();
81 | }
82 |
83 | return null;
84 | }
85 |
86 | /**
87 | * 安装Apk
88 | *
89 | * @param context
90 | * @param apkPath
91 | */
92 | public static void installApk(Context context, String apkPath) {
93 |
94 | Intent intent = new Intent(Intent.ACTION_VIEW);
95 | intent.setDataAndType(Uri.parse("file://" + apkPath),
96 | "application/vnd.android.package-archive");
97 |
98 | context.startActivity(intent);
99 | }
100 | }
--------------------------------------------------------------------------------
/IncrementalUpdate-Android/app/src/main/java/com/jph/iu/activity/Constants.java:
--------------------------------------------------------------------------------
1 | package com.jph.iu.activity;
2 |
3 | import java.io.File;
4 |
5 | import android.os.Environment;
6 |
7 | /**
8 | * 常量类
9 | * @author JPH
10 | */
11 | public class Constants {
12 |
13 | public static final boolean DEBUG = true;
14 |
15 | //KSD接单(V1.0.7).apk 正确的MD5值,如果本地安装的apk MD5值不是TA,说明本地安装的是被二次打包的apk
16 | public static final String KSD_OLD_MD5 = "6da2aaa9a5acfbbff2a8f6466e81ba6c";
17 |
18 | //KSD接单(V1.0.8).apk正确的MD5值
19 | public static final String KSD_NEW_MD5 = "7a333adaadfa08bd707e9b0b86a973e7";
20 |
21 | //用于测试的packageName
22 | public static final String TEST_PACKAGENAME = "com.ksudi.shuttle";
23 |
24 | public static final String PATH = Environment.getExternalStorageDirectory() + File.separator;
25 |
26 | //合成得到的新版apk
27 | public static final String NEW_APK_PATH = PATH + "KSD接单_new.apk";
28 |
29 | //从服务器下载来的差分包
30 | public static final String PATCH_PATH = PATH + "KSD接单.patch";
31 | // public static final String PATCH_PATH = PATH + "weibo.patch";
32 | }
--------------------------------------------------------------------------------
/IncrementalUpdate-Android/app/src/main/java/com/jph/iu/activity/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.jph.iu.activity;
2 |
3 | import android.app.ProgressDialog;
4 | import android.content.Context;
5 | import android.content.Intent;
6 | import android.content.pm.PackageInfo;
7 | import android.net.Uri;
8 | import android.os.AsyncTask;
9 | import android.os.Bundle;
10 | import android.support.v7.app.AppCompatActivity;
11 | import android.text.TextUtils;
12 | import android.view.View;
13 | import android.widget.Button;
14 | import android.widget.TextView;
15 | import android.widget.Toast;
16 |
17 | import com.jph.iu.simple.R;
18 | import com.jph.utils.PatchUtils;
19 |
20 | import java.io.File;
21 |
22 | /**
23 | * ApkPatchLibrary 使用Sample
24 | */
25 | public class MainActivity extends AppCompatActivity implements View.OnClickListener {
26 |
27 | private static final String TAG = Constants.DEBUG ? "MainActivity" : MainActivity.class.getSimpleName();
28 |
29 | // 成功
30 | private static final int WHAT_SUCCESS = 1;
31 |
32 | // 本地安装的APP MD5不正确
33 | private static final int WHAT_FAIL_OLD_MD5 = -1;
34 |
35 | // 新生成的APP MD5不正确
36 | private static final int WHAT_FAIL_GEN_MD5 = -2;
37 |
38 | // 合成失败
39 | private static final int WHAT_FAIL_PATCH = -3;
40 |
41 | // 获取源文件失败
42 | private static final int WHAT_FAIL_GET_SOURCE = -4;
43 |
44 | // 未知错误
45 | private static final int WHAT_FAIL_UNKNOWN = -5;
46 |
47 | private Context mContext = null;
48 |
49 | private ProgressDialog mProgressDialog;
50 | private TextView mResultView;
51 | private Button mStartButton, mGithubButton;
52 |
53 | private long mBeginTime, mEndTime;
54 |
55 | @Override
56 | protected void onCreate(Bundle savedInstanceState) {
57 | super.onCreate(savedInstanceState);
58 | setContentView(R.layout.activity_main);
59 |
60 | mContext = getApplicationContext();
61 |
62 | mProgressDialog = new ProgressDialog(this);
63 | mProgressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
64 | mProgressDialog.setMessage("正在合成...");
65 | mProgressDialog.setCancelable(false);
66 |
67 | mResultView = (TextView) findViewById(R.id.textview4);
68 |
69 | mStartButton = (Button) findViewById(R.id.start_btn);
70 | mGithubButton = (Button) findViewById(R.id.github_btn);
71 | mStartButton.setOnClickListener(this);
72 | mGithubButton.setOnClickListener(this);
73 | }
74 |
75 | @Override
76 | public void onClick(View v) {
77 | if (v == mStartButton) {
78 | File patchFile = new File(Constants.PATCH_PATH);
79 |
80 | if (!ApkUtils.isInstalled(mContext, Constants.TEST_PACKAGENAME)) {
81 | Toast.makeText(mContext, getString(R.string.demo_info1), Toast.LENGTH_LONG).show();
82 | } else if (!patchFile.exists()) {
83 | Toast.makeText(mContext, getString(R.string.demo_info2), Toast.LENGTH_LONG).show();
84 | } else {
85 | new PatchApkTask().execute();
86 | }
87 | } else if (v == mGithubButton) {
88 | Intent intent = new Intent("android.intent.action.VIEW", Uri.parse("https://github.com/crazycodeboy/IncrementalUpdate"));
89 | startActivity(intent);
90 | }
91 | }
92 |
93 | private String mCurentRealMD5, mNewRealMD5;
94 |
95 | /**
96 | * 模拟请求服务器,根据当前安装微博客户端的versionCode、versionName,来获取其文件的正确MD5,防止本地安装的是被篡改的版本
97 | */
98 | private void requestOldMD5(int versionCode, String versionName) {
99 | mCurentRealMD5 = Constants.KSD_OLD_MD5;
100 | mNewRealMD5 = Constants.KSD_NEW_MD5;
101 | }
102 |
103 | private class PatchApkTask extends AsyncTask {
104 |
105 | @Override
106 | protected void onPreExecute() {
107 | super.onPreExecute();
108 |
109 | mProgressDialog.show();
110 |
111 | mResultView.setText("");
112 | mBeginTime = System.currentTimeMillis();
113 | }
114 |
115 | @Override
116 | protected Integer doInBackground(String... params) {
117 |
118 | PackageInfo packageInfo = ApkUtils.getInstalledApkPackageInfo(mContext, Constants.TEST_PACKAGENAME);
119 |
120 | if (packageInfo != null) {
121 |
122 | requestOldMD5(packageInfo.versionCode, packageInfo.versionName);
123 |
124 | String oldApkSource = ApkUtils.getSourceApkPath(mContext, Constants.TEST_PACKAGENAME);
125 |
126 | if (!TextUtils.isEmpty(oldApkSource)) {
127 |
128 | // 校验一下本地安装APK的MD5是不是和真实的MD5一致
129 | if (SignUtils.checkMd5(oldApkSource, mCurentRealMD5)) {
130 | int patchResult = PatchUtils.patch(oldApkSource, Constants.NEW_APK_PATH, Constants.PATCH_PATH);
131 |
132 | if (patchResult == 0) {
133 |
134 | if (SignUtils.checkMd5(Constants.NEW_APK_PATH, mNewRealMD5)) {
135 | return WHAT_SUCCESS;
136 | } else {
137 | return WHAT_FAIL_GEN_MD5;
138 | }
139 | } else {
140 | return WHAT_FAIL_PATCH;
141 | }
142 | } else {
143 | return WHAT_FAIL_OLD_MD5;
144 | }
145 | } else {
146 | return WHAT_FAIL_GET_SOURCE;
147 | }
148 | } else {
149 | return WHAT_FAIL_UNKNOWN;
150 | }
151 | }
152 |
153 | @Override
154 | protected void onPostExecute(Integer result) {
155 | super.onPostExecute(result);
156 |
157 | if (mProgressDialog.isShowing()) {
158 | mProgressDialog.dismiss();
159 | }
160 |
161 | mEndTime = System.currentTimeMillis();
162 | mResultView.setText("耗时: " + (mEndTime - mBeginTime) + "ms");
163 |
164 | switch (result) {
165 | case WHAT_SUCCESS: {
166 |
167 | String text = "新apk已合成成功:" + Constants.NEW_APK_PATH;
168 | showToast(text);
169 |
170 | ApkUtils.installApk(MainActivity.this, Constants.NEW_APK_PATH);
171 | break;
172 | }
173 | case WHAT_FAIL_OLD_MD5: {
174 | String text = "现在安装的KSD接单(V1.0.7)的MD5不对!";
175 | showToast(text);
176 | break;
177 | }
178 | case WHAT_FAIL_GEN_MD5: {
179 | String text = "合成完毕,但是合成得到的apk MD5不对!";
180 | showToast(text);
181 | break;
182 | }
183 | case WHAT_FAIL_PATCH: {
184 | String text = "新apk已合成失败!";
185 | showToast(text);
186 | break;
187 | }
188 | case WHAT_FAIL_GET_SOURCE: {
189 | String text = "无法获取KSD接单的源apk文件,只能整包更新了!";
190 | showToast(text);
191 | break;
192 | }
193 | }
194 | }
195 | }
196 |
197 | private void showToast(final String text) {
198 | Toast.makeText(mContext, text, Toast.LENGTH_LONG).show();
199 | }
200 |
201 |
202 | static {
203 | System.loadLibrary("ApkPatchLibrary");
204 | }
205 | }
--------------------------------------------------------------------------------
/IncrementalUpdate-Android/app/src/main/java/com/jph/iu/activity/SignUtils.java:
--------------------------------------------------------------------------------
1 | package com.jph.iu.activity;
2 |
3 | import android.text.TextUtils;
4 | import android.util.Log;
5 |
6 | import java.io.File;
7 | import java.io.FileInputStream;
8 | import java.io.IOException;
9 | import java.security.MessageDigest;
10 |
11 | /**
12 | * apk 签名信息获取工具类
13 | */
14 | public class SignUtils {
15 |
16 | private static final boolean DEBUG = Constants.DEBUG;
17 |
18 | private static final String TAG = DEBUG ? "SignUtils" : SignUtils.class.getSimpleName();
19 |
20 | private static String bytes2Hex(byte[] src) {
21 | char[] res = new char[src.length * 2];
22 | final char hexDigits[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
23 | for (int i = 0, j = 0; i < src.length; i++) {
24 | res[j++] = hexDigits[src[i] >>> 4 & 0x0f];
25 | res[j++] = hexDigits[src[i] & 0x0f];
26 | }
27 |
28 | return new String(res);
29 | }
30 |
31 | private static String getMd5ByFile(File file) {
32 | String value = null;
33 | FileInputStream in = null;
34 | try {
35 | in = new FileInputStream(file);
36 |
37 | MessageDigest digester = MessageDigest.getInstance("MD5");
38 | byte[] bytes = new byte[8192];
39 | int byteCount;
40 | while ((byteCount = in.read(bytes)) > 0) {
41 | digester.update(bytes, 0, byteCount);
42 | }
43 | value = bytes2Hex(digester.digest());
44 | } catch (Exception e) {
45 | e.printStackTrace();
46 | } finally {
47 | if (null != in) {
48 | try {
49 | in.close();
50 | } catch (IOException e) {
51 | e.printStackTrace();
52 | }
53 | }
54 | }
55 | return value;
56 | }
57 |
58 | /**
59 | * 判断文件的MD5是否为指定值
60 | *
61 | * @param file
62 | * @param md5
63 | * @return
64 | */
65 | public static boolean checkMd5(File file, String md5) {
66 | if (TextUtils.isEmpty(md5)) {
67 | throw new RuntimeException("md5 cannot be empty");
68 | }
69 |
70 | String fileMd5 = getMd5ByFile(file);
71 |
72 | if (DEBUG) {
73 | Log.d(TAG, String.format("file's md5=%s, real md5=%s", fileMd5, md5));
74 | }
75 |
76 | if (md5.equals(fileMd5)) {
77 | return true;
78 | } else {
79 | return false;
80 | }
81 | }
82 |
83 | /**
84 | * 判断文件的MD5是否为指定值
85 | *
86 | * @param filePath
87 | * @param md5
88 | * @return
89 | */
90 | public static boolean checkMd5(String filePath, String md5) {
91 | return checkMd5(new File(filePath), md5);
92 | }
93 | }
--------------------------------------------------------------------------------
/IncrementalUpdate-Android/app/src/main/java/com/jph/utils/PatchUtils.java:
--------------------------------------------------------------------------------
1 | package com.jph.utils;
2 |
3 | /**
4 | * APK Patch工具类
5 | */
6 | public class PatchUtils {
7 |
8 | /**
9 | * native方法 使用路径为oldApkPath的apk与路径为patchPath的补丁包,合成新的apk,并存储于newApkPath
10 | *
11 | * 返回:0,说明操作成功
12 | *
13 | * @param oldApkPath 示例:/sdcard/old.apk
14 | * @param newApkPath 示例:/sdcard/new.apk
15 | * @param patchPath 示例:/sdcard/xx.patch
16 | * @return
17 | */
18 | public static native int patch(String oldApkPath, String newApkPath, String patchPath);
19 | }
--------------------------------------------------------------------------------
/IncrementalUpdate-Android/app/src/main/jniLibs/armeabi/libApkPatchLibrary.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/crazycodeboy/IncrementalUpdate/ad8d310c71ba319a0d1e14968865142978830816/IncrementalUpdate-Android/app/src/main/jniLibs/armeabi/libApkPatchLibrary.so
--------------------------------------------------------------------------------
/IncrementalUpdate-Android/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
12 |
13 |
22 |
23 |
31 |
32 |
40 |
41 |
47 |
48 |
54 |
55 |
60 |
61 |
62 |
--------------------------------------------------------------------------------
/IncrementalUpdate-Android/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/crazycodeboy/IncrementalUpdate/ad8d310c71ba319a0d1e14968865142978830816/IncrementalUpdate-Android/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/IncrementalUpdate-Android/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/crazycodeboy/IncrementalUpdate/ad8d310c71ba319a0d1e14968865142978830816/IncrementalUpdate-Android/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/IncrementalUpdate-Android/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/crazycodeboy/IncrementalUpdate/ad8d310c71ba319a0d1e14968865142978830816/IncrementalUpdate-Android/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/IncrementalUpdate-Android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/crazycodeboy/IncrementalUpdate/ad8d310c71ba319a0d1e14968865142978830816/IncrementalUpdate-Android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/IncrementalUpdate-Android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/crazycodeboy/IncrementalUpdate/ad8d310c71ba319a0d1e14968865142978830816/IncrementalUpdate-Android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/IncrementalUpdate-Android/app/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 64dp
6 |
7 |
--------------------------------------------------------------------------------
/IncrementalUpdate-Android/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 |
--------------------------------------------------------------------------------
/IncrementalUpdate-Android/app/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 |
6 |
--------------------------------------------------------------------------------
/IncrementalUpdate-Android/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | IncrementalUpdateSample
3 | Settings
4 |
5 | 1.请先安装KSD接单(V1.0.7)
6 | 2.将由服务器端生成的差分文件 KSD接单.patch(V1.0.7->V1.0.8)拷贝至:/sdcard/KSD接单.patch
7 | 3.点击 Start
8 | Start
9 | GitHub
10 |
11 |
--------------------------------------------------------------------------------
/IncrementalUpdate-Android/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/IncrementalUpdate-Android/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | buildscript {
4 | repositories {
5 | jcenter()
6 | }
7 | dependencies {
8 | classpath 'com.android.tools.build:gradle:2.0.0'
9 |
10 | // NOTE: Do not place your application dependencies here; they belong
11 | // in the individual module build.gradle files
12 | }
13 | }
14 |
15 | allprojects {
16 | repositories {
17 | jcenter()
18 | }
19 | }
20 |
21 | task clean(type: Delete) {
22 | delete rootProject.buildDir
23 | }
24 |
--------------------------------------------------------------------------------
/IncrementalUpdate-Android/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | # Default value: -Xmx10248m -XX:MaxPermSize=256m
13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
14 |
15 | # When configured, Gradle will run in incubating parallel mode.
16 | # This option should only be used with decoupled projects. More details, visit
17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
18 | # org.gradle.parallel=true
--------------------------------------------------------------------------------
/IncrementalUpdate-Android/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/crazycodeboy/IncrementalUpdate/ad8d310c71ba319a0d1e14968865142978830816/IncrementalUpdate-Android/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/IncrementalUpdate-Android/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Mon Dec 28 10:00:20 PST 2015
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.10-all.zip
7 |
--------------------------------------------------------------------------------
/IncrementalUpdate-Android/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # Attempt to set APP_HOME
46 | # Resolve links: $0 may be a link
47 | PRG="$0"
48 | # Need this for relative symlinks.
49 | while [ -h "$PRG" ] ; do
50 | ls=`ls -ld "$PRG"`
51 | link=`expr "$ls" : '.*-> \(.*\)$'`
52 | if expr "$link" : '/.*' > /dev/null; then
53 | PRG="$link"
54 | else
55 | PRG=`dirname "$PRG"`"/$link"
56 | fi
57 | done
58 | SAVED="`pwd`"
59 | cd "`dirname \"$PRG\"`/" >/dev/null
60 | APP_HOME="`pwd -P`"
61 | cd "$SAVED" >/dev/null
62 |
63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
64 |
65 | # Determine the Java command to use to start the JVM.
66 | if [ -n "$JAVA_HOME" ] ; then
67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
68 | # IBM's JDK on AIX uses strange locations for the executables
69 | JAVACMD="$JAVA_HOME/jre/sh/java"
70 | else
71 | JAVACMD="$JAVA_HOME/bin/java"
72 | fi
73 | if [ ! -x "$JAVACMD" ] ; then
74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
75 |
76 | Please set the JAVA_HOME variable in your environment to match the
77 | location of your Java installation."
78 | fi
79 | else
80 | JAVACMD="java"
81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
82 |
83 | Please set the JAVA_HOME variable in your environment to match the
84 | location of your Java installation."
85 | fi
86 |
87 | # Increase the maximum file descriptors if we can.
88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
89 | MAX_FD_LIMIT=`ulimit -H -n`
90 | if [ $? -eq 0 ] ; then
91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
92 | MAX_FD="$MAX_FD_LIMIT"
93 | fi
94 | ulimit -n $MAX_FD
95 | if [ $? -ne 0 ] ; then
96 | warn "Could not set maximum file descriptor limit: $MAX_FD"
97 | fi
98 | else
99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
100 | fi
101 | fi
102 |
103 | # For Darwin, add options to specify how the application appears in the dock
104 | if $darwin; then
105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
106 | fi
107 |
108 | # For Cygwin, switch paths to Windows format before running java
109 | if $cygwin ; then
110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
112 | JAVACMD=`cygpath --unix "$JAVACMD"`
113 |
114 | # We build the pattern for arguments to be converted via cygpath
115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
116 | SEP=""
117 | for dir in $ROOTDIRSRAW ; do
118 | ROOTDIRS="$ROOTDIRS$SEP$dir"
119 | SEP="|"
120 | done
121 | OURCYGPATTERN="(^($ROOTDIRS))"
122 | # Add a user-defined pattern to the cygpath arguments
123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
125 | fi
126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
127 | i=0
128 | for arg in "$@" ; do
129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
131 |
132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
134 | else
135 | eval `echo args$i`="\"$arg\""
136 | fi
137 | i=$((i+1))
138 | done
139 | case $i in
140 | (0) set -- ;;
141 | (1) set -- "$args0" ;;
142 | (2) set -- "$args0" "$args1" ;;
143 | (3) set -- "$args0" "$args1" "$args2" ;;
144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
150 | esac
151 | fi
152 |
153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
154 | function splitJvmOpts() {
155 | JVM_OPTS=("$@")
156 | }
157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
159 |
160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
161 |
--------------------------------------------------------------------------------
/IncrementalUpdate-Android/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/IncrementalUpdate-Android/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app'
2 |
--------------------------------------------------------------------------------
/IncrementalUpdate-web/.classpath:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/IncrementalUpdate-web/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | IncrementalUpdate-web
4 |
5 |
6 |
7 |
8 |
9 | org.eclipse.wst.jsdt.core.javascriptValidator
10 |
11 |
12 |
13 |
14 | org.eclipse.jdt.core.javabuilder
15 |
16 |
17 |
18 |
19 | org.eclipse.wst.common.project.facet.core.builder
20 |
21 |
22 |
23 |
24 | org.eclipse.wst.validation.validationbuilder
25 |
26 |
27 |
28 |
29 |
30 | org.eclipse.jem.workbench.JavaEMFNature
31 | org.eclipse.wst.common.modulecore.ModuleCoreNature
32 | org.eclipse.wst.common.project.facet.core.nature
33 | org.eclipse.jdt.core.javanature
34 | org.eclipse.wst.jsdt.core.jsNature
35 |
36 |
37 |
--------------------------------------------------------------------------------
/IncrementalUpdate-web/.settings/.jsdtscope:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/IncrementalUpdate-web/.settings/org.eclipse.core.resources.prefs:
--------------------------------------------------------------------------------
1 | eclipse.preferences.version=1
2 | encoding//WebContent/GenPatch.jsp=UTF-8
3 |
--------------------------------------------------------------------------------
/IncrementalUpdate-web/.settings/org.eclipse.jdt.core.prefs:
--------------------------------------------------------------------------------
1 | eclipse.preferences.version=1
2 | org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
3 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
4 | org.eclipse.jdt.core.compiler.compliance=1.7
5 | org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
6 | org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
7 | org.eclipse.jdt.core.compiler.source=1.7
8 |
--------------------------------------------------------------------------------
/IncrementalUpdate-web/.settings/org.eclipse.wst.common.component:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/IncrementalUpdate-web/.settings/org.eclipse.wst.common.project.facet.core.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/IncrementalUpdate-web/.settings/org.eclipse.wst.jsdt.ui.superType.container:
--------------------------------------------------------------------------------
1 | org.eclipse.wst.jsdt.launching.baseBrowserLibrary
--------------------------------------------------------------------------------
/IncrementalUpdate-web/.settings/org.eclipse.wst.jsdt.ui.superType.name:
--------------------------------------------------------------------------------
1 | Window
--------------------------------------------------------------------------------
/IncrementalUpdate-web/WebContent/ApplyPatch.jsp:
--------------------------------------------------------------------------------
1 | <%@ page language="java" contentType="text/html; charset=utf-8"
2 | pageEncoding="utf-8"%>
3 |
4 |
5 |
6 |
7 | 生成增量包
8 |
9 |
10 |
31 |
32 |
--------------------------------------------------------------------------------
/IncrementalUpdate-web/WebContent/GenPatch.jsp:
--------------------------------------------------------------------------------
1 | <%@ page language="java" contentType="text/html; charset=utf-8"
2 | pageEncoding="utf-8"%>
3 |
4 |
5 |
6 |
7 | 生成增量包
8 |
9 |
10 |
31 |
32 |
--------------------------------------------------------------------------------
/IncrementalUpdate-web/WebContent/META-INF/MANIFEST.MF:
--------------------------------------------------------------------------------
1 | Manifest-Version: 1.0
2 | Class-Path:
3 |
4 |
--------------------------------------------------------------------------------
/IncrementalUpdate-web/WebContent/WEB-INF/lib/bsdiff.exe:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/crazycodeboy/IncrementalUpdate/ad8d310c71ba319a0d1e14968865142978830816/IncrementalUpdate-web/WebContent/WEB-INF/lib/bsdiff.exe
--------------------------------------------------------------------------------
/IncrementalUpdate-web/WebContent/WEB-INF/lib/bspatch.exe:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/crazycodeboy/IncrementalUpdate/ad8d310c71ba319a0d1e14968865142978830816/IncrementalUpdate-web/WebContent/WEB-INF/lib/bspatch.exe
--------------------------------------------------------------------------------
/IncrementalUpdate-web/WebContent/WEB-INF/web.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | GenPatch.jsp
5 |
6 |
--------------------------------------------------------------------------------
/IncrementalUpdate-web/src/com/jph/iu/server/servlet/ApplyPatch.java:
--------------------------------------------------------------------------------
1 | package com.jph.iu.server.servlet;
2 |
3 | import java.io.IOException;
4 | import javax.servlet.ServletException;
5 | import javax.servlet.annotation.WebServlet;
6 | import javax.servlet.http.HttpServlet;
7 | import javax.servlet.http.HttpServletRequest;
8 | import javax.servlet.http.HttpServletResponse;
9 |
10 | import com.jph.iu.server.util.PatchFile;
11 |
12 | /**
13 | * 应用增量包
14 | */
15 | @WebServlet("/ApplyPatch")
16 | public class ApplyPatch extends HttpServlet {
17 | private static final long serialVersionUID = 1L;
18 |
19 | /**
20 | * @see HttpServlet#HttpServlet()
21 | */
22 | public ApplyPatch() {
23 | super();
24 | // TODO Auto-generated constructor stub
25 | }
26 |
27 | /**
28 | * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
29 | */
30 | protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
31 | // TODO Auto-generated method stub
32 | response.getWriter().append("Served at: ").append(request.getContextPath());
33 | }
34 |
35 | /**
36 | * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
37 | */
38 | protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
39 | // TODO Auto-generated method stub
40 | new PatchFile(request,true).patch();
41 | // doGet(request, response);
42 | response.sendRedirect("ApplyPatch.jsp");
43 | }
44 |
45 | }
46 |
--------------------------------------------------------------------------------
/IncrementalUpdate-web/src/com/jph/iu/server/servlet/GenPatch.java:
--------------------------------------------------------------------------------
1 | package com.jph.iu.server.servlet;
2 |
3 | import java.io.IOException;
4 |
5 | import javax.servlet.ServletException;
6 | import javax.servlet.annotation.WebServlet;
7 | import javax.servlet.http.HttpServlet;
8 | import javax.servlet.http.HttpServletRequest;
9 | import javax.servlet.http.HttpServletResponse;
10 |
11 | import com.jph.iu.server.util.PatchFile;
12 |
13 | /**
14 | * 生成增量包
15 | */
16 | @WebServlet("/GenPatch")
17 | public class GenPatch extends HttpServlet {
18 | private static final long serialVersionUID = 1L;
19 |
20 | /**
21 | * @see HttpServlet#HttpServlet()
22 | */
23 | public GenPatch() {
24 | super();
25 | // TODO Auto-generated constructor stub
26 | }
27 |
28 | /**
29 | * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
30 | */
31 | protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
32 | // TODO Auto-generated method stub
33 | response.getWriter().append("Served at: ").append(request.getContextPath());
34 | }
35 |
36 | /**
37 | * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
38 | */
39 | protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
40 | // TODO Auto-generated method stub
41 | new PatchFile(request,false).patch();
42 | // doGet(request, response);
43 | response.sendRedirect("GenPatch.jsp");
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/IncrementalUpdate-web/src/com/jph/iu/server/util/PatchFile.java:
--------------------------------------------------------------------------------
1 | package com.jph.iu.server.util;
2 |
3 | import java.io.File;
4 | import java.io.UnsupportedEncodingException;
5 | import javax.servlet.http.HttpServletRequest;
6 |
7 | /**
8 | * 生成增量包工具类
9 | *
10 | * @author Penn
11 | */
12 | public class PatchFile {
13 | private String bsdiffPath;
14 | private File oldFile;
15 | private File newFile;
16 | private File patchFile;
17 | private boolean isApplyPatch;
18 | public PatchFile(HttpServletRequest request,boolean isApplyPatch) {
19 | init(request,isApplyPatch);
20 | }
21 | private void init(HttpServletRequest request,boolean isApplyPatch) {
22 | this.isApplyPatch=isApplyPatch;
23 | try {
24 | request.setCharacterEncoding("UTF-8");
25 | } catch (UnsupportedEncodingException e) {
26 | // TODO Auto-generated catch block
27 | e.printStackTrace();
28 | }
29 | StringBuffer bsdiffPathSb=new StringBuffer();
30 | bsdiffPathSb.append("\"");
31 | bsdiffPathSb.append(request.getSession().getServletContext().getRealPath(""));
32 | bsdiffPathSb.append("WEB-INF/lib/");
33 | bsdiffPathSb.append(isApplyPatch?"bspatch.exe":"bsdiff.exe");
34 | bsdiffPathSb.append("\"");
35 | bsdiffPath=bsdiffPathSb.toString();
36 | oldFile=new File(request.getParameter("oldFile"));
37 | newFile=new File(request.getParameter("newFile"));
38 | }
39 | public boolean patch() {
40 | patchFile=new File(oldFile.getParentFile(), genPachFileName());
41 | Runtime rn = Runtime.getRuntime();
42 | Process p = null;
43 | try {
44 | StringBuffer path = new StringBuffer();
45 | path.append(bsdiffPath);
46 | path.append(" ");
47 | path.append(oldFile.getAbsolutePath());
48 | path.append(" ");
49 | if (isApplyPatch) {
50 | path.append(patchFile);
51 | path.append(" ");
52 | path.append(newFile.getAbsolutePath());
53 | }else {
54 | path.append(newFile.getAbsolutePath());
55 | path.append(" ");
56 | path.append(patchFile);
57 | }
58 |
59 | System.out.println("----------start patch----------");
60 | p = rn.exec(path.toString());
61 | p.waitFor();
62 | System.out.println("----------end patch----------");
63 | } catch (Exception e) {
64 | System.out.println("Error my exec ");
65 | return false;
66 | }
67 | return true;
68 | }
69 | private String genPachFileName() {
70 | StringBuffer sb=new StringBuffer();
71 | String oldFileName=oldFile.getName();
72 | String newFileName=newFile.getName();
73 | sb.append(oldFileName.substring(0,oldFileName.lastIndexOf(".")));
74 | sb.append("_");
75 | sb.append(newFileName.substring(0,newFileName.lastIndexOf(".")));
76 | sb.append(isApplyPatch?oldFileName.substring(oldFileName.lastIndexOf(".")):".patch");
77 | return sb.toString();
78 | }
79 |
80 | }
81 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
177 |
178 | APPENDIX: How to apply the Apache License to your work.
179 |
180 | To apply the Apache License to your work, attach the following
181 | boilerplate notice, with the fields enclosed by brackets "{}"
182 | replaced with your own identifying information. (Don't include
183 | the brackets!) The text should be enclosed in the appropriate
184 | comment syntax for the file format. We also recommend that a
185 | file or class name and description of purpose be included on the
186 | same "printed page" as the copyright notice for easier
187 | identification within third-party archives.
188 |
189 | Copyright {yyyy} {name of copyright owner}
190 |
191 | Licensed under the Apache License, Version 2.0 (the "License");
192 | you may not use this file except in compliance with the License.
193 | You may obtain a copy of the License at
194 |
195 | http://www.apache.org/licenses/LICENSE-2.0
196 |
197 | Unless required by applicable law or agreed to in writing, software
198 | distributed under the License is distributed on an "AS IS" BASIS,
199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200 | See the License for the specific language governing permissions and
201 | limitations under the License.
202 |
--------------------------------------------------------------------------------
/PatchUtil-cs/.vs/PatchUtil/v14/.suo:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/crazycodeboy/IncrementalUpdate/ad8d310c71ba319a0d1e14968865142978830816/PatchUtil-cs/.vs/PatchUtil/v14/.suo
--------------------------------------------------------------------------------
/PatchUtil-cs/PatchUtil.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio 14
4 | VisualStudioVersion = 14.0.25123.0
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PatchUtil", "PatchUtil\PatchUtil.csproj", "{1FD74B67-7E9C-44AC-9DFB-4194B5A32059}"
7 | EndProject
8 | Global
9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
10 | Debug|Any CPU = Debug|Any CPU
11 | Release|Any CPU = Release|Any CPU
12 | EndGlobalSection
13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
14 | {1FD74B67-7E9C-44AC-9DFB-4194B5A32059}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15 | {1FD74B67-7E9C-44AC-9DFB-4194B5A32059}.Debug|Any CPU.Build.0 = Debug|Any CPU
16 | {1FD74B67-7E9C-44AC-9DFB-4194B5A32059}.Release|Any CPU.ActiveCfg = Release|Any CPU
17 | {1FD74B67-7E9C-44AC-9DFB-4194B5A32059}.Release|Any CPU.Build.0 = Release|Any CPU
18 | EndGlobalSection
19 | GlobalSection(SolutionProperties) = preSolution
20 | HideSolutionNode = FALSE
21 | EndGlobalSection
22 | EndGlobal
23 |
--------------------------------------------------------------------------------
/PatchUtil-cs/PatchUtil/App.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/PatchUtil-cs/PatchUtil/Main.Designer.cs:
--------------------------------------------------------------------------------
1 | namespace WindowsFormsApplication2
2 | {
3 | partial class Main
4 | {
5 | ///
6 | /// 必需的设计器变量。
7 | ///
8 | private System.ComponentModel.IContainer components = null;
9 |
10 | ///
11 | /// 清理所有正在使用的资源。
12 | ///
13 | /// 如果应释放托管资源,为 true;否则为 false。
14 | protected override void Dispose(bool disposing)
15 | {
16 | if (disposing && (components != null))
17 | {
18 | components.Dispose();
19 | }
20 | base.Dispose(disposing);
21 | }
22 |
23 | #region Windows 窗体设计器生成的代码
24 |
25 | ///
26 | /// 设计器支持所需的方法 - 不要修改
27 | /// 使用代码编辑器修改此方法的内容。
28 | ///
29 | private void InitializeComponent()
30 | {
31 | this.openFileDialog1 = new System.Windows.Forms.OpenFileDialog();
32 | this.tabControl1 = new System.Windows.Forms.TabControl();
33 | this.tabPage1 = new System.Windows.Forms.TabPage();
34 | this.tbSaveFileName1 = new System.Windows.Forms.TextBox();
35 | this.btnSelectSaveFile_1 = new System.Windows.Forms.Button();
36 | this.tbNewFileName_1 = new System.Windows.Forms.TextBox();
37 | this.tbOldFileName_1 = new System.Windows.Forms.TextBox();
38 | this.btnSelectNewFile_1 = new System.Windows.Forms.Button();
39 | this.btnSelectOldFile_1 = new System.Windows.Forms.Button();
40 | this.btnGenPatch = new System.Windows.Forms.Button();
41 | this.tabPage2 = new System.Windows.Forms.TabPage();
42 | this.tbSaveFileName2 = new System.Windows.Forms.TextBox();
43 | this.btnSelectSaveFile_2 = new System.Windows.Forms.Button();
44 | this.tbNewFileName_2 = new System.Windows.Forms.TextBox();
45 | this.tbOldFileName_2 = new System.Windows.Forms.TextBox();
46 | this.btnSelectFile_2 = new System.Windows.Forms.Button();
47 | this.btnSelectOldFile_2 = new System.Windows.Forms.Button();
48 | this.btnApplyPatch = new System.Windows.Forms.Button();
49 | this.tabPage3 = new System.Windows.Forms.TabPage();
50 | this.label5 = new System.Windows.Forms.Label();
51 | this.label4 = new System.Windows.Forms.Label();
52 | this.linkLabel2 = new System.Windows.Forms.LinkLabel();
53 | this.label3 = new System.Windows.Forms.Label();
54 | this.linkLabel1 = new System.Windows.Forms.LinkLabel();
55 | this.label2 = new System.Windows.Forms.Label();
56 | this.label1 = new System.Windows.Forms.Label();
57 | this.saveFileDialog1 = new System.Windows.Forms.SaveFileDialog();
58 | this.tabControl1.SuspendLayout();
59 | this.tabPage1.SuspendLayout();
60 | this.tabPage2.SuspendLayout();
61 | this.tabPage3.SuspendLayout();
62 | this.SuspendLayout();
63 | //
64 | // tabControl1
65 | //
66 | this.tabControl1.Controls.Add(this.tabPage1);
67 | this.tabControl1.Controls.Add(this.tabPage2);
68 | this.tabControl1.Controls.Add(this.tabPage3);
69 | this.tabControl1.Cursor = System.Windows.Forms.Cursors.AppStarting;
70 | this.tabControl1.Location = new System.Drawing.Point(5, 12);
71 | this.tabControl1.Name = "tabControl1";
72 | this.tabControl1.SelectedIndex = 0;
73 | this.tabControl1.Size = new System.Drawing.Size(483, 342);
74 | this.tabControl1.TabIndex = 7;
75 | //
76 | // tabPage1
77 | //
78 | this.tabPage1.Controls.Add(this.tbSaveFileName1);
79 | this.tabPage1.Controls.Add(this.btnSelectSaveFile_1);
80 | this.tabPage1.Controls.Add(this.tbNewFileName_1);
81 | this.tabPage1.Controls.Add(this.tbOldFileName_1);
82 | this.tabPage1.Controls.Add(this.btnSelectNewFile_1);
83 | this.tabPage1.Controls.Add(this.btnSelectOldFile_1);
84 | this.tabPage1.Controls.Add(this.btnGenPatch);
85 | this.tabPage1.Location = new System.Drawing.Point(4, 22);
86 | this.tabPage1.Name = "tabPage1";
87 | this.tabPage1.Padding = new System.Windows.Forms.Padding(3);
88 | this.tabPage1.Size = new System.Drawing.Size(475, 316);
89 | this.tabPage1.TabIndex = 0;
90 | this.tabPage1.Text = "创建增量文件";
91 | this.tabPage1.UseVisualStyleBackColor = true;
92 | //
93 | // tbSaveFileName1
94 | //
95 | this.tbSaveFileName1.Location = new System.Drawing.Point(5, 164);
96 | this.tbSaveFileName1.Name = "tbSaveFileName1";
97 | this.tbSaveFileName1.Size = new System.Drawing.Size(365, 21);
98 | this.tbSaveFileName1.TabIndex = 13;
99 | //
100 | // btnSelectSaveFile_1
101 | //
102 | this.btnSelectSaveFile_1.Location = new System.Drawing.Point(379, 158);
103 | this.btnSelectSaveFile_1.Name = "btnSelectSaveFile_1";
104 | this.btnSelectSaveFile_1.Size = new System.Drawing.Size(88, 31);
105 | this.btnSelectSaveFile_1.TabIndex = 12;
106 | this.btnSelectSaveFile_1.Text = "输出路径";
107 | this.btnSelectSaveFile_1.UseVisualStyleBackColor = true;
108 | this.btnSelectSaveFile_1.Click += new System.EventHandler(this.btnSelectSaveFile_Click);
109 | //
110 | // tbNewFileName_1
111 | //
112 | this.tbNewFileName_1.Location = new System.Drawing.Point(6, 117);
113 | this.tbNewFileName_1.Name = "tbNewFileName_1";
114 | this.tbNewFileName_1.Size = new System.Drawing.Size(365, 21);
115 | this.tbNewFileName_1.TabIndex = 11;
116 | //
117 | // tbOldFileName_1
118 | //
119 | this.tbOldFileName_1.Location = new System.Drawing.Point(6, 68);
120 | this.tbOldFileName_1.Name = "tbOldFileName_1";
121 | this.tbOldFileName_1.Size = new System.Drawing.Size(368, 21);
122 | this.tbOldFileName_1.TabIndex = 10;
123 | //
124 | // btnSelectNewFile_1
125 | //
126 | this.btnSelectNewFile_1.Location = new System.Drawing.Point(380, 111);
127 | this.btnSelectNewFile_1.Name = "btnSelectNewFile_1";
128 | this.btnSelectNewFile_1.Size = new System.Drawing.Size(88, 31);
129 | this.btnSelectNewFile_1.TabIndex = 9;
130 | this.btnSelectNewFile_1.Text = "选择新文件";
131 | this.btnSelectNewFile_1.UseVisualStyleBackColor = true;
132 | this.btnSelectNewFile_1.Click += new System.EventHandler(this.btnSelectNewFile_Click);
133 | //
134 | // btnSelectOldFile_1
135 | //
136 | this.btnSelectOldFile_1.Location = new System.Drawing.Point(380, 61);
137 | this.btnSelectOldFile_1.Name = "btnSelectOldFile_1";
138 | this.btnSelectOldFile_1.Size = new System.Drawing.Size(88, 33);
139 | this.btnSelectOldFile_1.TabIndex = 8;
140 | this.btnSelectOldFile_1.Text = "选择目标文件";
141 | this.btnSelectOldFile_1.UseVisualStyleBackColor = true;
142 | this.btnSelectOldFile_1.Click += new System.EventHandler(this.btnSelectOldFile_Click);
143 | //
144 | // btnGenPatch
145 | //
146 | this.btnGenPatch.Location = new System.Drawing.Point(156, 217);
147 | this.btnGenPatch.Name = "btnGenPatch";
148 | this.btnGenPatch.Size = new System.Drawing.Size(121, 32);
149 | this.btnGenPatch.TabIndex = 7;
150 | this.btnGenPatch.Text = "生成增量包";
151 | this.btnGenPatch.UseVisualStyleBackColor = true;
152 | this.btnGenPatch.Click += new System.EventHandler(this.btnPatch_Click);
153 | //
154 | // tabPage2
155 | //
156 | this.tabPage2.Controls.Add(this.tbSaveFileName2);
157 | this.tabPage2.Controls.Add(this.btnSelectSaveFile_2);
158 | this.tabPage2.Controls.Add(this.tbNewFileName_2);
159 | this.tabPage2.Controls.Add(this.tbOldFileName_2);
160 | this.tabPage2.Controls.Add(this.btnSelectFile_2);
161 | this.tabPage2.Controls.Add(this.btnSelectOldFile_2);
162 | this.tabPage2.Controls.Add(this.btnApplyPatch);
163 | this.tabPage2.Location = new System.Drawing.Point(4, 22);
164 | this.tabPage2.Name = "tabPage2";
165 | this.tabPage2.Padding = new System.Windows.Forms.Padding(3);
166 | this.tabPage2.Size = new System.Drawing.Size(475, 316);
167 | this.tabPage2.TabIndex = 1;
168 | this.tabPage2.Text = "应用增量文件";
169 | this.tabPage2.UseVisualStyleBackColor = true;
170 | //
171 | // tbSaveFileName2
172 | //
173 | this.tbSaveFileName2.Location = new System.Drawing.Point(6, 164);
174 | this.tbSaveFileName2.Name = "tbSaveFileName2";
175 | this.tbSaveFileName2.Size = new System.Drawing.Size(365, 21);
176 | this.tbSaveFileName2.TabIndex = 18;
177 | //
178 | // btnSelectSaveFile_2
179 | //
180 | this.btnSelectSaveFile_2.Location = new System.Drawing.Point(380, 158);
181 | this.btnSelectSaveFile_2.Name = "btnSelectSaveFile_2";
182 | this.btnSelectSaveFile_2.Size = new System.Drawing.Size(88, 31);
183 | this.btnSelectSaveFile_2.TabIndex = 17;
184 | this.btnSelectSaveFile_2.Text = "输出路径";
185 | this.btnSelectSaveFile_2.UseVisualStyleBackColor = true;
186 | this.btnSelectSaveFile_2.Click += new System.EventHandler(this.btnSelectSaveFile_Click);
187 | //
188 | // tbNewFileName_2
189 | //
190 | this.tbNewFileName_2.Location = new System.Drawing.Point(6, 116);
191 | this.tbNewFileName_2.Name = "tbNewFileName_2";
192 | this.tbNewFileName_2.Size = new System.Drawing.Size(365, 21);
193 | this.tbNewFileName_2.TabIndex = 16;
194 | //
195 | // tbOldFileName_2
196 | //
197 | this.tbOldFileName_2.Location = new System.Drawing.Point(6, 67);
198 | this.tbOldFileName_2.Name = "tbOldFileName_2";
199 | this.tbOldFileName_2.Size = new System.Drawing.Size(368, 21);
200 | this.tbOldFileName_2.TabIndex = 15;
201 | //
202 | // btnSelectFile_2
203 | //
204 | this.btnSelectFile_2.Location = new System.Drawing.Point(380, 110);
205 | this.btnSelectFile_2.Name = "btnSelectFile_2";
206 | this.btnSelectFile_2.Size = new System.Drawing.Size(88, 31);
207 | this.btnSelectFile_2.TabIndex = 14;
208 | this.btnSelectFile_2.Text = "选择增量包";
209 | this.btnSelectFile_2.UseVisualStyleBackColor = true;
210 | this.btnSelectFile_2.Click += new System.EventHandler(this.btnSelectNewFile_Click);
211 | //
212 | // btnSelectOldFile_2
213 | //
214 | this.btnSelectOldFile_2.Location = new System.Drawing.Point(380, 60);
215 | this.btnSelectOldFile_2.Name = "btnSelectOldFile_2";
216 | this.btnSelectOldFile_2.Size = new System.Drawing.Size(88, 33);
217 | this.btnSelectOldFile_2.TabIndex = 13;
218 | this.btnSelectOldFile_2.Text = "选择目标文件";
219 | this.btnSelectOldFile_2.UseVisualStyleBackColor = true;
220 | this.btnSelectOldFile_2.Click += new System.EventHandler(this.btnSelectOldFile_Click);
221 | //
222 | // btnApplyPatch
223 | //
224 | this.btnApplyPatch.Location = new System.Drawing.Point(156, 214);
225 | this.btnApplyPatch.Name = "btnApplyPatch";
226 | this.btnApplyPatch.Size = new System.Drawing.Size(121, 32);
227 | this.btnApplyPatch.TabIndex = 12;
228 | this.btnApplyPatch.Text = "应用增量包";
229 | this.btnApplyPatch.UseVisualStyleBackColor = true;
230 | this.btnApplyPatch.Click += new System.EventHandler(this.btnPatch_Click);
231 | //
232 | // tabPage3
233 | //
234 | this.tabPage3.Controls.Add(this.label5);
235 | this.tabPage3.Controls.Add(this.label4);
236 | this.tabPage3.Controls.Add(this.linkLabel2);
237 | this.tabPage3.Controls.Add(this.label3);
238 | this.tabPage3.Controls.Add(this.linkLabel1);
239 | this.tabPage3.Controls.Add(this.label2);
240 | this.tabPage3.Controls.Add(this.label1);
241 | this.tabPage3.Location = new System.Drawing.Point(4, 22);
242 | this.tabPage3.Name = "tabPage3";
243 | this.tabPage3.Padding = new System.Windows.Forms.Padding(3);
244 | this.tabPage3.Size = new System.Drawing.Size(475, 316);
245 | this.tabPage3.TabIndex = 2;
246 | this.tabPage3.Text = "关于";
247 | this.tabPage3.UseVisualStyleBackColor = true;
248 | //
249 | // label5
250 | //
251 | this.label5.AutoSize = true;
252 | this.label5.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
253 | this.label5.Location = new System.Drawing.Point(384, 98);
254 | this.label5.Name = "label5";
255 | this.label5.Size = new System.Drawing.Size(59, 12);
256 | this.label5.TabIndex = 4;
257 | this.label5.Text = "版本:1.0";
258 | //
259 | // label4
260 | //
261 | this.label4.AutoSize = true;
262 | this.label4.Font = new System.Drawing.Font("宋体", 10.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
263 | this.label4.Location = new System.Drawing.Point(98, 84);
264 | this.label4.Name = "label4";
265 | this.label4.Size = new System.Drawing.Size(280, 14);
266 | this.label4.TabIndex = 3;
267 | this.label4.Text = "一款基于bsdiff4的增量文件生成及合成软件";
268 | //
269 | // linkLabel2
270 | //
271 | this.linkLabel2.AutoSize = true;
272 | this.linkLabel2.Font = new System.Drawing.Font("宋体", 10.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
273 | this.linkLabel2.Location = new System.Drawing.Point(219, 266);
274 | this.linkLabel2.Name = "linkLabel2";
275 | this.linkLabel2.Size = new System.Drawing.Size(224, 14);
276 | this.linkLabel2.TabIndex = 2;
277 | this.linkLabel2.TabStop = true;
278 | this.linkLabel2.Text = "https://github.com/crazycodeboy";
279 | this.linkLabel2.Click += new System.EventHandler(this.openWebSite);
280 | //
281 | // label3
282 | //
283 | this.label3.AutoSize = true;
284 | this.label3.Font = new System.Drawing.Font("宋体", 10.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
285 | this.label3.Location = new System.Drawing.Point(165, 266);
286 | this.label3.Name = "label3";
287 | this.label3.Size = new System.Drawing.Size(63, 14);
288 | this.label3.TabIndex = 1;
289 | this.label3.Text = "GitHub:";
290 | //
291 | // linkLabel1
292 | //
293 | this.linkLabel1.AutoSize = true;
294 | this.linkLabel1.Font = new System.Drawing.Font("宋体", 10.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
295 | this.linkLabel1.Location = new System.Drawing.Point(218, 289);
296 | this.linkLabel1.Name = "linkLabel1";
297 | this.linkLabel1.Size = new System.Drawing.Size(259, 14);
298 | this.linkLabel1.TabIndex = 2;
299 | this.linkLabel1.TabStop = true;
300 | this.linkLabel1.Text = "http://blog.csdn.net/fengyuzhengfan/";
301 | this.linkLabel1.Click += new System.EventHandler(this.openWebSite);
302 | //
303 | // label2
304 | //
305 | this.label2.AutoSize = true;
306 | this.label2.Font = new System.Drawing.Font("宋体", 10.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
307 | this.label2.Location = new System.Drawing.Point(165, 290);
308 | this.label2.Name = "label2";
309 | this.label2.Size = new System.Drawing.Size(49, 14);
310 | this.label2.TabIndex = 1;
311 | this.label2.Text = "Blog:";
312 | //
313 | // label1
314 | //
315 | this.label1.AutoSize = true;
316 | this.label1.Font = new System.Drawing.Font("宋体", 10.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
317 | this.label1.Location = new System.Drawing.Point(12, 289);
318 | this.label1.Name = "label1";
319 | this.label1.Size = new System.Drawing.Size(147, 14);
320 | this.label1.TabIndex = 0;
321 | this.label1.Text = "Author:CrazyCodeBoy";
322 | //
323 | // Main
324 | //
325 | this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
326 | this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
327 | this.ClientSize = new System.Drawing.Size(489, 366);
328 | this.Controls.Add(this.tabControl1);
329 | this.Name = "Main";
330 | this.Text = "增量工具";
331 | this.tabControl1.ResumeLayout(false);
332 | this.tabPage1.ResumeLayout(false);
333 | this.tabPage1.PerformLayout();
334 | this.tabPage2.ResumeLayout(false);
335 | this.tabPage2.PerformLayout();
336 | this.tabPage3.ResumeLayout(false);
337 | this.tabPage3.PerformLayout();
338 | this.ResumeLayout(false);
339 |
340 | }
341 |
342 | #endregion
343 | private System.Windows.Forms.OpenFileDialog openFileDialog1;
344 | private System.Windows.Forms.TabControl tabControl1;
345 | private System.Windows.Forms.TabPage tabPage1;
346 | private System.Windows.Forms.TabPage tabPage2;
347 | private System.Windows.Forms.TextBox tbNewFileName_1;
348 | private System.Windows.Forms.TextBox tbOldFileName_1;
349 | private System.Windows.Forms.Button btnSelectNewFile_1;
350 | private System.Windows.Forms.Button btnSelectOldFile_1;
351 | private System.Windows.Forms.Button btnGenPatch;
352 | private System.Windows.Forms.TextBox tbNewFileName_2;
353 | private System.Windows.Forms.TextBox tbOldFileName_2;
354 | private System.Windows.Forms.Button btnSelectFile_2;
355 | private System.Windows.Forms.Button btnSelectOldFile_2;
356 | private System.Windows.Forms.Button btnApplyPatch;
357 | private System.Windows.Forms.TextBox tbSaveFileName1;
358 | private System.Windows.Forms.Button btnSelectSaveFile_1;
359 | private System.Windows.Forms.TextBox tbSaveFileName2;
360 | private System.Windows.Forms.Button btnSelectSaveFile_2;
361 | private System.Windows.Forms.SaveFileDialog saveFileDialog1;
362 | private System.Windows.Forms.TabPage tabPage3;
363 | private System.Windows.Forms.Label label1;
364 | private System.Windows.Forms.Label label2;
365 | private System.Windows.Forms.LinkLabel linkLabel2;
366 | private System.Windows.Forms.Label label3;
367 | private System.Windows.Forms.LinkLabel linkLabel1;
368 | private System.Windows.Forms.Label label4;
369 | private System.Windows.Forms.Label label5;
370 | }
371 | }
372 |
373 |
--------------------------------------------------------------------------------
/PatchUtil-cs/PatchUtil/Main.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.IO;
3 | using System.Collections.Generic;
4 | using System.ComponentModel;
5 | using System.Data;
6 | using System.Drawing;
7 | using System.Linq;
8 | using System.Text;
9 | using System.Threading.Tasks;
10 | using System.Windows.Forms;
11 |
12 | namespace WindowsFormsApplication2
13 | {
14 | public partial class Main : Form
15 | {
16 | private String newFileName, oldFileName,saveFileName;
17 |
18 | public Main()
19 | {
20 | InitializeComponent();
21 | this.MaximizeBox = false;//使最大化窗口失效
22 | }
23 |
24 | private void btnSelectOldFile_Click(object sender, EventArgs e)
25 | {
26 | DialogResult dr=openFileDialog1.ShowDialog();
27 | if (dr == System.Windows.Forms.DialogResult.OK) {
28 | if (((Button)sender).Name == btnSelectOldFile_1.Name) {
29 | tbOldFileName_1.Text = openFileDialog1.FileName;
30 | } else {
31 | tbOldFileName_2.Text= openFileDialog1.FileName;
32 | }
33 | oldFileName = openFileDialog1.FileName;
34 | }
35 |
36 | }
37 |
38 | private void btnSelectNewFile_Click(object sender, EventArgs e)
39 | {
40 | DialogResult dr = openFileDialog1.ShowDialog();
41 | if (dr == System.Windows.Forms.DialogResult.OK)
42 | {
43 | if (((Button)sender).Name == btnSelectNewFile_1.Name)
44 | {
45 | tbNewFileName_1.Text = openFileDialog1.FileName;
46 | }
47 | else {
48 | tbNewFileName_2.Text = openFileDialog1.FileName;
49 | }
50 | newFileName = openFileDialog1.FileName;
51 | }
52 | }
53 | private void btnSelectSaveFile_Click(object sender, EventArgs e)
54 | {
55 | saveFileDialog1.FileName = genPatchFileName(((Button)sender).Name == btnSelectSaveFile_1.Name ? false : true,Path.GetFileName(oldFileName),Path.GetFileName(newFileName));
56 | DialogResult dr = saveFileDialog1.ShowDialog();
57 |
58 | if (dr == System.Windows.Forms.DialogResult.OK)
59 | {
60 | if (((Button)sender).Name == btnSelectSaveFile_1.Name)
61 | {
62 | tbSaveFileName1.Text = saveFileDialog1.FileName;
63 | }
64 | else
65 | {
66 | tbSaveFileName2.Text = saveFileDialog1.FileName;
67 | }
68 | saveFileName = saveFileDialog1.FileName;
69 | }
70 | }
71 | private void btnPatch_Click(object sender, EventArgs e)
72 | {
73 | if (((Button)sender).Name == btnGenPatch.Name)
74 | {
75 | genPatchFile();
76 | }
77 | else {
78 | applyPatchFile();
79 | }
80 | }
81 | public bool genPatchFile() {
82 | return onPreExecute(false);
83 | }
84 | public bool applyPatchFile()
85 | {
86 | return onPreExecute(true); ;
87 | }
88 | public bool onPreExecute(bool isApplyPatch) {
89 | String oldFileName,newFileName,saveFileName;
90 | StringBuilder fileNameCmd = new StringBuilder(System.AppDomain.CurrentDomain.BaseDirectory);//"C:\\Users\\Penn\\Documents\\Visual Studio 2015\\Projects\\WindowsFormsApplication2\\WindowsFormsApplication2\\bin\\Debug\\"
91 | StringBuilder argCmd = new StringBuilder();
92 | fileNameCmd.Append("lib\\");
93 | if (isApplyPatch) {
94 | fileNameCmd.Append("bspatch.exe");
95 | oldFileName = tbOldFileName_2.Text;
96 | newFileName = tbNewFileName_2.Text;
97 | saveFileName = tbSaveFileName2.Text;
98 | }
99 | else {
100 | fileNameCmd.Append("bsdiff.exe");
101 | oldFileName = tbOldFileName_1.Text;
102 | newFileName = tbNewFileName_1.Text;
103 | saveFileName = tbSaveFileName1.Text;
104 | }
105 | argCmd.Append("\"");
106 | argCmd.Append(oldFileName);
107 | argCmd.Append("\"");
108 | argCmd.Append(" ");
109 |
110 | if (isApplyPatch)
111 | {
112 | argCmd.Append("\"");
113 | argCmd.Append(saveFileName);
114 | argCmd.Append("\"");
115 | argCmd.Append(" ");
116 | argCmd.Append("\"");
117 | argCmd.Append(newFileName);
118 | argCmd.Append("\"");
119 |
120 | }
121 | else {
122 | argCmd.Append("\"");
123 | argCmd.Append(newFileName);
124 | argCmd.Append("\"");
125 | argCmd.Append(" ");
126 | argCmd.Append("\"");
127 | argCmd.Append(saveFileName);
128 | argCmd.Append("\"");
129 | }
130 |
131 | return onExecute(fileNameCmd.ToString(), argCmd.ToString());
132 | }
133 |
134 |
135 |
136 | public String genPatchFileName(bool isApplyPatch,String oldFileName, String newFileName) {
137 |
138 | StringBuilder sbPatchFileName = new StringBuilder();
139 | //sbPatchFileName.Append("\"");
140 | //sbPatchFileName.Append(directoryName);
141 | //if(!isApplyPatch) sbPatchFileName.Append("patch\\");
142 | //if (!Directory.Exists(sbPatchFileName.ToString().Trim('\"')))
143 | //{
144 | // Directory.CreateDirectory(sbPatchFileName.ToString().Trim('\"'));
145 | //}
146 | sbPatchFileName.Append(oldFileName.Substring(0, oldFileName.LastIndexOf('.')));
147 | sbPatchFileName.Append("_");
148 | sbPatchFileName.Append(newFileName.Substring(0, newFileName.LastIndexOf('.')));
149 | sbPatchFileName.Append(!isApplyPatch? ".patch" :oldFileName.Substring(oldFileName.LastIndexOf('.')));
150 | //sbPatchFileName.Append("\"");
151 | return sbPatchFileName.ToString();
152 | }
153 |
154 | public bool onExecute(String fileName,String arguments) {
155 | try
156 | {
157 | System.Diagnostics.Process p = new System.Diagnostics.Process();
158 | p.StartInfo.FileName = fileName;
159 | p.StartInfo.Arguments = arguments;
160 | p.Start();
161 | }
162 | catch(Exception e) {
163 | return false;
164 | }
165 | return true;
166 | }
167 |
168 | private void openWebSite(object sender, EventArgs e)
169 | {
170 | System.Diagnostics.Process.Start("iexplore.exe", ((Label)sender).Text);
171 | }
172 |
173 | }
174 |
175 |
176 | }
177 |
--------------------------------------------------------------------------------
/PatchUtil-cs/PatchUtil/Main.resx:
--------------------------------------------------------------------------------
1 |
2 |
3 |
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 | text/microsoft-resx
110 |
111 |
112 | 2.0
113 |
114 |
115 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
116 |
117 |
118 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
119 |
120 |
121 | 17, 17
122 |
123 |
124 | 165, 17
125 |
126 |
--------------------------------------------------------------------------------
/PatchUtil-cs/PatchUtil/PatchUtil.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | AnyCPU
7 | {1FD74B67-7E9C-44AC-9DFB-4194B5A32059}
8 | WinExe
9 | Properties
10 | WindowsFormsApplication2
11 | WindowsFormsApplication2
12 | v4.5.2
13 | 512
14 | true
15 |
16 |
17 | AnyCPU
18 | true
19 | full
20 | false
21 | bin\Debug\
22 | DEBUG;TRACE
23 | prompt
24 | 4
25 |
26 |
27 | AnyCPU
28 | pdbonly
29 | true
30 | bin\Release\
31 | TRACE
32 | prompt
33 | 4
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 | Form
51 |
52 |
53 | Main.cs
54 |
55 |
56 |
57 |
58 | Main.cs
59 |
60 |
61 | ResXFileCodeGenerator
62 | Resources.Designer.cs
63 | Designer
64 |
65 |
66 | True
67 | Resources.resx
68 |
69 |
70 | SettingsSingleFileGenerator
71 | Settings.Designer.cs
72 |
73 |
74 | True
75 | Settings.settings
76 | True
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
94 |
--------------------------------------------------------------------------------
/PatchUtil-cs/PatchUtil/Program.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Threading.Tasks;
5 | using System.Windows.Forms;
6 |
7 | namespace WindowsFormsApplication2
8 | {
9 | static class Program
10 | {
11 | ///
12 | /// 应用程序的主入口点。
13 | ///
14 | [STAThread]
15 | static void Main()
16 | {
17 | Application.EnableVisualStyles();
18 | Application.SetCompatibleTextRenderingDefault(false);
19 | Application.Run(new Main());
20 | }
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/PatchUtil-cs/PatchUtil/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // 有关程序集的一般信息由以下
6 | // 控制。更改这些特性值可修改
7 | // 与程序集关联的信息。
8 | [assembly: AssemblyTitle("WindowsFormsApplication2")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("")]
12 | [assembly: AssemblyProduct("WindowsFormsApplication2")]
13 | [assembly: AssemblyCopyright("Copyright © 2016")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | //将 ComVisible 设置为 false 将使此程序集中的类型
18 | //对 COM 组件不可见。 如果需要从 COM 访问此程序集中的类型,
19 | //请将此类型的 ComVisible 特性设置为 true。
20 | [assembly: ComVisible(false)]
21 |
22 | // 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID
23 | [assembly: Guid("1fd74b67-7e9c-44ac-9dfb-4194b5a32059")]
24 |
25 | // 程序集的版本信息由下列四个值组成:
26 | //
27 | // 主版本
28 | // 次版本
29 | // 生成号
30 | // 修订号
31 | //
32 | //可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值,
33 | // 方法是按如下所示使用“*”: :
34 | // [assembly: AssemblyVersion("1.0.*")]
35 | [assembly: AssemblyVersion("1.0.0.0")]
36 | [assembly: AssemblyFileVersion("1.0.0.0")]
37 |
--------------------------------------------------------------------------------
/PatchUtil-cs/PatchUtil/Properties/Resources.Designer.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | //
3 | // 此代码由工具生成。
4 | // 运行时版本: 4.0.30319.42000
5 | //
6 | // 对此文件的更改可能导致不正确的行为,如果
7 | // 重新生成代码,则所做更改将丢失。
8 | //
9 | //------------------------------------------------------------------------------
10 |
11 | namespace WindowsFormsApplication2.Properties
12 | {
13 |
14 |
15 | ///
16 | /// 强类型资源类,用于查找本地化字符串等。
17 | ///
18 | // 此类是由 StronglyTypedResourceBuilder
19 | // 类通过类似于 ResGen 或 Visual Studio 的工具自动生成的。
20 | // 若要添加或删除成员,请编辑 .ResX 文件,然后重新运行 ResGen
21 | // (以 /str 作为命令选项),或重新生成 VS 项目。
22 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
23 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
24 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
25 | internal class Resources
26 | {
27 |
28 | private static global::System.Resources.ResourceManager resourceMan;
29 |
30 | private static global::System.Globalization.CultureInfo resourceCulture;
31 |
32 | [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
33 | internal Resources()
34 | {
35 | }
36 |
37 | ///
38 | /// 返回此类使用的缓存 ResourceManager 实例。
39 | ///
40 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
41 | internal static global::System.Resources.ResourceManager ResourceManager
42 | {
43 | get
44 | {
45 | if ((resourceMan == null))
46 | {
47 | global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("WindowsFormsApplication2.Properties.Resources", typeof(Resources).Assembly);
48 | resourceMan = temp;
49 | }
50 | return resourceMan;
51 | }
52 | }
53 |
54 | ///
55 | /// 覆盖当前线程的 CurrentUICulture 属性
56 | /// 使用此强类型的资源类的资源查找。
57 | ///
58 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
59 | internal static global::System.Globalization.CultureInfo Culture
60 | {
61 | get
62 | {
63 | return resourceCulture;
64 | }
65 | set
66 | {
67 | resourceCulture = value;
68 | }
69 | }
70 | }
71 | }
72 |
--------------------------------------------------------------------------------
/PatchUtil-cs/PatchUtil/Properties/Resources.resx:
--------------------------------------------------------------------------------
1 |
2 |
3 |
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 | text/microsoft-resx
107 |
108 |
109 | 2.0
110 |
111 |
112 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
113 |
114 |
115 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
116 |
117 |
--------------------------------------------------------------------------------
/PatchUtil-cs/PatchUtil/Properties/Settings.Designer.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | //
3 | // This code was generated by a tool.
4 | // Runtime Version:4.0.30319.42000
5 | //
6 | // Changes to this file may cause incorrect behavior and will be lost if
7 | // the code is regenerated.
8 | //
9 | //------------------------------------------------------------------------------
10 |
11 | namespace WindowsFormsApplication2.Properties
12 | {
13 |
14 |
15 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
16 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")]
17 | internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase
18 | {
19 |
20 | private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
21 |
22 | public static Settings Default
23 | {
24 | get
25 | {
26 | return defaultInstance;
27 | }
28 | }
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/PatchUtil-cs/PatchUtil/Properties/Settings.settings:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/PatchUtil-cs/PatchUtil/lib/bsdiff.exe:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/crazycodeboy/IncrementalUpdate/ad8d310c71ba319a0d1e14968865142978830816/PatchUtil-cs/PatchUtil/lib/bsdiff.exe
--------------------------------------------------------------------------------
/PatchUtil-cs/PatchUtil/lib/bspatch.exe:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/crazycodeboy/IncrementalUpdate/ad8d310c71ba319a0d1e14968865142978830816/PatchUtil-cs/PatchUtil/lib/bspatch.exe
--------------------------------------------------------------------------------
/PatchUtil-cs/PatchUtil/obj/Debug/DesignTimeResolveAssemblyReferences.cache:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/crazycodeboy/IncrementalUpdate/ad8d310c71ba319a0d1e14968865142978830816/PatchUtil-cs/PatchUtil/obj/Debug/DesignTimeResolveAssemblyReferences.cache
--------------------------------------------------------------------------------
/PatchUtil-cs/PatchUtil/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/crazycodeboy/IncrementalUpdate/ad8d310c71ba319a0d1e14968865142978830816/PatchUtil-cs/PatchUtil/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache
--------------------------------------------------------------------------------
/PatchUtil-cs/PatchUtil/obj/Debug/PatchUtil.csproj.FileListAbsolute.txt:
--------------------------------------------------------------------------------
1 | C:\Users\Penn\Documents\Visual Studio 2015\Projects\WindowsFormsApplication2\WindowsFormsApplication2\bin\Debug\WindowsFormsApplication2.exe.config
2 | C:\Users\Penn\Documents\Visual Studio 2015\Projects\WindowsFormsApplication2\WindowsFormsApplication2\bin\Debug\WindowsFormsApplication2.exe
3 | C:\Users\Penn\Documents\Visual Studio 2015\Projects\WindowsFormsApplication2\WindowsFormsApplication2\bin\Debug\WindowsFormsApplication2.pdb
4 | C:\Users\Penn\Documents\Visual Studio 2015\Projects\WindowsFormsApplication2\WindowsFormsApplication2\obj\Debug\PatchUtil.csprojResolveAssemblyReference.cache
5 | C:\Users\Penn\Documents\Visual Studio 2015\Projects\WindowsFormsApplication2\WindowsFormsApplication2\obj\Debug\WindowsFormsApplication2.Main.resources
6 | C:\Users\Penn\Documents\Visual Studio 2015\Projects\WindowsFormsApplication2\WindowsFormsApplication2\obj\Debug\WindowsFormsApplication2.Properties.Resources.resources
7 | C:\Users\Penn\Documents\Visual Studio 2015\Projects\WindowsFormsApplication2\WindowsFormsApplication2\obj\Debug\PatchUtil.csproj.GenerateResource.Cache
8 | C:\Users\Penn\Documents\Visual Studio 2015\Projects\WindowsFormsApplication2\WindowsFormsApplication2\obj\Debug\WindowsFormsApplication2.exe
9 | C:\Users\Penn\Documents\Visual Studio 2015\Projects\WindowsFormsApplication2\WindowsFormsApplication2\obj\Debug\WindowsFormsApplication2.pdb
10 | C:\Users\Penn\Documents\Visual Studio 2015\Projects\PatchUtil\PatchUtil\bin\Debug\WindowsFormsApplication2.exe.config
11 | C:\Users\Penn\Documents\Visual Studio 2015\Projects\PatchUtil\PatchUtil\obj\Debug\WindowsFormsApplication2.exe
12 | C:\Users\Penn\Documents\Visual Studio 2015\Projects\PatchUtil\PatchUtil\obj\Debug\WindowsFormsApplication2.pdb
13 | C:\Users\Penn\Documents\Visual Studio 2015\Projects\PatchUtil\PatchUtil\bin\Debug\WindowsFormsApplication2.exe
14 | C:\Users\Penn\Documents\Visual Studio 2015\Projects\PatchUtil\PatchUtil\bin\Debug\WindowsFormsApplication2.pdb
15 | C:\Users\Penn\Documents\Visual Studio 2015\Projects\PatchUtil\PatchUtil\obj\Debug\PatchUtil.csprojResolveAssemblyReference.cache
16 | C:\Users\Penn\Documents\Visual Studio 2015\Projects\PatchUtil\PatchUtil\obj\Debug\WindowsFormsApplication2.Main.resources
17 | C:\Users\Penn\Documents\Visual Studio 2015\Projects\PatchUtil\PatchUtil\obj\Debug\WindowsFormsApplication2.Properties.Resources.resources
18 | C:\Users\Penn\Documents\Visual Studio 2015\Projects\PatchUtil\PatchUtil\obj\Debug\PatchUtil.csproj.GenerateResource.Cache
19 | E:\JiaPengHui\workplace\GitRepository\IncrementalUpdate\PatchUtil-cs\PatchUtil\bin\Debug\WindowsFormsApplication2.exe.config
20 | E:\JiaPengHui\workplace\GitRepository\IncrementalUpdate\PatchUtil-cs\PatchUtil\obj\Debug\WindowsFormsApplication2.exe
21 | E:\JiaPengHui\workplace\GitRepository\IncrementalUpdate\PatchUtil-cs\PatchUtil\obj\Debug\WindowsFormsApplication2.pdb
22 | E:\JiaPengHui\workplace\GitRepository\IncrementalUpdate\PatchUtil-cs\PatchUtil\bin\Debug\WindowsFormsApplication2.exe
23 | E:\JiaPengHui\workplace\GitRepository\IncrementalUpdate\PatchUtil-cs\PatchUtil\bin\Debug\WindowsFormsApplication2.pdb
24 | E:\JiaPengHui\workplace\GitRepository\IncrementalUpdate\PatchUtil-cs\PatchUtil\obj\Debug\PatchUtil.csprojResolveAssemblyReference.cache
25 | E:\JiaPengHui\workplace\GitRepository\IncrementalUpdate\PatchUtil-cs\PatchUtil\obj\Debug\WindowsFormsApplication2.Main.resources
26 | E:\JiaPengHui\workplace\GitRepository\IncrementalUpdate\PatchUtil-cs\PatchUtil\obj\Debug\WindowsFormsApplication2.Properties.Resources.resources
27 | E:\JiaPengHui\workplace\GitRepository\IncrementalUpdate\PatchUtil-cs\PatchUtil\obj\Debug\PatchUtil.csproj.GenerateResource.Cache
28 |
--------------------------------------------------------------------------------
/PatchUtil-cs/PatchUtil/obj/Debug/PatchUtil.csproj.GenerateResource.Cache:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/crazycodeboy/IncrementalUpdate/ad8d310c71ba319a0d1e14968865142978830816/PatchUtil-cs/PatchUtil/obj/Debug/PatchUtil.csproj.GenerateResource.Cache
--------------------------------------------------------------------------------
/PatchUtil-cs/PatchUtil/obj/Debug/PatchUtil.csprojResolveAssemblyReference.cache:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/crazycodeboy/IncrementalUpdate/ad8d310c71ba319a0d1e14968865142978830816/PatchUtil-cs/PatchUtil/obj/Debug/PatchUtil.csprojResolveAssemblyReference.cache
--------------------------------------------------------------------------------
/PatchUtil-cs/PatchUtil/obj/Debug/TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/crazycodeboy/IncrementalUpdate/ad8d310c71ba319a0d1e14968865142978830816/PatchUtil-cs/PatchUtil/obj/Debug/TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs
--------------------------------------------------------------------------------
/PatchUtil-cs/PatchUtil/obj/Debug/TemporaryGeneratedFile_5937a670-0e60-4077-877b-f7221da3dda1.cs:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/crazycodeboy/IncrementalUpdate/ad8d310c71ba319a0d1e14968865142978830816/PatchUtil-cs/PatchUtil/obj/Debug/TemporaryGeneratedFile_5937a670-0e60-4077-877b-f7221da3dda1.cs
--------------------------------------------------------------------------------
/PatchUtil-cs/PatchUtil/obj/Debug/TemporaryGeneratedFile_E7A71F73-0F8D-4B9B-B56E-8E70B10BC5D3.cs:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/crazycodeboy/IncrementalUpdate/ad8d310c71ba319a0d1e14968865142978830816/PatchUtil-cs/PatchUtil/obj/Debug/TemporaryGeneratedFile_E7A71F73-0F8D-4B9B-B56E-8E70B10BC5D3.cs
--------------------------------------------------------------------------------
/PatchUtil-cs/PatchUtil/obj/Debug/WindowsFormsApplication2.Main.resources:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/crazycodeboy/IncrementalUpdate/ad8d310c71ba319a0d1e14968865142978830816/PatchUtil-cs/PatchUtil/obj/Debug/WindowsFormsApplication2.Main.resources
--------------------------------------------------------------------------------
/PatchUtil-cs/PatchUtil/obj/Debug/WindowsFormsApplication2.Properties.Resources.resources:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/crazycodeboy/IncrementalUpdate/ad8d310c71ba319a0d1e14968865142978830816/PatchUtil-cs/PatchUtil/obj/Debug/WindowsFormsApplication2.Properties.Resources.resources
--------------------------------------------------------------------------------
/PatchUtil-cs/PatchUtil/obj/Debug/WindowsFormsApplication2.csproj.FileListAbsolute.txt:
--------------------------------------------------------------------------------
1 | c:\users\penn\documents\visual studio 2015\Projects\WindowsFormsApplication2\WindowsFormsApplication2\bin\Debug\WindowsFormsApplication2.exe.config
2 | c:\users\penn\documents\visual studio 2015\Projects\WindowsFormsApplication2\WindowsFormsApplication2\bin\Debug\WindowsFormsApplication2.exe
3 | c:\users\penn\documents\visual studio 2015\Projects\WindowsFormsApplication2\WindowsFormsApplication2\bin\Debug\WindowsFormsApplication2.pdb
4 | c:\users\penn\documents\visual studio 2015\Projects\WindowsFormsApplication2\WindowsFormsApplication2\obj\Debug\WindowsFormsApplication2.Properties.Resources.resources
5 | c:\users\penn\documents\visual studio 2015\Projects\WindowsFormsApplication2\WindowsFormsApplication2\obj\Debug\WindowsFormsApplication2.csproj.GenerateResource.Cache
6 | c:\users\penn\documents\visual studio 2015\Projects\WindowsFormsApplication2\WindowsFormsApplication2\obj\Debug\WindowsFormsApplication2.exe
7 | c:\users\penn\documents\visual studio 2015\Projects\WindowsFormsApplication2\WindowsFormsApplication2\obj\Debug\WindowsFormsApplication2.pdb
8 | C:\Users\Penn\Documents\Visual Studio 2015\Projects\WindowsFormsApplication2\WindowsFormsApplication2\obj\Debug\WindowsFormsApplication2.csprojResolveAssemblyReference.cache
9 | C:\Users\Penn\Documents\Visual Studio 2015\Projects\WindowsFormsApplication2\WindowsFormsApplication2\obj\Debug\WindowsFormsApplication2.Main.resources
10 |
--------------------------------------------------------------------------------
/PatchUtil-cs/PatchUtil/obj/Debug/WindowsFormsApplication2.csproj.GenerateResource.Cache:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/crazycodeboy/IncrementalUpdate/ad8d310c71ba319a0d1e14968865142978830816/PatchUtil-cs/PatchUtil/obj/Debug/WindowsFormsApplication2.csproj.GenerateResource.Cache
--------------------------------------------------------------------------------
/PatchUtil-cs/PatchUtil/obj/Debug/WindowsFormsApplication2.csprojResolveAssemblyReference.cache:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/crazycodeboy/IncrementalUpdate/ad8d310c71ba319a0d1e14968865142978830816/PatchUtil-cs/PatchUtil/obj/Debug/WindowsFormsApplication2.csprojResolveAssemblyReference.cache
--------------------------------------------------------------------------------
/PatchUtil-cs/PatchUtil/obj/Debug/WindowsFormsApplication2.exe:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/crazycodeboy/IncrementalUpdate/ad8d310c71ba319a0d1e14968865142978830816/PatchUtil-cs/PatchUtil/obj/Debug/WindowsFormsApplication2.exe
--------------------------------------------------------------------------------
/PatchUtil-cs/PatchUtil/obj/Debug/WindowsFormsApplication2.pdb:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/crazycodeboy/IncrementalUpdate/ad8d310c71ba319a0d1e14968865142978830816/PatchUtil-cs/PatchUtil/obj/Debug/WindowsFormsApplication2.pdb
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
2 | # Android应用省流量升级、增量更新、补丁生成与应用 - Incremental Update
3 |
4 |
5 | ## 介绍
6 |
7 | 这是一个用于Android应用程序增量更新的库。包括客户端、服务端两部分代码,其中服务器端又分为c/s、b/s。
8 |
9 | ## 项目结构
10 | * ApkPatchLibrary:客户端使用的apk合成库,用于生成libApkPatchLibrary.so,使用Eclipse开发;
11 | * IncrementalUpdate-Android:一个Sample,手机上安装 jinritoutiao_542.apk,通过与SD卡上预先存放的jinritoutiao_542_jinritoutiao_543.patch文件进行合并,得到jinritoutiao_543.apk,使用AndroidStudio开发。
12 | * IncrementalUpdate-web:基于bsdiff的Web端文件补丁生成与应用工具,使用Eclipse开发。
13 | * PatchUtil-cs:基于bsdiff的C/S版补丁生成与应用工具,使用Visual Studio开发。
14 |
15 | ## 为什么会有增量更新?
16 | 智能手机发展到现在,已经有成千上万的APP,这些APP的安装包也越来越大,小则几M,多则几十M甚至上百M。传统方式更新APP需要下载APP的完整包。如果安装包比较大,用户在更新APP的时候不仅等待的时间长,而且很消耗流量(二十一世纪最贵的莫非是流量了)。所以说用户很不愿意将APP更新到最新版本。
17 |
18 | 1. 对于用户来说下载完整包进行更新费流量,且等待时间长。
19 | 2. 对于每次版本迭代本身来说,一般是修复BUG,添加一些新功能,这些所产生的增量很小。
20 | 3. 对于APP的所有者来说,希望将用户使用的是最新的APP。
21 |
22 | (有需求就有市场)增量更新便解决了这些痛点。
23 |
24 | ## 原理
25 |
26 | 增量更新不是什么黑科技,而是对原有技术的新应用,就像AJAX。
27 |
28 | 现在越来越多的应用市场开始支持增量更新,比如百度手机助手,小米应用市场,华为应用市场等。
29 |
30 | 增量更新的原理,就是将手机上已安装apk与服务器端最新apk进行二进制对比,得到增量包,用户更新程序时,只需要下载增量包,并在本地使用增量包与已安装apk,合成新版apk。
31 |
32 | 例如,当前手机中已安装APPV1,大小为10MB,现在APP发布了最新版V2,大小为12.6MB,我们对两个版本的apk文件增量比对之后,发现差异只有2M,那么用户就只需要要下载一个2M的增量包,使用旧版apk与这个增量包,合成得到一个新版本apk,提醒用户安装即可,不需要整包下载12.6M的APPV2版apk。
33 |
34 | apk文件的增量、合成,可以通过 xdelta或开源的二进制比较工具 bsdiff 来实现,本项目主要基于bsdiff来实现增量更新,因为bsdiff依赖bzip2,所以我们还需要用到 bzip2, bsdiff中,`bsdiff.c` 用于生成增量包,`bspatch.c` 用于合成文件。
35 |
36 | 弄清楚原理之后,我们想实现增量更新,共需要做3件事:
37 |
38 | * 在服务器端,生成两个版本apk的增量包;
39 |
40 | * 在手机客户端,使用已安装的apk与这个增量包进行合成,得到新版的apk;
41 |
42 | * 校验新合成的apk文件是否完整,MD5或SHA1是否正确,如正确,则引导用户安装;
43 |
44 | ## 过程分析
45 |
46 | ### 1 生成增量包
47 |
48 | 这一步需要在服务器端来实现,一般来说,每当apk有新版本需要提示用户升级,都需要运营人员在后台管理端上传新apk,上传时就应该由程序生成与之前所有旧版本们与最新版的增量包。
49 |
50 | 例如:
51 | 你的apk已经发布了3个版,V1.0、V2.0、V3.0,这时候你要在后台发布V4.0,那么,当你在服务器上传最新的V4.0包时,服务器端就应该立即生成以下增量包:
52 |
53 | 1. V1.0 ——> V4.0的增量包;
54 | 2. V2.0 ——> V4.0的增量包;
55 | 3. V3.0 ——> V4.0的增量包;
56 |
57 |
58 | ### 2.使用旧版apk与增量包,在客户端合成新apk
59 |
60 | 需要在手机客户端实现,ApkPatchLibrary 工程封装了这个过程。
61 |
62 | #### 2.1 C部分
63 | 同ApkPatchLibraryServer工程一样,ApkPatchLibrary/jni/bzip2 目录中所有文件都来自bzip2项目。
64 |
65 | `ApkPatchLibrary/jni/com_jph_utils_PatchUtils.c`、`ApkPatchLibrary/jni/com_jph_utils_PatchUtils.c`实现文件的合并过程,其中`com_jph_utils_PatchUtils.c`修改自`bsdiff/bspatch.c`。
66 |
67 | 我们需要用NDK编译出一个libApkPatchLibrary.so文件,生成的so文件位于libs/armeabi/ 下,其他 Android 工程便可以使用该libApkPatchLibrary.so文件来合成apk(如果需要支持多种CPU架构需要自己配置)。
68 |
69 | `com_jph_utils_PatchUtils.Java_com_jph_utils_PatchUtils_patch()`方法,即为生成增量包的代码:
70 |
71 | ```C
72 | /*
73 | * Class: com_jph_utils_PatchUtils
74 | * Method: patch
75 | * Signature: (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)I
76 | */
77 | JNIEXPORT jint JNICALL Java_com_jph_utils_PatchUtils_patch(JNIEnv *env,
78 | jobject obj, jstring old, jstring new, jstring patch) {
79 |
80 | char * ch[4];
81 | ch[0] = "bspatch";
82 | ch[1] = (char*) ((*env)->GetStringUTFChars(env, old, 0));
83 | ch[2] = (char*) ((*env)->GetStringUTFChars(env, new, 0));
84 | ch[3] = (char*) ((*env)->GetStringUTFChars(env, patch, 0));
85 |
86 | __android_log_print(ANDROID_LOG_INFO, "ApkPatchLibrary", "old = %s ", ch[1]);
87 | __android_log_print(ANDROID_LOG_INFO, "ApkPatchLibrary", "new = %s ", ch[2]);
88 | __android_log_print(ANDROID_LOG_INFO, "ApkPatchLibrary", "patch = %s ", ch[3]);
89 |
90 | int ret = applypatch(4, ch);
91 |
92 | __android_log_print(ANDROID_LOG_INFO, "ApkPatchLibrary", "applypatch result = %d ", ret);
93 |
94 | (*env)->ReleaseStringUTFChars(env, old, ch[1]);
95 | (*env)->ReleaseStringUTFChars(env, new, ch[2]);
96 | (*env)->ReleaseStringUTFChars(env, patch, ch[3]);
97 |
98 | return ret;
99 | }
100 | ```
101 |
102 | #### 2.2 Java部分
103 |
104 | com.jph.utils包,为调用C语言的Java实现;
105 |
106 | 调用,`com.jph.utils.PatchUtils中patch()`方法,可以通过旧apk与增量包,合成为新apk。
107 |
108 | ```java
109 | /**
110 | * APK Patch工具类
111 | *
112 | * @author jph
113 | */
114 | public class PatchUtils {
115 |
116 | /**
117 | * native方法 使用路径为oldApkPath的apk与路径为patchPath的补丁包,合成新的apk,并存储于 newApkPath
118 | *
119 | * 返回:0,说明操作成功
120 | *
121 | * @param oldApkPath 示例:/sdcard/old.apk
122 | * @param newApkPath 示例:/sdcard/new.apk
123 | * @param patchPath 示例:/sdcard/xx.patch
124 | * @return
125 | */
126 | public static native int patch(String oldApkPath, String newApkPath,
127 | String patchPath);
128 | }
129 | ```
130 |
131 | ### 3.校验新合成的apk文件
132 |
133 | 在执行patch之前,需要先读取本地安装旧版本APK的MD5或SHA1,判断当前安装的文件是否为合法版本,同样,patch得到新包之后,也需要对它进行MD5或SHA1校验,校验失败,说明合成过程有问题。
134 |
135 | ## 注意事项
136 |
137 | 增量更新的前提条件,是在手机客户端能让我们读取到当前应用程序安装后的源apk,如果获取不到源apk,那么就无法进行增量更新了,另外,如果你的应用程序不是很大,比如只有2、3M,那么完全没有必要使用增量更新,增量更新只适用于apk包比较大的情况,比如手机游戏客户端。
138 |
139 |
140 |
141 |
142 |
143 |
144 |
--------------------------------------------------------------------------------