diff options
| author | Luke Pulverenti <luke.pulverenti@gmail.com> | 2016-11-09 12:24:57 -0500 |
|---|---|---|
| committer | Luke Pulverenti <luke.pulverenti@gmail.com> | 2016-11-09 12:24:57 -0500 |
| commit | 48a5fa17b034947669d7ce0e81cbe599f628acf9 (patch) | |
| tree | 12aa6b0ef59ab7086f938026b86cc2bac1c88676 /Emby.Common.Implementations/IO/ManagedFileSystem.cs | |
| parent | 24532f3e2d7de2542b664383c5e0bc0cce61d7fc (diff) | |
update file saving
Diffstat (limited to 'Emby.Common.Implementations/IO/ManagedFileSystem.cs')
| -rw-r--r-- | Emby.Common.Implementations/IO/ManagedFileSystem.cs | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/Emby.Common.Implementations/IO/ManagedFileSystem.cs b/Emby.Common.Implementations/IO/ManagedFileSystem.cs index 5b965efdc..37b457598 100644 --- a/Emby.Common.Implementations/IO/ManagedFileSystem.cs +++ b/Emby.Common.Implementations/IO/ManagedFileSystem.cs @@ -419,6 +419,25 @@ namespace Emby.Common.Implementations.IO } } + public void SetReadOnly(string path, bool isReadOnly) + { + var info = GetFileInfo(path); + + if (info.Exists && info.IsReadOnly != isReadOnly) + { + if (isReadOnly) + { + File.SetAttributes(path, File.GetAttributes(path) | FileAttributes.ReadOnly); + } + else + { + FileAttributes attributes = File.GetAttributes(path); + attributes = RemoveAttribute(attributes, FileAttributes.ReadOnly); + File.SetAttributes(path, attributes); + } + } + } + private static FileAttributes RemoveAttribute(FileAttributes attributes, FileAttributes attributesToRemove) { return attributes & ~attributesToRemove; @@ -564,6 +583,20 @@ namespace Emby.Common.Implementations.IO public void DeleteFile(string path) { + var fileInfo = GetFileInfo(path); + + if (fileInfo.Exists) + { + if (fileInfo.IsHidden) + { + SetHidden(path, false); + } + if (fileInfo.IsReadOnly) + { + SetReadOnly(path, false); + } + } + File.Delete(path); } |
