From 718d2c690b4e43a7aac4f9e266fd6a53c866b788 Mon Sep 17 00:00:00 2001 From: Wenhai Lin Date: Mon, 18 Jan 2016 17:58:04 +0800 Subject: [PATCH] Remove CocosPlayClient --- cocos/audio/android/AudioEngine-inl.cpp | 3 - cocos/platform/android/Android.mk | 3 +- .../platform/android/CCFileUtils-android.cpp | 34 +- .../cocosplay/client/CocosPlayClient.java | 59 --- .../org/cocos2dx/lib/Cocos2dxActivity.java | 3 - .../src/org/cocos2dx/lib/Cocos2dxHelper.java | 8 +- .../src/org/cocos2dx/lib/Cocos2dxMusic.java | 6 - .../src/org/cocos2dx/lib/Cocos2dxSound.java | 6 - .../org/cocos2dx/lib/Cocos2dxVideoView.java | 6 - .../cocos2dx/lib/Cocos2dxWebViewHelper.java | 6 - .../platform/android/jni/CocosPlayClient.cpp | 423 ------------------ cocos/platform/android/jni/CocosPlayClient.h | 86 ---- 12 files changed, 4 insertions(+), 639 deletions(-) delete mode 100644 cocos/platform/android/java/src/com/chukong/cocosplay/client/CocosPlayClient.java delete mode 100644 cocos/platform/android/jni/CocosPlayClient.cpp delete mode 100644 cocos/platform/android/jni/CocosPlayClient.h diff --git a/cocos/audio/android/AudioEngine-inl.cpp b/cocos/audio/android/AudioEngine-inl.cpp index e41782eb35..18a391f179 100644 --- a/cocos/audio/android/AudioEngine-inl.cpp +++ b/cocos/audio/android/AudioEngine-inl.cpp @@ -38,7 +38,6 @@ #include "base/CCDirector.h" #include "base/CCScheduler.h" #include "platform/android/CCFileUtils-android.h" -#include "platform/android/jni/CocosPlayClient.h" using namespace cocos2d; using namespace cocos2d::experimental; @@ -249,14 +248,12 @@ int AudioEngineImpl::play2d(const std::string &filePath ,bool loop ,float volume auto& player = _audioPlayers[currentAudioID]; auto fullPath = FileUtils::getInstance()->fullPathForFilename(filePath); - cocosplay::updateAssets(fullPath); auto initPlayer = player.init(_engineEngine, _outputMixObject, fullPath, volume, loop); if (!initPlayer){ _audioPlayers.erase(currentAudioID); log("%s,%d message:create player for %s fail", __func__, __LINE__, filePath.c_str()); break; } - cocosplay::notifyFileLoaded(fullPath); audioId = currentAudioID++; player._audioID = audioId; diff --git a/cocos/platform/android/Android.mk b/cocos/platform/android/Android.mk index 5e36900388..a7a816f888 100644 --- a/cocos/platform/android/Android.mk +++ b/cocos/platform/android/Android.mk @@ -19,8 +19,7 @@ jni/Java_org_cocos2dx_lib_Cocos2dxBitmap.cpp \ jni/Java_org_cocos2dx_lib_Cocos2dxHelper.cpp \ jni/Java_org_cocos2dx_lib_Cocos2dxRenderer.cpp \ jni/JniHelper.cpp \ -jni/TouchesJni.cpp \ -jni/CocosPlayClient.cpp +jni/TouchesJni.cpp LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH) diff --git a/cocos/platform/android/CCFileUtils-android.cpp b/cocos/platform/android/CCFileUtils-android.cpp index 9c3a1b2050..bf055f97dd 100644 --- a/cocos/platform/android/CCFileUtils-android.cpp +++ b/cocos/platform/android/CCFileUtils-android.cpp @@ -29,7 +29,6 @@ THE SOFTWARE. #include "CCFileUtils-android.h" #include "platform/CCCommon.h" #include "platform/android/jni/JniHelper.h" -#include "platform/android/jni/CocosPlayClient.h" #include "android/asset_manager.h" #include "android/asset_manager_jni.h" #include @@ -78,15 +77,7 @@ FileUtilsAndroid::~FileUtilsAndroid() bool FileUtilsAndroid::init() { - cocosplay::lazyInit(); - if (cocosplay::isEnabled() && !cocosplay::isDemo()) - { - _defaultResRootPath = cocosplay::getGameRoot(); - } - else - { - _defaultResRootPath = "assets/"; - } + _defaultResRootPath = "assets/"; return FileUtils::init(); } @@ -150,11 +141,6 @@ bool FileUtilsAndroid::isFileExistInternal(const std::string& strFilePath) const return false; } - if (cocosplay::isEnabled() && !cocosplay::isDemo()) - { - return cocosplay::fileExists(strFilePath); - } - bool bFound = false; // Check whether file exists in apk. @@ -200,16 +186,6 @@ bool FileUtilsAndroid::isDirectoryExistInternal(const std::string& dirPath) cons int lenOfAssets = 7; std::string tmpStr; - if (cocosplay::isEnabled() && !cocosplay::isDemo()) - { - // redirect assets/*** path to cocosplay resource dir - tmpStr.append(_defaultResRootPath); - if ('/' != tmpStr[tmpStr.length() - 1]) - { - tmpStr += '/'; - } - tmpStr.append(s + lenOfAssets); - } // find absolute path in flash memory if (s[0] == '/') @@ -264,7 +240,6 @@ Data FileUtilsAndroid::getData(const std::string& filename, bool forString) unsigned char* data = nullptr; ssize_t size = 0; string fullPath = fullPathForFilename(filename); - cocosplay::updateAssets(fullPath); if (fullPath[0] != '/') { @@ -356,7 +331,6 @@ Data FileUtilsAndroid::getData(const std::string& filename, bool forString) else { ret.fastSet(data, size); - cocosplay::notifyFileLoaded(fullPath); } return ret; @@ -387,7 +361,6 @@ unsigned char* FileUtilsAndroid::getFileData(const std::string& filename, const } string fullPath = fullPathForFilename(filename); - cocosplay::updateAssets(fullPath); if (fullPath[0] != '/') { @@ -459,10 +432,7 @@ unsigned char* FileUtilsAndroid::getFileData(const std::string& filename, const msg.append(filename).append(") failed!"); CCLOG("%s", msg.c_str()); } - else - { - cocosplay::notifyFileLoaded(fullPath); - } + return data; } diff --git a/cocos/platform/android/java/src/com/chukong/cocosplay/client/CocosPlayClient.java b/cocos/platform/android/java/src/com/chukong/cocosplay/client/CocosPlayClient.java deleted file mode 100644 index 06a869034c..0000000000 --- a/cocos/platform/android/java/src/com/chukong/cocosplay/client/CocosPlayClient.java +++ /dev/null @@ -1,59 +0,0 @@ -/**************************************************************************** -Copyright (c) 2015 Chukong Technologies Inc. - -http://www.cocos2d-x.org - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. - ****************************************************************************/ -package com.chukong.cocosplay.client; - -import android.app.Activity; - -public class CocosPlayClient { - - public static boolean init(Activity activity, boolean isDemo) { - return false; - } - - public static boolean isEnabled() { - return false; - } - - public static boolean isDemo() { - return false; - } - - public static boolean isNotifyFileLoadedEnabled() { - return false; - } - - public static void notifyFileLoaded(String filePath) { - - } - - public static void updateAssets(String filePath) { - - } - - public static String getGameRoot() { - return ""; - } - - public static native String[] getSearchPaths(); -} diff --git a/cocos/platform/android/java/src/org/cocos2dx/lib/Cocos2dxActivity.java b/cocos/platform/android/java/src/org/cocos2dx/lib/Cocos2dxActivity.java index 851e1b4bfe..75b4f95e21 100644 --- a/cocos/platform/android/java/src/org/cocos2dx/lib/Cocos2dxActivity.java +++ b/cocos/platform/android/java/src/org/cocos2dx/lib/Cocos2dxActivity.java @@ -42,8 +42,6 @@ import android.view.Window; import android.view.WindowManager; import android.widget.FrameLayout; -import com.chukong.cocosplay.client.CocosPlayClient; - import org.cocos2dx.lib.Cocos2dxHelper.Cocos2dxHelperListener; import javax.microedition.khronos.egl.EGL10; @@ -258,7 +256,6 @@ public abstract class Cocos2dxActivity extends Activity implements Cocos2dxHelpe @Override protected void onCreate(final Bundle savedInstanceState) { super.onCreate(savedInstanceState); - CocosPlayClient.init(this, false); onLoadNativeLibraries(); diff --git a/cocos/platform/android/java/src/org/cocos2dx/lib/Cocos2dxHelper.java b/cocos/platform/android/java/src/org/cocos2dx/lib/Cocos2dxHelper.java index 282382da6f..9cd24e82f9 100644 --- a/cocos/platform/android/java/src/org/cocos2dx/lib/Cocos2dxHelper.java +++ b/cocos/platform/android/java/src/org/cocos2dx/lib/Cocos2dxHelper.java @@ -41,7 +41,6 @@ import android.util.DisplayMetrics; import android.view.Display; import android.view.WindowManager; -import com.chukong.cocosplay.client.CocosPlayClient; import com.enhance.gameservice.IGameTuningService; import java.io.UnsupportedEncodingException; @@ -94,12 +93,7 @@ public class Cocos2dxHelper { final ApplicationInfo applicationInfo = activity.getApplicationInfo(); Cocos2dxHelper.sPackageName = applicationInfo.packageName; - if (CocosPlayClient.isEnabled() && !CocosPlayClient.isDemo()) { - Cocos2dxHelper.sFileDirectory = CocosPlayClient.getGameRoot(); - } - else { - Cocos2dxHelper.sFileDirectory = activity.getFilesDir().getAbsolutePath(); - } + Cocos2dxHelper.sFileDirectory = activity.getFilesDir().getAbsolutePath(); Cocos2dxHelper.nativeSetApkPath(applicationInfo.sourceDir); diff --git a/cocos/platform/android/java/src/org/cocos2dx/lib/Cocos2dxMusic.java b/cocos/platform/android/java/src/org/cocos2dx/lib/Cocos2dxMusic.java index e9bae8458e..0e9f2e499f 100644 --- a/cocos/platform/android/java/src/org/cocos2dx/lib/Cocos2dxMusic.java +++ b/cocos/platform/android/java/src/org/cocos2dx/lib/Cocos2dxMusic.java @@ -30,8 +30,6 @@ import android.content.res.AssetFileDescriptor; import android.media.MediaPlayer; import android.util.Log; -import com.chukong.cocosplay.client.CocosPlayClient; - import java.io.FileInputStream; public class Cocos2dxMusic { @@ -247,10 +245,6 @@ public class Cocos2dxMusic { MediaPlayer mediaPlayer = new MediaPlayer(); try { - if (CocosPlayClient.isEnabled() && !CocosPlayClient.isDemo()) { - CocosPlayClient.updateAssets(path); - } - CocosPlayClient.notifyFileLoaded(path); if (path.startsWith("/")) { final FileInputStream fis = new FileInputStream(path); mediaPlayer.setDataSource(fis.getFD()); diff --git a/cocos/platform/android/java/src/org/cocos2dx/lib/Cocos2dxSound.java b/cocos/platform/android/java/src/org/cocos2dx/lib/Cocos2dxSound.java index 688de896fb..a54317020d 100644 --- a/cocos/platform/android/java/src/org/cocos2dx/lib/Cocos2dxSound.java +++ b/cocos/platform/android/java/src/org/cocos2dx/lib/Cocos2dxSound.java @@ -29,8 +29,6 @@ import android.media.AudioManager; import android.media.SoundPool; import android.util.Log; -import com.chukong.cocosplay.client.CocosPlayClient; - import java.util.ArrayList; import java.util.HashMap; import java.util.Iterator; @@ -98,10 +96,6 @@ public class Cocos2dxSound { } public int preloadEffect(final String path) { - if (CocosPlayClient.isEnabled() && !CocosPlayClient.isDemo()) { - CocosPlayClient.updateAssets(path); - } - CocosPlayClient.notifyFileLoaded(path); Integer soundID = this.mPathSoundIDMap.get(path); if (soundID == null) { diff --git a/cocos/platform/android/java/src/org/cocos2dx/lib/Cocos2dxVideoView.java b/cocos/platform/android/java/src/org/cocos2dx/lib/Cocos2dxVideoView.java index 04e7d7c6b8..b4a2e7848c 100644 --- a/cocos/platform/android/java/src/org/cocos2dx/lib/Cocos2dxVideoView.java +++ b/cocos/platform/android/java/src/org/cocos2dx/lib/Cocos2dxVideoView.java @@ -34,8 +34,6 @@ import android.view.SurfaceView; import android.widget.FrameLayout; import android.widget.MediaController.MediaPlayerControl; -import com.chukong.cocosplay.client.CocosPlayClient; - import java.io.IOException; import java.util.Map; @@ -219,10 +217,6 @@ public class Cocos2dxVideoView extends SurfaceView implements MediaPlayerControl if (path.startsWith(AssetResourceRoot)) { path = path.substring(AssetResourceRoot.length()); } - if (CocosPlayClient.isEnabled() && !CocosPlayClient.isDemo()) { - CocosPlayClient.updateAssets(path); - } - CocosPlayClient.notifyFileLoaded(path); if (path.startsWith("/")) { mIsAssetRouse = false; setVideoURI(Uri.parse(path),null); diff --git a/cocos/platform/android/java/src/org/cocos2dx/lib/Cocos2dxWebViewHelper.java b/cocos/platform/android/java/src/org/cocos2dx/lib/Cocos2dxWebViewHelper.java index 1b11c9a879..0d036215a9 100755 --- a/cocos/platform/android/java/src/org/cocos2dx/lib/Cocos2dxWebViewHelper.java +++ b/cocos/platform/android/java/src/org/cocos2dx/lib/Cocos2dxWebViewHelper.java @@ -6,8 +6,6 @@ import android.util.SparseArray; import android.view.View; import android.widget.FrameLayout; -import com.chukong.cocosplay.client.CocosPlayClient; - import java.util.concurrent.Callable; import java.util.concurrent.ExecutionException; import java.util.concurrent.FutureTask; @@ -157,10 +155,6 @@ public class Cocos2dxWebViewHelper { } public static void loadFile(final int index, final String filePath) { - if (CocosPlayClient.isEnabled() && !CocosPlayClient.isDemo()) { - CocosPlayClient.updateAssets(filePath); - } - CocosPlayClient.notifyFileLoaded(filePath); sCocos2dxActivity.runOnUiThread(new Runnable() { @Override public void run() { diff --git a/cocos/platform/android/jni/CocosPlayClient.cpp b/cocos/platform/android/jni/CocosPlayClient.cpp deleted file mode 100644 index 13ecdf03bd..0000000000 --- a/cocos/platform/android/jni/CocosPlayClient.cpp +++ /dev/null @@ -1,423 +0,0 @@ -/**************************************************************************** -Copyright (c) 2015 Chukong Technologies Inc. - -http://www.cocos2d-x.org - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. -****************************************************************************/ -#include "CocosPlayClient.h" -#include -#include -#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) -#include "jni/JniHelper.h" -#include "platform/CCCommon.h" -#include "platform/CCFileUtils.h" - -using namespace cocos2d; - -#define LOG_TAG "CocosPlayClient.cpp" -#if COCOS2D_DEBUG -#define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG,LOG_TAG,__VA_ARGS__) -#define LOGW(...) __android_log_print(ANDROID_LOG_WARN,LOG_TAG,__VA_ARGS__) -#define LOGE(...) __android_log_print(ANDROID_LOG_ERROR,LOG_TAG,__VA_ARGS__) -#else -#define LOGD(...) -#define LOGW(...) -#define LOGE(...) -#endif - -static std::string __gameRootPath; -static std::unordered_map __fileExistsCaches; -static bool __isCocosPlayInited = false; -static bool __isCocosPlayEnabled = false; -static bool __isDemo = false; -static bool __isNotifyFileLoadedEnabled = false; -static jobject __classLoader; -static jmethodID __findClassMethod; -static pthread_key_t __threadKey; - - -#define COCOSPLAYCLIENT_CLASS_NAME "com/chukong/cocosplay/client/CocosPlayClient" - -extern "C" { - jobjectArray Java_com_chukong_cocosplay_client_CocosPlayClient_getSearchPaths(JNIEnv* env, jobject thiz) - { - auto stringClass = env->FindClass("java/lang/String"); - auto& paths = cocos2d::FileUtils::getInstance()->getSearchPaths(); - auto count = paths.size(); - auto pathArray = env->NewObjectArray(count, stringClass, 0); - for (int i = 0; i < count; ++i) - { - env->SetObjectArrayElement(pathArray, i, env->NewStringUTF(paths[i].c_str())); - } - - return pathArray; - } -} - -namespace cocosplay { - -static void detachCurrentThread(void *env) { - JniHelper::getJavaVM()->DetachCurrentThread(); -} - -static bool getEnv(JNIEnv **env) -{ - bool bRet = false; - - switch(JniHelper::getJavaVM()->GetEnv((void**)env, JNI_VERSION_1_4)) - { - case JNI_OK: - bRet = true; - break; - case JNI_EDETACHED: - pthread_key_create (&__threadKey, detachCurrentThread); - if (JniHelper::getJavaVM()->AttachCurrentThread(env, 0) < 0) - { - LOGD("%s", "Failed to get the environment using AttachCurrentThread()"); - break; - } - if (pthread_getspecific(__threadKey) == NULL) { - pthread_setspecific(__threadKey, env); - } - bRet = true; - break; - default: - LOGE("%s", "Failed to get the environment using GetEnv()"); - break; - } - - return bRet; -} - -static void initClassLoaderForMultiThread() -{ - JNIEnv *env = 0; - do - { - if (! getEnv(&env)) - { - break; - } - jclass cocos2dClass = env->FindClass(COCOSPLAYCLIENT_CLASS_NAME); - if(env->ExceptionCheck()) - { - env->ExceptionDescribe(); - env->ExceptionClear(); - LOGW("Exception initClassLoaderForMultiThread cocos2dClass is exception"); - break; - } - - jclass classClass = env->GetObjectClass(cocos2dClass); - if(env->ExceptionCheck()) - { - env->ExceptionDescribe(); - env->ExceptionClear(); - LOGW("Exception initClassLoaderForMultiThread classClass is exception"); - break; - } - - jclass classLoaderClass = env->FindClass("java/lang/ClassLoader"); - if(env->ExceptionCheck()) - { - env->ExceptionDescribe(); - env->ExceptionClear(); - LOGW("Exception initClassLoaderForMultiThread classLoaderClass"); - break; - } - - jmethodID getClassLoaderMethod = env->GetMethodID(classClass,"getClassLoader","()Ljava/lang/ClassLoader;"); - jobject classLoader = env->CallObjectMethod(cocos2dClass, getClassLoaderMethod); - if(env->ExceptionCheck()) - { - env->ExceptionDescribe(); - env->ExceptionClear(); - LOGW("Exception initClassLoaderForMultiThread classLoader"); - break; - } - __classLoader = env->NewGlobalRef(classLoader); - jmethodID findClassMethod = env->GetMethodID(classLoaderClass, "findClass", "(Ljava/lang/String;)Ljava/lang/Class;"); - __findClassMethod = findClassMethod; - - if(env->ExceptionCheck()) - { - env->ExceptionDescribe(); - env->ExceptionClear(); - __findClassMethod = NULL; - __classLoader = NULL; - LOGW("Exception initClassLoaderForMultiThread findClassMethod"); - break; - } - }while(0); -} - -static jclass getClassID_(const char *className, JNIEnv *env) -{ - JNIEnv *pEnv = env; - jclass ret = 0; - - do - { - if (! pEnv) - { - if (! getEnv(&pEnv)) - { - break; - } - } - - ret = pEnv->FindClass(className); - if (! ret) - { - if(__classLoader) - { - pEnv->ExceptionClear(); - jstring jstrName = (pEnv)->NewStringUTF(className); - ret = (jclass)pEnv->CallObjectMethod(__classLoader, __findClassMethod, jstrName); - pEnv->DeleteLocalRef(jstrName); - if(ret) break; - } - - LOGE("Failed to find class of %s", className); - break; - } - } while (0); - - return ret; -} - -static bool getStaticMethodInfo(cocos2d::JniMethodInfo &methodinfo, const char *className, const char *methodName, const char *paramCode) -{ - jmethodID methodID = 0; - JNIEnv *pEnv = 0; - bool bRet = false; - - do - { - if (! getEnv(&pEnv)) - { - break; - } - - jclass classID = getClassID_(className, pEnv); - if(!classID) break; - - methodID = pEnv->GetStaticMethodID(classID, methodName, paramCode); - if (! methodID) - { - LOGW("Failed to find static method id of %s", methodName); - break; - } - - methodinfo.classID = classID; - methodinfo.env = pEnv; - methodinfo.methodID = methodID; - - bRet = true; - } while (0); - - return bRet; -} - -void lazyInit() -{ - if (__isCocosPlayInited) - return; - - JniMethodInfo t; - if (JniHelper::getStaticMethodInfo(t, COCOSPLAYCLIENT_CLASS_NAME, "isEnabled", "()Z")) - { - __isCocosPlayEnabled = t.env->CallStaticBooleanMethod(t.classID, t.methodID); - t.env->DeleteLocalRef(t.classID); - LOGD("isEnabled = %d", __isCocosPlayEnabled); - } - - if (JniHelper::getStaticMethodInfo(t, COCOSPLAYCLIENT_CLASS_NAME, "isDemo", "()Z")) - { - __isDemo = t.env->CallStaticBooleanMethod(t.classID, t.methodID); - t.env->DeleteLocalRef(t.classID); - LOGD("isDemo = %d",__isDemo); - } - - if (JniHelper::getStaticMethodInfo(t, COCOSPLAYCLIENT_CLASS_NAME, "isNotifyFileLoadedEnabled", "()Z")) - { - __isNotifyFileLoadedEnabled = t.env->CallStaticBooleanMethod(t.classID, t.methodID); - t.env->DeleteLocalRef(t.classID); - LOGD("isNotifyFileLoadedEnabled = %d", __isNotifyFileLoadedEnabled); - } - - if (__isCocosPlayEnabled) - { - initClassLoaderForMultiThread(); - } - - __isCocosPlayInited = true; -} - -bool isEnabled() -{ - return __isCocosPlayEnabled; -} - -bool isDemo() -{ - return __isDemo; -} - -void updateAssets(const std::string& filePath) -{ - if (!__isCocosPlayInited) - { - lazyInit(); - } - - if (!__isCocosPlayEnabled || __isDemo) - { - return; - } - - if (!fileExists(filePath)) - { - LOGD("file ( %s ) doesn't exist, updateAssets cancelled", filePath.c_str()); - return; - } - - JniMethodInfo t; - if (getStaticMethodInfo(t, COCOSPLAYCLIENT_CLASS_NAME, "updateAssets", "(Ljava/lang/String;)V")) - { - jstring stringArg = t.env->NewStringUTF(filePath.c_str()); - t.env->CallStaticVoidMethod(t.classID, t.methodID, stringArg); - t.env->DeleteLocalRef(stringArg); - t.env->DeleteLocalRef(t.classID); - } - - LOGD("updateAssets (%s) OK!", filePath.c_str()); -} - -bool fileExists(const std::string& filePath) -{ - auto iter = __fileExistsCaches.find(filePath); - if (iter != __fileExistsCaches.end()) - { - LOGD("Return file path ( %s ) in cache!", filePath.c_str()); - if(!iter->second) - { - auto fp = fopen(filePath.c_str(), "r"); - if (fp) - { - iter->second = true; - fclose(fp); - } - } - return iter->second; - } - - bool ret = false; - JniMethodInfo t; - if (getStaticMethodInfo(t, COCOSPLAYCLIENT_CLASS_NAME, "fileExists", "(Ljava/lang/String;)Z")) - { - jstring stringArg = t.env->NewStringUTF(filePath.c_str()); - ret = t.env->CallStaticBooleanMethod(t.classID, t.methodID, stringArg); - t.env->DeleteLocalRef(stringArg); - t.env->DeleteLocalRef(t.classID); - } - - __fileExistsCaches[filePath] = ret; - - LOGD("fileExists return (%d), path (%s)!", ret, filePath.c_str()); - return ret; -} - -void notifyFileLoaded(const std::string& filePath) -{ - if (!__isNotifyFileLoadedEnabled) - return; - - JniMethodInfo t; - if (getStaticMethodInfo(t, COCOSPLAYCLIENT_CLASS_NAME, "notifyFileLoaded", "(Ljava/lang/String;)V")) - { - jstring stringArg = t.env->NewStringUTF(filePath.c_str()); - t.env->CallStaticVoidMethod(t.classID, t.methodID, stringArg); - t.env->DeleteLocalRef(stringArg); - t.env->DeleteLocalRef(t.classID); - } -} - -std::string getGameRoot() -{ - if (!__isCocosPlayEnabled) - { - LOGW("CocosPlayClient isn't enabled!"); - return ""; - } - - if (__gameRootPath.empty()) - { - JniMethodInfo t; - if (JniHelper::getStaticMethodInfo(t, COCOSPLAYCLIENT_CLASS_NAME, "getGameRoot", "()Ljava/lang/String;")) - { - jstring str = (jstring)t.env->CallStaticObjectMethod(t.classID, t.methodID); - __gameRootPath = JniHelper::jstring2string(str); - t.env->DeleteLocalRef(str); - t.env->DeleteLocalRef(t.classID); - } - LOGD("GameRoot : %s", __gameRootPath.c_str()); - } - return __gameRootPath; -} - -void purgeCachedEntries() -{ - __fileExistsCaches.clear(); -} - -void purgeCachedByFile(const std::string& filePath) -{ - __fileExistsCaches.erase(filePath); -} - -void notifyDemoEnded() -{ - JniMethodInfo t; - if (JniHelper::getStaticMethodInfo(t, COCOSPLAYCLIENT_CLASS_NAME, "notifyDemoEnded", "()V")) - { - t.env->CallStaticVoidMethod(t.classID, t.methodID); - t.env->DeleteLocalRef(t.classID); - LOGD("Game demo was ended!"); - } -} - -} // namespace cocosplay { - -#else - -namespace cocosplay { - -bool isEnabled() { return false; } -bool isDemo() { return false; } -void updateAssets(const std::string& filePath) {} -bool fileExists(const std::string& filePath) { return false; } -void notifyFileLoaded(const std::string& filePath) {} -std::string getGameRoot() { return ""; } -void purgeCachedEntries() {} -void notifyDemoEnded() {} -void purgeCachedByFile(const std::string& filePath){} -} // namespace cocosplay { - -#endif diff --git a/cocos/platform/android/jni/CocosPlayClient.h b/cocos/platform/android/jni/CocosPlayClient.h deleted file mode 100644 index 9c44f26795..0000000000 --- a/cocos/platform/android/jni/CocosPlayClient.h +++ /dev/null @@ -1,86 +0,0 @@ -/**************************************************************************** -Copyright (c) 2015 Chukong Technologies Inc. - -http://www.cocos2d-x.org - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. -****************************************************************************/ -#ifndef __COCOSPLAYCLIENT_H__ -#define __COCOSPLAYCLIENT_H__ - -#include - -namespace cocosplay { - -void lazyInit(); - -/** - * Checks whether CocosPlay is enabled - */ -bool isEnabled(); - -/** - * Checks whether CocosPlay is in demo mode - */ -bool isDemo(); - -/** - * Updates assets by filePath, if the file doesn't exist, CocosPlay will show a progress page of downloading. - * And this interface will be hung up until the scene package was downloaded. - */ -void updateAssets(const std::string& filePath); - -/** - * Checks whether the file exists - */ -bool fileExists(const std::string& filePath); - -/** - * Notifies to Cocos Play SDK that a file was loaded - * It will do nothing if game doesn't run on Cocos Play - */ -void notifyFileLoaded(const std::string& filePath); - -/** - * Gets the resource root path of current game - * @return A writable path of current game - */ -std::string getGameRoot(); - -/** - * Purges the file searching cache. - * - * @note It should be invoked after the resources were updated. - * For instance, it could be used when there is a small update in games. - */ -void purgeCachedEntries(); - -/** - * Purges the file searching cache by giving file path. - */ -void purgeCachedByFile(const std::string& filePath); - -/** - * Notifies that the game demo was ended - */ -void notifyDemoEnded(); - -} // namespace cocosplay { - -#endif // __COCOSPLAYCLIENT_H__