[PATCH] android.cpp: update path retriaval scheme

Lubomir I. Ivanov neolit123 at gmail.com
Sun Oct 11 09:55:04 PDT 2015


From: "Lubomir I. Ivanov" <neolit123 at gmail.com>

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 at gmail.com>
---
code tested without the QAndoroid* API calls in an external test
project. not tested for the actual OS on runtime or as a compile
target!
---
 android.cpp | 27 +++++++++++++++++++++++----
 1 file changed, 23 insertions(+), 4 deletions(-)

diff --git a/android.cpp b/android.cpp
index c4bd191..3e14bec 100644
--- a/android.cpp
+++ b/android.cpp
@@ -42,19 +42,38 @@ bool subsurface_ignore_font(const char *font)
 void subsurface_user_info(struct user_info *user)
 { /* 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 */
 	QAndroidJniObject externalStorage = QAndroidJniObject::callStaticObjectMethod("android/os/Environment", "getExternalStorageDirectory", "()Ljava/io/File;");
 	QAndroidJniObject externalStorageAbsolute = externalStorage.callObjectMethod("getAbsolutePath", "()Ljava/lang/String;");
-	QString system_default_filename = externalStorageAbsolute.toString() + "/subsurface.xml";
+	QString path = externalStorageAbsolute.toString();
 	QAndroidJniEnvironment env;
 	if (env->ExceptionCheck()) {
 		// FIXME: Handle exception here.
 		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)
-- 
1.7.11.msysgit.0



More information about the subsurface mailing list