ZFFramework
 
Loading...
Searching...
No Matches
ZFIO_res.h File Reference

abstract IO More...

#include "ZFIODef.h"

Go to the source code of this file.

Functions

const zfstringZFPathType_res ()
 see ZFPathInfo
 
ZFInput ZFInputForRes (const zfstring &resFilePath)
 util to create a resource file input callback, see ZFResOpen for what resource file is
 
void ZFResExtPathAdd (const ZFPathInfo &pathInfo)
 add an additional path to search as resource files
 
void ZFResExtPathRemove (const ZFPathInfo &pathInfo)
 see ZFResExtPathAdd
 
ZFCoreArray< ZFPathInfoZFResExtPathList ()
 see ZFResExtPathAdd
 
zfbool ZFResExtPathCheck (ZFPathInfo &resExtPath, const zfstring &resPath)
 see ZFResExtPathAdd
 
zfbool ZFResIsExist (const zfstring &resPath)
 return true if res file specified by path is exist
 
zfbool ZFResIsDir (const zfstring &resPath)
 return true if res file specified by path is a directory
 
zfbool ZFResFindFirst (ZFIOFindData &fd, const zfstring &resPath)
 
zfbool ZFResFindNext (ZFIOFindData &fd)
 
void ZFResFindClose (ZFIOFindData &fd)
 
void * ZFResOpen (const zfstring &resPath)
 open a resource file for read only, see ZFFileOpen
 
zfbool ZFResClose (void *token)
 see ZFResOpen ZFFileClose
 
zfindex ZFResTell (void *token)
 see ZFResOpen ZFFileTell
 
zfbool ZFResSeek (void *token, zfindex byteSize, ZFSeekPos seekPos=(ZFSeekPosBegin))
 see ZFResOpen ZFFileSeek
 
zfindex ZFResRead (void *token, void *buf, zfindex maxByteSize)
 see ZFResOpen ZFFileRead
 
zfindex ZFResSize (void *token)
 see ZFResOpen, ZFFileSize
 

Detailed Description

abstract IO

Function Documentation

◆ ZFPathType_res()

const zfstring & ZFPathType_res ( )
extern

see ZFPathInfo

pathData is the res path

Note
path must be well formed, use ZFPathFormat if necessary

◆ ZFInputForRes()

ZFInput ZFInputForRes ( const zfstring & resFilePath)
inline

util to create a resource file input callback, see ZFResOpen for what resource file is

param:

  • (const zfstring &)resFilePath: resource file path to use

auto open and auto close files, may return a null callback if open file error

◆ ZFResExtPathAdd()

void ZFResExtPathAdd ( const ZFPathInfo & pathInfo)
extern

add an additional path to search as resource files

by default, resource files are placed in a fixed builtin location, you may add additional path to search as resource files
to make things clear, while accessing resource files using a res path, we would:

  1. search all additional resource path to find whether the file exists
  2. if exist, use the additional resource file
  3. if not exist, use builtin resource file
  4. if builtin resource file not exist, fail

this method would affect all methods that process with resource files, such as ZFResOpen, ZFResFindFirst
typically, additional resource path should be modified during startup only

◆ ZFResExtPathCheck()

zfbool ZFResExtPathCheck ( ZFPathInfo & resExtPath,
const zfstring & resPath )
extern

see ZFResExtPathAdd

return the registered additional resource path if file exist, or null if not exist
if return value is not null, the final file path should be "return value + '/' + resPath"

Note
path must be well formed, use ZFPathFormat if necessary

◆ ZFResIsExist()

zfbool ZFResIsExist ( const zfstring & resPath)
extern

return true if res file specified by path is exist

Note
path must be well formed, use ZFPathFormat if necessary

◆ ZFResIsDir()

zfbool ZFResIsDir ( const zfstring & resPath)
extern

return true if res file specified by path is a directory

Note
path must be well formed, use ZFPathFormat if necessary

◆ ZFResFindFirst()

zfbool ZFResFindFirst ( ZFIOFindData & fd,
const zfstring & resPath )
extern
See also
see ZFResOpen, ZFFileFindFirst

use empty string to find resource's root directory

Note
path must be well formed, use ZFPathFormat if necessary

◆ ZFResFindNext()

zfbool ZFResFindNext ( ZFIOFindData & fd)
extern
See also
see ZFResOpen, ZFFileFindNext

◆ ZFResFindClose()

void ZFResFindClose ( ZFIOFindData & fd)
extern
See also
see ZFResOpen, ZFFileFindClose

◆ ZFResOpen()

void * ZFResOpen ( const zfstring & resPath)
extern

open a resource file for read only, see ZFFileOpen

since the resource files may or may not be opened by normal method (i.e. ZFFileOpen), such as those in Android project which are located in apk/assets, so use ZFResOpen and ZFResFindFirst to access it for cross-platform
also, since the resource files may or may not be compressed into app, accessing them may or may not take much time
a resource file is a file in "zfres" directory of native project, such as "project_path/zfres/1.png" and "project_path/zfres/subdir/1.png", which should be "1.png" and "subdir/1.png" when ZFResOpen
file name could be the same if under different directories, and is recommended to keep all lower case for cross-platform

note that the token is defined same type as the one used by ZFFileOpen, it's your responsibility to make sure not to misuse it

Note
path must be well formed, use ZFPathFormat if necessary

ADVANCED:
resource can be "extended" by ZFResExtPathAdd, use ZFResRaw series to bypass the logic