aboutsummaryrefslogtreecommitdiff
path: root/src/3rdParty/efsw/WatcherWin32.hpp
blob: ea1e8e4558c5f0da679dcc159b3a4624ea8404a2 (plain)
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
71
72
73
74
75
76
77
78
79
#ifndef EFSW_WATCHERWIN32_HPP
#define EFSW_WATCHERWIN32_HPP

#include <efsw/FileInfo.hpp>
#include <efsw/FileWatcherImpl.hpp>
#include <vector>

#if EFSW_PLATFORM == EFSW_PLATFORM_WIN32

#include <windows.h>

#ifdef EFSW_COMPILER_MSVC
#pragma comment( lib, "comctl32.lib" )
#pragma comment( lib, "user32.lib" )
#pragma comment( lib, "ole32.lib" )

// disable secure warnings
#pragma warning( disable : 4996 )
#endif

namespace efsw {

class WatcherWin32;

enum RefreshResult { Failed, Success, SucessEx };

/// Internal watch data
struct WatcherStructWin32 {
	OVERLAPPED Overlapped;
	WatcherWin32* Watch;
};

struct sLastModifiedEvent {
	FileInfo file;
	std::string fileName;
};

RefreshResult RefreshWatch( WatcherStructWin32* pWatch );

void CALLBACK WatchCallback( DWORD dwNumberOfBytesTransfered, LPOVERLAPPED lpOverlapped );

void DestroyWatch( WatcherStructWin32* pWatch );

WatcherStructWin32* CreateWatch( LPCWSTR szDirectory, bool recursive,
							     DWORD bufferSize, DWORD notifyFilter, HANDLE iocp );

class WatcherWin32 : public Watcher {
  public:
	WatcherWin32(DWORD dwBufferSize) :
		Struct( NULL ),
		DirHandle( NULL ),
		Buffer(),
		lParam( 0 ),
		NotifyFilter( 0 ),
		StopNow( false ),
		Extended( false ),
		Watch( NULL ),
		DirName( NULL ) {
			Buffer.resize(dwBufferSize);
		}

	WatcherStructWin32* Struct;
	HANDLE DirHandle;
	std::vector<BYTE> Buffer;
	LPARAM lParam;
	DWORD NotifyFilter;
	bool StopNow;
	bool Extended;
	FileWatcherImpl* Watch;
	char* DirName;
	sLastModifiedEvent LastModifiedEvent;
	std::vector<std::pair<std::string, LARGE_INTEGER>> OldFiles;
};

} // namespace efsw

#endif

#endif