| 37 | //----------------------------------------------------------------------------- |
| 38 | |
| 39 | bool FileSystemChangeNotifier::addNotification( const Path &path, ChangeDelegate callback ) |
| 40 | { |
| 41 | // Notifications are for files... if the path is empty |
| 42 | // then there is nothing to do. |
| 43 | if ( path.isEmpty() ) |
| 44 | return false; |
| 45 | |
| 46 | // strip the filename and extension - we notify on dirs |
| 47 | Path dir(cleanPath(path)); |
| 48 | if (dir.isEmpty()) |
| 49 | return false; |
| 50 | |
| 51 | dir.setFileName( String() ); |
| 52 | dir.setExtension( String () ); |
| 53 | |
| 54 | // first lookup the dir to see if we already have an entry for it... |
| 55 | DirMap::Iterator itr = mDirMap.find( dir ); |
| 56 | |
| 57 | FileInfoList *fileList = NULL; |
| 58 | bool addedDir = false; |
| 59 | |
| 60 | // Note that GetFileAttributes can fail here if the file doesn't |
| 61 | // exist, but thats ok and expected. You can have notifications |
| 62 | // on files that don't exist yet. |
| 63 | FileNode::Attributes attr; |
| 64 | GetFileAttributes(path, &attr); |
| 65 | |
| 66 | if ( itr != mDirMap.end() ) |
| 67 | { |
| 68 | fileList = &(itr->value); |
| 69 | |
| 70 | // look for the file and return if we find it |
| 71 | for ( U32 i = 0; i < fileList->getSize(); i++ ) |
| 72 | { |
| 73 | FileInfo &fInfo = (*fileList)[i]; |
| 74 | if ( fInfo.filePath == path ) |
| 75 | { |
| 76 | // NOTE: This is bad... we should store the mod |
| 77 | // time for each callback seperately in the future. |
| 78 | // |
| 79 | fInfo.savedLastModTime = attr.mtime; |
| 80 | fInfo.signal.notify(callback); |
| 81 | return true; |
| 82 | } |
| 83 | } |
| 84 | } |
| 85 | else |
| 86 | { |
| 87 | // otherwise we need to add the dir to our map and let the inherited class add it |
| 88 | itr = mDirMap.insert( dir, FileInfoList() ); |
| 89 | |
| 90 | fileList = &(itr->value); |
| 91 | |
| 92 | addedDir = true; |
| 93 | } |
| 94 | |
| 95 | FileInfo newInfo; |
| 96 | newInfo.signal.notify(callback); |
no test coverage detected