1- using System . Threading . Tasks ;
2- using System . Threading ;
3-
41using ITHit . FileSystem ;
52using ITHit . FileSystem . Samples . Common . Windows ;
3+ using ITHit . FileSystem . Windows . Explorer ;
4+ using System ;
5+ using System . Collections . Concurrent ;
6+ using System . Collections . Generic ;
7+ using System . Threading ;
8+ using System . Threading . Tasks ;
69
710namespace VirtualDrive
811{
@@ -50,9 +53,48 @@ public override async Task<IFileSystemItem> GetFileSystemItemAsync(byte[] remote
5053 }
5154 }
5255
56+ private ConcurrentDictionary < string , DateTime > FoldersWithColumns = new ConcurrentDictionary < string , DateTime > ( ) ;
57+
58+ /// <summary>
59+ /// Updates Windows Explorer columns.
60+ /// This method is called when user navigates to a new folder or listing occures in Windows Explorer.
61+ /// </summary>
62+ /// <param name="sender"></param>
63+ /// <param name="path">Path for which navigation or listing occured.</param>
64+ private void UpdateExplorerColumns ( object sender , string path )
65+ {
66+ if ( string . IsNullOrWhiteSpace ( path ) )
67+ return ;
68+
69+ // Add columns only one time for each folder.
70+ if ( ! FoldersWithColumns . TryAdd ( path , DateTime . UtcNow ) )
71+ return ;
72+
73+ try
74+ {
75+ var allWindows = WindowsExplorer . GetExplorerWindows ( path ) ;
76+
77+ foreach ( var window in allWindows )
78+ {
79+ if ( window . TryAddColumns ( new [ ] { new ColumnListItem ( "System.FileAttributes" ) } ) . IsSuccess &&
80+ window . TrySetViewMode ( FolderViewMode . Details ) . IsSuccess )
81+ {
82+ window . TryRefresh ( ) ;
83+ }
84+ }
85+ }
86+ catch ( Exception ex )
87+ {
88+ Logger ? . LogError ( $ "Failed to update Explorer columns for path: { path } ", path , null , ex ) ;
89+ }
90+ }
91+
92+
5393 /// <inheritdoc/>
5494 public override async Task StartAsync ( bool processModified = true , CancellationToken cancellationToken = default )
5595 {
96+ WindowsExplorer . FolderNavigation += UpdateExplorerColumns ;
97+ WindowsExplorer . FolderListing += UpdateExplorerColumns ;
5698 await base . StartAsync ( processModified , cancellationToken ) ;
5799 await RemoteStorageMonitor . StartAsync ( ) ;
58100 }
@@ -62,6 +104,8 @@ public override async Task StopAsync()
62104 {
63105 await base . StopAsync ( ) ;
64106 await RemoteStorageMonitor . StopAsync ( ) ;
107+ WindowsExplorer . FolderNavigation -= UpdateExplorerColumns ;
108+ WindowsExplorer . FolderListing -= UpdateExplorerColumns ;
65109 }
66110
67111 private bool disposedValue ;
0 commit comments