@@ -78,6 +78,9 @@ internal static async Task<uint> CreateAsync(string userFileSystemParentPath, Fi
7878 {
7979 string userFileSystemItemPath = Path . Combine ( userFileSystemParentPath , child . Name ) ;
8080 await ETag . SetETagAsync ( userFileSystemItemPath , child . ETag ) ;
81+
82+ // Set the lock icon and read-only attribute, to indicate that the item is locked by another user.
83+ await new UserFileSystemRawItem ( userFileSystemItemPath ) . SetLockedByAnotherUserAsync ( child . LockedByAnotherUser ) ;
8184 }
8285
8386 return created ;
@@ -113,14 +116,23 @@ internal async Task<bool> UpdateAsync(FileSystemItemBasicInfo itemInfo)
113116 {
114117 PlaceholderItem placeholderItem = PlaceholderItem . GetItem ( userFileSystemPath ) ;
115118
119+ // To be able to update the item we need to remove the read-only attribute.
120+ if ( ( FsPath . GetFileSystemItem ( userFileSystemPath ) . Attributes | System . IO . FileAttributes . ReadOnly ) != 0 )
121+ {
122+ FsPath . GetFileSystemItem ( userFileSystemPath ) . Attributes &= ~ System . IO . FileAttributes . ReadOnly ;
123+ }
124+
116125 // Dehydrate/hydrate the file, update file size, custom data, creation date, modification date, attributes.
117126 placeholderItem . SetItemInfo ( itemInfo ) ;
118127
119128 // Set ETag.
120129 await ETag . SetETagAsync ( userFileSystemPath , itemInfo . ETag ) ;
121130
122131 // Clear icon.
123- await ClearStateAsync ( ) ;
132+ //await ClearStateAsync();
133+
134+ // Set the lock icon and read-only attribute, to indicate that the item is locked by another user.
135+ await SetLockedByAnotherUserAsync ( itemInfo . LockedByAnotherUser ) ;
124136
125137 return true ;
126138 }
@@ -377,6 +389,15 @@ internal async Task SetLockPendingIconAsync(bool set)
377389 await SetIconAsync ( set , 2 , "LockedPending.ico" , "Updating lock..." ) ;
378390 }
379391
392+ /// <summary>
393+ /// Sets or removes "Locked another another user" icon.
394+ /// </summary>
395+ /// <param name="set">True to display the icon. False - to remove the icon.</param>
396+ private async Task SetLockedByAnotherUserIconAsync ( bool set )
397+ {
398+ await SetIconAsync ( set , 2 , "LockedByAnotherUser.ico" , "The item is locked by another user" ) ;
399+ }
400+
380401 /// <summary>
381402 /// Sets or removes icon.
382403 /// </summary>
@@ -430,5 +451,40 @@ private async Task SetIconAsync(bool set, int? id = null, string iconFile = null
430451 }
431452 }
432453 }
454+
455+ /// <summary>
456+ /// Sets or removes "Locked another another user" icon and read-only attribute on files.
457+ /// </summary>
458+ /// <param name="set">True to display the icon and read-only attribute. False - to remove the icon and read-only attribute.</param>
459+ internal async Task SetLockedByAnotherUserAsync ( bool set )
460+ {
461+ // Can not set icon on read-only files.
462+ // Changing read-only attribute on folders triggers folders listing. Changing it on files only.
463+
464+ if ( FsPath . IsFile ( userFileSystemPath ) )
465+ {
466+ FileInfo file = new FileInfo ( userFileSystemPath ) ;
467+ if ( set != file . IsReadOnly )
468+ {
469+ // Remove read-only attribute.
470+ new FileInfo ( userFileSystemPath ) . Attributes &= ~ System . IO . FileAttributes . ReadOnly ;
471+
472+ // Update the lock icon, to indicate that the item is locked by another user.
473+ await SetLockedByAnotherUserIconAsync ( set ) ;
474+
475+ // Set read-only attribute.
476+ if ( set )
477+ {
478+ new FileInfo ( userFileSystemPath ) . Attributes |= System . IO . FileAttributes . ReadOnly ;
479+ }
480+ }
481+ }
482+ else
483+ {
484+ // Update the lock icon, to indicate that the item is locked by another user.
485+ await SetLockedByAnotherUserIconAsync ( set ) ;
486+ }
487+ }
488+
433489 }
434490}
0 commit comments