]> git.tdb.fi Git - libs/core.git/commitdiff
Chdir into a sensible location before starting the application
authorMikko Rasa <tdb@tdb.fi>
Wed, 12 Nov 2014 20:22:15 +0000 (22:22 +0200)
committerMikko Rasa <tdb@tdb.fi>
Wed, 12 Nov 2014 20:22:15 +0000 (22:22 +0200)
System location accessors will ultimately return this directory.  The
default is /, which can easily cause problems.  In particular, many of
my applications expect to have their data in get_sys_data_dir()/"data".
On Android /data exists but is not readable.

source/core/android/mainthread.cpp

index 7219cdf2fdd9ef1476072f90aac28a1364beb776..473379bd71ce373c4e8e8829d4a00ece43ff3c57 100644 (file)
@@ -1,5 +1,7 @@
 #include <cstring>
+#include <msp/fs/dir.h>
 #include <msp/fs/path.h>
+#include <msp/fs/utils.h>
 #include "application.h"
 #include "errorlogger.h"
 #include "mainthread.h"
@@ -49,9 +51,10 @@ void MainThread::main()
 {
        /* I have no idea how dependable this is, but it seems to be the only way
        to get the package name aside from making a Java call through JNI */
-       char *appname = strdup(FS::Path(activity->internalDataPath)[-2].c_str());
+       char *appname = strdup(int_data_path[-2].c_str());
        char *argv[] = { appname, 0 };
        Msp::Android::ErrorLogger err_logger;
+       FS::chdir(FS::dirname(int_data_path));
        Msp::Application::run(1, argv, this, &app_created);
        free(appname);
        if(activity)