Android implementation

This commit is contained in:
Jonathan Carter
2016-03-12 15:15:40 -08:00
parent eee43ecc23
commit e27968e32e
3 changed files with 7 additions and 11 deletions

View File

@@ -365,7 +365,7 @@ public class CodePush {
try {
WritableMap mutableUpdatePackage = CodePushUtils.convertReadableMapToWritableMap(updatePackage);
mutableUpdatePackage.putString(BINARY_MODIFIED_TIME_KEY, "" + getBinaryResourcesModifiedTime());
codePushPackage.downloadPackage(applicationContext, mutableUpdatePackage, new DownloadProgressCallback() {
codePushPackage.downloadPackage(applicationContext, mutableUpdatePackage, CodePush.this.assetsBundleFileName, new DownloadProgressCallback() {
@Override
public void call(DownloadProgress downloadProgress) {
getReactApplicationContext()

View File

@@ -151,7 +151,7 @@ public class CodePushPackage {
}
}
public void downloadPackage(Context applicationContext, ReadableMap updatePackage,
public void downloadPackage(Context applicationContext, ReadableMap updatePackage, String expectedBundleFileName,
DownloadProgressCallback progressCallback) throws IOException {
String newUpdateHash = CodePushUtils.tryGetString(updatePackage, PACKAGE_HASH_KEY);
String newUpdateFolderPath = getPackageFolderPath(newUpdateHash);
@@ -243,7 +243,7 @@ public class CodePushPackage {
// For zip updates, we need to find the relative path to the jsBundle and save it in the
// metadata so that we can find and run it easily the next time.
String relativeBundlePath = CodePushUpdateUtils.findJSBundleInUpdateContents(newUpdateFolderPath);
String relativeBundlePath = CodePushUpdateUtils.findJSBundleInUpdateContents(newUpdateFolderPath, expectedBundleFileName);
if (relativeBundlePath == null) {
throw new CodePushInvalidUpdateException("Update is invalid - no files with extension .bundle, .js or .jsbundle were found in the update package.");

View File

@@ -79,24 +79,20 @@ public class CodePushUpdateUtils {
}
}
public static String findJSBundleInUpdateContents(String folderPath) {
public static String findJSBundleInUpdateContents(String folderPath, String expectedFileName) {
File folder = new File(folderPath);
File[] folderFiles = folder.listFiles();
for (File file : folderFiles) {
String fullFilePath = CodePushUtils.appendPathComponent(folderPath, file.getName());
if (file.isDirectory()) {
String mainBundlePathInSubFolder = findJSBundleInUpdateContents(fullFilePath);
String mainBundlePathInSubFolder = findJSBundleInUpdateContents(fullFilePath, expectedFileName);
if (mainBundlePathInSubFolder != null) {
return CodePushUtils.appendPathComponent(file.getName(), mainBundlePathInSubFolder);
}
} else {
String fileName = file.getName();
int dotIndex = fileName.lastIndexOf(".");
if (dotIndex >= 0) {
String fileExtension = fileName.substring(dotIndex + 1);
if (fileExtension.equals("bundle") || fileExtension.equals("js") || fileExtension.equals("jsbundle")) {
return fileName;
}
if (fileName.equals(expectedFileName)) {
return fileName;
}
}
}