summaryrefslogtreecommitdiff
path: root/hammer/FileChangeWatcher.h
diff options
context:
space:
mode:
authorFluorescentCIAAfricanAmerican <[email protected]>2020-04-22 12:56:21 -0400
committerFluorescentCIAAfricanAmerican <[email protected]>2020-04-22 12:56:21 -0400
commit3bf9df6b2785fa6d951086978a3e66f49427166a (patch)
tree2c0f1f0c63c4832882bc93814ebd2c2b1c6224e5 /hammer/FileChangeWatcher.h
downloadarchived-source-engine-2018-hl2-src-master.tar.xz
archived-source-engine-2018-hl2-src-master.zip
Diffstat (limited to 'hammer/FileChangeWatcher.h')
-rw-r--r--hammer/FileChangeWatcher.h70
1 files changed, 70 insertions, 0 deletions
diff --git a/hammer/FileChangeWatcher.h b/hammer/FileChangeWatcher.h
new file mode 100644
index 0000000..f33ed3d
--- /dev/null
+++ b/hammer/FileChangeWatcher.h
@@ -0,0 +1,70 @@
+//========= Copyright Valve Corporation, All rights reserved. ============//
+//
+// Purpose:
+//
+//=============================================================================
+
+#ifndef FILECHANGEWATCHER_H
+#define FILECHANGEWATCHER_H
+#ifdef _WIN32
+#pragma once
+#endif
+
+
+#include "tier1/utlvector.h"
+
+
+//-----------------------------------------------------------------------------
+// Purpose: This class provides notifications of changes in directories.
+// Call AddDirectory to tell it which directories to watch, then
+// call Update() periodically to check for updates.
+//-----------------------------------------------------------------------------
+class CFileChangeWatcher
+{
+public:
+ class ICallbacks
+ {
+ public:
+ // Note: this is called if the file is added, removed, or modified. It's up to the app to figure out
+ // what it wants to do with the change.
+ virtual void OnFileChange( const char *pRelativeFilename, const char *pFullFilename ) = 0;
+ };
+
+
+ CFileChangeWatcher();
+ ~CFileChangeWatcher();
+
+ void Init( ICallbacks *pCallbacks );
+
+ // pSearchPathBase would be like "c:\valve\hl2" and pDirName would be like "materials".
+ bool AddDirectory( const char *pSearchPathBase, const char *pDirName, bool bRecursive );
+ void Term();
+
+ // Call this periodically to update. It'll call your ICallbacks functions for anything it finds.
+ // Returns the number of updates it got.
+ int Update();
+
+private:
+ class CDirWatch
+ {
+ public:
+ char m_SearchPathBase[MAX_PATH];
+ char m_DirName[MAX_PATH];
+ char m_FullDirName[MAX_PATH];
+ OVERLAPPED m_Overlapped;
+ HANDLE m_hEvent;
+ HANDLE m_hDir; // Created with CreateFile.
+ char m_Buffer[1024 * 16];
+ };
+
+ void SendNotification( CFileChangeWatcher::CDirWatch *pDirWatch, const char *pRelativeFilename );
+ BOOL CallReadDirectoryChanges( CFileChangeWatcher::CDirWatch *pDirWatch );
+
+private:
+ // Override these.
+ CUtlVector<CDirWatch*> m_DirWatches;
+ ICallbacks *m_pCallbacks;
+};
+
+
+#endif // FILECHANGEWATCHER_H