Android Fix

This commit is contained in:
valfieri
2019-08-18 17:11:20 +02:00
parent 7328c45013
commit 9be1d44788
4 changed files with 49 additions and 16 deletions

View File

@@ -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:

View File

@@ -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);

View File

@@ -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)
{

View File

@@ -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);