Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/ManagedShell.ShellFolders/ChangeWatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public ChangeWatcher(List<string> pathList, FileSystemEventHandler changedEventH
{
FileSystemWatcher watcher = new FileSystemWatcher(path)
{
NotifyFilter = NotifyFilters.DirectoryName | NotifyFilters.FileName | NotifyFilters.LastWrite | NotifyFilters.Size
NotifyFilter = NotifyFilters.Attributes | NotifyFilters.DirectoryName | NotifyFilters.FileName | NotifyFilters.LastWrite | NotifyFilters.Size
};

watcher.Changed += _changedEventHandler;
Expand Down
33 changes: 29 additions & 4 deletions src/ManagedShell.ShellFolders/ShellFolder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -257,13 +257,21 @@ private void ChangedEventHandler(object sender, FileSystemEventArgs e)
if (file.Path == e.FullPath)
{
exists = true;
file.Refresh();

if (FileIsHidden(file.Path))
{
RemoveFile(file.Path);
}
else
{
file.Refresh();
}

break;
}
}

if (!exists)
if (!exists && !FileIsHidden(e.FullPath))
{
AddFile(e.FullPath);
}
Expand All @@ -276,7 +284,7 @@ private void CreatedEventHandler(object sender, FileSystemEventArgs e)
{
ShellLogger.Info($"ShellFolder: Item {e.ChangeType}: {e.Name} ({e.FullPath})");

if (!FileExists(e.FullPath))
if (!FileExists(e.FullPath) && !FileIsHidden(e.FullPath))
{
AddFile(e.FullPath);
}
Expand All @@ -301,7 +309,7 @@ private void RenamedEventHandler(object sender, RenamedEventArgs e)

int existing = RemoveFile(e.OldFullPath);

if (!FileExists(e.FullPath))
if (!FileExists(e.FullPath) && !FileIsHidden(e.FullPath))
{
AddFile(e.FullPath, existing);
}
Expand Down Expand Up @@ -405,6 +413,23 @@ private bool FileExists(string parsingName)

return exists;
}

private bool FileIsHidden(string parsingName)
{
try
{
FileAttributes attributes = File.GetAttributes(parsingName);
if ((attributes & FileAttributes.Hidden) == FileAttributes.Hidden)
{
return true;
}
}
catch (Exception ex)
{
ShellLogger.Warning($"ShellFolder: Unable to retrieve attributes for {parsingName}: {ex.Message}");
}
return false;
}
#endregion

public new void Dispose()
Expand Down