Page 1 of 1

Loading resources.cfg for Android

Posted: Mon Jul 23, 2012 2:44 pm
by BigDave2001
Hi,

I've followed the Android code thread by Wolfman and I'm currently trying to implement my own stand alone app (using the Android Ogre code).

I have my resources.cfg in the assets folder, and the following code doesn't work: (it does work, but it doesn't find the file)

Code: Select all

Ogre::ConfigFile cf;
cf.load("resources.cfg");
Bear with me as I'm not too hot on Android - but how do I get the assets directory? As I see it, Wolfman hasn't included any Java code, so I can't get it from Java - is there another way to get the folder (as a string) to access the file?

Thanks

Re: resources.cfg

Posted: Mon Jul 23, 2012 5:43 pm
by BigDave2001
Ok, got the file directory using :

Code: Select all

static void handleCmd(struct android_app* app, int32_t cmd)
       {
...
            ANativeActivity* nativeActivity = app->activity;                              
            const char* internalPath = nativeActivity->internalDataPath;
But

Code: Select all

Ogre::ConfigFile cf;
cf.load("resources.cfg");
would appear to assume the file is loadable directly, using ifstream, and if my googling serves me right, you can't access the contents of an APK using ifstream (I may be wrong..).

So I'm now stuck... will continue to look, but if anyone with better Android experience can help, that would be great!

Re: resources.cfg

Posted: Mon Jul 23, 2012 6:36 pm
by BigDave2001
A question, if anyone can answer:

How / where does Wolfman's Android port load 'resources.cfg'?

Re: resources.cfg

Posted: Mon Jul 23, 2012 6:51 pm
by Wolfmanfx
Hi,

Just saw your post - the title is pretty useless ;)
Search the samplebrowser app - loadAPK or something like that i cannot remember.
I load the cfg files directly from the apk.

Standalone example should follow with android-ogre sdk which we have on the roadmap for 1.9.

Re: Loading resources.cfg for Android

Posted: Mon Jul 23, 2012 7:19 pm
by BigDave2001
Thanks! Yeah changed the title - probably for the best :)

Ok - I've found 'openAPKFile' - I'll see how that works.

Re: Loading resources.cfg for Android

Posted: Mon Jul 23, 2012 7:46 pm
by BigDave2001
Yep - that works!

If you are interested, I'm testing on a new Nexus 7 - the sample browser works great on that.

Re: Loading resources.cfg for Android

Posted: Thu May 28, 2015 2:08 pm
by jaalberteris
On an application based on Qt and Ogre I did it like this:

Code: Select all

    Ogre::DataStreamPtr stream;

    QFile resourcesFile("assets:/resources.cfg");

    if(!resourcesFile.open(QIODevice::ReadOnly | QIODevice::Text))
    {
        Ogre::LogManager::getSingletonPtr()->logMessage("I can't open file 'resources.cfg'.");
        qApp->closeAllWindows();
        qApp->exit(1);
    }

    QByteArray buffer = resourcesFile.readAll();

    void *membuffer = OGRE_MALLOC(buffer.length(), Ogre::MEMCATEGORY_GENERAL);
    memcpy(membuffer, buffer.data(), buffer.length());
    stream = Ogre::DataStreamPtr(new Ogre::MemoryDataStream(membuffer, buffer.length(), true, true));

    cf.load(stream);