Loading resources.cfg for Android

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

Loading resources.cfg for Android

Postby BigDave2001 » Mon Jul 23, 2012 2:44 pm

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.
0 x

BigDave2001
Kobold
Posts: 37
Joined: Tue Feb 21, 2012 3:57 pm

Re: resources.cfg

Postby BigDave2001 » Mon Jul 23, 2012 5:43 pm

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!
0 x

BigDave2001
Kobold
Posts: 37
Joined: Tue Feb 21, 2012 3:57 pm

Re: resources.cfg

Postby BigDave2001 » Mon Jul 23, 2012 6:36 pm

A question, if anyone can answer:

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

User avatar
Wolfmanfx
OGRE Team Member
OGRE Team Member
Posts: 1525
Joined: Fri Feb 03, 2006 10:37 pm
Location: Austria - Leoben
Contact:

Re: resources.cfg

Postby Wolfmanfx » Mon Jul 23, 2012 6:51 pm

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.
0 x

BigDave2001
Kobold
Posts: 37
Joined: Tue Feb 21, 2012 3:57 pm

Re: Loading resources.cfg for Android

Postby BigDave2001 » Mon Jul 23, 2012 7:19 pm

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

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

BigDave2001
Kobold
Posts: 37
Joined: Tue Feb 21, 2012 3:57 pm

Re: Loading resources.cfg for Android

Postby BigDave2001 » Mon Jul 23, 2012 7:46 pm

Yep - that works!

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

jaalberteris
Gnoblar
Posts: 1
Joined: Thu May 28, 2015 2:02 pm

Re: Loading resources.cfg for Android

Postby jaalberteris » Thu May 28, 2015 2:08 pm

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);
0 x


Return to “Mobile Devices”

Who is online

Users browsing this forum: No registered users and 1 guest