The SWORD Project
1.9.0.svnversion
|
#include <filemgr.h>
Public Member Functions | |
void | close (FileDesc *file) |
FileMgr (int maxFiles=35) | |
virtual void | flush () |
SWBuf | getHomeDir () |
virtual long | lastAccess () |
FileDesc * | open (const char *path, int mode, bool tryDowngrade) |
FileDesc * | open (const char *path, unsigned int mode, bool tryDowngrade) |
FileDesc * | open (const char *path, unsigned int mode, unsigned int perms=IREAD|IWRITE, bool tryDowngrade=false) |
FileDesc * | open (const char *path, int mode, int perms=IREAD|IWRITE, bool tryDowngrade=false) |
virtual long | resourceConsumption () |
signed char | trunc (FileDesc *file) |
~FileMgr () | |
Static Public Member Functions | |
static void | closeFile (int fd) |
static int | copyDir (const char *srcDir, const char *destDir) |
static int | copyFile (const char *srcFile, const char *destFile) |
static int | createParent (const char *pName) |
static int | createPathAndFile (const char *fName) |
static signed char | existsDir (const char *ipath, const char *idirName=0) |
static signed char | existsFile (const char *ipath, const char *ifileName=0) |
static std::vector< struct DirEntry > | getDirList (const char *dirPath, bool includeSize=false, bool includeIsDirectory=true) |
static SWBuf | getEnvValue (const char *variableName) |
static long | getFileSize (const char *path) |
static char | getLine (FileDesc *fDesc, SWBuf &line) |
static FileMgr * | getSystemFileMgr () |
static bool | hasAccess (const char *path, int mode) |
static char | isDirectory (const char *path) |
static int | openFile (const char *fName, int mode, int perms) |
static int | openFileReadOnly (const char *fName) |
static int | removeDir (const char *targetDir) |
static int | removeFile (const char *fName) |
static void | setSystemFileMgr (FileMgr *newFileMgr) |
static long | write (int fd, const void *buf, long count) |
Public Attributes | |
int | maxFiles |
Static Public Attributes | |
static unsigned int | APPEND = O_APPEND |
static unsigned int | CREAT = O_CREAT |
static unsigned int | IREAD = S_IREAD |
static unsigned int | IWRITE = S_IWRITE |
static unsigned int | RDONLY = O_RDONLY |
static unsigned int | RDWR = O_RDWR |
static unsigned int | TRUNC = O_TRUNC |
static unsigned int | WRONLY = O_WRONLY |
Static Protected Attributes | |
static FileMgr * | systemFileMgr = 0 |
Private Member Functions | |
int | sysOpen (FileDesc *file) |
Private Attributes | |
FileDesc * | files |
Friends | |
class | __staticsystemFileMgr |
class | FileDesc |
This class isolates all file io for SWORD, making OS level quirks easier to fix. This class is typically copied and replaced if necessary to get SWORD to run on a specific platform (e.g., Windows Mobile), but in the future, statics should be removed to make possible to instead simply subclass and override necessary methods.
This class also provides many convenience methods which make working with data storage easier.
Conceptually, this factory exposes an interface which allows SWORD to 'open' every file it wants, without worrying about OS limits, and takes care of opening and closing the actual file descriptors when necessary.
FileMgr::FileMgr | ( | int | maxFiles = 35 | ) |
Constructor.
maxFiles | The number of files that this FileMgr may open in parallel, if necessary. |
Definition at line 158 of file filemgr.cpp.
FileMgr::~FileMgr | ( | ) |
Destructor. Clean things up. Will close all files opened by this FileMgr object.
Definition at line 164 of file filemgr.cpp.
void FileMgr::close | ( | FileDesc * | file | ) |
Close a given file and delete its FileDesc object. Will only close the file if it was created by this FileMgr object.
file | The file to close. |
Definition at line 196 of file filemgr.cpp.
|
static |
Definition at line 491 of file filemgr.cpp.
Definition at line 618 of file filemgr.cpp.
Definition at line 496 of file filemgr.cpp.
|
static |
Definition at line 426 of file filemgr.cpp.
|
static |
Definition at line 479 of file filemgr.cpp.
Checks for the existence and readability of a directory.
ipath | Path to directory. |
idirName | Name of directory to check for. |
Definition at line 357 of file filemgr.cpp.
Checks for the existence and readability of a file.
ipath | Path to file. |
ifileName | Name of file to check for. |
Definition at line 337 of file filemgr.cpp.
|
virtual |
Cacher methods overridden
Reimplemented from SWCacher.
Definition at line 657 of file filemgr.cpp.
|
static |
Given a directory path, returns contents of directory
dirPath | Path to directory |
includeSize | Optimization flag to allow passing false to skip file size lookup (true forces both size and directory lookup) |
includeIsDirectory | Optimization flag to allow passing false to skip isDirectory lookup |
Definition at line 379 of file filemgr.cpp.
Get an environment variable from the OS
variableName | the name of the env variable to retrieve |
Definition at line 316 of file filemgr.cpp.
|
static |
Definition at line 605 of file filemgr.cpp.
SWBuf FileMgr::getHomeDir | ( | ) |
Determines where SWORD looks for the user's home folder. This is typically used as a place to find any additional personal SWORD modules which a user might wish to be added to a system-wide library (e.g., added from ~/.sword/mods.d/ or ~/sword/mods.d/)
or if a user or UI wishes to override SWORD system configuration settings (e.g., /etc/sword.conf) with a custom configuration (e.g., ~/.sword/sword.conf)
Definition at line 681 of file filemgr.cpp.
Definition at line 527 of file filemgr.cpp.
|
static |
Definition at line 101 of file filemgr.cpp.
|
static |
Check if a path can be access with supplied permissions
path | Path to the resource |
mode | Desired access mode |
Definition at line 327 of file filemgr.cpp.
|
static |
Definition at line 592 of file filemgr.cpp.
|
virtualinherited |
Definition at line 46 of file swcacher.cpp.
Open a file and return a FileDesc for it. The file itself will only be opened when FileDesc::getFd() is called.
path | Filename. |
mode | File access mode. |
tryDowngrade | if we can't open the file for permissions requested, try to open the file with less permissions |
Definition at line 175 of file filemgr.cpp.
Definition at line 108 of file filemgr.h.
|
inline |
Open a file and return a FileDesc for it. The file itself will only be opened when FileDesc::getFd() is called.
path | Filename. |
mode | File access mode. |
perms | Permissions. |
tryDowngrade |
Definition at line 118 of file filemgr.h.
FileDesc * FileMgr::open | ( | const char * | path, |
int | mode, | ||
int | perms = IREAD | IWRITE , |
||
bool | tryDowngrade = false |
||
) |
Definition at line 180 of file filemgr.cpp.
|
static |
attempts to open a file readonly
fName | filename to open |
Definition at line 463 of file filemgr.cpp.
|
static |
Definition at line 474 of file filemgr.cpp.
|
static |
Definition at line 639 of file filemgr.cpp.
|
static |
Definition at line 517 of file filemgr.cpp.
|
virtual |
|
static |
Definition at line 109 of file filemgr.cpp.
|
private |
Definition at line 209 of file filemgr.cpp.
signed char FileMgr::trunc | ( | FileDesc * | file | ) |
Truncate a file at its current position leaving byte at current possition intact deleting everything afterward.
file | The file to operate on. |
Definition at line 256 of file filemgr.cpp.
|
static |
Definition at line 115 of file filemgr.cpp.
|
friend |
|
static |
int FileMgr::maxFiles |