MCPcopy Create free account
hub / github.com/TorqueGameEngines/Torque3D / addNotification

Method addNotification

Engine/source/core/volume.cpp:39–103  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

37//-----------------------------------------------------------------------------
38
39bool 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);

Callers 1

AddChangeNotificationFunction · 0.80

Calls 13

GetFileAttributesFunction · 0.85
_mergeMethod · 0.80
getFileSystemMethod · 0.80
getChangeNotifierMethod · 0.80
StringClass · 0.50
isEmptyMethod · 0.45
setExtensionMethod · 0.45
findMethod · 0.45
endMethod · 0.45
getSizeMethod · 0.45
notifyMethod · 0.45
insertMethod · 0.45

Tested by

no test coverage detected