Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

android add google diff-match-patch #1393

Closed
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ public void downloadPackage(JSONObject updatePackage, String expectedBundleFileN
if (isDiffUpdate) {
String currentPackageFolderPath = getCurrentPackageFolderPath();
CodePushUpdateUtils.copyNecessaryFilesFromCurrentPackage(diffManifestFilePath, currentPackageFolderPath, newUpdateFolderPath);
CodePushUpdateUtils.diffPatchApplyNecessaryFilesFromCurrentPackage(diffManifestFilePath, currentPackageFolderPath, unzippedFolderPath);
File diffManifestFile = new File(diffManifestFilePath);
diffManifestFile.delete();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,12 @@
import java.security.spec.X509EncodedKeySpec;
import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

import name.fraser.neil.plaintext.diff_match_patch;

public class CodePushUpdateUtils {

public static final String NEW_LINE = System.getProperty("line.separator");
Expand Down Expand Up @@ -113,6 +117,31 @@ public static void copyNecessaryFilesFromCurrentPackage(String diffManifestFileP
}
}

public static void diffPatchApplyNecessaryFilesFromCurrentPackage(String diffManifestFilePath, String currentPackageFolderPath, String unzippedFolderPath) throws IOException {
diff_match_patch dmp = new diff_match_patch();
JSONObject diffManifest = CodePushUtils.getJsonObjectFromFile(diffManifestFilePath);
JSONArray patchedFiles = new JSONArray();
try {
patchedFiles = diffManifest.getJSONArray("patchedFiles");
} catch (JSONException ignored) {

}
try {
for (int i = 0; i < patchedFiles.length(); i++) {
String fileNameToPatch = patchedFiles.getString(i);
File fileToPatch = new File(currentPackageFolderPath, fileNameToPatch);
File patchFile = new File(unzippedFolderPath, fileNameToPatch);
if (fileToPatch.exists() && patchFile.exists()) {
List<diff_match_patch.Patch> patches = dmp.patch_fromText(FileUtils.readFileToString(patchFile.getAbsolutePath()));
Object[] results = dmp.patch_apply((LinkedList<diff_match_patch.Patch>) patches, FileUtils.readFileToString(fileToPatch.getAbsolutePath()));
FileUtils.writeStringToFile((String) results[0], patchFile.getAbsolutePath());
}
}
} catch (JSONException e) {
throw new CodePushUnknownException("Unable to diff-patch-apply files from current package during diff update", e);
}
}

public static String findJSBundleInUpdateContents(String folderPath, String expectedFileName) {
File folder = new File(folderPath);
File[] folderFiles = folder.listFiles();
Expand Down Expand Up @@ -264,4 +293,4 @@ public static void verifyUpdateSignature(String folderPath, String packageHash,

CodePushUtils.log("The update contents succeeded the code signing check.");
}
}
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what this ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you mean just the last brace then it is mean that you added new line at the end of file. Possible it is so because your automation code-style generator added this new line.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks, it's right, i found the answer when open with sublime text2.

}
Loading