Refactoring a bit to allow JNI cleanCache call

This commit is contained in:
Rohan Kuruvilla 2013-01-24 23:27:08 -08:00
parent 9532e5e6c7
commit 6d0d9e7375
4 changed files with 25 additions and 25 deletions

View File

@ -10,7 +10,6 @@
#define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG,LOG_TAG,__VA_ARGS__) #define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG,LOG_TAG,__VA_ARGS__)
#define SOCKET_CLASS_NAME "org/cocos2dx/cocosplayer/CocosPlayerSocket" #define SOCKET_CLASS_NAME "org/cocos2dx/cocosplayer/CocosPlayerSocket"
#define HELPER_CLASS_NAME "org/cocos2dx/cocosplayer/CCBFileUtilsHelper"
using namespace cocos2d; using namespace cocos2d;
using namespace std; using namespace std;
@ -26,7 +25,7 @@ extern "C" {
void cleanCacheDirJNI() { void cleanCacheDirJNI() {
JniMethodInfo t; JniMethodInfo t;
if (JniHelper::getStaticMethodInfo(t, HELPER_CLASS_NAME, "cleanCache", "()V")) { if (JniHelper::getStaticMethodInfo(t, SOCKET_CLASS_NAME, "cleanCache", "()V")) {
t.env->CallStaticVoidMethod(t.classID, t.methodID); t.env->CallStaticVoidMethod(t.classID, t.methodID);
t.env->DeleteLocalRef(t.classID); t.env->DeleteLocalRef(t.classID);
} }

View File

@ -151,25 +151,4 @@ public class CCBFileUtilsHelper {
return android.os.Environment.getExternalStorageDirectory(); return android.os.Environment.getExternalStorageDirectory();
} }
private static void cleanDir(File dir) {
long bytesDeleted = 0;
File[] files = dir.listFiles();
for (File file : files) {
if(file.isDirectory()) {
cleanDir(file);
continue;
}
Log.i(TAG, "Deleting file: "+file.getName());
bytesDeleted += file.length();
file.delete();
}
}
public static void cleanCache(Context cw) {
File path = new File(getBaseDirectory(cw));
cleanDir(path);
}
} }

View File

@ -39,6 +39,6 @@ public class CocosPlayer extends Cocos2dxActivity{
} }
static { static {
System.loadLibrary("cocosdragonjs"); System.loadLibrary("cocosplayer");
} }
} }

View File

@ -21,6 +21,7 @@ import java.io.OutputStream;
import java.io.InputStream; import java.io.InputStream;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.File;
import com.dd.plist.NSDictionary; import com.dd.plist.NSDictionary;
import com.dd.plist.NSData; import com.dd.plist.NSData;
@ -78,7 +79,7 @@ public class CocosPlayerSocket {
for(int i =0 ; i < keys.length; ++i ) { for(int i =0 ; i < keys.length; ++i ) {
} }
if(cmd.equalsIgnoreCase("zip")) { if(cmd.equalsIgnoreCase("zip")) {
CCBFileUtilsHelper.cleanCache(cw); cleanCache();
try { try {
Log.i(TAG, "Size of NSDATA payload: "+((NSData)data.objectForKey("data")).bytes().length); Log.i(TAG, "Size of NSDATA payload: "+((NSData)data.objectForKey("data")).bytes().length);
CCBFileUtilsHelper.unzipCCB(((NSData)data.objectForKey("data")).bytes(), cw); CCBFileUtilsHelper.unzipCCB(((NSData)data.objectForKey("data")).bytes(), cw);
@ -99,6 +100,27 @@ public class CocosPlayerSocket {
} }
} }
private static void cleanDir(File dir) {
long bytesDeleted = 0;
File[] files = dir.listFiles();
for (File file : files) {
if(file.isDirectory()) {
cleanDir(file);
continue;
}
Log.i(TAG, "Deleting file: "+file.getName());
bytesDeleted += file.length();
file.delete();
}
}
public static void cleanCache() {
File path = new File(CCBFileUtilsHelper.getBaseDirectory(cw));
cleanDir(path);
}
private void parsePayload(byte[] b) { private void parsePayload(byte[] b) {
try { try {
NSDictionary rootDict = CCBStreamHandler.parseBinaryPLIST(b); NSDictionary rootDict = CCBStreamHandler.parseBinaryPLIST(b);