/* findContainedFiles does the hard work in the FileInfo class. If self is a directory, it gets a list of all the files contained in that directory, creates a FileInfo for each of them and keeps an array with those FileInfo objects. It is called internally, and is called lazily -- if information about the children was gathered immediately, this would cause huge startup times since the entire file tree would have to be travesed to gather the appropriate information.
/* containedFiles returns the NSArray of files contained in self. If self is a normal file, the answer is nil. If self is a directory, the answer may be a 0 length array. If self has never checked for the existence of children, it calls findContainedFiles to create the FileInfo objects for all its children.
*/
-(NSArray *) containedFiles;
{
if (filetype == NSFileTypeDirectory)
{
if (containedFiles == nil)
{
//cache them up
[self findContainedFiles];
}
return containedFiles;
}
else
return nil;
}
// accessor functions for the FileInfo.
-(NSString*) filename
{
return filename;
}
-(NSString*) fullPathName
{
return fullPathName;
}
-(NSString*) filetype
{
return filetype;
}
-(NSString*) lastModified
{
return lastModified;
}
// cleanup functions
- (void)dealloc
{
// this should never be called directly, but the system will call it when the
// last copy of a particular object is released. At this point it is necessary
// to free all the objects that have been copied or retained by this object
// NOTE: it is not necessary to check that the objects have already been allocated --
// if they haven't they will be nil, and sending release to nil is guaranteed not
// to cause an error or do anything stupid. (actually sending nil to any object has
// the same guarantee).
[filename release];
[filetype release];
[lastModified release];
[fullPathName release];
[containedFiles release];
}
- (NSComparisonResult)compare:(FileInfo *)obj
{
NSComparisonResult result = NSOrderedDescending;
if ( obj )
{
result = [[self filetype] compare:[obj filetype]];
if ( result == NSOrderedSame )
result = [[self filename] compare:[obj filename]];