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
+1
View File
@@ -394,6 +394,7 @@ class JGE
void SetJNIEnv(JNIEnv * env, jclass cls); void SetJNIEnv(JNIEnv * env, jclass cls);
void sendJNICommand(std::string command); void sendJNICommand(std::string command);
std::string getFileSystemLocation(); std::string getFileSystemLocation();
std::string getFileUserFolderPath();
#endif #endif
protected: protected:
+3 -2
View File
@@ -131,10 +131,11 @@ JFileSystem::JFileSystem(const string & _userPath, const string & _systemPath)
systemPath = [[documentsDirectory stringByAppendingString: @"/Res/"] cStringUsingEncoding:1]; systemPath = [[documentsDirectory stringByAppendingString: @"/Res/"] cStringUsingEncoding:1];
#elif defined (ANDROID) #elif defined (ANDROID)
userPath = JGE::GetInstance()->getFileSystemLocation(); userPath = JGE::GetInstance()->getFileUserFolderPath();
systemPath = ""; systemPath = JGE::GetInstance()->getFileSystemLocation();
DebugTrace("User path " << userPath); DebugTrace("User path " << userPath);
DebugTrace("System path " << systemPath);
#elif defined (QT_CONFIG) #elif defined (QT_CONFIG)
QDir sysDir(RESDIR); QDir sysDir(RESDIR);
+31 -2
View File
@@ -668,7 +668,7 @@ string JGE::getFileSystemLocation()
if (env == NULL) 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"); 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"); jclass jniClass = env->FindClass("org/libsdl/app/SDLActivity");
@@ -677,7 +677,36 @@ string JGE::getFileSystemLocation()
if (methodId == 0) if (methodId == 0)
{ {
DebugTrace("An Error Occurred in getting the JNI methodID for getSystemFolderPath. Defaulting to /mnt/sdcard/Wagic"); 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);
// 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;
}
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); jstring systemPath = (jstring) env->CallStaticObjectMethod(jniClass, methodId);
@@ -88,10 +88,11 @@ public class SDLActivity extends Activity implements OnKeyListener
public String mErrorMessage = ""; public String mErrorMessage = "";
public Boolean mErrorHappened = false; public Boolean mErrorHappened = false;
public final static String RES_FOLDER = Environment.getExternalStorageDirectory().getPath() + "/Wagic/Res/"; 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/"; 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 ) // path to the onboard sd card that is not removable (typically /mnt/sdcard )
private String internalPath = ""; private String internalPath = "";
@@ -368,7 +369,8 @@ public class SDLActivity extends Activity implements OnKeyListener
private void startDownload() private void startDownload()
{ {
String url = getResourceUrl(); //String url = getResourceUrl();
String url = RES_URL;
if (!checkStorageState()) if (!checkStorageState())
{ {
Log.e(TAG, "Error in initializing storage space."); Log.e(TAG, "Error in initializing storage space.");
@@ -500,7 +502,7 @@ public class SDLActivity extends Activity implements OnKeyListener
// So we can call stuff from static callbacks // So we can call stuff from static callbacks
mSingleton = this; mSingleton = this;
mContext = this.getApplicationContext(); mContext = this.getApplicationContext();
RES_FILENAME = getResourceName(); //RES_FILENAME = getResourceName();
StorageOptions.determineStorageOptions(); StorageOptions.determineStorageOptions();
checkStorageLocationPreference(); checkStorageLocationPreference();
@@ -812,7 +814,7 @@ public class SDLActivity extends Activity implements OnKeyListener
input = new BufferedInputStream(url.openStream()); input = new BufferedInputStream(url.openStream());
// create a File object for the output file // 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); output = new FileOutputStream(outputFile);
@@ -830,9 +832,9 @@ public class SDLActivity extends Activity implements OnKeyListener
} catch (Exception e) } 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"; 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); //mSingleton.downloadError(errorMessage);
Log.e(TAG, errorMessage); //Log.e(TAG, errorMessage);
Log.e(TAG, e.getMessage()); //Log.e(TAG, e.getMessage());
} }
return Long.valueOf(totalBytes); return Long.valueOf(totalBytes);