88#include <stdio.h>
99#include <stdlib.h>
1010#include <unistd.h>
11+ #include <dirent.h>
1112#include <jni.h>
1213
1314#include "SDL.h"
@@ -53,18 +54,27 @@ PyMODINIT_FUNC initandroidembed(void) {
5354 /* (void) Py_InitModule("androidembed", AndroidEmbedMethods); */
5455}
5556
56- int dir_exists (char * filename )
57- /* Function from http://stackoverflow.com/questions/12510874/how-can-i-check-if-a-directory-exists-on-linux-in-c# */
58- {
59- if (0 != access ("filename" , F_OK )) {
60- if (ENOENT == errno ) {
61- return 0 ;
62- }
63- if (ENOTDIR == errno ) {
64- return 0 ;
65- }
57+ /* int dir_exists(char* filename) */
58+ /* /\* Function from http://stackoverflow.com/questions/12510874/how-can-i-check-if-a-directory-exists-on-linux-in-c# *\/ */
59+ /* { */
60+ /* if (0 != access(filename, F_OK)) { */
61+ /* if (ENOENT == errno) { */
62+ /* return 0; */
63+ /* } */
64+ /* if (ENOTDIR == errno) { */
65+ /* return 0; */
66+ /* } */
67+ /* return 1; */
68+ /* } */
69+ /* } */
70+
71+ int dir_exists (char * filename ) {
72+ DIR * dip ;
73+ if (dip = opendir (filename )) {
74+ closedir (filename );
6675 return 1 ;
6776 }
77+ return 0 ;
6878}
6979
7080int file_exists (const char * filename )
@@ -108,7 +118,21 @@ int main(int argc, char *argv[]) {
108118 */
109119 PyImport_AppendInittab ("androidembed" , initandroidembed );
110120
121+ LOG ("Preparing to initialize python" );
122+
123+ if (dir_exists ("../libs" )) {
124+ LOG ("libs exists" );
125+ } else {
126+ LOG ("libs does not exist" );
127+ }
128+
129+ if (dir_exists ("crystax_python" )) {
130+ LOG ("exists without slash" );
131+ }
132+
111133 if (dir_exists ("crystax_python/" )) {
134+ /* if (1) { */
135+ LOG ("crystax_python exists" );
112136 char paths [256 ];
113137 snprintf (paths , 256 , "%s/crystax_python/stdlib.zip:%s/crystax_python/modules" , env_argument , env_argument );
114138 /* snprintf(paths, 256, "%s/stdlib.zip:%s/modules", env_argument, env_argument); */
@@ -118,7 +142,7 @@ int main(int argc, char *argv[]) {
118142 wchar_t * wchar_paths = Py_DecodeLocale (paths , NULL );
119143 Py_SetPath (wchar_paths );
120144 LOG ("set wchar paths..." );
121- }
145+ } else { LOG ( "crystax_python does not exist" );}
122146
123147 Py_Initialize ();
124148
@@ -152,18 +176,19 @@ int main(int argc, char *argv[]) {
152176 " private + '/lib/python2.7/lib-dynload/', \n" \
153177 " private + '/lib/python2.7/site-packages/', \n" \
154178 " argument ]\n" );
155- } else {
179+ } else {
156180
157181 char add_site_packages_dir [256 ];
158182 snprintf (add_site_packages_dir , 256 , "sys.path.append('%s/crystax_python/site-packages')" ,
159183 env_argument );
160184
161185 PyRun_SimpleString (
162- "import sys\n" \
163- "sys.argv = ['notaninterpreterreally']\n" \
186+ "import sys\n" \
187+ "sys.argv = ['notaninterpreterreally']\n" \
164188 "from os.path import realpath, join, dirname" );
165189 PyRun_SimpleString (add_site_packages_dir );
166- /* "sys.path.append(join(dirname(realpath(__file__)), 'site-packages'))") */
190+ /* "sys.path.append(join(dirname(realpath(__file__)), 'site-packages'))") */
191+ PyRun_SimpleString ("sys.path = ['.'] + sys.path" );
167192 }
168193
169194 PyRun_SimpleString (
0 commit comments