1
0
mirror of https://gitcode.com/gh_mirrors/re/react-native-pushy.git synced 2025-09-18 01:36:11 +08:00
Code Issues Packages Projects Releases Wiki Activity GitHub Gitee
This commit is contained in:
tdzl2003
2016-04-05 15:36:05 +08:00
parent 67ed31fe98
commit 1c9fd7dd98
6 changed files with 45 additions and 13 deletions

View File

@@ -4,6 +4,7 @@ import android.content.Context;
import android.os.AsyncTask;
import android.util.Log;
import com.facebook.stetho.inspector.elements.ShadowDocument;
import com.squareup.okhttp.OkHttpClient;
import com.squareup.okhttp.Request;
import com.squareup.okhttp.Response;
@@ -46,7 +47,7 @@ class DownloadTask extends AsyncTask<DownloadTaskParams, Void, Void> {
System.loadLibrary("rnupdate");
}
private void removeDirectory(File file) {
private void removeDirectory(File file) throws IOException {
if (UpdateContext.DEBUG) {
Log.d("RNUpdate", "Removing " + file);
}
@@ -60,7 +61,9 @@ class DownloadTask extends AsyncTask<DownloadTaskParams, Void, Void> {
removeDirectory(f);
}
}
file.delete();
if (!file.delete()) {
throw new IOException("Failed to delete directory");
}
}
private void downloadFile(String url, File writePath) throws IOException {
@@ -389,8 +392,24 @@ class DownloadTask extends AsyncTask<DownloadTaskParams, Void, Void> {
Log.d("RNUpdate", "Unzip finished");
}
}
private void doCleanUp(DownloadTaskParams param) {
private void doCleanUp(DownloadTaskParams param) throws IOException {
if (UpdateContext.DEBUG) {
Log.d("RNUpdate", "Start cleaning up");
}
File root = param.unzipDirectory;
for (File sub : root.listFiles()) {
if (sub.getName().charAt(0) == '.') {
continue;
}
if (sub.isFile()) {
sub.delete();
} else {
if (sub.getName().equals(param.hash) || sub.getName().equals(param.originHash)) {
continue;
}
removeDirectory(sub);
}
}
}
@Override

View File

@@ -178,7 +178,8 @@ public class UpdateContext {
DownloadTaskParams params = new DownloadTaskParams();
params.type = DownloadTaskParams.TASK_TYPE_CLEARUP;
params.hash = sp.getString("currentVersion", null);
params.originHash = sp.getString("lastVersion", null);;
params.originHash = sp.getString("lastVersion", null);
params.unzipDirectory = rootDir;
params.listener = new DownloadFileListener() {
@Override
public void onDownloadCompleted() {