Skip to content

Commit

Permalink
Fix for file system watcher adding files when including subdirectories
Browse files Browse the repository at this point in the history
  • Loading branch information
Ruben2776 committed Dec 7, 2024
1 parent 69616c1 commit cecacff
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
7 changes: 5 additions & 2 deletions src/PicView.Avalonia/Navigation/ImageIterator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,10 @@ private async Task OnFileAdded(FileSystemEventArgs e)
}

IsRunning = true;

var sourceFileInfo = SettingsHelper.Settings.Sorting.IncludeSubDirectories ? new FileInfo(_watcher.Path) : fileInfo;

var newList = await Task.FromResult(_vm.PlatformService.GetFiles(fileInfo));
var newList = await Task.FromResult(_vm.PlatformService.GetFiles(sourceFileInfo));
if (newList.Count == 0)
{
return;
Expand Down Expand Up @@ -268,7 +270,8 @@ private async Task OnFileRenamed(RenamedEventArgs e)
return;
}

var newList = FileListHelper.RetrieveFiles(fileInfo).ToList();
var sourceFileInfo = SettingsHelper.Settings.Sorting.IncludeSubDirectories ? new FileInfo(_watcher.Path) : fileInfo;
var newList = FileListHelper.RetrieveFiles(sourceFileInfo).ToList();
if (newList.Count == 0)
{
return;
Expand Down
19 changes: 14 additions & 5 deletions src/PicView.Avalonia/Navigation/Preloader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -135,15 +135,24 @@ public async Task<bool> RefreshFileInfo(int index, List<string> list)

public void RefreshAllFileInfo(List<string> list)
{
foreach (var item in _preLoadList)
try
{
if (item.Value is null) continue;
var fileInfo = new FileInfo(list[item.Key]);
if (item.Value.ImageModel != null)
foreach (var item in _preLoadList)
{
item.Value.ImageModel.FileInfo = fileInfo;
if (item.Value is null) continue;
var fileInfo = new FileInfo(list[item.Key]);
if (item.Value.ImageModel != null)
{
item.Value.ImageModel.FileInfo = fileInfo;
}
}
}
catch (Exception e)
{
#if DEBUG
Trace.WriteLine($"{nameof(PreLoader)}.{nameof(RefreshAllFileInfo)} \n{e.Message}");
#endif
}
}

/// <summary>
Expand Down

0 comments on commit cecacff

Please sign in to comment.