blob: f33ed3d4bab114dba7e1e2e1f8934611a121773f (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
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
|