android.cpp: update path retriaval scheme

Android was skipped as a OS target when the recent path retriaval
modifications in <os>.c were made.

Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Lubomir I. Ivanov 2015-10-11 19:55:04 +03:00 committed by Dirk Hohndel
parent d0d83d5d7d
commit 80056278f7

View file

@ -42,19 +42,38 @@ bool subsurface_ignore_font(const char *font)
void subsurface_user_info(struct user_info *user) void subsurface_user_info(struct user_info *user)
{ /* Encourage use of at least libgit2-0.20 */ } { /* Encourage use of at least libgit2-0.20 */ }
const char *system_default_filename(void) static const char *system_default_path_append(const char *append)
{ {
/* Replace this when QtCore/QStandardPaths getExternalStorageDirectory landed */ /* Replace this when QtCore/QStandardPaths getExternalStorageDirectory landed */
QAndroidJniObject externalStorage = QAndroidJniObject::callStaticObjectMethod("android/os/Environment", "getExternalStorageDirectory", "()Ljava/io/File;"); QAndroidJniObject externalStorage = QAndroidJniObject::callStaticObjectMethod("android/os/Environment", "getExternalStorageDirectory", "()Ljava/io/File;");
QAndroidJniObject externalStorageAbsolute = externalStorage.callObjectMethod("getAbsolutePath", "()Ljava/lang/String;"); QAndroidJniObject externalStorageAbsolute = externalStorage.callObjectMethod("getAbsolutePath", "()Ljava/lang/String;");
QString system_default_filename = externalStorageAbsolute.toString() + "/subsurface.xml"; QString path = externalStorageAbsolute.toString();
QAndroidJniEnvironment env; QAndroidJniEnvironment env;
if (env->ExceptionCheck()) { if (env->ExceptionCheck()) {
// FIXME: Handle exception here. // FIXME: Handle exception here.
env->ExceptionClear(); env->ExceptionClear();
return strdup("/sdcard/subsurface.xml"); path = QString("/sdcard");
} }
return strdup(system_default_filename.toUtf8().data()); if (append)
path += QString("/%1").arg(append);
return strdup(path.toUtf8().data());
}
const char *system_default_directory(void)
{
static const char *path = NULL;
if (!path)
path = system_default_path_append(NULL);
return path;
}
const char *system_default_filename(void)
{
static const char *filename = "subsurface.xml";
static const char *path = NULL;
if (!path)
path = system_default_path_append(filename);
return path;
} }
int enumerate_devices(device_callback_t callback, void *userdata, int dc_type) int enumerate_devices(device_callback_t callback, void *userdata, int dc_type)