Skip to content

Commit ad2f2fb

Browse files
committed
Add md docs
1 parent c286111 commit ad2f2fb

5 files changed

+53
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# Monitor File Changes Under Windows System
2+
3+
## Method 1
4+
5+
### Details
6+
- Windows system API: `ReadDirectoryChangesW()`
7+
- Like `DWORD WINAPI MonitorThread(LPVOID lp)` in `TaskThreads.cpp`
8+
- Firstly we create a handle for each volume in system, like `C:\`
9+
- Then we monitor `C:\` with the handle by `ReadDirectoryChangesW()`
10+
- We can set many flags when we monitor the volume, like `FILE_NOTIFY_CHANGE_FILE_NAME`, `FILE_NOTIFY_CHANGE_DIR_NAME`, `FILE_NOTIFY_CHANGE_SIZE`, and we only concern file add, delete, modify
11+
```cpp
12+
// hVolume is the volume handle
13+
// notifyInfo is a FILE_NOTIFY_INFORMATION structure, system will populate data in it
14+
ReadDirectoryChangesW(
15+
hVolume,
16+
&notifyInfo,
17+
sizeof(notifyInfo),
18+
true, // Monitor sub directory
19+
FILE_NOTIFY_CHANGE_FILE_NAME | FILE_NOTIFY_CHANGE_DIR_NAME | FILE_NOTIFY_CHANGE_SIZE,
20+
&retBytes,
21+
nullptr,
22+
nullptr)
23+
```
24+
- We call `ReadDirectoryChangesW()` in a sub thread, in this thread we use this function in a dead loop until receive exit event
25+
- After we receive the file changes event, we won't handle it immediately in monitor thread
26+
- Cause there are too many event in system, we may lost other events if we cost time to handle current event.
27+
- So we just push this event into a global task queue `g_updateDataBaseTaskList`, and handle those events one by one in another thread `UpdateSqlDataBaseThread`
28+
29+
### Advantages
30+
- It's very simple to carry on, cause Windows system offers everything
31+
32+
### Disadvantages
33+
- Sometimes we cannot receive file change events under a specail volume, such as `C:`, Windows system won't send the event ? or there are bugs in this software ? don't know
34+
35+
## Method 2
36+
37+
- So how does `Everything` monitor files change events ? need some time to analyse
38+
- To be continue ...

Docs/Topics/2_Sqlite3SpeedupMethod.md

Whitespace-only changes.

Docs/Topics/3_SpeedupQtTableViewAddContent.md

Whitespace-only changes.

MiniThing.vcxproj

+3
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,9 @@
190190
<ItemGroup>
191191
<None Include=".github\workflows\msbuild.yml" />
192192
<None Include=".gitignore" />
193+
<None Include="Docs\Topics\1_MonitorFileChangesUnderWindowsSystem.md" />
194+
<None Include="Docs\Topics\2_Sqlite3SpeedupMethod.md" />
195+
<None Include="Docs\Topics\3_SpeedupQtTableViewAddContent.md" />
193196
<None Include="LICENSE" />
194197
<None Include="README-CN.md" />
195198
<None Include="README.md" />

MiniThing.vcxproj.filters

+12
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,9 @@
7070
<Filter Include=".github\workflows">
7171
<UniqueIdentifier>{e7177173-df38-4607-8632-68e5ad8df407}</UniqueIdentifier>
7272
</Filter>
73+
<Filter Include="Docs\Topics">
74+
<UniqueIdentifier>{7b35985d-9917-4cd9-8cad-ab071dbf4f89}</UniqueIdentifier>
75+
</Filter>
7376
</ItemGroup>
7477
<ItemGroup>
7578
<ClCompile Include="MiniThing\Core\MiniThingCore.cpp">
@@ -160,6 +163,15 @@
160163
<None Include=".github\workflows\msbuild.yml">
161164
<Filter>.github\workflows</Filter>
162165
</None>
166+
<None Include="Docs\Topics\1_MonitorFileChangesUnderWindowsSystem.md">
167+
<Filter>Docs\Topics</Filter>
168+
</None>
169+
<None Include="Docs\Topics\2_Sqlite3SpeedupMethod.md">
170+
<Filter>Docs\Topics</Filter>
171+
</None>
172+
<None Include="Docs\Topics\3_SpeedupQtTableViewAddContent.md">
173+
<Filter>Docs\Topics</Filter>
174+
</None>
163175
</ItemGroup>
164176
<ItemGroup>
165177
<Image Include="Docs\Pictures\Architecture.png">

0 commit comments

Comments
 (0)