Loading resources.cfg for Android

Discussion of issues specific to mobile platforms such as iOS, Android, Symbian and Meego.
Post Reply
BigDave2001
Kobold
Posts: 37
Joined: Tue Feb 21, 2012 3:57 pm

Loading resources.cfg for Android

Post 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
Last edited by BigDave2001 on Mon Jul 23, 2012 7:15 pm, edited 1 time in total.
BigDave2001
Kobold
Posts: 37
Joined: Tue Feb 21, 2012 3:57 pm

Re: resources.cfg

Post 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!
BigDave2001
Kobold
Posts: 37
Joined: Tue Feb 21, 2012 3:57 pm

Re: resources.cfg

Post by BigDave2001 »

A question, if anyone can answer:

How / where does Wolfman's Android port load 'resources.cfg'?
User avatar
Wolfmanfx
OGRE Team Member
OGRE Team Member
Posts: 1525
Joined: Fri Feb 03, 2006 10:37 pm
Location: Austria - Leoben
x 99
Contact:

Re: resources.cfg

Post 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.
BigDave2001
Kobold
Posts: 37
Joined: Tue Feb 21, 2012 3:57 pm

Re: Loading resources.cfg for Android

Post by BigDave2001 »

Thanks! Yeah changed the title - probably for the best :)

Ok - I've found 'openAPKFile' - I'll see how that works.
BigDave2001
Kobold
Posts: 37
Joined: Tue Feb 21, 2012 3:57 pm

Re: Loading resources.cfg for Android

Post by BigDave2001 »

Yep - that works!

If you are interested, I'm testing on a new Nexus 7 - the sample browser works great on that.
jaalberteris
Gnoblar
Posts: 1
Joined: Thu May 28, 2015 2:02 pm

Re: Loading resources.cfg for Android

Post 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);
Post Reply