04/20/14 01:48:23 (10 years ago)
Maciej Komosinski

Android compilation and access to RESOURCES and HOME files

1 edited


  • cpp/common/nonstd_stdio.cpp

    r215 r227  
    140140#ifdef __ANDROID__
    141 //#include "framsg.h"
     141#include "framsg.h"
    142142#include "nonstd.h"
     143#include "nonstd_stl.h"
    143144MFILE *mfopen(const char *path, const char *mode)
    145         NvFile *rfile=NULL; //umie tylko czytac
     146        string respath=GET_APP_RESOURCES; //the macro can be char* or std::string, we don't know (nonstd.h, INITIAL_DIR_IS_RES, cwd.cpp) so we convert it to std::string
     147        //printFM("Opening '%s', mode='%s'",path,mode);
     148        //printFM("GET_APP_RESOURCES='%s'",respath.c_str());
     149        NvFile *rfile=NULL; //can only read
    146150        FILE *rwfile=NULL;
    147         if (strstr(path,GET_APP_RESOURCES)==path) //otwieramy resource! wiec uzywamy czytania z assets
    148         {
    149                 if (path[0]=='.' && path[1]=='/') path+=2; //nie rozpoznaje sciezek "./costam", a w sailorze zrobiles tak ze nie moze byc pusty path bo to jest znacznik ze jest niezainicjowany, dlatego uzywasz "./" i musimy je tu obcinac
    150                 rfile=NvFOpen(path); //"mode" not supported! umie tylko czytac
     151        if (strstr(path,respath.c_str())==path) //opening resource! so we use a dedicated way to read from assets
     152        {
     153                path+=respath.length(); //strip the prefix, we need a relative path in assets
     154                if (strstr(mode,"w"))
     155                        printFM("Warning: attempt to open a read-only resource '%s' in writable mode '%s'",path,mode);
     156                rfile=NvFOpen(path); //"mode" not supported! can only read
     157                //printFM("Opened RES file as %p",rfile);
    151158                if (rfile==NULL) return NULL;
    152         } else //"normalny" dostep (do HOME)
     159        } else //a "normal" access (HOME)
    153160        {
    154161                rwfile=fopen(path,mode);
     162                //printFM("Opened HOME file as %p",rwfile);
    155163                if (rwfile==NULL) return NULL;
    156164        }
    175183        if (f->rfile)
    176                 return size==0?0:NvFRead(ptr, size, count, f->rfile)/size; //blad nvidii w interpretacji zwracanej wartosci - zwraca liczbe bajtow zamiast liczbe porcji
     184                return NvFRead(ptr, size, count, f->rfile); //nvidia introduced my corrections in SDK v10.14, so a fix is no longer needed here
    177185        else
    178186                return fread(ptr, size, count, f->rwfile);
    183191        if (f->rfile)
    184                 return 0; //write not supported funkcjami nvidii
     192                return 0; //write not supported in assets using nvidia functions
    185193        else
    186194                return fwrite(ptr, size, count, f->rwfile);
    198206        if (f->rfile)
    199                 return NvFGets(str, num, f->rfile);
     207        {
     208                char *ret=NvFGets(str, num, f->rfile);
     209                //fixing nvidia inconsistency... their function never returns NULL (fix submitted)
     210                if (ret!=NULL && *ret==0 && num>0) //nothing has been read, must have been eof
     211                        return NULL;
     212                return ret;
     213        }
    200214        else
    201215                return fgets(str,num,f->rwfile);
    214228        if (f->rfile)
    215                 return NvFSeek(f->rfile, position, type)==-1; // off_t AAsset_seek(AAsset* asset, off_t offset, int whence): Returns the new position on success, or (off_t) -1 on error.
     229                return NvFSeek(f->rfile, position, type); //nvidia introduced my corrections in SDK v10.14, so a fix is no longer needed here
    216230        else
    217231                return fseek(f->rwfile, position, type);
Note: See TracChangeset for help on using the changeset viewer.