@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.
Files changed (191) hide show
  1. package/AlertAdapter.js +24 -0
  2. package/CONTRIBUTING.md +136 -0
  3. package/CodePush.js +666 -0
  4. package/CodePush.podspec +27 -0
  5. package/LICENSE.md +13 -0
  6. package/README.md +386 -0
  7. package/RestartManager.js +59 -0
  8. package/android/app/build.gradle +31 -0
  9. package/android/app/proguard-rules.pro +25 -0
  10. package/android/app/src/main/AndroidManifest.xml +10 -0
  11. package/android/app/src/main/java/com/microsoft/codepush/react/CodePush.java +395 -0
  12. package/android/app/src/main/java/com/microsoft/codepush/react/CodePushBuilder.java +37 -0
  13. package/android/app/src/main/java/com/microsoft/codepush/react/CodePushConstants.java +34 -0
  14. package/android/app/src/main/java/com/microsoft/codepush/react/CodePushDialog.java +102 -0
  15. package/android/app/src/main/java/com/microsoft/codepush/react/CodePushInstallMode.java +16 -0
  16. package/android/app/src/main/java/com/microsoft/codepush/react/CodePushInvalidPublicKeyException.java +12 -0
  17. package/android/app/src/main/java/com/microsoft/codepush/react/CodePushInvalidUpdateException.java +7 -0
  18. package/android/app/src/main/java/com/microsoft/codepush/react/CodePushMalformedDataException.java +12 -0
  19. package/android/app/src/main/java/com/microsoft/codepush/react/CodePushNativeModule.java +641 -0
  20. package/android/app/src/main/java/com/microsoft/codepush/react/CodePushNotInitializedException.java +12 -0
  21. package/android/app/src/main/java/com/microsoft/codepush/react/CodePushTelemetryManager.java +175 -0
  22. package/android/app/src/main/java/com/microsoft/codepush/react/CodePushUnknownException.java +12 -0
  23. package/android/app/src/main/java/com/microsoft/codepush/react/CodePushUpdateManager.java +369 -0
  24. package/android/app/src/main/java/com/microsoft/codepush/react/CodePushUpdateState.java +15 -0
  25. package/android/app/src/main/java/com/microsoft/codepush/react/CodePushUpdateUtils.java +267 -0
  26. package/android/app/src/main/java/com/microsoft/codepush/react/CodePushUtils.java +236 -0
  27. package/android/app/src/main/java/com/microsoft/codepush/react/DownloadProgress.java +30 -0
  28. package/android/app/src/main/java/com/microsoft/codepush/react/DownloadProgressCallback.java +5 -0
  29. package/android/app/src/main/java/com/microsoft/codepush/react/FileUtils.java +190 -0
  30. package/android/app/src/main/java/com/microsoft/codepush/react/ReactInstanceHolder.java +17 -0
  31. package/android/app/src/main/java/com/microsoft/codepush/react/SettingsManager.java +173 -0
  32. package/android/build.gradle +20 -0
  33. package/android/codepush.gradle +113 -0
  34. package/android/gradle/wrapper/gradle-wrapper.jar +0 -0
  35. package/android/gradle/wrapper/gradle-wrapper.properties +5 -0
  36. package/android/gradle.properties +20 -0
  37. package/android/gradlew +164 -0
  38. package/android/gradlew.bat +90 -0
  39. package/android/settings.gradle +1 -0
  40. package/docs/api-android.md +65 -0
  41. package/docs/api-ios.md +31 -0
  42. package/docs/api-js.md +592 -0
  43. package/docs/multi-deployment-testing-android.md +107 -0
  44. package/docs/multi-deployment-testing-ios.md +53 -0
  45. package/docs/setup-android.md +406 -0
  46. package/docs/setup-ios.md +229 -0
  47. package/docs/setup-windows.md +65 -0
  48. package/gulpfile.js +302 -0
  49. package/ios/CodePush/Base64/Base64/MF_Base64Additions.h +34 -0
  50. package/ios/CodePush/Base64/Base64/MF_Base64Additions.m +252 -0
  51. package/ios/CodePush/Base64/README.md +47 -0
  52. package/ios/CodePush/CodePush.h +235 -0
  53. package/ios/CodePush/CodePush.m +1041 -0
  54. package/ios/CodePush/CodePushConfig.m +116 -0
  55. package/ios/CodePush/CodePushDownloadHandler.m +130 -0
  56. package/ios/CodePush/CodePushErrorUtils.m +20 -0
  57. package/ios/CodePush/CodePushPackage.m +598 -0
  58. package/ios/CodePush/CodePushTelemetryManager.m +175 -0
  59. package/ios/CodePush/CodePushUpdateUtils.m +376 -0
  60. package/ios/CodePush/CodePushUtils.m +9 -0
  61. package/ios/CodePush/JWT/Core/Algorithms/Base/JWTAlgorithm.h +69 -0
  62. package/ios/CodePush/JWT/Core/Algorithms/Base/JWTAlgorithmFactory.h +16 -0
  63. package/ios/CodePush/JWT/Core/Algorithms/Base/JWTAlgorithmFactory.m +51 -0
  64. package/ios/CodePush/JWT/Core/Algorithms/Base/JWTAlgorithmNone.h +15 -0
  65. package/ios/CodePush/JWT/Core/Algorithms/Base/JWTAlgorithmNone.m +55 -0
  66. package/ios/CodePush/JWT/Core/Algorithms/ESFamily/JWTAlgorithmESBase.h +24 -0
  67. package/ios/CodePush/JWT/Core/Algorithms/ESFamily/JWTAlgorithmESBase.m +41 -0
  68. package/ios/CodePush/JWT/Core/Algorithms/HSFamily/JWTAlgorithmHSBase.h +28 -0
  69. package/ios/CodePush/JWT/Core/Algorithms/HSFamily/JWTAlgorithmHSBase.m +205 -0
  70. package/ios/CodePush/JWT/Core/Algorithms/Holders/JWTAlgorithmDataHolder.h +103 -0
  71. package/ios/CodePush/JWT/Core/Algorithms/Holders/JWTAlgorithmDataHolder.m +322 -0
  72. package/ios/CodePush/JWT/Core/Algorithms/Holders/JWTAlgorithmDataHolderChain.h +37 -0
  73. package/ios/CodePush/JWT/Core/Algorithms/Holders/JWTAlgorithmDataHolderChain.m +145 -0
  74. package/ios/CodePush/JWT/Core/Algorithms/RSFamily/JWTAlgorithmRSBase.h +35 -0
  75. package/ios/CodePush/JWT/Core/Algorithms/RSFamily/JWTAlgorithmRSBase.m +551 -0
  76. package/ios/CodePush/JWT/Core/Algorithms/RSFamily/JWTRSAlgorithm.h +23 -0
  77. package/ios/CodePush/JWT/Core/Algorithms/RSFamily/RSKeys/JWTCryptoKey.h +43 -0
  78. package/ios/CodePush/JWT/Core/Algorithms/RSFamily/RSKeys/JWTCryptoKey.m +230 -0
  79. package/ios/CodePush/JWT/Core/Algorithms/RSFamily/RSKeys/JWTCryptoKeyExtractor.h +31 -0
  80. package/ios/CodePush/JWT/Core/Algorithms/RSFamily/RSKeys/JWTCryptoKeyExtractor.m +113 -0
  81. package/ios/CodePush/JWT/Core/Algorithms/RSFamily/RSKeys/JWTCryptoSecurity.h +38 -0
  82. package/ios/CodePush/JWT/Core/Algorithms/RSFamily/RSKeys/JWTCryptoSecurity.m +500 -0
  83. package/ios/CodePush/JWT/Core/ClaimSet/JWTClaim.h +18 -0
  84. package/ios/CodePush/JWT/Core/ClaimSet/JWTClaim.m +214 -0
  85. package/ios/CodePush/JWT/Core/ClaimSet/JWTClaimsSet.h +23 -0
  86. package/ios/CodePush/JWT/Core/ClaimSet/JWTClaimsSet.m +29 -0
  87. package/ios/CodePush/JWT/Core/ClaimSet/JWTClaimsSetSerializer.h +19 -0
  88. package/ios/CodePush/JWT/Core/ClaimSet/JWTClaimsSetSerializer.m +68 -0
  89. package/ios/CodePush/JWT/Core/ClaimSet/JWTClaimsSetVerifier.h +18 -0
  90. package/ios/CodePush/JWT/Core/ClaimSet/JWTClaimsSetVerifier.m +72 -0
  91. package/ios/CodePush/JWT/Core/Coding/JWTCoding+ResultTypes.h +67 -0
  92. package/ios/CodePush/JWT/Core/Coding/JWTCoding+ResultTypes.m +111 -0
  93. package/ios/CodePush/JWT/Core/Coding/JWTCoding+VersionOne.h +119 -0
  94. package/ios/CodePush/JWT/Core/Coding/JWTCoding+VersionOne.m +307 -0
  95. package/ios/CodePush/JWT/Core/Coding/JWTCoding+VersionThree.h +94 -0
  96. package/ios/CodePush/JWT/Core/Coding/JWTCoding+VersionThree.m +619 -0
  97. package/ios/CodePush/JWT/Core/Coding/JWTCoding+VersionTwo.h +164 -0
  98. package/ios/CodePush/JWT/Core/Coding/JWTCoding+VersionTwo.m +514 -0
  99. package/ios/CodePush/JWT/Core/Coding/JWTCoding.h +24 -0
  100. package/ios/CodePush/JWT/Core/Coding/JWTCoding.m +11 -0
  101. package/ios/CodePush/JWT/Core/FrameworkSupplement/JWT.h +52 -0
  102. package/ios/CodePush/JWT/Core/FrameworkSupplement/Map.modulemap +5 -0
  103. package/ios/CodePush/JWT/Core/Supplement/JWTBase64Coder.h +28 -0
  104. package/ios/CodePush/JWT/Core/Supplement/JWTBase64Coder.m +70 -0
  105. package/ios/CodePush/JWT/Core/Supplement/JWTDeprecations.h +22 -0
  106. package/ios/CodePush/JWT/Core/Supplement/JWTErrorDescription.h +34 -0
  107. package/ios/CodePush/JWT/Core/Supplement/JWTErrorDescription.m +73 -0
  108. package/ios/CodePush/JWT/LICENSE +19 -0
  109. package/ios/CodePush/JWT/README.md +489 -0
  110. package/ios/CodePush/RCTConvert+CodePushInstallMode.m +20 -0
  111. package/ios/CodePush/RCTConvert+CodePushUpdateState.m +20 -0
  112. package/ios/CodePush/SSZipArchive/Common.h +81 -0
  113. package/ios/CodePush/SSZipArchive/README.md +1 -0
  114. package/ios/CodePush/SSZipArchive/SSZipArchive.h +76 -0
  115. package/ios/CodePush/SSZipArchive/SSZipArchive.m +691 -0
  116. package/ios/CodePush/SSZipArchive/aes/aes.h +198 -0
  117. package/ios/CodePush/SSZipArchive/aes/aes_via_ace.h +541 -0
  118. package/ios/CodePush/SSZipArchive/aes/aescrypt.c +294 -0
  119. package/ios/CodePush/SSZipArchive/aes/aeskey.c +548 -0
  120. package/ios/CodePush/SSZipArchive/aes/aesopt.h +739 -0
  121. package/ios/CodePush/SSZipArchive/aes/aestab.c +391 -0
  122. package/ios/CodePush/SSZipArchive/aes/aestab.h +173 -0
  123. package/ios/CodePush/SSZipArchive/aes/brg_endian.h +126 -0
  124. package/ios/CodePush/SSZipArchive/aes/brg_types.h +219 -0
  125. package/ios/CodePush/SSZipArchive/aes/entropy.c +54 -0
  126. package/ios/CodePush/SSZipArchive/aes/entropy.h +16 -0
  127. package/ios/CodePush/SSZipArchive/aes/fileenc.c +144 -0
  128. package/ios/CodePush/SSZipArchive/aes/fileenc.h +121 -0
  129. package/ios/CodePush/SSZipArchive/aes/hmac.c +145 -0
  130. package/ios/CodePush/SSZipArchive/aes/hmac.h +103 -0
  131. package/ios/CodePush/SSZipArchive/aes/prng.c +155 -0
  132. package/ios/CodePush/SSZipArchive/aes/prng.h +82 -0
  133. package/ios/CodePush/SSZipArchive/aes/pwd2key.c +103 -0
  134. package/ios/CodePush/SSZipArchive/aes/pwd2key.h +57 -0
  135. package/ios/CodePush/SSZipArchive/aes/sha1.c +258 -0
  136. package/ios/CodePush/SSZipArchive/aes/sha1.h +73 -0
  137. package/ios/CodePush/SSZipArchive/minizip/crypt.h +130 -0
  138. package/ios/CodePush/SSZipArchive/minizip/ioapi.c +369 -0
  139. package/ios/CodePush/SSZipArchive/minizip/ioapi.h +175 -0
  140. package/ios/CodePush/SSZipArchive/minizip/mztools.c +284 -0
  141. package/ios/CodePush/SSZipArchive/minizip/mztools.h +31 -0
  142. package/ios/CodePush/SSZipArchive/minizip/unzip.c +1839 -0
  143. package/ios/CodePush/SSZipArchive/minizip/unzip.h +248 -0
  144. package/ios/CodePush/SSZipArchive/minizip/zip.c +1910 -0
  145. package/ios/CodePush/SSZipArchive/minizip/zip.h +202 -0
  146. package/ios/CodePush.xcodeproj/project.pbxproj +937 -0
  147. package/ios/CodePush.xcodeproj/project.xcworkspace/contents.xcworkspacedata +7 -0
  148. package/ios/CodePush.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +8 -0
  149. package/logging.js +6 -0
  150. package/package-mixins.js +69 -0
  151. package/package.json +47 -0
  152. package/request-fetch-adapter.js +52 -0
  153. package/scripts/generateBundledResourcesHash.js +125 -0
  154. package/scripts/getFilesInFolder.js +19 -0
  155. package/scripts/postlink/android/postlink.js +87 -0
  156. package/scripts/postlink/ios/postlink.js +116 -0
  157. package/scripts/postlink/run.js +11 -0
  158. package/scripts/postunlink/android/postunlink.js +74 -0
  159. package/scripts/postunlink/ios/postunlink.js +87 -0
  160. package/scripts/postunlink/run.js +11 -0
  161. package/scripts/recordFilesBeforeBundleCommand.js +41 -0
  162. package/scripts/tools/linkToolsAndroid.js +57 -0
  163. package/scripts/tools/linkToolsIos.js +130 -0
  164. package/typings/react-native-code-push.d.ts +446 -0
  165. package/windows/CodePush/CodePush.csproj +128 -0
  166. package/windows/CodePush/CodePushUtils.cs +47 -0
  167. package/windows/CodePush/FileUtils.cs +40 -0
  168. package/windows/CodePush/Properties/AssemblyInfo.cs +29 -0
  169. package/windows/CodePush/Properties/CodePush.rd.xml +33 -0
  170. package/windows/CodePush/UpdateManager.cs +305 -0
  171. package/windows/CodePush/UpdateUtils.cs +46 -0
  172. package/windows/CodePush.Net46/Adapters/Http/HttpProgress.cs +28 -0
  173. package/windows/CodePush.Net46/Adapters/Storage/ApplicationDataContainer.cs +106 -0
  174. package/windows/CodePush.Net46/CodePush.Net46.csproj +103 -0
  175. package/windows/CodePush.Net46/CodePushUtils.cs +158 -0
  176. package/windows/CodePush.Net46/FileUtils.cs +55 -0
  177. package/windows/CodePush.Net46/Properties/AssemblyInfo.cs +36 -0
  178. package/windows/CodePush.Net46/UpdateManager.cs +330 -0
  179. package/windows/CodePush.Net46/UpdateUtils.cs +70 -0
  180. package/windows/CodePush.Net46/packages.config +5 -0
  181. package/windows/CodePush.Shared/CodePush.Shared.projitems +22 -0
  182. package/windows/CodePush.Shared/CodePush.Shared.shproj +13 -0
  183. package/windows/CodePush.Shared/CodePushConstants.cs +35 -0
  184. package/windows/CodePush.Shared/CodePushNativeModule.cs +329 -0
  185. package/windows/CodePush.Shared/CodePushReactPackage.cs +235 -0
  186. package/windows/CodePush.Shared/CodePushUtils.cs +70 -0
  187. package/windows/CodePush.Shared/InstallMode.cs +9 -0
  188. package/windows/CodePush.Shared/MinimumBackgroundListener.cs +44 -0
  189. package/windows/CodePush.Shared/SettingsManager.cs +148 -0
  190. package/windows/CodePush.Shared/TelemetryManager.cs +250 -0
  191. package/windows/CodePush.Shared/UpdateState.cs +9 -0
@@ -0,0 +1,158 @@
1
+ using Newtonsoft.Json.Linq;
2
+ using PCLStorage;
3
+ using System;
4
+ using System.Diagnostics;
5
+ using System.IO;
6
+ using System.Management;
7
+ using System.Threading.Tasks;
8
+
9
+ namespace CodePush.ReactNative
10
+ {
11
+ internal partial class CodePushUtils
12
+ {
13
+ class ApplicationInfo
14
+ {
15
+ public ApplicationInfo()
16
+ {
17
+ var info = FileVersionInfo.GetVersionInfo(Environment.GetCommandLineArgs()[0]);
18
+ Version = $"{info.FileMajorPart}.{info.FileMinorPart}.{info.FileBuildPart}";
19
+ CompanyName = string.IsNullOrEmpty(info.CompanyName) ? info.ProductName : info.CompanyName;
20
+ ProductName = info.ProductName;
21
+ }
22
+
23
+ public string Version { private set; get; }
24
+ public string CompanyName { private set; get; }
25
+ public string ProductName { private set; get; }
26
+ }
27
+
28
+ static ApplicationInfo applicationInfo = new ApplicationInfo();
29
+ static string _bundlePath;
30
+
31
+ internal static string GetFileBundlePrefix()
32
+ {
33
+ // For Windows desktop application the prefix of a bundle is the full path to the folder where
34
+ // bundle should be installed.
35
+ //
36
+ // Desktop application can be installed at any location, the most popular are:
37
+ // - User local data folder, in this case the bundle can be stored in the same location and be
38
+ // unique for the user.
39
+ // - Program Files folder, in this case the application is unique for the system and will be shared
40
+ // amoung all users of the system, the bundle should be unique for the system as well.
41
+ // Commonly, user has no write access to Program Files folder or at least admin privileges have to been requested.
42
+ // In this case the bundle will be stored in ProgramData folder as it is recommended by MS.
43
+
44
+ if (!string.IsNullOrEmpty(_bundlePath))
45
+ {
46
+ return _bundlePath;
47
+ }
48
+
49
+ _bundlePath = GetAppFolder();
50
+
51
+ if (!HasWriteAccessToFolder(_bundlePath))
52
+ {
53
+ _bundlePath = $"{Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), applicationInfo.CompanyName, applicationInfo.ProductName, applicationInfo.Version)}\\";
54
+ }
55
+
56
+ return _bundlePath;
57
+ }
58
+
59
+ internal async static Task<JObject> GetJObjectFromFileAsync(IFile file)
60
+ {
61
+ string jsonString = await file.ReadAllTextAsync().ConfigureAwait(false);
62
+ if (jsonString.Length == 0)
63
+ {
64
+ return new JObject();
65
+ }
66
+
67
+ try
68
+ {
69
+ return JObject.Parse(jsonString);
70
+ }
71
+ catch (Exception)
72
+ {
73
+ return null;
74
+ }
75
+ }
76
+
77
+ static string GetDeviceIdImpl()
78
+ {
79
+ var mbId = GetSerialNumber();
80
+ var procId = GetProcId();
81
+
82
+ if (string.IsNullOrEmpty(procId))
83
+ {
84
+ procId = GetMAC();
85
+ }
86
+
87
+ return procId + '-' + mbId;
88
+ }
89
+
90
+ static string GetSerialNumber()
91
+ {
92
+ var mos = new ManagementObjectSearcher("SELECT * FROM Win32_BaseBoard");
93
+ var moc = mos.Get();
94
+ var mbId = String.Empty;
95
+
96
+ foreach (ManagementObject mo in moc)
97
+ {
98
+ mbId = (string)mo["SerialNumber"];
99
+ if (!string.IsNullOrEmpty(mbId))
100
+ break;
101
+ }
102
+
103
+ return mbId;
104
+ }
105
+
106
+ static string GetProcId()
107
+ {
108
+ var mos = new ManagementObjectSearcher("Select * From Win32_processor");
109
+ var moc = mos.Get();
110
+ var procId = string.Empty;
111
+
112
+ foreach (ManagementObject mo in moc)
113
+ {
114
+ procId = (string)mo["ProcessorID"];
115
+ if (!string.IsNullOrEmpty(procId))
116
+ break;
117
+ }
118
+ return procId;
119
+ }
120
+
121
+ static string GetMAC()
122
+ {
123
+ var mos = new ManagementObjectSearcher("Select * From Win32_NetworkAdapterConfiguration");
124
+ var moc = mos.Get();
125
+ var mac = string.Empty;
126
+
127
+ foreach (ManagementObject mo in moc)
128
+ {
129
+ try
130
+ {
131
+ if ((bool)mo["IPEnabled"])
132
+ {
133
+ mac = (string)mo["MacAddress"];
134
+ break;
135
+ }
136
+ }
137
+ catch (Exception)
138
+ {
139
+ }
140
+ }
141
+
142
+ return mac;
143
+ }
144
+
145
+ static bool HasWriteAccessToFolder(string path)
146
+ {
147
+ try
148
+ {
149
+ File.Open(Path.Combine(path, ".security-check"), FileMode.OpenOrCreate).Close();
150
+ return true;
151
+ }
152
+ catch
153
+ {
154
+ return false;
155
+ }
156
+ }
157
+ }
158
+ }
@@ -0,0 +1,55 @@
1
+ using PCLStorage;
2
+ using System;
3
+ using System.IO;
4
+ using System.Threading.Tasks;
5
+
6
+ namespace CodePush.ReactNative
7
+ {
8
+ internal class FileUtils
9
+ {
10
+ internal async static Task MergeFoldersAsync(IFolder source, IFolder target)
11
+ {
12
+ foreach (IFile sourceFile in await source.GetFilesAsync().ConfigureAwait(false))
13
+ {
14
+ await CopyFileAsync(sourceFile.Path, Path.Combine(target.Path, sourceFile.Name)).ConfigureAwait(false);
15
+ }
16
+
17
+ foreach (IFolder sourceDirectory in await source.GetFoldersAsync().ConfigureAwait(false))
18
+ {
19
+ var nextTargetSubDir = await target.CreateFolderAsync(sourceDirectory.Name, CreationCollisionOption.OpenIfExists).ConfigureAwait(false);
20
+ await MergeFoldersAsync(sourceDirectory, nextTargetSubDir).ConfigureAwait(false);
21
+ }
22
+ }
23
+
24
+ internal async static Task ClearReactDevBundleCacheAsync()
25
+ {
26
+
27
+ if (await FileSystem.Current.LocalStorage.CheckExistsAsync(CodePushConstants.ReactDevBundleCacheFileName).ConfigureAwait(false) != ExistenceCheckResult.FileExists)
28
+ return;
29
+
30
+ var devBundleCacheFile = await FileSystem.Current.LocalStorage.GetFileAsync(CodePushConstants.ReactDevBundleCacheFileName).ConfigureAwait(false);
31
+ await devBundleCacheFile.DeleteAsync().ConfigureAwait(false);
32
+ }
33
+
34
+ internal static Task<long> GetBinaryResourcesModifiedTimeAsync(string fileName)
35
+ {
36
+ var pathToAssembly = CodePushUtils.GetAppFolder();
37
+ var pathToAssemblyResource = Path.Combine(pathToAssembly, CodePushConstants.AssetsBundlePrefix, fileName);
38
+ var lastUpdateTime = File.GetCreationTime(pathToAssemblyResource);
39
+
40
+ return Task.FromResult(new DateTimeOffset(lastUpdateTime).ToUnixTimeMilliseconds());
41
+ }
42
+
43
+ internal async static Task CopyFileAsync(string sourcePath, string destinationPath)
44
+ {
45
+ using (var source = File.Open(sourcePath, FileMode.Open, System.IO.FileAccess.Read))
46
+ {
47
+ using (var destination = File.Create(destinationPath)) // Replace if exists
48
+ {
49
+ await source.CopyToAsync(destination);
50
+ }
51
+ }
52
+ }
53
+
54
+ }
55
+ }
@@ -0,0 +1,36 @@
1
+ using System.Reflection;
2
+ using System.Runtime.CompilerServices;
3
+ using System.Runtime.InteropServices;
4
+
5
+ // General Information about an assembly is controlled through the following
6
+ // set of attributes. Change these attribute values to modify the information
7
+ // associated with an assembly.
8
+ [assembly: AssemblyTitle("CodePush.Net46")]
9
+ [assembly: AssemblyDescription("")]
10
+ [assembly: AssemblyConfiguration("")]
11
+ [assembly: AssemblyCompany("")]
12
+ [assembly: AssemblyProduct("CodePush.Net46")]
13
+ [assembly: AssemblyCopyright("Copyright © 2017")]
14
+ [assembly: AssemblyTrademark("")]
15
+ [assembly: AssemblyCulture("")]
16
+
17
+ // Setting ComVisible to false makes the types in this assembly not visible
18
+ // to COM components. If you need to access a type in this assembly from
19
+ // COM, set the ComVisible attribute to true on that type.
20
+ [assembly: ComVisible(false)]
21
+
22
+ // The following GUID is for the ID of the typelib if this project is exposed to COM
23
+ [assembly: Guid("4dfe3f9f-5e15-4f17-8fd4-33ff0519348e")]
24
+
25
+ // Version information for an assembly consists of the following four values:
26
+ //
27
+ // Major Version
28
+ // Minor Version
29
+ // Build Number
30
+ // Revision
31
+ //
32
+ // You can specify all the values or you can default the Build and Revision Numbers
33
+ // by using the '*' as shown below:
34
+ // [assembly: AssemblyVersion("1.0.*")]
35
+ [assembly: AssemblyVersion("1.0.0.0")]
36
+ [assembly: AssemblyFileVersion("1.0.0.0")]
@@ -0,0 +1,330 @@
1
+ using CodePush.Net46.Adapters.Http;
2
+ using Newtonsoft.Json;
3
+ using Newtonsoft.Json.Linq;
4
+ using PCLStorage;
5
+ using System;
6
+ using System.IO;
7
+ using System.IO.Compression;
8
+ using System.Runtime.CompilerServices;
9
+ using System.Threading.Tasks;
10
+
11
+ namespace CodePush.ReactNative
12
+ {
13
+ internal class UpdateManager
14
+ {
15
+ #region Internal methods
16
+
17
+ internal async Task ClearUpdatesAsync()
18
+ {
19
+ await (await UpdateUtils.GetCodePushFolderAsync().ConfigureAwait(false)).DeleteAsync().ConfigureAwait(false);
20
+ }
21
+
22
+ internal async Task DownloadPackageAsync(JObject updatePackage, string expectedBundleFileName, Progress<HttpProgress> downloadProgress)
23
+ {
24
+ // Using its hash, get the folder where the new update will be saved
25
+ var codePushFolder = await UpdateUtils.GetCodePushFolderAsync().ConfigureAwait(false);
26
+ var newUpdateHash = (string)updatePackage[CodePushConstants.PackageHashKey];
27
+ var newUpdateFolder = await GetPackageFolderAsync(newUpdateHash, false).ConfigureAwait(false);
28
+ if (newUpdateFolder != null)
29
+ {
30
+ // This removes any stale data in newUpdateFolder that could have been left
31
+ // uncleared due to a crash or error during the download or install process.
32
+ await newUpdateFolder.DeleteAsync().ConfigureAwait(false);
33
+ }
34
+
35
+ newUpdateFolder = await GetPackageFolderAsync(newUpdateHash, true).ConfigureAwait(false);
36
+ var newUpdateMetadataFile = await newUpdateFolder.CreateFileAsync(CodePushConstants.PackageFileName, CreationCollisionOption.ReplaceExisting).ConfigureAwait(false);
37
+ var downloadUrlString = (string)updatePackage[CodePushConstants.DownloadUrlKey];
38
+ var downloadFile = await GetDownloadFileAsync().ConfigureAwait(false);
39
+
40
+ await UpdateUtils.DownloadBundleAsync(downloadUrlString, downloadFile.Path, downloadProgress);
41
+
42
+ try
43
+ {
44
+ // Unzip the downloaded file and then delete the zip
45
+ var unzippedFolder = await CreateUnzippedFolderAsync().ConfigureAwait(false);
46
+ /**
47
+ * TODO:
48
+ * 1) ZipFile.ExtractToDirectory is not reliable and throws exception if:
49
+ * - path is too long (> 250 chars)
50
+ *
51
+ * 2) Un-zipping is quite long operation. Does it make sense for async?
52
+ * await UpdateUtils.UnzipBundleAsync(downloadFile.Path, unzippedFolder.Path);
53
+ *
54
+ * Possible implementation
55
+ *
56
+ * internal async static Task UnzipBundleAsync(string zipFileName, string targetDir)
57
+ * {
58
+ * await Task.Run(() =>
59
+ * {
60
+ * ZipFile.ExtractToDirectory(zipFileName, targetDir)
61
+ * return Task.CompletedTask;
62
+ * });
63
+ * }
64
+ */
65
+ ZipFile.ExtractToDirectory(downloadFile.Path, unzippedFolder.Path);
66
+ await downloadFile.DeleteAsync().ConfigureAwait(false);
67
+
68
+ // Merge contents with current update based on the manifest
69
+ IFile diffManifestFile = null;
70
+ try
71
+ {
72
+ diffManifestFile = await unzippedFolder.GetFileAsync(CodePushConstants.DiffManifestFileName).ConfigureAwait(false);
73
+ }
74
+ catch (FileNotFoundException)
75
+ {
76
+ //file may not be present in folder just skip it
77
+ }
78
+ if (diffManifestFile != null)
79
+ {
80
+ var currentPackageFolder = await GetCurrentPackageFolderAsync().ConfigureAwait(false);
81
+ if (currentPackageFolder == null)
82
+ {
83
+ throw new InvalidDataException("Received a diff update, but there is no current version to diff against.");
84
+ }
85
+
86
+ await UpdateUtils.CopyNecessaryFilesFromCurrentPackageAsync(diffManifestFile, currentPackageFolder, newUpdateFolder).ConfigureAwait(false);
87
+ await diffManifestFile.DeleteAsync().ConfigureAwait(false);
88
+ }
89
+
90
+ await FileUtils.MergeFoldersAsync(unzippedFolder, newUpdateFolder).ConfigureAwait(false);
91
+ await unzippedFolder.DeleteAsync().ConfigureAwait(false);
92
+
93
+ // For zip updates, we need to find the relative path to the jsBundle and save it in the
94
+ // metadata so that we can find and run it easily the next time.
95
+ var relativeBundlePath = await UpdateUtils.FindJSBundleInUpdateContentsAsync(newUpdateFolder, expectedBundleFileName).ConfigureAwait(false);
96
+ if (relativeBundlePath == null)
97
+ {
98
+ throw new InvalidDataException("Update is invalid - A JS bundle file named \"" + expectedBundleFileName + "\" could not be found within the downloaded contents. Please check that you are releasing your CodePush updates using the exact same JS bundle file name that was shipped with your app's binary.");
99
+ }
100
+ else
101
+ {
102
+ if (diffManifestFile != null)
103
+ {
104
+ // TODO verify hash for diff update
105
+ // CodePushUpdateUtils.verifyHashForDiffUpdate(newUpdateFolderPath, newUpdateHash);
106
+ }
107
+
108
+ updatePackage[CodePushConstants.RelativeBundlePathKey] = relativeBundlePath;
109
+ }
110
+ }
111
+ catch (InvalidDataException)
112
+ {
113
+ // Downloaded file is not a zip, assume it is a jsbundle
114
+ await downloadFile.RenameAsync(expectedBundleFileName).ConfigureAwait(false);
115
+ await downloadFile.MoveAsync(newUpdateFolder.Path, NameCollisionOption.ReplaceExisting).ConfigureAwait(false);
116
+ }
117
+
118
+ // Save metadata to the folder
119
+ await newUpdateMetadataFile.WriteAllTextAsync(JsonConvert.SerializeObject(updatePackage)).ConfigureAwait(false);
120
+ }
121
+
122
+ internal async Task<JObject> GetCurrentPackageAsync()
123
+ {
124
+ var packageHash = await GetCurrentPackageHashAsync().ConfigureAwait(false);
125
+ return packageHash == null ? null : await GetPackageAsync(packageHash).ConfigureAwait(false);
126
+ }
127
+
128
+ internal async Task<IFile> GetCurrentPackageBundleAsync(string bundleFileName)
129
+ {
130
+ var packageFolder = await GetCurrentPackageFolderAsync().ConfigureAwait(false);
131
+ if (packageFolder == null)
132
+ {
133
+ return null;
134
+ }
135
+
136
+ var currentPackage = await GetCurrentPackageAsync().ConfigureAwait(false);
137
+ var relativeBundlePath = (string)currentPackage[CodePushConstants.RelativeBundlePathKey];
138
+
139
+ return relativeBundlePath == null
140
+ ? await packageFolder.GetFileAsync(bundleFileName).ConfigureAwait(false)
141
+ : await packageFolder.GetFileAsync(relativeBundlePath).ConfigureAwait(false);
142
+ }
143
+
144
+ internal async Task<string> GetCurrentPackageHashAsync()
145
+ {
146
+ var info = await GetCurrentPackageInfoAsync().ConfigureAwait(false);
147
+ var currentPackageShortHash = (string)info[CodePushConstants.CurrentPackageKey];
148
+ if (currentPackageShortHash == null)
149
+ {
150
+ return null;
151
+ }
152
+
153
+ var currentPackageMetadata = await GetPackageAsync(currentPackageShortHash).ConfigureAwait(false);
154
+ return currentPackageMetadata == null ? null : (string)currentPackageMetadata[CodePushConstants.PackageHashKey];
155
+ }
156
+
157
+ internal async Task<JObject> GetPackageAsync(string packageHash)
158
+ {
159
+ var packageFolder = await GetPackageFolderAsync(packageHash, false).ConfigureAwait(false);
160
+ if (packageFolder == null)
161
+ {
162
+ return null;
163
+ }
164
+
165
+ try
166
+ {
167
+ var packageFile = await packageFolder.GetFileAsync(CodePushConstants.PackageFileName).ConfigureAwait(false);
168
+ return await CodePushUtils.GetJObjectFromFileAsync(packageFile).ConfigureAwait(false);
169
+ }
170
+ catch (IOException)
171
+ {
172
+ return null;
173
+ }
174
+ }
175
+
176
+ internal async Task<IFolder> GetPackageFolderAsync(string packageHash, bool createIfNotExists)
177
+ {
178
+ var codePushFolder = await UpdateUtils.GetCodePushFolderAsync().ConfigureAwait(false);
179
+ try
180
+ {
181
+ packageHash = ShortenPackageHash(packageHash);
182
+ return createIfNotExists
183
+ ? await codePushFolder.CreateFolderAsync(packageHash, CreationCollisionOption.OpenIfExists).ConfigureAwait(false)
184
+ : await codePushFolder.GetFolderAsync(packageHash).ConfigureAwait(false);
185
+ }
186
+ catch (FileNotFoundException)
187
+ {
188
+ return null;
189
+ }
190
+ catch (DirectoryNotFoundException)
191
+ {
192
+ return null;
193
+ }
194
+ }
195
+
196
+ internal async Task<JObject> GetPreviousPackageAsync()
197
+ {
198
+ var packageHash = await GetPreviousPackageHashAsync().ConfigureAwait(false);
199
+ return packageHash == null ? null : await GetPackageAsync(packageHash).ConfigureAwait(false);
200
+ }
201
+
202
+ internal async Task<string> GetPreviousPackageHashAsync()
203
+ {
204
+ var info = await GetCurrentPackageInfoAsync().ConfigureAwait(false);
205
+ var previousPackageShortHash = (string)info[CodePushConstants.PreviousPackageKey];
206
+ if (previousPackageShortHash == null)
207
+ {
208
+ return null;
209
+ }
210
+
211
+ var previousPackageMetadata = await GetPackageAsync(previousPackageShortHash).ConfigureAwait(false);
212
+ return previousPackageMetadata == null ? null : (string)previousPackageMetadata[CodePushConstants.PackageHashKey];
213
+ }
214
+
215
+ internal async Task InstallPackageAsync(JObject updatePackage, bool currentUpdateIsPending)
216
+ {
217
+ var packageHash = (string)updatePackage[CodePushConstants.PackageHashKey];
218
+ var info = await GetCurrentPackageInfoAsync().ConfigureAwait(false);
219
+ if (currentUpdateIsPending)
220
+ {
221
+ // Don't back up current update to the "previous" position because
222
+ // it is an unverified update which should not be rolled back to.
223
+ var currentPackageFolder = await GetCurrentPackageFolderAsync().ConfigureAwait(false);
224
+ if (currentPackageFolder != null)
225
+ {
226
+ await currentPackageFolder.DeleteAsync().ConfigureAwait(false);
227
+ }
228
+ }
229
+ else
230
+ {
231
+ var previousPackageHash = await GetPreviousPackageHashAsync().ConfigureAwait(false);
232
+ if (previousPackageHash != null && !previousPackageHash.Equals(packageHash))
233
+ {
234
+ var previousPackageFolder = await GetPackageFolderAsync(previousPackageHash, false).ConfigureAwait(false);
235
+ if (previousPackageFolder != null)
236
+ {
237
+ await previousPackageFolder.DeleteAsync().ConfigureAwait(false);
238
+ }
239
+ }
240
+
241
+ info[CodePushConstants.PreviousPackageKey] = info[CodePushConstants.CurrentPackageKey];
242
+ }
243
+
244
+ info[CodePushConstants.CurrentPackageKey] = packageHash;
245
+ await UpdateCurrentPackageInfoAsync(info).ConfigureAwait(false);
246
+ }
247
+
248
+ internal async Task RollbackPackageAsync()
249
+ {
250
+ var info = await GetCurrentPackageInfoAsync().ConfigureAwait(false);
251
+ var currentPackageFolder = await GetCurrentPackageFolderAsync().ConfigureAwait(false);
252
+ if (currentPackageFolder != null)
253
+ {
254
+ await currentPackageFolder.DeleteAsync().ConfigureAwait(false);
255
+ }
256
+
257
+ info[CodePushConstants.CurrentPackageKey] = info[CodePushConstants.PreviousPackageKey];
258
+ info[CodePushConstants.PreviousPackageKey] = null;
259
+ await UpdateCurrentPackageInfoAsync(info).ConfigureAwait(false);
260
+ }
261
+
262
+ #endregion
263
+
264
+ #region Private methods
265
+
266
+ private async Task<IFolder> GetCurrentPackageFolderAsync()
267
+ {
268
+ var info = await GetCurrentPackageInfoAsync().ConfigureAwait(false);
269
+ if (info == null)
270
+ {
271
+ return null;
272
+ }
273
+ var packageHash = (string)info[CodePushConstants.CurrentPackageKey];
274
+ return packageHash == null ? null : await GetPackageFolderAsync(packageHash, false).ConfigureAwait(false);
275
+ }
276
+
277
+ private async Task<JObject> GetCurrentPackageInfoAsync()
278
+ {
279
+ var statusFile = await GetStatusFileAsync().ConfigureAwait(false);
280
+ var info = await CodePushUtils.GetJObjectFromFileAsync(statusFile).ConfigureAwait(false);
281
+
282
+ if (info != null)
283
+ {
284
+ return info;
285
+ }
286
+
287
+ // info file has been corrupted - re-create it
288
+ await statusFile.DeleteAsync().ConfigureAwait(false);
289
+ statusFile = await GetStatusFileAsync().ConfigureAwait(false);
290
+ return await CodePushUtils.GetJObjectFromFileAsync(statusFile).ConfigureAwait(false);
291
+ }
292
+
293
+ private async Task<IFile> GetDownloadFileAsync()
294
+ {
295
+ var codePushFolder = await UpdateUtils.GetCodePushFolderAsync().ConfigureAwait(false);
296
+ return await codePushFolder.CreateFileAsync(CodePushConstants.DownloadFileName, CreationCollisionOption.OpenIfExists).ConfigureAwait(false);
297
+ }
298
+
299
+ private async Task<IFile> GetStatusFileAsync()
300
+ {
301
+ var codePushFolder = await UpdateUtils.GetCodePushFolderAsync().ConfigureAwait(false);
302
+ return await codePushFolder.CreateFileAsync(CodePushConstants.StatusFileName, CreationCollisionOption.OpenIfExists).ConfigureAwait(false);
303
+ }
304
+
305
+ private async Task<IFolder> CreateUnzippedFolderAsync()
306
+ {
307
+ var codePushFolder = await UpdateUtils.GetCodePushFolderAsync().ConfigureAwait(false);
308
+ var isUnzippedFolderExists = await codePushFolder.CheckExistsAsync(CodePushConstants.UnzippedFolderName).ConfigureAwait(false);
309
+
310
+ if (isUnzippedFolderExists != ExistenceCheckResult.NotFound)
311
+ {
312
+ await codePushFolder.GetFolderAsync(CodePushConstants.UnzippedFolderName).ContinueWith((existingFolder) => existingFolder.Result.DeleteAsync());
313
+ }
314
+
315
+ return await codePushFolder.CreateFolderAsync(CodePushConstants.UnzippedFolderName, CreationCollisionOption.OpenIfExists).ConfigureAwait(false);
316
+ }
317
+
318
+ private string ShortenPackageHash(string longPackageHash)
319
+ {
320
+ return longPackageHash.Substring(0, 8);
321
+ }
322
+
323
+ private async Task UpdateCurrentPackageInfoAsync(JObject packageInfo)
324
+ {
325
+ var file = await GetStatusFileAsync().ConfigureAwait(false);
326
+ await file.WriteAllTextAsync(JsonConvert.SerializeObject(packageInfo)).ConfigureAwait(false);
327
+ }
328
+ #endregion
329
+ }
330
+ }
@@ -0,0 +1,70 @@
1
+ using CodePush.Net46.Adapters.Http;
2
+ using Newtonsoft.Json.Linq;
3
+ using PCLStorage;
4
+ using System;
5
+ using System.IO;
6
+ using System.Net;
7
+ using System.Threading.Tasks;
8
+
9
+ namespace CodePush.ReactNative
10
+ {
11
+ internal class UpdateUtils
12
+ {
13
+ internal async static Task CopyNecessaryFilesFromCurrentPackageAsync(IFile diffManifestFile, IFolder currentPackageFolder, IFolder newPackageFolder)
14
+ {
15
+ await FileUtils.MergeFoldersAsync(currentPackageFolder, newPackageFolder).ConfigureAwait(false);
16
+ JObject diffManifest = await CodePushUtils.GetJObjectFromFileAsync(diffManifestFile).ConfigureAwait(false);
17
+ var deletedFiles = (JArray)diffManifest["deletedFiles"];
18
+ foreach (string fileNameToDelete in deletedFiles)
19
+ {
20
+ var fileToDelete = await newPackageFolder.GetFileAsync(fileNameToDelete).ConfigureAwait(false);
21
+ await fileToDelete.DeleteAsync().ConfigureAwait(false);
22
+ }
23
+ }
24
+
25
+ internal async static Task<string> FindJSBundleInUpdateContentsAsync(IFolder updateFolder, string expectedFileName)
26
+ {
27
+ foreach (IFile file in await updateFolder.GetFilesAsync().ConfigureAwait(false))
28
+ {
29
+ string fileName = file.Name;
30
+ if (fileName.Equals(expectedFileName))
31
+ {
32
+ return fileName;
33
+ }
34
+ }
35
+
36
+ foreach (IFolder folder in await updateFolder.GetFoldersAsync().ConfigureAwait(false))
37
+ {
38
+ string mainBundlePathInSubFolder = await FindJSBundleInUpdateContentsAsync(folder, expectedFileName).ConfigureAwait(false);
39
+ if (mainBundlePathInSubFolder != null)
40
+ {
41
+ return Path.Combine(folder.Name, mainBundlePathInSubFolder);
42
+ }
43
+ }
44
+
45
+ return null;
46
+ }
47
+
48
+ internal async static Task DownloadBundleAsync(string url, string fileName, IProgress<HttpProgress> downloadProgress)
49
+ {
50
+ var uri = new Uri(url);
51
+ var client = new WebClient();
52
+ client.DownloadProgressChanged += (s, e) =>
53
+ {
54
+ downloadProgress.Report(new HttpProgress
55
+ {
56
+ BytesReceived = (ulong)e.BytesReceived, //conversion long to ulong is safe
57
+ TotalBytesToReceive = (ulong)e.TotalBytesToReceive //because size can't be negative
58
+ });
59
+ };
60
+
61
+ await client.DownloadFileTaskAsync(uri, fileName);
62
+ }
63
+
64
+ internal static async Task<IFolder> GetCodePushFolderAsync()
65
+ {
66
+ var pathToCodePush = Path.Combine(CodePushUtils.GetFileBundlePrefix(), CodePushConstants.CodePushFolderPrefix);
67
+ return await FileSystem.Current.LocalStorage.CreateFolderAsync(pathToCodePush, CreationCollisionOption.OpenIfExists).ConfigureAwait(false);
68
+ }
69
+ }
70
+ }
@@ -0,0 +1,5 @@
1
+ <?xml version="1.0" encoding="utf-8"?>
2
+ <packages>
3
+ <package id="Newtonsoft.Json" version="9.0.1" targetFramework="net452" />
4
+ <package id="PCLStorage" version="1.0.2" targetFramework="net46" />
5
+ </packages>
@@ -0,0 +1,22 @@
1
+ <?xml version="1.0" encoding="utf-8"?>
2
+ <Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3
+ <PropertyGroup>
4
+ <MSBuildAllProjects>$(MSBuildAllProjects);$(MSBuildThisFileFullPath)</MSBuildAllProjects>
5
+ <HasSharedItems>true</HasSharedItems>
6
+ <SharedGUID>4ad4c826-cc26-4f1d-b60d-b97b22f52e90</SharedGUID>
7
+ </PropertyGroup>
8
+ <PropertyGroup Label="Configuration">
9
+ <Import_RootNamespace>CodePush.Shared</Import_RootNamespace>
10
+ </PropertyGroup>
11
+ <ItemGroup>
12
+ <Compile Include="$(MSBuildThisFileDirectory)CodePushConstants.cs" />
13
+ <Compile Include="$(MSBuildThisFileDirectory)CodePushNativeModule.cs" />
14
+ <Compile Include="$(MSBuildThisFileDirectory)CodePushReactPackage.cs" />
15
+ <Compile Include="$(MSBuildThisFileDirectory)CodePushUtils.cs" />
16
+ <Compile Include="$(MSBuildThisFileDirectory)InstallMode.cs" />
17
+ <Compile Include="$(MSBuildThisFileDirectory)MinimumBackgroundListener.cs" />
18
+ <Compile Include="$(MSBuildThisFileDirectory)SettingsManager.cs" />
19
+ <Compile Include="$(MSBuildThisFileDirectory)TelemetryManager.cs" />
20
+ <Compile Include="$(MSBuildThisFileDirectory)UpdateState.cs" />
21
+ </ItemGroup>
22
+ </Project>