Skip to content

Commit 8477e13

Browse files
committed
updated to .net10 + changed namespace
1 parent 57bbc77 commit 8477e13

21 files changed

Lines changed: 223 additions & 248 deletions

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2025 Duong Dieu Phap
3+
Copyright (c) 2018-2026 Duong Dieu Phap
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# FileWatcherEx for Windows
1+
# D2Phap.FileWatcherEx for Windows
22
A wrapper of `System.IO.FileSystemWatcher` to standardize the events and avoid false change notifications. It has been being used in [ImageGlass - A lightweight, versatile image viewer](https://github.com/d2phap/ImageGlass) project.
33

44
This project is based on the *VSCode FileWatcher*: https://github.com/Microsoft/vscode-filewatcher-windows
@@ -7,28 +7,28 @@ This project is based on the *VSCode FileWatcher*: https://github.com/Microsoft/
77

88

99
## Resource links
10-
- Nuget package: [https://www.nuget.org/packages/FileWatcherEx](https://www.nuget.org/packages/FileWatcherEx/)
10+
- Nuget package: [https://www.nuget.org/packages/D2Phap.FileWatcherEx](https://www.nuget.org/packages/D2Phap.FileWatcherEx/)
1111
- Project url: [https://github.com/d2phap/FileWatcherEx](https://github.com/d2phap/FileWatcherEx)
1212
- Website: [https://imageglass.org](https://imageglass.org)
1313

1414
## Features
1515
- Standardizes the events of `System.IO.FileSystemWatcher`.
1616
- No false change notifications when a file system item is created, deleted, changed or renamed.
17-
- Supports .NET 6.0, 7.0, 8.0, 9.0
17+
- Supports .NET 8.0, 10.0
1818

1919
## Installation
2020
Run the command:
2121

2222
```bash
2323
# Nuget package
24-
Install-Package FileWatcherEx
24+
Install-Package D2Phap.FileWatcherEx
2525
```
2626

2727
## Usage
2828
See Demo project for full details!
2929

3030
```cs
31-
using FileWatcherEx;
31+
using D2Phap.FileWatcherEx;
3232

3333

3434
var _fw = new FileSystemWatcherEx(@"C:\path\to\watch");

Source/Demo/Demo.WinForms.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22

33
<PropertyGroup>
44
<OutputType>WinExe</OutputType>
5-
<TargetFramework>net9.0-windows</TargetFramework>
5+
<TargetFramework>net10.0-windows</TargetFramework>
66
<Nullable>enable</Nullable>
77
<UseWindowsForms>true</UseWindowsForms>
88
<ImplicitUsings>enable</ImplicitUsings>
99
</PropertyGroup>
1010

1111
<ItemGroup>
12-
<ProjectReference Include="..\FileWatcherEx\FileWatcherEx.csproj" />
12+
<ProjectReference Include="..\FileWatcherEx\D2Phap.FileWatcherEx.csproj" />
1313
</ItemGroup>
1414

1515
</Project>

Source/Demo/Form1.cs

Lines changed: 87 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -1,122 +1,120 @@
1+
using D2Phap.FileWatcherEx;
12

2-
using FileWatcherEx;
3+
namespace Demo;
34

4-
namespace Demo
5+
public partial class Form1 : Form
56
{
6-
public partial class Form1 : Form
7+
private FileSystemWatcherEx _fw = new();
8+
9+
public Form1()
710
{
8-
private FileSystemWatcherEx _fw = new();
11+
InitializeComponent();
12+
}
913

10-
public Form1()
11-
{
12-
InitializeComponent();
13-
}
1414

1515

16+
private void BtnStart_Click(object sender, EventArgs e)
17+
{
18+
_fw = new FileSystemWatcherEx(txtPath.Text.Trim(), FW_OnLog);
1619

17-
private void BtnStart_Click(object sender, EventArgs e)
18-
{
19-
_fw = new FileSystemWatcherEx(txtPath.Text.Trim(), FW_OnLog);
20-
21-
_fw.OnRenamed += FW_OnRenamed;
22-
_fw.OnCreated += FW_OnCreated;
23-
_fw.OnDeleted += FW_OnDeleted;
24-
_fw.OnChanged += FW_OnChanged;
25-
_fw.OnError += FW_OnError;
26-
27-
_fw.SynchronizingObject = this;
28-
_fw.IncludeSubdirectories = true;
29-
30-
try
31-
{
32-
_fw.Start();
33-
34-
btnStart.Enabled = true;
35-
btnSelectFolder.Enabled = false;
36-
txtPath.Enabled = false;
37-
btnStop.Enabled = true;
38-
}
39-
catch (Exception ex)
40-
{
41-
MessageBox.Show(ex.Message);
42-
}
43-
}
20+
_fw.OnRenamed += FW_OnRenamed;
21+
_fw.OnCreated += FW_OnCreated;
22+
_fw.OnDeleted += FW_OnDeleted;
23+
_fw.OnChanged += FW_OnChanged;
24+
_fw.OnError += FW_OnError;
4425

45-
private void FW_OnError(object? sender, ErrorEventArgs e)
46-
{
47-
if (txtConsole.InvokeRequired)
48-
{
49-
txtConsole.Invoke(FW_OnError, sender, e);
50-
}
51-
else
52-
{
53-
txtConsole.Text += "[ERROR]: " + e.GetException().Message + "\r\n";
54-
}
55-
}
26+
_fw.SynchronizingObject = this;
27+
_fw.IncludeSubdirectories = true;
5628

57-
private void FW_OnChanged(object? sender, FileChangedEvent e)
29+
try
5830
{
59-
txtConsole.Text += string.Format("[cha] {0} | {1}",
60-
Enum.GetName(typeof(ChangeType), e.ChangeType),
61-
e.FullPath) + "\r\n";
62-
}
31+
_fw.Start();
6332

64-
private void FW_OnDeleted(object? sender, FileChangedEvent e)
65-
{
66-
txtConsole.Text += string.Format("[del] {0} | {1}",
67-
Enum.GetName(typeof(ChangeType), e.ChangeType),
68-
e.FullPath) + "\r\n";
33+
btnStart.Enabled = true;
34+
btnSelectFolder.Enabled = false;
35+
txtPath.Enabled = false;
36+
btnStop.Enabled = true;
6937
}
70-
71-
private void FW_OnCreated(object? sender, FileChangedEvent e)
38+
catch (Exception ex)
7239
{
73-
txtConsole.Text += string.Format("[cre] {0} | {1}",
74-
Enum.GetName(typeof(ChangeType), e.ChangeType),
75-
e.FullPath) + "\r\n";
40+
MessageBox.Show(ex.Message);
7641
}
42+
}
7743

78-
private void FW_OnRenamed(object? sender, FileChangedEvent e)
44+
private void FW_OnError(object? sender, ErrorEventArgs e)
45+
{
46+
if (txtConsole.InvokeRequired)
7947
{
80-
txtConsole.Text += string.Format("[ren] {0} | {1} ----> {2}",
81-
Enum.GetName(typeof(ChangeType), e.ChangeType),
82-
e.OldFullPath,
83-
e.FullPath) + "\r\n";
48+
txtConsole.Invoke(FW_OnError, sender, e);
8449
}
85-
86-
private void FW_OnLog(string value)
50+
else
8751
{
88-
txtConsole.Text += $@"[log] {value}" + "\r\n";
52+
txtConsole.Text += "[ERROR]: " + e.GetException().Message + "\r\n";
8953
}
54+
}
9055

91-
private void BtnStop_Click(object sender, EventArgs e)
92-
{
93-
_fw.Stop();
56+
private void FW_OnChanged(object? sender, FileChangedEvent e)
57+
{
58+
txtConsole.Text += string.Format("[cha] {0} | {1}",
59+
Enum.GetName(e.ChangeType),
60+
e.FullPath) + "\r\n";
61+
}
9462

95-
btnStart.Enabled = true;
96-
btnSelectFolder.Enabled = true;
97-
txtPath.Enabled = true;
98-
btnStop.Enabled = false;
99-
btnStop.Enabled = true;
100-
}
63+
private void FW_OnDeleted(object? sender, FileChangedEvent e)
64+
{
65+
txtConsole.Text += string.Format("[del] {0} | {1}",
66+
Enum.GetName(e.ChangeType),
67+
e.FullPath) + "\r\n";
68+
}
10169

70+
private void FW_OnCreated(object? sender, FileChangedEvent e)
71+
{
72+
txtConsole.Text += string.Format("[cre] {0} | {1}",
73+
Enum.GetName(e.ChangeType),
74+
e.FullPath) + "\r\n";
75+
}
10276

103-
private void BtnSelectFolder_Click(object sender, EventArgs e)
104-
{
105-
var fb = new FolderBrowserDialog();
77+
private void FW_OnRenamed(object? sender, FileChangedEvent e)
78+
{
79+
txtConsole.Text += string.Format("[ren] {0} | {1} ----> {2}",
80+
Enum.GetName(e.ChangeType),
81+
e.OldFullPath,
82+
e.FullPath) + "\r\n";
83+
}
10684

85+
private void FW_OnLog(string value)
86+
{
87+
txtConsole.Text += $@"[log] {value}" + "\r\n";
88+
}
10789

108-
if (fb.ShowDialog() == DialogResult.OK)
109-
{
110-
txtPath.Text = fb.SelectedPath;
90+
private void BtnStop_Click(object sender, EventArgs e)
91+
{
92+
_fw.Stop();
93+
94+
btnStart.Enabled = true;
95+
btnSelectFolder.Enabled = true;
96+
txtPath.Enabled = true;
97+
btnStop.Enabled = false;
98+
btnStop.Enabled = true;
99+
}
100+
101+
102+
private void BtnSelectFolder_Click(object sender, EventArgs e)
103+
{
104+
var fb = new FolderBrowserDialog();
111105

112-
_fw.Stop();
113-
_fw.Dispose();
114-
}
115-
}
116106

117-
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
107+
if (fb.ShowDialog() == DialogResult.OK)
118108
{
109+
txtPath.Text = fb.SelectedPath;
110+
111+
_fw.Stop();
119112
_fw.Dispose();
120113
}
121114
}
115+
116+
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
117+
{
118+
_fw.Dispose();
119+
}
122120
}

Source/FileSystemEventRecorder/FileSystemEventRecorder.cs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,14 @@ public static void Main(string[] args)
3535
{
3636
var (watchedDirectory, csvOutputFile) = ProcessArguments(args);
3737

38-
var watcher = new FileSystemWatcher();
39-
watcher.Path = watchedDirectory;
40-
watcher.IncludeSubdirectories = true;
41-
watcher.NotifyFilter = NotifyFilters.LastWrite
42-
| NotifyFilters.FileName
43-
| NotifyFilters.DirectoryName;
38+
var watcher = new FileSystemWatcher
39+
{
40+
Path = watchedDirectory,
41+
IncludeSubdirectories = true,
42+
NotifyFilter = NotifyFilters.LastWrite
43+
| NotifyFilters.FileName
44+
| NotifyFilters.DirectoryName
45+
};
4446

4547
watcher.Created += (_, ev) =>
4648
EventRecords.Enqueue(new EventRecord(ev.FullPath, "created", null, Stopwatch.GetTimestamp()));

Source/FileSystemEventRecorder/FileSystemEventRecorder.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22

33
<PropertyGroup>
44
<OutputType>Exe</OutputType>
5-
<TargetFramework>net9.0</TargetFramework>
5+
<TargetFramework>net10.0</TargetFramework>
66
<ImplicitUsings>enable</ImplicitUsings>
77
<Nullable>enable</Nullable>
88
</PropertyGroup>
99

1010
<ItemGroup>
11-
<ProjectReference Include="..\FileWatcherEx\FileWatcherEx.csproj" />
11+
<ProjectReference Include="..\FileWatcherEx\D2Phap.FileWatcherEx.csproj" />
1212
</ItemGroup>
1313

1414
<ItemGroup>

Source/FileWatcherEx.sln

Lines changed: 0 additions & 43 deletions
This file was deleted.

Source/FileWatcherEx.slnx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<Solution>
2+
<Project Path="Demo/Demo.WinForms.csproj" />
3+
<Project Path="FileSystemEventRecorder/FileSystemEventRecorder.csproj" />
4+
<Project Path="FileWatcherEx/D2Phap.FileWatcherEx.csproj" />
5+
<Project Path="FileWatcherExTests/FileWatcherExTests.csproj" />
6+
</Solution>

Source/FileWatcherEx/FileWatcherEx.csproj renamed to Source/FileWatcherEx/D2Phap.FileWatcherEx.csproj

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFrameworks>net6.0;net7.0;net8.0;net9.0</TargetFrameworks>
4+
<TargetFrameworks>net8.0;net10.0</TargetFrameworks>
55
<ImplicitUsings>enable</ImplicitUsings>
66
<Nullable>enable</Nullable>
7-
<Copyright>Copyright © 2018-2025 Duong Dieu Phap</Copyright>
7+
<Copyright>Copyright © 2018-2026 Duong Dieu Phap</Copyright>
88
<PackageProjectUrl>https://github.com/d2phap/FileWatcherEx</PackageProjectUrl>
99
<PackageReadmeFile>README.md</PackageReadmeFile>
1010
<RepositoryUrl>https://github.com/d2phap/FileWatcherEx</RepositoryUrl>
@@ -13,7 +13,7 @@
1313
<Description>A wrapper of FileSystemWatcher to standardize the events and avoid false change notifications, used in ImageGlass project (https://imageglass.org). This project is based on the VSCode FileWatcher: https://github.com/Microsoft/vscode-filewatcher-windows.</Description>
1414
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
1515
<FileVersion>$(Version)</FileVersion>
16-
<VersionPrefix>2.7.0</VersionPrefix>
16+
<VersionPrefix>3.0.0</VersionPrefix>
1717
<PackageReleaseNotes>See https://github.com/d2phap/FileWatcherEx/releases</PackageReleaseNotes>
1818
<Authors>d2phap</Authors>
1919
<Title>FileWatcherEx - A file system watcher</Title>
@@ -22,6 +22,11 @@
2222
<PackageLicenseFile>LICENSE</PackageLicenseFile>
2323
<SignAssembly>False</SignAssembly>
2424
<LangVersion>latest</LangVersion>
25+
26+
<PublishTrimmed>true</PublishTrimmed>
27+
<EnableTrimAnalyzer>true</EnableTrimAnalyzer>
28+
<TrimmerRemoveSymbols>true</TrimmerRemoveSymbols>
29+
<TrimmerSingleWarn>false</TrimmerSingleWarn>
2530
</PropertyGroup>
2631

2732
<ItemGroup>

0 commit comments

Comments
 (0)