fix debug file watcher
This commit is contained in:
parent
a43ffc46f9
commit
bfc02d4f5a
|
@ -5,12 +5,11 @@
|
||||||
Public Class DebugFileWatcher
|
Public Class DebugFileWatcher
|
||||||
|
|
||||||
Private Shared _changedFiles As List(Of String)
|
Private Shared _changedFiles As List(Of String)
|
||||||
Private Shared _watchers As List(Of FileSystemWatcher)
|
Private Shared _watcher As FileSystemWatcher
|
||||||
Private Shared _isWatching As Boolean = False
|
Private Shared _isWatching As Boolean = False
|
||||||
|
|
||||||
Shared Sub New()
|
Shared Sub New()
|
||||||
_changedFiles = New List(Of String)()
|
_changedFiles = New List(Of String)()
|
||||||
_watchers = New List(Of FileSystemWatcher)()
|
|
||||||
End Sub
|
End Sub
|
||||||
|
|
||||||
Public Shared Sub TriggerReload()
|
Public Shared Sub TriggerReload()
|
||||||
|
@ -41,40 +40,42 @@ Public Class DebugFileWatcher
|
||||||
|
|
||||||
Dim projectPath = GetProjectPath()
|
Dim projectPath = GetProjectPath()
|
||||||
|
|
||||||
' MAPS
|
Dim contentPath = Path.Combine(projectPath, "Content")
|
||||||
Dim mapsPath = Path.Combine(projectPath, "Content\Data\maps")
|
_watcher = New FileSystemWatcher With {
|
||||||
Dim mapsWatcher = New FileSystemWatcher With {
|
.Path = contentPath,
|
||||||
.Path = mapsPath,
|
.NotifyFilter = NotifyFilters.LastWrite Or NotifyFilters.LastAccess,
|
||||||
.NotifyFilter = NotifyFilters.LastWrite,
|
|
||||||
.IncludeSubdirectories = True
|
.IncludeSubdirectories = True
|
||||||
}
|
}
|
||||||
|
|
||||||
AddHandler mapsWatcher.Changed, AddressOf OnChanged
|
AddHandler _watcher.Changed, AddressOf OnChanged
|
||||||
mapsWatcher.EnableRaisingEvents = True
|
_watcher.EnableRaisingEvents = True
|
||||||
|
|
||||||
_watchers.Add(mapsWatcher)
|
|
||||||
|
|
||||||
' SCRIPTS
|
|
||||||
Dim scriptsPath = Path.Combine(projectPath, "Content\Data\Scripts")
|
|
||||||
Dim scriptsWatcher = New FileSystemWatcher With {
|
|
||||||
.Path = scriptsPath,
|
|
||||||
.NotifyFilter = NotifyFilters.LastWrite,
|
|
||||||
.IncludeSubdirectories = True
|
|
||||||
}
|
|
||||||
|
|
||||||
AddHandler scriptsWatcher.Changed, AddressOf OnChanged
|
|
||||||
scriptsWatcher.EnableRaisingEvents = True
|
|
||||||
|
|
||||||
_watchers.Add(scriptsWatcher)
|
|
||||||
End If
|
End If
|
||||||
End Sub
|
End Sub
|
||||||
|
|
||||||
Private Shared Sub OnChanged(source As Object, e As FileSystemEventArgs)
|
Private Shared Sub OnChanged(source As Object, e As FileSystemEventArgs)
|
||||||
SyncLock _changedFiles
|
SyncLock _changedFiles
|
||||||
Dim file = e.FullPath
|
Dim file = e.FullPath
|
||||||
If Not _changedFiles.Contains(file) Then
|
' if files are edited with certain programs, FileSystemWatcher freaks out.
|
||||||
Logger.Debug("File changed: " + file)
|
' it replaces the filename with some random sequence of chars.
|
||||||
_changedFiles.Add(file)
|
If IO.File.Exists(file) Then
|
||||||
|
If Not _changedFiles.Contains(file) Then
|
||||||
|
Logger.Debug("File changed: " + file)
|
||||||
|
_changedFiles.Add(file)
|
||||||
|
End If
|
||||||
|
Else
|
||||||
|
' Distinct trait of these changes are that the filename ends with a tilde.
|
||||||
|
' only thing that can be done is watch the entire folder instead of just a single file...
|
||||||
|
If file.EndsWith("~") Then
|
||||||
|
Dim dir = Path.GetDirectoryName(file)
|
||||||
|
Logger.Debug("Single file can't be watched. Watch folder """ + dir + """ instead.")
|
||||||
|
For Each dirFile In Directory.GetFiles(dir)
|
||||||
|
If Not _changedFiles.Contains(dirFile) Then
|
||||||
|
Logger.Debug("File changed: " + dirFile)
|
||||||
|
_changedFiles.Add(dirFile)
|
||||||
|
End If
|
||||||
|
Next
|
||||||
|
End If
|
||||||
End If
|
End If
|
||||||
End SyncLock
|
End SyncLock
|
||||||
End Sub
|
End Sub
|
||||||
|
|
Loading…
Reference in New Issue