mirror of
https://github.com/zhigang1992/react-native-code-push.git
synced 2026-06-10 07:10:36 +08:00
package->update android
This commit is contained in:
@@ -153,13 +153,13 @@ public class CodePushPackage {
|
||||
|
||||
public void downloadPackage(Context applicationContext, ReadableMap updatePackage,
|
||||
DownloadProgressCallback progressCallback) throws IOException {
|
||||
String newPackageHash = CodePushUtils.tryGetString(updatePackage, PACKAGE_HASH_KEY);
|
||||
String newPackageFolderPath = getPackageFolderPath(newPackageHash);
|
||||
String newPackageMetadataPath = CodePushUtils.appendPathComponent(newPackageFolderPath, PACKAGE_FILE_NAME);
|
||||
if (FileUtils.fileAtPathExists(newPackageFolderPath)) {
|
||||
String newUpdateHash = CodePushUtils.tryGetString(updatePackage, PACKAGE_HASH_KEY);
|
||||
String newUpdateFolderPath = getPackageFolderPath(newUpdateHash);
|
||||
String newUpdateMetadataPath = CodePushUtils.appendPathComponent(newUpdateFolderPath, PACKAGE_FILE_NAME);
|
||||
if (FileUtils.fileAtPathExists(newUpdateFolderPath)) {
|
||||
// This removes any stale data in newPackageFolderPath that could have been left
|
||||
// uncleared due to a crash or error during the download or install process.
|
||||
FileUtils.deleteDirectoryAtPath(newPackageFolderPath);
|
||||
FileUtils.deleteDirectoryAtPath(newUpdateFolderPath);
|
||||
}
|
||||
|
||||
String downloadUrlString = CodePushUtils.tryGetString(updatePackage, DOWNLOAD_URL_KEY);
|
||||
@@ -232,27 +232,27 @@ public class CodePushPackage {
|
||||
DIFF_MANIFEST_FILE_NAME);
|
||||
if (FileUtils.fileAtPathExists(diffManifestFilePath)) {
|
||||
String currentPackageFolderPath = getCurrentPackageFolderPath();
|
||||
CodePushUpdateUtils.copyNecessaryFilesFromCurrentPackage(diffManifestFilePath, currentPackageFolderPath, newPackageFolderPath);
|
||||
CodePushUpdateUtils.copyNecessaryFilesFromCurrentPackage(diffManifestFilePath, currentPackageFolderPath, newUpdateFolderPath);
|
||||
File diffManifestFile = new File(diffManifestFilePath);
|
||||
diffManifestFile.delete();
|
||||
}
|
||||
|
||||
FileUtils.copyDirectoryContents(unzippedFolderPath, newPackageFolderPath);
|
||||
FileUtils.copyDirectoryContents(unzippedFolderPath, newUpdateFolderPath);
|
||||
FileUtils.deleteFileAtPathSilently(unzippedFolderPath);
|
||||
|
||||
// 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(newPackageFolderPath);
|
||||
String relativeBundlePath = CodePushUpdateUtils.findJSBundleInUpdateContents(newUpdateFolderPath);
|
||||
|
||||
if (relativeBundlePath == null) {
|
||||
throw new CodePushInvalidUpdateException("Update is invalid - no files with extension .bundle, .js or .jsbundle were found in the update package.");
|
||||
} else {
|
||||
if (FileUtils.fileAtPathExists(newPackageMetadataPath)) {
|
||||
File metadataFileFromOldUpdate = new File(newPackageMetadataPath);
|
||||
if (FileUtils.fileAtPathExists(newUpdateMetadataPath)) {
|
||||
File metadataFileFromOldUpdate = new File(newUpdateMetadataPath);
|
||||
metadataFileFromOldUpdate.delete();
|
||||
}
|
||||
|
||||
CodePushUpdateUtils.verifyHashForZipUpdate(newPackageFolderPath, newPackageHash);
|
||||
CodePushUpdateUtils.verifyHashForZipUpdate(newUpdateFolderPath, newUpdateHash);
|
||||
|
||||
JSONObject updatePackageJSON = CodePushUtils.convertReadableToJsonObject(updatePackage);
|
||||
try {
|
||||
@@ -267,11 +267,11 @@ public class CodePushPackage {
|
||||
}
|
||||
} else {
|
||||
// File is a jsbundle, move it to a folder with the packageHash as its name
|
||||
FileUtils.moveFile(downloadFile, newPackageFolderPath, UPDATE_BUNDLE_FILE_NAME);
|
||||
FileUtils.moveFile(downloadFile, newUpdateFolderPath, UPDATE_BUNDLE_FILE_NAME);
|
||||
}
|
||||
|
||||
// Save metadata to the folder.
|
||||
CodePushUtils.writeReadableMapToFile(updatePackage, newPackageMetadataPath);
|
||||
CodePushUtils.writeReadableMapToFile(updatePackage, newUpdateMetadataPath);
|
||||
}
|
||||
|
||||
public void installPackage(ReadableMap updatePackage, boolean removePendingUpdate) throws IOException {
|
||||
|
||||
Reference in New Issue
Block a user