comparison menu.c @ 882:75453bf2ffac

SDL_AndroidGetExternalStoragePath did not do what I thought. Use JNI directly to call Environment.getExternalStorageDirectory
author Michael Pavone <pavone@retrodev.com>
date Mon, 09 Nov 2015 22:34:36 -0800
parents 54ffba3768d6
children 252dfd29831d
comparison
equal deleted inserted replaced
881:415bb1911bd2 882:75453bf2ffac
48 } 48 }
49 } 49 }
50 //make sure we terminate the string even if we did not hit a null terminator in the source 50 //make sure we terminate the string even if we did not hit a null terminator in the source
51 buf[maxchars-1] = 0; 51 buf[maxchars-1] = 0;
52 } 52 }
53
54 #ifdef __ANDROID__
55 #include <SDL.h>
56 #include <jni.h>
57 char *get_external_storage_path()
58 {
59 static char *ret;
60 if (ret) {
61 return ret;
62 }
63 JNIEnv *env = SDL_AndroidGetJNIEnv();
64 if ((*env)->PushLocalFrame(env, 8) < 0) {
65 return NULL;
66 }
67
68 jclass Environment = (*env)->FindClass(env, "android/os/Environment");
69 jmethodID getExternalStorageDirectory =
70 (*env)->GetStaticMethodID(env, Environment, "getExternalStorageDirectory", "()Ljava/io/File;");
71 jobject file = (*env)->CallStaticObjectMethod(env, Environment, getExternalStorageDirectory);
72 if (!file) {
73 goto cleanup;
74 }
75
76 jmethodID getAbsolutePath = (*env)->GetMethodID(env, (*env)->GetObjectClass(env, file),
77 "getAbsolutePath", "()Ljava/lang/String;");
78 jstring path = (*env)->CallObjectMethod(env, file, getAbsolutePath);
79
80 char const *tmp = (*env)->GetStringUTFChars(env, path, NULL);
81 ret = strdup(tmp);
82 (*env)->ReleaseStringUTFChars(env, path, tmp);
83
84 cleanup:
85 (*env)->PopLocalFrame(env, NULL);
86 return ret;
87 }
88 #endif
53 89
54 void * menu_write_w(uint32_t address, void * context, uint16_t value) 90 void * menu_write_w(uint32_t address, void * context, uint16_t value)
55 { 91 {
56 m68k_context *m68k = context; 92 m68k_context *m68k = context;
57 genesis_context *gen = m68k->system; 93 genesis_context *gen = m68k->system;
61 menu->curpath = tern_find_path(config, "ui\0initial_path\0").ptrval; 97 menu->curpath = tern_find_path(config, "ui\0initial_path\0").ptrval;
62 if (menu->curpath) { 98 if (menu->curpath) {
63 menu->curpath = strdup(menu->curpath); 99 menu->curpath = strdup(menu->curpath);
64 } else { 100 } else {
65 #ifdef __ANDROID__ 101 #ifdef __ANDROID__
66 menu->curpath = strdup(SDL_AndroidGetExternalStoragePath()); 102 menu->curpath = strdup(get_external_storage_path());
67 #else 103 #else
68 menu->curpath = strdup(get_home_dir()); 104 menu->curpath = strdup(get_home_dir());
69 #endif 105 #endif
70 } 106 }
71 } 107 }