Skip to content

Commit feb568a

Browse files
committed
[Core.IO] Modernize code
1 parent fcca67b commit feb568a

24 files changed

Lines changed: 1749 additions & 1840 deletions

sources/core/Stride.Core.IO/DirectoryWatcher.Desktop.cs

Lines changed: 243 additions & 253 deletions
Large diffs are not rendered by default.
Lines changed: 93 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,49 @@
11
// Copyright (c) .NET Foundation and Contributors (https://dotnetfoundation.org/ & https://stride3d.net) and Silicon Studio Corp. (https://www.siliconstudio.co.jp)
22
// Distributed under the MIT license. See the LICENSE.md file in the project root for more information.
3-
using System;
4-
using System.Collections.Generic;
5-
using System.Threading;
3+
namespace Stride.Core.IO;
64

7-
namespace Stride.Core.IO
5+
/// <summary>
6+
/// Track file system events from several directories.
7+
/// </summary>
8+
public partial class DirectoryWatcher : IDisposable
89
{
10+
private const int SleepBetweenWatcherCheck = 200;
11+
private Thread? watcherCheckThread;
12+
private bool exitThread;
13+
14+
/// <summary>
15+
/// Occurs when a file/directory change occurred.
16+
/// </summary>
17+
public event EventHandler<FileEvent>? Modified;
18+
919
/// <summary>
10-
/// Track file system events from several directories.
20+
/// Initializes a new instance of the <see cref="DirectoryWatcher"/> class.
1121
/// </summary>
12-
public partial class DirectoryWatcher : IDisposable
22+
/// <param name="fileFilter">The file filter By default null default to *.*</param>
23+
public DirectoryWatcher(string? fileFilter = null)
1324
{
14-
private const int SleepBetweenWatcherCheck = 200;
15-
private Thread watcherCheckThread;
16-
private bool exitThread;
17-
18-
/// <summary>
19-
/// Occurs when a file/directory change occurred.
20-
/// </summary>
21-
public event EventHandler<FileEvent> Modified;
22-
23-
/// <summary>
24-
/// Initializes a new instance of the <see cref="DirectoryWatcher"/> class.
25-
/// </summary>
26-
/// <param name="fileFilter">The file filter By default null default to *.*</param>
27-
public DirectoryWatcher(string fileFilter = null)
28-
{
29-
FileFilter = fileFilter ?? "*.*";
30-
InitializeInternal();
31-
}
25+
FileFilter = fileFilter ?? "*.*";
26+
InitializeInternal();
27+
}
28+
29+
/// <summary>
30+
/// Gets the file filter used by this instance.
31+
/// </summary>
32+
/// <value>The file filter.</value>
33+
public string FileFilter { get; private set; }
3234

33-
/// <summary>
34-
/// Gets the file filter used by this instance.
35-
/// </summary>
36-
/// <value>The file filter.</value>
37-
public string FileFilter { get; private set; }
35+
/// <summary>
36+
/// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
37+
/// </summary>
38+
public void Dispose()
39+
{
40+
Dispose(true);
41+
GC.SuppressFinalize(this);
42+
}
3843

39-
/// <summary>
40-
/// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
41-
/// </summary>
42-
public virtual void Dispose()
44+
protected virtual void Dispose(bool disposing)
45+
{
46+
if (disposing)
4347
{
4448
exitThread = true;
4549
if (watcherCheckThread != null)
@@ -49,72 +53,72 @@ public virtual void Dispose()
4953
}
5054
DisposeInternal();
5155
}
56+
}
5257

53-
/// <summary>
54-
/// Gets a list of current directories being tracked.
55-
/// </summary>
56-
/// <returns>A list of current directories being tracked</returns>
57-
public List<string> GetTrackedDirectories()
58-
{
59-
return GetTrackedDirectoriesInternal();
60-
}
58+
/// <summary>
59+
/// Gets a list of current directories being tracked.
60+
/// </summary>
61+
/// <returns>A list of current directories being tracked</returns>
62+
public List<string> GetTrackedDirectories()
63+
{
64+
return GetTrackedDirectoriesInternal();
65+
}
6166

62-
/// <summary>
63-
/// Tracks the specified path.
64-
/// </summary>
65-
/// <param name="path">The path.</param>
66-
/// <remarks>
67-
/// If path is a file, this will used the parent directory. If the path is invalid, it will not fail but just skip it.
68-
/// </remarks>
69-
public void Track(string path)
70-
{
71-
TrackInternal(path);
72-
}
67+
/// <summary>
68+
/// Tracks the specified path.
69+
/// </summary>
70+
/// <param name="path">The path.</param>
71+
/// <remarks>
72+
/// If path is a file, this will used the parent directory. If the path is invalid, it will not fail but just skip it.
73+
/// </remarks>
74+
public void Track(string path)
75+
{
76+
TrackInternal(path);
77+
}
7378

74-
/// <summary>
75-
/// UnTracks the specified path.
76-
/// </summary>
77-
/// <remarks>
78-
/// If path is a file, this will used the parent directory. If the path is invalid, it will not fail but just skip it.
79-
/// </remarks>
80-
public void UnTrack(string path)
81-
{
82-
UnTrackInternal(path);
83-
}
79+
/// <summary>
80+
/// UnTracks the specified path.
81+
/// </summary>
82+
/// <remarks>
83+
/// If path is a file, this will used the parent directory. If the path is invalid, it will not fail but just skip it.
84+
/// </remarks>
85+
public void UnTrack(string path)
86+
{
87+
UnTrackInternal(path);
88+
}
8489

85-
/// <summary>
86-
/// Called when a file event occurred.
87-
/// </summary>
88-
/// <param name="sender">The sender.</param>
89-
/// <param name="e">The file event.</param>
90-
protected virtual void OnModified(object sender, FileEvent e)
91-
{
92-
Modified?.Invoke(sender, e);
93-
}
90+
/// <summary>
91+
/// Called when a file event occurred.
92+
/// </summary>
93+
/// <param name="sender">The sender.</param>
94+
/// <param name="e">The file event.</param>
95+
protected virtual void OnModified(object sender, FileEvent e)
96+
{
97+
Modified?.Invoke(sender, e);
98+
}
9499

95100
#if !STRIDE_PLATFORM_DESKTOP
96-
// Doesn't throw any exceptions on other platforms
101+
// Doesn't throw any exceptions on other platforms
97102

98-
private void InitializeInternal()
99-
{
100-
}
103+
private void InitializeInternal()
104+
{
105+
}
101106

102-
private void DisposeInternal()
103-
{
104-
}
107+
private void DisposeInternal()
108+
{
109+
}
105110

106-
private void TrackInternal(string path)
107-
{
108-
}
111+
private void TrackInternal(string path)
112+
{
113+
}
109114

110-
private void UnTrackInternal(string path)
111-
{
112-
}
115+
private void UnTrackInternal(string path)
116+
{
117+
}
113118

114-
private List<string> GetTrackedDirectoriesInternal()
115-
{
116-
return new List<string>();
117-
}
118-
#endif
119+
private List<string> GetTrackedDirectoriesInternal()
120+
{
121+
return new List<string>();
119122
}
123+
#endif
120124
}

0 commit comments

Comments
 (0)