From 9be1d447882ddd5c284463f4170314ba3915cef4 Mon Sep 17 00:00:00 2001 From: valfieri Date: Sun, 18 Aug 2019 17:11:20 +0200 Subject: [PATCH] Android Fix --- JGE/include/JGE.h | 1 + JGE/src/JFileSystem.cpp | 7 ++-- JGE/src/JGE.cpp | 33 +++++++++++++++++-- .../src/org/libsdl/app/SDLActivity.java | 24 +++++++------- 4 files changed, 49 insertions(+), 16 deletions(-) diff --git a/JGE/include/JGE.h b/JGE/include/JGE.h index 80a2e3717..aefae786e 100644 --- a/JGE/include/JGE.h +++ b/JGE/include/JGE.h @@ -394,6 +394,7 @@ class JGE void SetJNIEnv(JNIEnv * env, jclass cls); void sendJNICommand(std::string command); std::string getFileSystemLocation(); + std::string getFileUserFolderPath(); #endif protected: diff --git a/JGE/src/JFileSystem.cpp b/JGE/src/JFileSystem.cpp index f8add0a29..5d7f3d56e 100644 --- a/JGE/src/JFileSystem.cpp +++ b/JGE/src/JFileSystem.cpp @@ -131,10 +131,11 @@ JFileSystem::JFileSystem(const string & _userPath, const string & _systemPath) systemPath = [[documentsDirectory stringByAppendingString: @"/Res/"] cStringUsingEncoding:1]; #elif defined (ANDROID) - userPath = JGE::GetInstance()->getFileSystemLocation(); - systemPath = ""; + userPath = JGE::GetInstance()->getFileUserFolderPath(); + systemPath = JGE::GetInstance()->getFileSystemLocation(); - DebugTrace("User path " << userPath); + DebugTrace("User path " << userPath); + DebugTrace("System path " << systemPath); #elif defined (QT_CONFIG) QDir sysDir(RESDIR); diff --git a/JGE/src/JGE.cpp b/JGE/src/JGE.cpp index 6a7da0839..8b03c16bb 100644 --- a/JGE/src/JGE.cpp +++ b/JGE/src/JGE.cpp @@ -668,7 +668,7 @@ string JGE::getFileSystemLocation() if (env == NULL) { DebugTrace("An Error Occurred in getting the JNI Environment whie trying to get the system folder location. Defaulting to /mnt/sdcard/net.wagic.app/Wagic"); - return "/mnt/sdcard/Wagic"; + return "/mnt/sdcard/Wagic/Res"; }; jclass jniClass = env->FindClass("org/libsdl/app/SDLActivity"); @@ -677,7 +677,7 @@ string JGE::getFileSystemLocation() if (methodId == 0) { DebugTrace("An Error Occurred in getting the JNI methodID for getSystemFolderPath. Defaulting to /mnt/sdcard/Wagic"); - return "/mnt/sdcard/Wagic"; + return "/mnt/sdcard/Wagic/Res"; }; jstring systemPath = (jstring) env->CallStaticObjectMethod(jniClass, methodId); @@ -691,6 +691,35 @@ string JGE::getFileSystemLocation() return retVal; } +string JGE::getFileUserFolderPath() +{ + JNIEnv * env = getJNIEnv(); + if (env == NULL) + { + DebugTrace("An Error Occurred in getting the JNI Environment whie trying to get the system folder location. Defaulting to /mnt/sdcard/net.wagic.app/Wagic"); + return "/mnt/sdcard/Wagic/User"; + }; + + jclass jniClass = env->FindClass("org/libsdl/app/SDLActivity"); + jmethodID methodId = env->GetStaticMethodID( jniClass, "getUserFolderPath", "()Ljava/lang/String;"); + + if (methodId == 0) + { + DebugTrace("An Error Occurred in getting the JNI methodID for getSystemFolderPath. Defaulting to /mnt/sdcard/Wagic"); + return "/mnt/sdcard/Wagic/User"; + }; + + jstring systemPath = (jstring) env->CallStaticObjectMethod(jniClass, methodId); + + // Now convert the Java String to C++ char array + const char* cstr = env->GetStringUTFChars(systemPath, 0); + string retVal (cstr); + env->ReleaseStringUTFChars(systemPath, cstr); + env->DeleteLocalRef(systemPath); + + return retVal; +} + /// Access to JNI Environment void JGE::SetJNIEnv(JNIEnv * env, jclass cls) { diff --git a/projects/mtg/Android/src/org/libsdl/app/SDLActivity.java b/projects/mtg/Android/src/org/libsdl/app/SDLActivity.java index 8b4cce0c7..99c910bb0 100644 --- a/projects/mtg/Android/src/org/libsdl/app/SDLActivity.java +++ b/projects/mtg/Android/src/org/libsdl/app/SDLActivity.java @@ -88,10 +88,11 @@ public class SDLActivity extends Activity implements OnKeyListener public String mErrorMessage = ""; public Boolean mErrorHappened = false; public final static String RES_FOLDER = Environment.getExternalStorageDirectory().getPath() + "/Wagic/Res/"; - public static String RES_FILENAME = "core_0184.zip"; + public static String RES_FILENAME = "core_0211.zip"; + public static String RES_URL = "https://github.com/Vitty85/wagic/releases/download/wagic-v0.21.1/core_0211.zip"; public String systemFolder = Environment.getExternalStorageDirectory().getPath() + "/Wagic/Res/"; - private String userFolder; + private String userFolder = Environment.getExternalStorageDirectory().getPath() + "/Wagic/User/"; // path to the onboard sd card that is not removable (typically /mnt/sdcard ) private String internalPath = ""; @@ -368,7 +369,8 @@ public class SDLActivity extends Activity implements OnKeyListener private void startDownload() { - String url = getResourceUrl(); + //String url = getResourceUrl(); + String url = RES_URL; if (!checkStorageState()) { Log.e(TAG, "Error in initializing storage space."); @@ -486,7 +488,7 @@ public class SDLActivity extends Activity implements OnKeyListener // mGLView.setFocusableInTouchMode(true); // mGLView.setFocusable(true); // adView.requestFreshAd(); - setContentView(_videoLayout, new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT)); + setContentView(_videoLayout, new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT)); mSurface.requestFocus(); } @@ -500,9 +502,9 @@ public class SDLActivity extends Activity implements OnKeyListener // So we can call stuff from static callbacks mSingleton = this; mContext = this.getApplicationContext(); - RES_FILENAME = getResourceName(); - - StorageOptions.determineStorageOptions(); + //RES_FILENAME = getResourceName(); + + StorageOptions.determineStorageOptions(); checkStorageLocationPreference(); } @@ -812,7 +814,7 @@ public class SDLActivity extends Activity implements OnKeyListener input = new BufferedInputStream(url.openStream()); // create a File object for the output file - File outputFile = new File(resDirectory, filename + ".tmp"); + File outputFile = new File(resDirectory, filename); output = new FileOutputStream(outputFile); @@ -830,9 +832,9 @@ public class SDLActivity extends Activity implements OnKeyListener } catch (Exception e) { String errorMessage = "An error happened while downloading the resources. It could be that our server is temporarily down, that your device is not connected to a network, or that we cannot write to " + mSingleton.getSystemStorageLocation() + ". Please check your phone settings and try again. For more help please go to http://wagic.net"; - mSingleton.downloadError(errorMessage); - Log.e(TAG, errorMessage); - Log.e(TAG, e.getMessage()); + //mSingleton.downloadError(errorMessage); + //Log.e(TAG, errorMessage); + //Log.e(TAG, e.getMessage()); } return Long.valueOf(totalBytes);