@appzung/react-native-code-push 5.7.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AlertAdapter.js +24 -0
- package/CONTRIBUTING.md +136 -0
- package/CodePush.js +666 -0
- package/CodePush.podspec +27 -0
- package/LICENSE.md +13 -0
- package/README.md +386 -0
- package/RestartManager.js +59 -0
- package/android/app/build.gradle +31 -0
- package/android/app/proguard-rules.pro +25 -0
- package/android/app/src/main/AndroidManifest.xml +10 -0
- package/android/app/src/main/java/com/microsoft/codepush/react/CodePush.java +395 -0
- package/android/app/src/main/java/com/microsoft/codepush/react/CodePushBuilder.java +37 -0
- package/android/app/src/main/java/com/microsoft/codepush/react/CodePushConstants.java +34 -0
- package/android/app/src/main/java/com/microsoft/codepush/react/CodePushDialog.java +102 -0
- package/android/app/src/main/java/com/microsoft/codepush/react/CodePushInstallMode.java +16 -0
- package/android/app/src/main/java/com/microsoft/codepush/react/CodePushInvalidPublicKeyException.java +12 -0
- package/android/app/src/main/java/com/microsoft/codepush/react/CodePushInvalidUpdateException.java +7 -0
- package/android/app/src/main/java/com/microsoft/codepush/react/CodePushMalformedDataException.java +12 -0
- package/android/app/src/main/java/com/microsoft/codepush/react/CodePushNativeModule.java +641 -0
- package/android/app/src/main/java/com/microsoft/codepush/react/CodePushNotInitializedException.java +12 -0
- package/android/app/src/main/java/com/microsoft/codepush/react/CodePushTelemetryManager.java +175 -0
- package/android/app/src/main/java/com/microsoft/codepush/react/CodePushUnknownException.java +12 -0
- package/android/app/src/main/java/com/microsoft/codepush/react/CodePushUpdateManager.java +369 -0
- package/android/app/src/main/java/com/microsoft/codepush/react/CodePushUpdateState.java +15 -0
- package/android/app/src/main/java/com/microsoft/codepush/react/CodePushUpdateUtils.java +267 -0
- package/android/app/src/main/java/com/microsoft/codepush/react/CodePushUtils.java +236 -0
- package/android/app/src/main/java/com/microsoft/codepush/react/DownloadProgress.java +30 -0
- package/android/app/src/main/java/com/microsoft/codepush/react/DownloadProgressCallback.java +5 -0
- package/android/app/src/main/java/com/microsoft/codepush/react/FileUtils.java +190 -0
- package/android/app/src/main/java/com/microsoft/codepush/react/ReactInstanceHolder.java +17 -0
- package/android/app/src/main/java/com/microsoft/codepush/react/SettingsManager.java +173 -0
- package/android/build.gradle +20 -0
- package/android/codepush.gradle +113 -0
- package/android/gradle/wrapper/gradle-wrapper.jar +0 -0
- package/android/gradle/wrapper/gradle-wrapper.properties +5 -0
- package/android/gradle.properties +20 -0
- package/android/gradlew +164 -0
- package/android/gradlew.bat +90 -0
- package/android/settings.gradle +1 -0
- package/docs/api-android.md +65 -0
- package/docs/api-ios.md +31 -0
- package/docs/api-js.md +592 -0
- package/docs/multi-deployment-testing-android.md +107 -0
- package/docs/multi-deployment-testing-ios.md +53 -0
- package/docs/setup-android.md +406 -0
- package/docs/setup-ios.md +229 -0
- package/docs/setup-windows.md +65 -0
- package/gulpfile.js +302 -0
- package/ios/CodePush/Base64/Base64/MF_Base64Additions.h +34 -0
- package/ios/CodePush/Base64/Base64/MF_Base64Additions.m +252 -0
- package/ios/CodePush/Base64/README.md +47 -0
- package/ios/CodePush/CodePush.h +235 -0
- package/ios/CodePush/CodePush.m +1041 -0
- package/ios/CodePush/CodePushConfig.m +116 -0
- package/ios/CodePush/CodePushDownloadHandler.m +130 -0
- package/ios/CodePush/CodePushErrorUtils.m +20 -0
- package/ios/CodePush/CodePushPackage.m +598 -0
- package/ios/CodePush/CodePushTelemetryManager.m +175 -0
- package/ios/CodePush/CodePushUpdateUtils.m +376 -0
- package/ios/CodePush/CodePushUtils.m +9 -0
- package/ios/CodePush/JWT/Core/Algorithms/Base/JWTAlgorithm.h +69 -0
- package/ios/CodePush/JWT/Core/Algorithms/Base/JWTAlgorithmFactory.h +16 -0
- package/ios/CodePush/JWT/Core/Algorithms/Base/JWTAlgorithmFactory.m +51 -0
- package/ios/CodePush/JWT/Core/Algorithms/Base/JWTAlgorithmNone.h +15 -0
- package/ios/CodePush/JWT/Core/Algorithms/Base/JWTAlgorithmNone.m +55 -0
- package/ios/CodePush/JWT/Core/Algorithms/ESFamily/JWTAlgorithmESBase.h +24 -0
- package/ios/CodePush/JWT/Core/Algorithms/ESFamily/JWTAlgorithmESBase.m +41 -0
- package/ios/CodePush/JWT/Core/Algorithms/HSFamily/JWTAlgorithmHSBase.h +28 -0
- package/ios/CodePush/JWT/Core/Algorithms/HSFamily/JWTAlgorithmHSBase.m +205 -0
- package/ios/CodePush/JWT/Core/Algorithms/Holders/JWTAlgorithmDataHolder.h +103 -0
- package/ios/CodePush/JWT/Core/Algorithms/Holders/JWTAlgorithmDataHolder.m +322 -0
- package/ios/CodePush/JWT/Core/Algorithms/Holders/JWTAlgorithmDataHolderChain.h +37 -0
- package/ios/CodePush/JWT/Core/Algorithms/Holders/JWTAlgorithmDataHolderChain.m +145 -0
- package/ios/CodePush/JWT/Core/Algorithms/RSFamily/JWTAlgorithmRSBase.h +35 -0
- package/ios/CodePush/JWT/Core/Algorithms/RSFamily/JWTAlgorithmRSBase.m +551 -0
- package/ios/CodePush/JWT/Core/Algorithms/RSFamily/JWTRSAlgorithm.h +23 -0
- package/ios/CodePush/JWT/Core/Algorithms/RSFamily/RSKeys/JWTCryptoKey.h +43 -0
- package/ios/CodePush/JWT/Core/Algorithms/RSFamily/RSKeys/JWTCryptoKey.m +230 -0
- package/ios/CodePush/JWT/Core/Algorithms/RSFamily/RSKeys/JWTCryptoKeyExtractor.h +31 -0
- package/ios/CodePush/JWT/Core/Algorithms/RSFamily/RSKeys/JWTCryptoKeyExtractor.m +113 -0
- package/ios/CodePush/JWT/Core/Algorithms/RSFamily/RSKeys/JWTCryptoSecurity.h +38 -0
- package/ios/CodePush/JWT/Core/Algorithms/RSFamily/RSKeys/JWTCryptoSecurity.m +500 -0
- package/ios/CodePush/JWT/Core/ClaimSet/JWTClaim.h +18 -0
- package/ios/CodePush/JWT/Core/ClaimSet/JWTClaim.m +214 -0
- package/ios/CodePush/JWT/Core/ClaimSet/JWTClaimsSet.h +23 -0
- package/ios/CodePush/JWT/Core/ClaimSet/JWTClaimsSet.m +29 -0
- package/ios/CodePush/JWT/Core/ClaimSet/JWTClaimsSetSerializer.h +19 -0
- package/ios/CodePush/JWT/Core/ClaimSet/JWTClaimsSetSerializer.m +68 -0
- package/ios/CodePush/JWT/Core/ClaimSet/JWTClaimsSetVerifier.h +18 -0
- package/ios/CodePush/JWT/Core/ClaimSet/JWTClaimsSetVerifier.m +72 -0
- package/ios/CodePush/JWT/Core/Coding/JWTCoding+ResultTypes.h +67 -0
- package/ios/CodePush/JWT/Core/Coding/JWTCoding+ResultTypes.m +111 -0
- package/ios/CodePush/JWT/Core/Coding/JWTCoding+VersionOne.h +119 -0
- package/ios/CodePush/JWT/Core/Coding/JWTCoding+VersionOne.m +307 -0
- package/ios/CodePush/JWT/Core/Coding/JWTCoding+VersionThree.h +94 -0
- package/ios/CodePush/JWT/Core/Coding/JWTCoding+VersionThree.m +619 -0
- package/ios/CodePush/JWT/Core/Coding/JWTCoding+VersionTwo.h +164 -0
- package/ios/CodePush/JWT/Core/Coding/JWTCoding+VersionTwo.m +514 -0
- package/ios/CodePush/JWT/Core/Coding/JWTCoding.h +24 -0
- package/ios/CodePush/JWT/Core/Coding/JWTCoding.m +11 -0
- package/ios/CodePush/JWT/Core/FrameworkSupplement/JWT.h +52 -0
- package/ios/CodePush/JWT/Core/FrameworkSupplement/Map.modulemap +5 -0
- package/ios/CodePush/JWT/Core/Supplement/JWTBase64Coder.h +28 -0
- package/ios/CodePush/JWT/Core/Supplement/JWTBase64Coder.m +70 -0
- package/ios/CodePush/JWT/Core/Supplement/JWTDeprecations.h +22 -0
- package/ios/CodePush/JWT/Core/Supplement/JWTErrorDescription.h +34 -0
- package/ios/CodePush/JWT/Core/Supplement/JWTErrorDescription.m +73 -0
- package/ios/CodePush/JWT/LICENSE +19 -0
- package/ios/CodePush/JWT/README.md +489 -0
- package/ios/CodePush/RCTConvert+CodePushInstallMode.m +20 -0
- package/ios/CodePush/RCTConvert+CodePushUpdateState.m +20 -0
- package/ios/CodePush/SSZipArchive/Common.h +81 -0
- package/ios/CodePush/SSZipArchive/README.md +1 -0
- package/ios/CodePush/SSZipArchive/SSZipArchive.h +76 -0
- package/ios/CodePush/SSZipArchive/SSZipArchive.m +691 -0
- package/ios/CodePush/SSZipArchive/aes/aes.h +198 -0
- package/ios/CodePush/SSZipArchive/aes/aes_via_ace.h +541 -0
- package/ios/CodePush/SSZipArchive/aes/aescrypt.c +294 -0
- package/ios/CodePush/SSZipArchive/aes/aeskey.c +548 -0
- package/ios/CodePush/SSZipArchive/aes/aesopt.h +739 -0
- package/ios/CodePush/SSZipArchive/aes/aestab.c +391 -0
- package/ios/CodePush/SSZipArchive/aes/aestab.h +173 -0
- package/ios/CodePush/SSZipArchive/aes/brg_endian.h +126 -0
- package/ios/CodePush/SSZipArchive/aes/brg_types.h +219 -0
- package/ios/CodePush/SSZipArchive/aes/entropy.c +54 -0
- package/ios/CodePush/SSZipArchive/aes/entropy.h +16 -0
- package/ios/CodePush/SSZipArchive/aes/fileenc.c +144 -0
- package/ios/CodePush/SSZipArchive/aes/fileenc.h +121 -0
- package/ios/CodePush/SSZipArchive/aes/hmac.c +145 -0
- package/ios/CodePush/SSZipArchive/aes/hmac.h +103 -0
- package/ios/CodePush/SSZipArchive/aes/prng.c +155 -0
- package/ios/CodePush/SSZipArchive/aes/prng.h +82 -0
- package/ios/CodePush/SSZipArchive/aes/pwd2key.c +103 -0
- package/ios/CodePush/SSZipArchive/aes/pwd2key.h +57 -0
- package/ios/CodePush/SSZipArchive/aes/sha1.c +258 -0
- package/ios/CodePush/SSZipArchive/aes/sha1.h +73 -0
- package/ios/CodePush/SSZipArchive/minizip/crypt.h +130 -0
- package/ios/CodePush/SSZipArchive/minizip/ioapi.c +369 -0
- package/ios/CodePush/SSZipArchive/minizip/ioapi.h +175 -0
- package/ios/CodePush/SSZipArchive/minizip/mztools.c +284 -0
- package/ios/CodePush/SSZipArchive/minizip/mztools.h +31 -0
- package/ios/CodePush/SSZipArchive/minizip/unzip.c +1839 -0
- package/ios/CodePush/SSZipArchive/minizip/unzip.h +248 -0
- package/ios/CodePush/SSZipArchive/minizip/zip.c +1910 -0
- package/ios/CodePush/SSZipArchive/minizip/zip.h +202 -0
- package/ios/CodePush.xcodeproj/project.pbxproj +937 -0
- package/ios/CodePush.xcodeproj/project.xcworkspace/contents.xcworkspacedata +7 -0
- package/ios/CodePush.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +8 -0
- package/logging.js +6 -0
- package/package-mixins.js +69 -0
- package/package.json +47 -0
- package/request-fetch-adapter.js +52 -0
- package/scripts/generateBundledResourcesHash.js +125 -0
- package/scripts/getFilesInFolder.js +19 -0
- package/scripts/postlink/android/postlink.js +87 -0
- package/scripts/postlink/ios/postlink.js +116 -0
- package/scripts/postlink/run.js +11 -0
- package/scripts/postunlink/android/postunlink.js +74 -0
- package/scripts/postunlink/ios/postunlink.js +87 -0
- package/scripts/postunlink/run.js +11 -0
- package/scripts/recordFilesBeforeBundleCommand.js +41 -0
- package/scripts/tools/linkToolsAndroid.js +57 -0
- package/scripts/tools/linkToolsIos.js +130 -0
- package/typings/react-native-code-push.d.ts +446 -0
- package/windows/CodePush/CodePush.csproj +128 -0
- package/windows/CodePush/CodePushUtils.cs +47 -0
- package/windows/CodePush/FileUtils.cs +40 -0
- package/windows/CodePush/Properties/AssemblyInfo.cs +29 -0
- package/windows/CodePush/Properties/CodePush.rd.xml +33 -0
- package/windows/CodePush/UpdateManager.cs +305 -0
- package/windows/CodePush/UpdateUtils.cs +46 -0
- package/windows/CodePush.Net46/Adapters/Http/HttpProgress.cs +28 -0
- package/windows/CodePush.Net46/Adapters/Storage/ApplicationDataContainer.cs +106 -0
- package/windows/CodePush.Net46/CodePush.Net46.csproj +103 -0
- package/windows/CodePush.Net46/CodePushUtils.cs +158 -0
- package/windows/CodePush.Net46/FileUtils.cs +55 -0
- package/windows/CodePush.Net46/Properties/AssemblyInfo.cs +36 -0
- package/windows/CodePush.Net46/UpdateManager.cs +330 -0
- package/windows/CodePush.Net46/UpdateUtils.cs +70 -0
- package/windows/CodePush.Net46/packages.config +5 -0
- package/windows/CodePush.Shared/CodePush.Shared.projitems +22 -0
- package/windows/CodePush.Shared/CodePush.Shared.shproj +13 -0
- package/windows/CodePush.Shared/CodePushConstants.cs +35 -0
- package/windows/CodePush.Shared/CodePushNativeModule.cs +329 -0
- package/windows/CodePush.Shared/CodePushReactPackage.cs +235 -0
- package/windows/CodePush.Shared/CodePushUtils.cs +70 -0
- package/windows/CodePush.Shared/InstallMode.cs +9 -0
- package/windows/CodePush.Shared/MinimumBackgroundListener.cs +44 -0
- package/windows/CodePush.Shared/SettingsManager.cs +148 -0
- package/windows/CodePush.Shared/TelemetryManager.cs +250 -0
- package/windows/CodePush.Shared/UpdateState.cs +9 -0
|
@@ -0,0 +1,284 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Additional tools for Minizip
|
|
3
|
+
Code: Xavier Roche '2004
|
|
4
|
+
License: Same as ZLIB (www.gzip.org)
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
/* Code */
|
|
8
|
+
#include <stdio.h>
|
|
9
|
+
#include <stdlib.h>
|
|
10
|
+
#include <string.h>
|
|
11
|
+
#include "zlib.h"
|
|
12
|
+
#include "unzip.h"
|
|
13
|
+
#include "mztools.h"
|
|
14
|
+
|
|
15
|
+
#define READ_8(adr) ((unsigned char)*(adr))
|
|
16
|
+
#define READ_16(adr) ( READ_8(adr) | (READ_8(adr+1) << 8) )
|
|
17
|
+
#define READ_32(adr) ( READ_16(adr) | (READ_16((adr)+2) << 16) )
|
|
18
|
+
|
|
19
|
+
#define WRITE_8(buff, n) do { \
|
|
20
|
+
*((unsigned char*)(buff)) = (unsigned char) ((n) & 0xff); \
|
|
21
|
+
} while(0)
|
|
22
|
+
#define WRITE_16(buff, n) do { \
|
|
23
|
+
WRITE_8((unsigned char*)(buff), n); \
|
|
24
|
+
WRITE_8(((unsigned char*)(buff)) + 1, (n) >> 8); \
|
|
25
|
+
} while(0)
|
|
26
|
+
#define WRITE_32(buff, n) do { \
|
|
27
|
+
WRITE_16((unsigned char*)(buff), (n) & 0xffff); \
|
|
28
|
+
WRITE_16((unsigned char*)(buff) + 2, (n) >> 16); \
|
|
29
|
+
} while(0)
|
|
30
|
+
|
|
31
|
+
extern int ZEXPORT unzRepair(file, fileOut, fileOutTmp, nRecovered, bytesRecovered)
|
|
32
|
+
const char* file;
|
|
33
|
+
const char* fileOut;
|
|
34
|
+
const char* fileOutTmp;
|
|
35
|
+
uLong* nRecovered;
|
|
36
|
+
uLong* bytesRecovered;
|
|
37
|
+
{
|
|
38
|
+
int err = Z_OK;
|
|
39
|
+
FILE* fpZip = fopen(file, "rb");
|
|
40
|
+
FILE* fpOut = fopen(fileOut, "wb");
|
|
41
|
+
FILE* fpOutCD = fopen(fileOutTmp, "wb");
|
|
42
|
+
if (fpZip != NULL && fpOut != NULL) {
|
|
43
|
+
int entries = 0;
|
|
44
|
+
uLong totalBytes = 0;
|
|
45
|
+
char header[30];
|
|
46
|
+
char filename[256];
|
|
47
|
+
char extra[1024];
|
|
48
|
+
int offset = 0;
|
|
49
|
+
int offsetCD = 0;
|
|
50
|
+
while ( fread(header, 1, 30, fpZip) == 30 ) {
|
|
51
|
+
int currentOffset = offset;
|
|
52
|
+
|
|
53
|
+
/* File entry */
|
|
54
|
+
if (READ_32(header) == 0x04034b50) {
|
|
55
|
+
unsigned int version = READ_16(header + 4);
|
|
56
|
+
unsigned int gpflag = READ_16(header + 6);
|
|
57
|
+
unsigned int method = READ_16(header + 8);
|
|
58
|
+
unsigned int filetime = READ_16(header + 10);
|
|
59
|
+
unsigned int filedate = READ_16(header + 12);
|
|
60
|
+
unsigned int crc = READ_32(header + 14); /* crc */
|
|
61
|
+
unsigned int cpsize = READ_32(header + 18); /* compressed size */
|
|
62
|
+
unsigned int uncpsize = READ_32(header + 22); /* uncompressed sz */
|
|
63
|
+
unsigned int fnsize = READ_16(header + 26); /* file name length */
|
|
64
|
+
unsigned int extsize = READ_16(header + 28); /* extra field length */
|
|
65
|
+
filename[0] = extra[0] = '\0';
|
|
66
|
+
|
|
67
|
+
/* Header */
|
|
68
|
+
if (fwrite(header, 1, 30, fpOut) == 30) {
|
|
69
|
+
offset += 30;
|
|
70
|
+
} else {
|
|
71
|
+
err = Z_ERRNO;
|
|
72
|
+
break;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/* Filename */
|
|
76
|
+
if (fnsize > 0) {
|
|
77
|
+
if (fread(filename, 1, fnsize, fpZip) == fnsize) {
|
|
78
|
+
if (fwrite(filename, 1, fnsize, fpOut) == fnsize) {
|
|
79
|
+
offset += fnsize;
|
|
80
|
+
} else {
|
|
81
|
+
err = Z_ERRNO;
|
|
82
|
+
break;
|
|
83
|
+
}
|
|
84
|
+
} else {
|
|
85
|
+
err = Z_ERRNO;
|
|
86
|
+
break;
|
|
87
|
+
}
|
|
88
|
+
} else {
|
|
89
|
+
err = Z_STREAM_ERROR;
|
|
90
|
+
break;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/* Extra field */
|
|
94
|
+
if (extsize > 0) {
|
|
95
|
+
if (fread(extra, 1, extsize, fpZip) == extsize) {
|
|
96
|
+
if (fwrite(extra, 1, extsize, fpOut) == extsize) {
|
|
97
|
+
offset += extsize;
|
|
98
|
+
} else {
|
|
99
|
+
err = Z_ERRNO;
|
|
100
|
+
break;
|
|
101
|
+
}
|
|
102
|
+
} else {
|
|
103
|
+
err = Z_ERRNO;
|
|
104
|
+
break;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/* Data */
|
|
109
|
+
{
|
|
110
|
+
int dataSize = cpsize;
|
|
111
|
+
if (dataSize == 0) {
|
|
112
|
+
dataSize = uncpsize;
|
|
113
|
+
}
|
|
114
|
+
if (dataSize > 0) {
|
|
115
|
+
char* data = malloc(dataSize);
|
|
116
|
+
if (data != NULL) {
|
|
117
|
+
if ((int)fread(data, 1, dataSize, fpZip) == dataSize) {
|
|
118
|
+
if ((int)fwrite(data, 1, dataSize, fpOut) == dataSize) {
|
|
119
|
+
offset += dataSize;
|
|
120
|
+
totalBytes += dataSize;
|
|
121
|
+
} else {
|
|
122
|
+
err = Z_ERRNO;
|
|
123
|
+
}
|
|
124
|
+
} else {
|
|
125
|
+
err = Z_ERRNO;
|
|
126
|
+
}
|
|
127
|
+
free(data);
|
|
128
|
+
if (err != Z_OK) {
|
|
129
|
+
break;
|
|
130
|
+
}
|
|
131
|
+
} else {
|
|
132
|
+
err = Z_MEM_ERROR;
|
|
133
|
+
break;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/* Central directory entry */
|
|
139
|
+
{
|
|
140
|
+
char centralDirectoryEntryHeader[46];
|
|
141
|
+
//char* comment = "";
|
|
142
|
+
//int comsize = (int) strlen(comment);
|
|
143
|
+
WRITE_32(centralDirectoryEntryHeader, 0x02014b50);
|
|
144
|
+
WRITE_16(centralDirectoryEntryHeader + 4, version);
|
|
145
|
+
WRITE_16(centralDirectoryEntryHeader + 6, version);
|
|
146
|
+
WRITE_16(centralDirectoryEntryHeader + 8, gpflag);
|
|
147
|
+
WRITE_16(centralDirectoryEntryHeader + 10, method);
|
|
148
|
+
WRITE_16(centralDirectoryEntryHeader + 12, filetime);
|
|
149
|
+
WRITE_16(centralDirectoryEntryHeader + 14, filedate);
|
|
150
|
+
WRITE_32(centralDirectoryEntryHeader + 16, crc);
|
|
151
|
+
WRITE_32(centralDirectoryEntryHeader + 20, cpsize);
|
|
152
|
+
WRITE_32(centralDirectoryEntryHeader + 24, uncpsize);
|
|
153
|
+
WRITE_16(centralDirectoryEntryHeader + 28, fnsize);
|
|
154
|
+
WRITE_16(centralDirectoryEntryHeader + 30, extsize);
|
|
155
|
+
WRITE_16(centralDirectoryEntryHeader + 32, 0 /*comsize*/);
|
|
156
|
+
WRITE_16(centralDirectoryEntryHeader + 34, 0); /* disk # */
|
|
157
|
+
WRITE_16(centralDirectoryEntryHeader + 36, 0); /* int attrb */
|
|
158
|
+
WRITE_32(centralDirectoryEntryHeader + 38, 0); /* ext attrb */
|
|
159
|
+
WRITE_32(centralDirectoryEntryHeader + 42, currentOffset);
|
|
160
|
+
/* Header */
|
|
161
|
+
if (fwrite(centralDirectoryEntryHeader, 1, 46, fpOutCD) == 46) {
|
|
162
|
+
offsetCD += 46;
|
|
163
|
+
|
|
164
|
+
/* Filename */
|
|
165
|
+
if (fnsize > 0) {
|
|
166
|
+
if (fwrite(filename, 1, fnsize, fpOutCD) == fnsize) {
|
|
167
|
+
offsetCD += fnsize;
|
|
168
|
+
} else {
|
|
169
|
+
err = Z_ERRNO;
|
|
170
|
+
break;
|
|
171
|
+
}
|
|
172
|
+
} else {
|
|
173
|
+
err = Z_STREAM_ERROR;
|
|
174
|
+
break;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/* Extra field */
|
|
178
|
+
if (extsize > 0) {
|
|
179
|
+
if (fwrite(extra, 1, extsize, fpOutCD) == extsize) {
|
|
180
|
+
offsetCD += extsize;
|
|
181
|
+
} else {
|
|
182
|
+
err = Z_ERRNO;
|
|
183
|
+
break;
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
/* Comment field */
|
|
188
|
+
/*
|
|
189
|
+
if (comsize > 0) {
|
|
190
|
+
if ((int)fwrite(comment, 1, comsize, fpOutCD) == comsize) {
|
|
191
|
+
offsetCD += comsize;
|
|
192
|
+
} else {
|
|
193
|
+
err = Z_ERRNO;
|
|
194
|
+
break;
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
*/
|
|
198
|
+
|
|
199
|
+
} else {
|
|
200
|
+
err = Z_ERRNO;
|
|
201
|
+
break;
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
/* Success */
|
|
206
|
+
entries++;
|
|
207
|
+
|
|
208
|
+
} else {
|
|
209
|
+
break;
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
/* Final central directory */
|
|
214
|
+
{
|
|
215
|
+
int entriesZip = entries;
|
|
216
|
+
char finalCentralDirectoryHeader[22];
|
|
217
|
+
//char* comment = ""; // "ZIP File recovered by zlib/minizip/mztools";
|
|
218
|
+
//int comsize = (int) strlen(comment);
|
|
219
|
+
if (entriesZip > 0xffff) {
|
|
220
|
+
entriesZip = 0xffff;
|
|
221
|
+
}
|
|
222
|
+
WRITE_32(finalCentralDirectoryHeader, 0x06054b50);
|
|
223
|
+
WRITE_16(finalCentralDirectoryHeader + 4, 0); /* disk # */
|
|
224
|
+
WRITE_16(finalCentralDirectoryHeader + 6, 0); /* disk # */
|
|
225
|
+
WRITE_16(finalCentralDirectoryHeader + 8, entriesZip); /* hack */
|
|
226
|
+
WRITE_16(finalCentralDirectoryHeader + 10, entriesZip); /* hack */
|
|
227
|
+
WRITE_32(finalCentralDirectoryHeader + 12, offsetCD); /* size of CD */
|
|
228
|
+
WRITE_32(finalCentralDirectoryHeader + 16, offset); /* offset to CD */
|
|
229
|
+
WRITE_16(finalCentralDirectoryHeader + 20, 0 /*comsize*/); /* comment */
|
|
230
|
+
|
|
231
|
+
/* Header */
|
|
232
|
+
if (fwrite(finalCentralDirectoryHeader, 1, 22, fpOutCD) == 22) {
|
|
233
|
+
|
|
234
|
+
/* Comment field */
|
|
235
|
+
/*
|
|
236
|
+
if (comsize > 0) {
|
|
237
|
+
if ((int)fwrite(comment, 1, comsize, fpOutCD) != comsize) {
|
|
238
|
+
err = Z_ERRNO;
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
*/
|
|
242
|
+
} else {
|
|
243
|
+
err = Z_ERRNO;
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
/* Final merge (file + central directory) */
|
|
248
|
+
fclose(fpOutCD);
|
|
249
|
+
if (err == Z_OK) {
|
|
250
|
+
fpOutCD = fopen(fileOutTmp, "rb");
|
|
251
|
+
if (fpOutCD != NULL) {
|
|
252
|
+
int nRead;
|
|
253
|
+
char buffer[8192];
|
|
254
|
+
while ( (nRead = (int)fread(buffer, 1, sizeof(buffer), fpOutCD)) > 0) {
|
|
255
|
+
if ((int)fwrite(buffer, 1, nRead, fpOut) != nRead) {
|
|
256
|
+
err = Z_ERRNO;
|
|
257
|
+
break;
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
fclose(fpOutCD);
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
/* Close */
|
|
265
|
+
fclose(fpZip);
|
|
266
|
+
fclose(fpOut);
|
|
267
|
+
|
|
268
|
+
/* Wipe temporary file */
|
|
269
|
+
(void)remove(fileOutTmp);
|
|
270
|
+
|
|
271
|
+
/* Number of recovered entries */
|
|
272
|
+
if (err == Z_OK) {
|
|
273
|
+
if (nRecovered != NULL) {
|
|
274
|
+
*nRecovered = entries;
|
|
275
|
+
}
|
|
276
|
+
if (bytesRecovered != NULL) {
|
|
277
|
+
*bytesRecovered = totalBytes;
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
} else {
|
|
281
|
+
err = Z_STREAM_ERROR;
|
|
282
|
+
}
|
|
283
|
+
return err;
|
|
284
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Additional tools for Minizip
|
|
3
|
+
Code: Xavier Roche '2004
|
|
4
|
+
License: Same as ZLIB (www.gzip.org)
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
#ifndef _zip_tools_H
|
|
8
|
+
#define _zip_tools_H
|
|
9
|
+
|
|
10
|
+
#ifdef __cplusplus
|
|
11
|
+
extern "C" {
|
|
12
|
+
#endif
|
|
13
|
+
|
|
14
|
+
#ifndef _ZLIB_H
|
|
15
|
+
#include "zlib.h"
|
|
16
|
+
#endif
|
|
17
|
+
|
|
18
|
+
#include "unzip.h"
|
|
19
|
+
|
|
20
|
+
/* Repair a ZIP file (missing central directory)
|
|
21
|
+
file: file to recover
|
|
22
|
+
fileOut: output file after recovery
|
|
23
|
+
fileOutTmp: temporary file name used for recovery
|
|
24
|
+
*/
|
|
25
|
+
extern int ZEXPORT unzRepair(const char* file,
|
|
26
|
+
const char* fileOut,
|
|
27
|
+
const char* fileOutTmp,
|
|
28
|
+
uLong* nRecovered,
|
|
29
|
+
uLong* bytesRecovered);
|
|
30
|
+
|
|
31
|
+
#endif
|