diff options
| author | Luke Pulverenti <luke.pulverenti@gmail.com> | 2017-05-12 00:54:19 -0400 |
|---|---|---|
| committer | Luke Pulverenti <luke.pulverenti@gmail.com> | 2017-05-12 00:54:19 -0400 |
| commit | 1991da85af51b8500d84d60c1b4c5b42ac0eb923 (patch) | |
| tree | 4f3d83fba518126817dc40c2c19c7716285b3f70 /Emby.Common.Implementations/IO/ManagedFileSystem.cs | |
| parent | fa132ada88973c540e99ff178c4a5ae42d40c753 (diff) | |
update setting of file attributes
Diffstat (limited to 'Emby.Common.Implementations/IO/ManagedFileSystem.cs')
| -rw-r--r-- | Emby.Common.Implementations/IO/ManagedFileSystem.cs | 58 |
1 files changed, 44 insertions, 14 deletions
diff --git a/Emby.Common.Implementations/IO/ManagedFileSystem.cs b/Emby.Common.Implementations/IO/ManagedFileSystem.cs index 6cbf39758..7d14e521f 100644 --- a/Emby.Common.Implementations/IO/ManagedFileSystem.cs +++ b/Emby.Common.Implementations/IO/ManagedFileSystem.cs @@ -518,6 +518,49 @@ namespace Emby.Common.Implementations.IO } } + public void SetAttributes(string path, bool isHidden, bool isReadOnly) + { + if (_sharpCifsFileSystem.IsEnabledForPath(path)) + { + _sharpCifsFileSystem.SetAttributes(path, isHidden, isReadOnly); + return; + } + + var info = GetFileInfo(path); + + if (!info.Exists) + { + return; + } + + if (info.IsReadOnly == isReadOnly && info.IsHidden == isHidden) + { + return; + } + + var attributes = File.GetAttributes(path); + + if (isReadOnly) + { + attributes = attributes | FileAttributes.ReadOnly; + } + else + { + attributes = RemoveAttribute(attributes, FileAttributes.ReadOnly); + } + + if (isHidden) + { + attributes = attributes | FileAttributes.Hidden; + } + else + { + attributes = RemoveAttribute(attributes, FileAttributes.Hidden); + } + + File.SetAttributes(path, attributes); + } + private static FileAttributes RemoveAttribute(FileAttributes attributes, FileAttributes attributesToRemove) { return attributes & ~attributesToRemove; @@ -690,20 +733,7 @@ namespace Emby.Common.Implementations.IO return; } - var fileInfo = GetFileInfo(path); - - if (fileInfo.Exists) - { - if (fileInfo.IsHidden) - { - SetHidden(path, false); - } - if (fileInfo.IsReadOnly) - { - SetReadOnly(path, false); - } - } - + SetAttributes(path, false, false); File.Delete(path); } |
