Mercurial > dwindows
comparison android/dw.cpp @ 2658:ad6fc7f1a9af
Android: Asset/Resource refactoring for compatibility with other platforms.
Other platforms are able to access the bundled assets via the filesystem.
Android keeps the assets in the Zipped APK archive, so during initialization
we now extract the non-resource (numeric images) into the app cache dir.
dw_app_dir() now returns the path to the application cache.
dw_user_dir() returns either the HOME directory or the path to the
application root directory (usually the parent of the cache).
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Fri, 24 Sep 2021 13:57:16 +0000 |
parents | 9535f533a230 |
children | 917f2d1f9cae |
comparison
equal
deleted
inserted
replaced
2657:9535f533a230 | 2658:ad6fc7f1a9af |
---|---|
46 | 46 |
47 /* Dynamic Windows internal variables */ | 47 /* Dynamic Windows internal variables */ |
48 static char _dw_app_id[_DW_APP_ID_SIZE+1]= {0}; | 48 static char _dw_app_id[_DW_APP_ID_SIZE+1]= {0}; |
49 static char _dw_app_name[_DW_APP_ID_SIZE+1]= {0}; | 49 static char _dw_app_name[_DW_APP_ID_SIZE+1]= {0}; |
50 static char _dw_exec_dir[MAX_PATH+1] = {0}; | 50 static char _dw_exec_dir[MAX_PATH+1] = {0}; |
51 static char _dw_user_dir[MAX_PATH+1] = {0}; | |
51 static int _dw_android_api = 0; | 52 static int _dw_android_api = 0; |
52 | 53 |
53 static pthread_key_t _dw_env_key; | 54 static pthread_key_t _dw_env_key; |
54 static pthread_key_t _dw_fgcolor_key; | 55 static pthread_key_t _dw_fgcolor_key; |
55 static pthread_key_t _dw_bgcolor_key; | 56 static pthread_key_t _dw_bgcolor_key; |
160 * to be called and return. | 161 * to be called and return. |
161 * Parameters: | 162 * Parameters: |
162 * path: The path to the Android app. | 163 * path: The path to the Android app. |
163 */ | 164 */ |
164 JNIEXPORT void JNICALL | 165 JNIEXPORT void JNICALL |
165 Java_org_dbsoft_dwindows_DWindows_dwindowsInit(JNIEnv* env, jobject obj, jstring path, jstring appID) | 166 Java_org_dbsoft_dwindows_DWindows_dwindowsInit(JNIEnv* env, jobject obj, jstring apppath, jstring appcache, jstring appID) |
166 { | 167 { |
167 char *arg = strdup(env->GetStringUTFChars((jstring)path, nullptr)); | 168 char *arg = strdup(env->GetStringUTFChars((jstring)apppath, nullptr)); |
169 const char *cache = env->GetStringUTFChars((jstring)appcache, nullptr); | |
168 const char *appid = env->GetStringUTFChars((jstring)appID, nullptr); | 170 const char *appid = env->GetStringUTFChars((jstring)appID, nullptr); |
171 char *home = getenv("HOME"); | |
169 | 172 |
170 if(!_dw_main_event) | 173 if(!_dw_main_event) |
171 { | 174 { |
172 /* Save our class object pointer for later */ | 175 /* Save our class object pointer for later */ |
173 _dw_obj = env->NewGlobalRef(obj); | 176 _dw_obj = env->NewGlobalRef(obj); |
182 | 185 |
183 /* Create the dwmain event */ | 186 /* Create the dwmain event */ |
184 _dw_main_event = dw_event_new(); | 187 _dw_main_event = dw_event_new(); |
185 } | 188 } |
186 | 189 |
187 if(arg) | 190 if(cache) |
188 { | 191 { |
189 /* Store the passed in path for dw_app_dir() */ | 192 /* Store the passed in path for dw_app_dir() */ |
190 strncpy(_dw_exec_dir, arg, MAX_PATH); | 193 strncpy(_dw_exec_dir, cache, MAX_PATH); |
191 } | 194 } |
195 /* Store the best path for dw_user_dir() */ | |
196 if(home) | |
197 strncpy(_dw_user_dir, home, MAX_PATH); | |
198 else if(arg) | |
199 strncpy(_dw_user_dir, arg, MAX_PATH); | |
200 else | |
201 strcpy(_dw_user_dir, "/"); | |
192 if(appid) | 202 if(appid) |
193 { | 203 { |
194 /* Store our reported Android AppID */ | 204 /* Store our reported Android AppID */ |
195 strncpy(_dw_app_id, appid, _DW_APP_ID_SIZE); | 205 strncpy(_dw_app_id, appid, _DW_APP_ID_SIZE); |
196 } | 206 } |
1048 * current user directory. Or the root directory if it could | 1058 * current user directory. Or the root directory if it could |
1049 * not be determined. | 1059 * not be determined. |
1050 */ | 1060 */ |
1051 char * API dw_user_dir(void) | 1061 char * API dw_user_dir(void) |
1052 { | 1062 { |
1053 static char _dw_user_dir[MAX_PATH+1] = {0}; | |
1054 | |
1055 if(!_dw_user_dir[0]) | |
1056 { | |
1057 char *home = getenv("HOME"); | |
1058 | |
1059 if(home) | |
1060 strcpy(_dw_user_dir, home); | |
1061 else if(_dw_exec_dir[0]) | |
1062 strcpy(_dw_user_dir, _dw_exec_dir); | |
1063 else | |
1064 strcpy(_dw_user_dir, "/"); | |
1065 } | |
1066 return _dw_user_dir; | 1063 return _dw_user_dir; |
1067 } | 1064 } |
1068 | 1065 |
1069 /* | 1066 /* |
1070 * Returns a pointer to a static buffer which contains the | 1067 * Returns a pointer to a static buffer which contains the |