OOFILE  1.9
Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | List of all members

Provides cross-platform directory specification and iteration. More...

#include <ooffiles.h>

Collaboration diagram for oofDirectory:
Collaboration graph
[legend]

Public Member Functions

void closeWDDirectory ()
 
void delDirectory (bool delDirAsWellAsContents=true, bool delTree=true, bool delSubdirs=true)
 del contents and optionally dir itself. More...
 
void fillInFSSpec (const char *nameCanBeNull, FSSpec &) const
 Fill in an FSSpec from our current member variables and optional filename. More...
 
void gotoDirectory () const
 Change current dir to this oofDirectory. More...
 
 oofDirectory ()
 
 oofDirectory (short vRefNum, long dirID, bool searchForDirAllVols=false)
 
 oofDirectory (short vRefNum, long dirID, const char *fallBackPath, bool searchForDirAllVols=false)
 
 oofDirectory (const FSSpec &)
 Cope with file spec and set matching directory to that containing file. More...
 
 oofDirectory (const char *path, char *outFileName=0, bool createSubdirsIfMissing=false, bool makeAbsolute=true)
 
bool openFile (const char *justFileName) const
 launch files as if double-click on desktop More...
 
void setDirFromPath (const char *path, char *outFileName=0, bool createSubdirsIfMissing=false, bool makeAbsolute=true)
 setDirFromPath core conversion routine for external call or constructing oofDirectory from incoming path More...
 
virtual ~oofDirectory ()
 
reflective functions
bool validDir () const
 
bool containsFile (const char *justFileName) const
 
const oofStringpath () const
 
oofString filename () const
 
bool isEmpty () const
 
bool createdDiskDir () const
 
file lists and visiting
oofFileListmakeFileList () const
 
virtual void visitFiles (oofDirectoryVisitor &, unsigned long remainingVisitDepth=1024, bool firstVisit=true)
 
void extract (std::ostream &)
 

Static Public Member Functions

static oofDirectory createDirectory (const char *path)
 
static char directoryTerminator ()
 
static bool fileExists (const char *fullPath)
 Confirm a file exists. More...
 
static oofString FSSpecToPath (const FSSpec &)
 static conversion utility. More...
 
static void gotoDirectory (const oofString &)
 Make the directory identified by inPath the current default. More...
 
static void gotoDirectory (short vRefNum, long dirID)
 Make the directory identified by vRefNum & dirID the current default. More...
 
static const char * parentDirPath ()
 
static const char * relativeRootPath ()
 

Protected Member Functions

void createDirID (const unsigned char *pascalPartialPath=0, bool searchForDirAllVols=false)
 A simple wrapper to call the approriate directory method depending on target enviroment. More...
 
void CreateHardDirID (const unsigned char *pascalPartialPath, bool searchForDirAllVols)
 
void CreateSubDirs (const unsigned char *pascalPartialPath)
 a simple wrapper to allow us to call CreateSubdirsAndWorkingDirID Will modify members: mWorkingDirID mVRefNum More...
 
void CreateSubdirsAndWorkingDirID (const unsigned char *pascalPartialPath)
 Find the directory identified by pascalPartialPath and make the oofDirectory point to the directory. More...
 
void CreateWorkingDirID (const unsigned char *pascalPartialPath=0, bool searchForDirAllVols=false)
 Search from current location for the directory identified by the partial path. More...
 
oofString CurrentPath () const
 calculates current path so valid if renaming has occurred. More...
 
void GetCurrentLocation ()
 Set this oofDirectory to point to current default location. More...
 
void PathToDirID (const unsigned char *pascalPath)
 Sets the oofDirectory to point to the directory identified by the path alters the members: mDirID possibly the mVRefNum if path is absolute Uses working directories, updating mWorkingDirID. More...
 

Protected Attributes

bool mCreatedDiskDir
 
long mDirID
 directory ID on specified volume, preserved unless dir recreated. More...
 
oofString mPath
 
bool mValidDir
 
short mVRefNum
 volume number of a mounted volume, not meaningful over reboots More...
 
short mWorkingDirID
 old Mac Classic Working Directory number, combines mVRefNum & mDirID More...
 

Detailed Description

Provides cross-platform directory specification and iteration.

For Macintosh, we deal with three different approaches:

OSX Paths
We do NOT cache the path, relying on mFSRef as the immutable location but path may have changed due to renaming at some point, so any time we return a path() or use chdir, it is recalculated.
See also
oofDirectoryVisitor for iterator object, eg; used to list directories or read a tree into a database (ooftst46).

Definition at line 235 of file ooffiles.h.

Constructor & Destructor Documentation

oofDirectory::oofDirectory ( )

Definition at line 755 of file ooffiles.cpp.

References GetCurrentLocation().

Referenced by createDirectory().

oofDirectory::oofDirectory ( short  vRefNum,
long  dirID,
bool  searchForDirAllVols = false 
)

Definition at line 227 of file ooffilesMac.cpp.

References createDirID(), CurrentPath(), mPath, and mValidDir.

oofDirectory::oofDirectory ( short  vRefNum,
long  dirID,
const char *  fallBackPath,
bool  searchForDirAllVols = false 
)

Definition at line 245 of file ooffilesMac.cpp.

References createDirID(), CurrentPath(), mPath, mValidDir, and setDirFromPath().

oofDirectory::oofDirectory ( const FSSpec &  inSpec)

Cope with file spec and set matching directory to that containing file.

Definition at line 290 of file ooffilesMac.cpp.

References createDirID(), CurrentPath(), FSSpecToPath(), oofString::lastChar(), mDirID, mPath, mValidDir, mVRefNum, and mWorkingDirID.

oofDirectory::oofDirectory ( const char *  path,
char *  outFileName = 0,
bool  createSubdirsIfMissing = false,
bool  makeAbsolute = true 
)

Definition at line 772 of file ooffiles.cpp.

References GetCurrentLocation(), oofString::isEmpty(), mPath, and setDirFromPath().

oofDirectory::~oofDirectory ( )
virtual

Definition at line 765 of file ooffiles.cpp.

References closeWDDirectory().

Member Function Documentation

void oofDirectory::closeWDDirectory ( )

Definition at line 265 of file ooffilesMac.cpp.

References mWorkingDirID.

Referenced by delDirectory(), and ~oofDirectory().

bool oofDirectory::containsFile ( const char *  justFileName) const

Definition at line 1520 of file ooffilesMac.cpp.

bool oofDirectory::createdDiskDir ( ) const
inline

Definition at line 545 of file ooffiles.h.

References mCreatedDiskDir.

Referenced by dbConnect::deleteStorage().

oofDirectory oofDirectory::createDirectory ( const char *  path)
static

Definition at line 1555 of file ooffiles.cpp.

References oofDirectory().

void oofDirectory::createDirID ( const unsigned char *  pascalPartialPath = 0,
bool  searchForDirAllVols = false 
)
protected

A simple wrapper to call the approriate directory method depending on target enviroment.

Definition at line 487 of file ooffilesMac.cpp.

References CreateHardDirID(), and CreateWorkingDirID().

Referenced by CreateSubdirsAndWorkingDirID(), oofDirectory(), and PathToDirID().

void oofDirectory::CreateHardDirID ( const unsigned char *  pascalPartialPath,
bool  searchForDirAllVols 
)
protected

Referenced by createDirID().

void oofDirectory::CreateSubDirs ( const unsigned char *  pascalPartialPath)
protected

a simple wrapper to allow us to call CreateSubdirsAndWorkingDirID Will modify members: mWorkingDirID mVRefNum

Will set mValidDir = true if sucseeful else false mWorkingDirID, &mVRefNum, &mDirID

Definition at line 935 of file ooffilesMac.cpp.

References CreateSubdirsAndWorkingDirID().

Referenced by setDirFromPath().

void oofDirectory::CreateSubdirsAndWorkingDirID ( const unsigned char *  pascalPartialPath)
protected

Find the directory identified by pascalPartialPath and make the oofDirectory point to the directory.

If the directory does not exist create it and any other missing directories. Will modify members: mWorkingDirID mVRefNum

Will set mValidDir = true if sucseeful else false mWorkingDirID, &mVRefNum, &mDirID

Algorithm is as follows. IF we have a partial path IF path is relative THEN GET default working directory ID ELSE IF path is absolute AND vol name in path exists THEN SET mVRefNum = volnum of vol with name at beginning of pascalPartialPath ELSE SET mValidDir = false END_IF

END_IF IF volume exists THEN GET catinfo on named object IF named object exists THEN GET catinfo on named object IF named object is dir create a working directory and SET mWorkingDirID ELSE SET mValidDir false it's a file or something return END_IF ELSE // must make a directory loop back through path name until an existing folder name is found or in current dir loop through path name from valid point creating missing nested directories PBOpenWD SET mWorkingDirID to wpb.ioVRefNum (jus open wdirectory) ELSE SET mValidDir = false END_IF IF mValidDir THEN convert current dir to path END_IF ELSE CALL GETCurrentLocation ENDIF

Definition at line 994 of file ooffilesMac.cpp.

References createDirID(), FSSpecToPath(), GetCurrentLocation(), oofString::lastChar(), mCreatedDiskDir, mDirID, mPath, mValidDir, mVRefNum, mWorkingDirID, path(), and RAISE_EXCEPTION.

Referenced by CreateSubDirs().

void oofDirectory::CreateWorkingDirID ( const unsigned char *  pascalPartialPath = 0,
bool  searchForDirAllVols = false 
)
protected

Search from current location for the directory identified by the partial path.

and set: mDirID & possibly the mVRefNum if the dir is found This will result in oofDirectory pointing to directory identified partial path If the path has more than one leading ":" recurse up the directry tree and then start then search else search down if directory not found and searchForDirAllVols is true search other volumes If not found mValidDir will be false Named CreateHardDirID to match the original CreateWorkingDirID. Does not create a directory just gets the hard dirID of the directory identified by the pascalPartialPath.

See also
createDirID Search for the directory from current location for the directory identified by the partial path and set: mWorkingDirID mValidDir mVRefNum if the dir is found
Todo:
check if PBOpenWDSync can handle paths like :::sea:saw:

Definition at line 643 of file ooffilesMac.cpp.

References mDirID, mValidDir, mVRefNum, and mWorkingDirID.

Referenced by createDirID().

oofString oofDirectory::CurrentPath ( ) const
protected

calculates current path so valid if renaming has occurred.

as we use working dir ID or FSRef as path-independent directory locations

Definition at line 1599 of file ooffilesMac.cpp.

References fillInFSSpec(), FSSpecToPath(), oofFileRef::kMaxOSXPathBufferLen, oofString::lastChar(), and RAISE_EXCEPTION.

Referenced by oofDirectory(), and path().

void oofDirectory::delDirectory ( bool  delDirAsWellAsContents = true,
bool  delTree = true,
bool  delSubdirs = true 
)

del contents and optionally dir itself.

Todo:

central registration of WD's so can delete more flexibly

remove hard-coded depth of 1024 used to detect cycles in deleting trees

Definition at line 796 of file ooffiles.cpp.

References closeWDDirectory(), oofFileRef::deleteFile(), oofFileRef::eDir, mValidDir, and visitFiles().

Referenced by dbConnect::deleteStorage().

char oofDirectory::directoryTerminator ( )
inlinestatic

Definition at line 588 of file ooffiles.h.

Referenced by visitFiles().

void oofDirectory::extract ( std::ostream &  )

Definition at line 1562 of file ooffiles.cpp.

References visitFiles().

Referenced by operator<<().

bool oofDirectory::fileExists ( const char *  fullPath)
static

Confirm a file exists.

Warning
very old code relying on parsing Pascal paths
Todo:

rewrite to use relative path conversion

handle larger paths, maybe using oofFileRef

Bug:
AD 2004-02-03 the PBGetCatInfoSync seems to wrongly return true with default vol & dir, maybe OS version-dependent (10.2.X?)

Definition at line 1552 of file ooffilesMac.cpp.

Referenced by dbConnect::fileExists().

oofString oofDirectory::filename ( ) const

Definition at line 1575 of file ooffilesMac.cpp.

References mDirID, and mVRefNum.

void oofDirectory::fillInFSSpec ( const char *  filename,
FSSpec &  ioSpec 
) const

Fill in an FSSpec from our current member variables and optional filename.

Parameters
filenamemay be up to 255 chars on Carbon, 63 on Classic (allows for volume:name) For _Macintosh_Carbon uses FSMakeFSSpec which allows for larger filenames and keeps FSSpec opaque.

Definition at line 1355 of file ooffilesMac.cpp.

Referenced by OOF_dbaseBackend::createTableInConnection(), CurrentPath(), oofFileRef::moveToDirectory(), oofFileRef::oofFileRef(), and oofFileRef::operator=().

OOF_String oofDirectory::FSSpecToPath ( const FSSpec &  inSpec)
static
void oofDirectory::GetCurrentLocation ( )
protected

Set this oofDirectory to point to current default location.

By getting Current default volume and directory, then setting members: mVRefNum mDirID mWorkingDirID mPath

Definition at line 1224 of file ooffilesMac.cpp.

References FSSpecToPath(), oofString::lastChar(), mDirID, mPath, mVRefNum, and mWorkingDirID.

Referenced by CreateSubdirsAndWorkingDirID(), oofDirectory(), and PathToDirID().

void oofDirectory::gotoDirectory ( ) const

Change current dir to this oofDirectory.

directory identified by mWorkingDirI, DmVRefNum & mDirID (classic) or mFSRef (classic or carbon)

For _Macintosh_Mach calculates current path and sets. Note that we do NOT cache the path, relying on mFSRef as the immutable location but path may have changed due to renaming at some point.

mPath is set by setFSRef or ctor but may now be wrong, hence path() recalculates.

Todo:
check for error from FSRefMakePath and try different size buffer?
Note
thanks very much to John Cebasek for help sorting out the OS/X implications

Definition at line 1317 of file ooffilesMac.cpp.

References oofFileRef::kMaxOSXPathBufferLen, mDirID, mVRefNum, mWorkingDirID, and RAISE_EXCEPTION.

Referenced by oofRepStreamEnv::canDraw(), oofRepWindow::DoSaveAs(), dbConnect::gotoDatabaseDir(), gotoDirectory(), oofFileRef::gotoParentDirectory(), DODAInterface::loadDODA(), OOFCTResource::newFile(), OOFCTResource::openFile(), OOFCTResource::openIFile(), OOF_XMLrepParser::parseFile(), and stSaveDirectory::~stSaveDirectory().

void oofDirectory::gotoDirectory ( const oofString inPath)
static

Make the directory identified by inPath the current default.

Little expensive but safer to rely on the ctor's.

Exceptions
oofE_InvalidDir

Definition at line 1260 of file ooffilesMac.cpp.

References gotoDirectory(), and oofString::isEmpty().

void oofDirectory::gotoDirectory ( short  vRefNum,
long  dirID 
)
static

Make the directory identified by vRefNum & dirID the current default.

Little expensive but safer to rely on the ctor's.

Exceptions
oofE_InvalidDir

Definition at line 1276 of file ooffilesMac.cpp.

References gotoDirectory().

bool oofDirectory::isEmpty ( ) const

Definition at line 1502 of file ooffilesMac.cpp.

References mDirID, and mVRefNum.

Referenced by dbConnect::deleteStorage().

oofFileList * oofDirectory::makeFileList ( ) const

Definition at line 1477 of file ooffilesMac.cpp.

References oofFileList::append(), oofFileRef::eDir, oofFileRef::eFile, mDirID, and mVRefNum.

Referenced by visitFiles().

bool oofDirectory::openFile ( const char *  justFileName) const

launch files as if double-click on desktop

Definition at line 1388 of file ooffilesMac.cpp.

References OpenSelection().

const char * oofDirectory::parentDirPath ( )
inlinestatic

Definition at line 562 of file ooffiles.h.

const oofString & oofDirectory::path ( ) const
inline

Definition at line 552 of file ooffiles.h.

References CurrentPath(), and mPath.

Referenced by CreateSubdirsAndWorkingDirID(), oofE_InvalidDir::extract(), and oofFileRef::path().

void oofDirectory::PathToDirID ( const unsigned char *  pascalPath)
protected

Sets the oofDirectory to point to the directory identified by the path alters the members: mDirID possibly the mVRefNum if path is absolute Uses working directories, updating mWorkingDirID.

Definition at line 460 of file ooffilesMac.cpp.

References createDirID(), GetCurrentLocation(), mDirID, mPath, mValidDir, mVRefNum, and mWorkingDirID.

Referenced by setDirFromPath().

const char * oofDirectory::relativeRootPath ( )
inlinestatic

Definition at line 575 of file ooffiles.h.

void oofDirectory::setDirFromPath ( const char *  path,
char *  outFileName = 0,
bool  createSubdirsIfMissing = false,
bool  makeAbsolute = true 
)

setDirFromPath core conversion routine for external call or constructing oofDirectory from incoming path

a non-null outFileName indicates the caller expects the path to terminate in a filename

incoming paths converted to current platform if possible

Parameters
createSubdirsIfMissingcontrols if directory creation occurs - it is LEGAL to specify an invalid dir, so user can test

Definition at line 368 of file ooffilesMac.cpp.

References oofString::chars(), CreateSubDirs(), oofPathString::isMacPath(), oofPathString::isRelativePath(), oofString::length(), PathToDirID(), oofPathString::pathType(), and oofPathString::relativePathPlatform().

Referenced by oofDirectory().

bool oofDirectory::validDir ( ) const
inline

Definition at line 538 of file ooffiles.h.

References mValidDir.

Referenced by oofFileRef::moveToDirectory().

void oofDirectory::visitFiles ( oofDirectoryVisitor theVisitor,
unsigned long  remainingVisitDepth = 1024,
bool  firstVisit = true 
)
virtual

Member Data Documentation

bool oofDirectory::mCreatedDiskDir
protected

Definition at line 331 of file ooffiles.h.

Referenced by createdDiskDir(), and CreateSubdirsAndWorkingDirID().

long oofDirectory::mDirID
protected

directory ID on specified volume, preserved unless dir recreated.

Definition at line 308 of file ooffiles.h.

Referenced by CreateSubdirsAndWorkingDirID(), CreateWorkingDirID(), filename(), GetCurrentLocation(), gotoDirectory(), isEmpty(), makeFileList(), oofDirectory(), and PathToDirID().

oofString oofDirectory::mPath
protected
bool oofDirectory::mValidDir
protected
short oofDirectory::mVRefNum
protected

volume number of a mounted volume, not meaningful over reboots

Definition at line 309 of file ooffiles.h.

Referenced by CreateSubdirsAndWorkingDirID(), CreateWorkingDirID(), filename(), GetCurrentLocation(), gotoDirectory(), isEmpty(), makeFileList(), oofDirectory(), and PathToDirID().

short oofDirectory::mWorkingDirID
protected

old Mac Classic Working Directory number, combines mVRefNum & mDirID

Definition at line 306 of file ooffiles.h.

Referenced by closeWDDirectory(), CreateSubdirsAndWorkingDirID(), CreateWorkingDirID(), GetCurrentLocation(), gotoDirectory(), oofDirectory(), and PathToDirID().


The documentation for this class was generated from the following files: