@@ -1714,8 +1714,10 @@ private void WatchForDirectoryChanges(string path, CloudDriveSyncStatus syncStat
1714
1714
return ;
1715
1715
}
1716
1716
1717
+ var hasSyncStatus = syncStatus != CloudDriveSyncStatus . NotSynced && syncStatus != CloudDriveSyncStatus . Unknown ;
1718
+
1717
1719
var cts = new CancellationTokenSource ( ) ;
1718
- _ = Windows . System . Threading . ThreadPool . RunAsync ( ( x ) => ProcessOperationQueue ( cts . Token ) ) ;
1720
+ _ = Windows . System . Threading . ThreadPool . RunAsync ( ( x ) => ProcessOperationQueue ( cts . Token , hasSyncStatus ) ) ;
1719
1721
1720
1722
aWatcherAction = Windows . System . Threading . ThreadPool . RunAsync ( ( x ) =>
1721
1723
{
@@ -1724,7 +1726,7 @@ private void WatchForDirectoryChanges(string path, CloudDriveSyncStatus syncStat
1724
1726
buff = new byte [ 4096 ] ;
1725
1727
int notifyFilters = FILE_NOTIFY_CHANGE_DIR_NAME | FILE_NOTIFY_CHANGE_FILE_NAME | FILE_NOTIFY_CHANGE_LAST_WRITE | FILE_NOTIFY_CHANGE_SIZE ;
1726
1728
1727
- if ( syncStatus != CloudDriveSyncStatus . NotSynced && syncStatus != CloudDriveSyncStatus . Unknown )
1729
+ if ( hasSyncStatus )
1728
1730
{
1729
1731
notifyFilters |= FILE_NOTIFY_CHANGE_ATTRIBUTES ;
1730
1732
}
@@ -1804,7 +1806,7 @@ private void WatchForDirectoryChanges(string path, CloudDriveSyncStatus syncStat
1804
1806
Debug . WriteLine ( "Task exiting..." ) ;
1805
1807
}
1806
1808
1807
- private async void ProcessOperationQueue ( CancellationToken cancellationToken )
1809
+ private async void ProcessOperationQueue ( CancellationToken cancellationToken , bool hasSyncStatus )
1808
1810
{
1809
1811
ApplicationDataContainer localSettings = ApplicationData . Current . LocalSettings ;
1810
1812
string returnformat = Enum . Parse < TimeStyle > ( localSettings . Values [ Constants . LocalSettings . DateTimeFormat ] . ToString ( ) ) == TimeStyle . Application ? "D" : "g" ;
@@ -1816,6 +1818,7 @@ private async void ProcessOperationQueue(CancellationToken cancellationToken)
1816
1818
const uint FILE_ACTION_RENAMED_NEW_NAME = 0x00000005 ;
1817
1819
1818
1820
var sampler = new IntervalSampler ( 200 ) ;
1821
+ var updateList = new HashSet < string > ( ) ;
1819
1822
bool anyEdits = false ;
1820
1823
1821
1824
try
@@ -1825,6 +1828,8 @@ private async void ProcessOperationQueue(CancellationToken cancellationToken)
1825
1828
if ( operationEvent . Wait ( 200 , cancellationToken ) )
1826
1829
{
1827
1830
operationEvent . Reset ( ) ;
1831
+
1832
+
1828
1833
while ( operationQueue . TryDequeue ( out var operation ) )
1829
1834
{
1830
1835
if ( cancellationToken . IsCancellationRequested ) break ;
@@ -1839,7 +1844,7 @@ private async void ProcessOperationQueue(CancellationToken cancellationToken)
1839
1844
break ;
1840
1845
1841
1846
case FILE_ACTION_MODIFIED :
1842
- await UpdateFileOrFolderAsync ( operation . FileName ) ;
1847
+ updateList . Add ( operation . FileName ) ;
1843
1848
break ;
1844
1849
1845
1850
case FILE_ACTION_REMOVED :
@@ -1861,9 +1866,20 @@ private async void ProcessOperationQueue(CancellationToken cancellationToken)
1861
1866
anyEdits = false ;
1862
1867
}
1863
1868
}
1869
+
1870
+ foreach ( var entry in updateList . ToList ( ) )
1871
+ {
1872
+ await UpdateFileOrFolderAsync ( entry , hasSyncStatus ) ;
1873
+ updateList . Remove ( entry ) ;
1874
+
1875
+ if ( sampler . CheckNow ( ) && operationQueue . Any ( i => i . Action != FILE_ACTION_MODIFIED ) )
1876
+ {
1877
+ break ;
1878
+ }
1879
+ }
1864
1880
}
1865
1881
1866
- if ( anyEdits && sampler . CheckNow ( ) )
1882
+ if ( anyEdits )
1867
1883
{
1868
1884
await OrderFilesAndFoldersAsync ( ) ;
1869
1885
await ApplyFilesAndFoldersChangesAsync ( ) ;
@@ -1959,26 +1975,22 @@ public ListedItem AddFileOrFolderFromShellFile(ShellFileItem item, string dateRe
1959
1975
1960
1976
private async Task AddFileOrFolderAsync ( ListedItem item )
1961
1977
{
1962
- try
1963
- {
1964
- await enumFolderSemaphore . WaitAsync ( semaphoreCTS . Token ) ;
1965
- }
1966
- catch ( OperationCanceledException )
1978
+ if ( item == null )
1967
1979
{
1968
1980
return ;
1969
1981
}
1970
1982
1971
1983
try
1972
1984
{
1973
- if ( item != null )
1974
- {
1975
- filesAndFolders . Add ( item ) ;
1976
- }
1985
+ await enumFolderSemaphore . WaitAsync ( semaphoreCTS . Token ) ;
1977
1986
}
1978
- finally
1987
+ catch ( OperationCanceledException )
1979
1988
{
1980
- enumFolderSemaphore . Release ( ) ;
1989
+ return ;
1981
1990
}
1991
+
1992
+ filesAndFolders . Add ( item ) ;
1993
+ enumFolderSemaphore . Release ( ) ;
1982
1994
}
1983
1995
1984
1996
private async Task AddFileOrFolderAsync ( string fileOrFolderPath , string dateReturnFormat )
@@ -2015,13 +2027,10 @@ private async Task AddFileOrFolderAsync(string fileOrFolderPath, string dateRetu
2015
2027
listedItem = await Win32StorageEnumerator . GetFile ( findData , Directory . GetParent ( fileOrFolderPath ) . FullName , dateReturnFormat , Connection , addFilesCTS . Token ) ;
2016
2028
}
2017
2029
2018
- if ( listedItem != null )
2019
- {
2020
- filesAndFolders . Add ( listedItem ) ;
2021
- }
2030
+ await AddFileOrFolderAsync ( listedItem ) ;
2022
2031
}
2023
2032
2024
- private async Task UpdateFileOrFolderAsync ( ListedItem item )
2033
+ private async Task UpdateFileOrFolderAsync ( ListedItem item , bool hasSyncStatus = false )
2025
2034
{
2026
2035
IStorageItem storageItem = null ;
2027
2036
if ( item . PrimaryItemAttribute == StorageItemTypes . File )
@@ -2034,10 +2043,13 @@ private async Task UpdateFileOrFolderAsync(ListedItem item)
2034
2043
}
2035
2044
if ( storageItem != null )
2036
2045
{
2037
- var syncStatus = await CheckCloudDriveSyncStatusAsync ( storageItem ) ;
2046
+ var syncStatus = hasSyncStatus ? await CheckCloudDriveSyncStatusAsync ( storageItem ) : CloudDriveSyncStatus . NotSynced ;
2038
2047
await CoreApplication . MainView . DispatcherQueue . EnqueueAsync ( async ( ) =>
2039
2048
{
2040
- item . SyncStatusUI = CloudDriveSyncStatusUI . FromCloudDriveSyncStatus ( syncStatus ) ;
2049
+ if ( hasSyncStatus )
2050
+ {
2051
+ item . SyncStatusUI = CloudDriveSyncStatusUI . FromCloudDriveSyncStatus ( syncStatus ) ;
2052
+ }
2041
2053
2042
2054
if ( storageItem . IsOfType ( StorageItemTypes . File ) )
2043
2055
{
@@ -2057,7 +2069,7 @@ await CoreApplication.MainView.DispatcherQueue.EnqueueAsync(async () =>
2057
2069
}
2058
2070
}
2059
2071
2060
- private async Task UpdateFileOrFolderAsync ( string path )
2072
+ private async Task UpdateFileOrFolderAsync ( string path , bool hasSyncStatus = false )
2061
2073
{
2062
2074
try
2063
2075
{
@@ -2074,7 +2086,7 @@ private async Task UpdateFileOrFolderAsync(string path)
2074
2086
2075
2087
if ( matchingItem != null )
2076
2088
{
2077
- await UpdateFileOrFolderAsync ( matchingItem ) ;
2089
+ await UpdateFileOrFolderAsync ( matchingItem , hasSyncStatus ) ;
2078
2090
}
2079
2091
}
2080
2092
finally
0 commit comments