mirror of
https://github.com/zhigang1992/react-native-code-push.git
synced 2026-06-16 02:44:33 +08:00
upgrade to RN 0.19
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
package com.microsoft.codepush.react;
|
||||
|
||||
import android.app.DownloadManager;
|
||||
import android.content.Context;
|
||||
import android.net.Uri;
|
||||
|
||||
import com.facebook.react.bridge.ReadableArray;
|
||||
import com.facebook.react.bridge.ReadableMap;
|
||||
@@ -157,7 +159,6 @@ public class CodePushPackage {
|
||||
|
||||
String newPackageFolderPath = getPackageFolderPath(CodePushUtils.tryGetString(updatePackage, PACKAGE_HASH_KEY));
|
||||
String downloadUrlString = CodePushUtils.tryGetString(updatePackage, DOWNLOAD_URL_KEY);
|
||||
|
||||
URL downloadUrl = null;
|
||||
HttpURLConnection connection = null;
|
||||
BufferedInputStream bin = null;
|
||||
@@ -220,7 +221,7 @@ public class CodePushPackage {
|
||||
// Unzip the downloaded file and then delete the zip
|
||||
String unzippedFolderPath = getUnzippedFolderPath();
|
||||
FileUtils.unzipFile(downloadFile, unzippedFolderPath);
|
||||
FileUtils.deleteFileSilently(downloadFile);
|
||||
FileUtils.deleteFileOrFolderSilently(downloadFile);
|
||||
|
||||
// Merge contents with current update based on the manifest
|
||||
String diffManifestFilePath = CodePushUtils.appendPathComponent(unzippedFolderPath,
|
||||
@@ -248,13 +249,12 @@ public class CodePushPackage {
|
||||
RELATIVE_BUNDLE_PATH_KEY + " to value " + relativeBundlePath +
|
||||
" in update package.", e);
|
||||
}
|
||||
|
||||
|
||||
updatePackage = CodePushUtils.convertJsonObjectToWriteable(updatePackageJSON);
|
||||
}
|
||||
} else {
|
||||
// File is a jsBundle, move it to a folder with the packageHash as its name
|
||||
File updateBundleFile = new File(newPackageFolderPath, UPDATE_BUNDLE_FILE_NAME);
|
||||
downloadFile.renameTo(updateBundleFile);
|
||||
// File is a jsbundle, move it to a folder with the packageHash as its name
|
||||
FileUtils.moveFile(downloadFile, newPackageFolderPath, UPDATE_BUNDLE_FILE_NAME);
|
||||
}
|
||||
|
||||
// Save metadata to the folder.
|
||||
|
||||
@@ -15,7 +15,7 @@ public class CodePushUpdateUtils {
|
||||
for (int i = 0; i < deletedFiles.size(); i++) {
|
||||
String fileNameToDelete = deletedFiles.getString(i);
|
||||
File fileToDelete = new File(newPackageFolderPath, fileNameToDelete);
|
||||
FileUtils.deleteFileSilently(fileToDelete);
|
||||
FileUtils.deleteFileOrFolderSilently(fileToDelete);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@ import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.PrintWriter;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipFile;
|
||||
import java.util.zip.ZipInputStream;
|
||||
|
||||
public class FileUtils {
|
||||
@@ -81,10 +82,23 @@ public class FileUtils {
|
||||
}
|
||||
|
||||
public static void deleteFileAtPathSilently(String path) {
|
||||
deleteFileSilently(new File(path));
|
||||
deleteFileOrFolderSilently(new File(path));
|
||||
}
|
||||
|
||||
public static void deleteFileSilently(File file) {
|
||||
public static void deleteFileOrFolderSilently(File file) {
|
||||
if (file.isDirectory()) {
|
||||
File[] files = file.listFiles();
|
||||
for (int i = 0; i < files.length; i++) {
|
||||
if (files[i].isDirectory()) {
|
||||
deleteFileOrFolderSilently(files[i]);
|
||||
} else {
|
||||
if (!file.delete()) {
|
||||
files[i].delete();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!file.delete()) {
|
||||
CodePushUtils.log("Error deleting file " + file.getName());
|
||||
}
|
||||
@@ -94,6 +108,19 @@ public class FileUtils {
|
||||
return new File(filePath).exists();
|
||||
}
|
||||
|
||||
public static void moveFile(File fileToMove, String newFolderPath, String newFileName) {
|
||||
File newFolder = new File(newFolderPath);
|
||||
if (!newFolder.exists()) {
|
||||
newFolder.mkdirs();
|
||||
}
|
||||
|
||||
File newFilePath = new File(newFolderPath, newFileName);
|
||||
if (!fileToMove.renameTo(newFilePath)) {
|
||||
throw new CodePushUnknownException("Unable to move file from " +
|
||||
fileToMove.getAbsolutePath() + " to " + newFilePath.getAbsolutePath() + ".");
|
||||
}
|
||||
}
|
||||
|
||||
public static String readFileToString(String filePath) throws IOException {
|
||||
FileInputStream fin = null;
|
||||
BufferedReader reader = null;
|
||||
|
||||
Reference in New Issue
Block a user