1 // TortoiseGit - a Windows shell extension for easy version control
3 // External Cache Copyright (C) 2007-2008 - TortoiseSVN
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License
7 // as published by the Free Software Foundation; either version 2
8 // of the License, or (at your option) any later version.
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software Foundation,
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 #define READ_DIR_CHANGE_BUFFER_SIZE 4096
24 typedef CComCritSecLock
<CComCriticalSection
> AutoLocker
;
28 * Watches the file system for changes.
30 * When a CPathWatcher object is created, a new thread is started which
31 * waits for file system change notifications.
32 * To add folders to the list of watched folders, call \c AddPath().
34 * The folders are watched recursively. To prevent having too many folders watched,
35 * children of already watched folders are automatically removed from watching.
44 * Adds a new path to be watched. The path \b must point to a directory.
45 * If the path is already watched because a parent of that path is already
46 * watched recursively, then the new path is just ignored and the method
49 bool AddPath(const CTGitPath
& path
);
51 * Removes a path and all its children from the watched list.
53 bool RemovePathAndChildren(const CTGitPath
& path
);
56 * Returns the number of recursively watched paths.
58 int GetNumberOfWatchedPaths() {return watchedPaths
.GetCount();}
61 * Stops the watching thread.
66 * Returns the number of changed paths up to now.
68 int GetNumberOfChangedPaths() {return m_changedPaths
.GetCount();}
71 * Returns the list of paths which maybe got changed, i.e., for which
72 * a change notification was received.
74 CTGitPathList
GetChangedPaths() {return m_changedPaths
;}
77 * Clears the list of changed paths
79 void ClearChangedPaths() {AutoLocker
lock(m_critSec
); m_changedPaths
.Clear();}
82 static unsigned int __stdcall
ThreadEntry(void* pContext
);
88 CComAutoCriticalSection m_critSec
;
91 volatile LONG m_bRunning
;
93 CTGitPathList watchedPaths
; ///< list of watched paths.
94 CTGitPathList m_changedPaths
; ///< list of paths which got changed
97 * Helper class: provides information about watched directories.
102 CDirWatchInfo(); // private & not implemented
103 CDirWatchInfo
& operator=(const CDirWatchInfo
& rhs
);//so that they're aren't accidentally used. -- you'll get a linker error
105 CDirWatchInfo(HANDLE hDir
, const CTGitPath
& DirectoryName
);
110 bool CloseDirectoryHandle();
112 HANDLE m_hDir
; ///< handle to the directory that we're watching
113 CTGitPath m_DirName
; ///< the directory that we're watching
114 CHAR m_Buffer
[READ_DIR_CHANGE_BUFFER_SIZE
]; ///< buffer for ReadDirectoryChangesW
115 DWORD m_dwBufLength
; ///< length or returned data from ReadDirectoryChangesW -- ignored?...
116 OVERLAPPED m_Overlapped
;
117 CString m_DirPath
; ///< the directory name we're watching with a backslash at the end
118 //HDEVNOTIFY m_hDevNotify; ///< Notification handle
121 std::map
<HANDLE
, CDirWatchInfo
*> watchInfoMap
;