From cd859ac2e6d499ce2cdf531058e64a4c3402910f Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Thu, 19 Dec 2013 16:51:32 -0500 Subject: added IHasImages and IHasUserData --- .../IO/CommonFileSystem.cs | 42 ++++++++++++++++++++++ 1 file changed, 42 insertions(+) (limited to 'MediaBrowser.Common.Implementations/IO/CommonFileSystem.cs') diff --git a/MediaBrowser.Common.Implementations/IO/CommonFileSystem.cs b/MediaBrowser.Common.Implementations/IO/CommonFileSystem.cs index ed9baf3b2..616981d50 100644 --- a/MediaBrowser.Common.Implementations/IO/CommonFileSystem.cs +++ b/MediaBrowser.Common.Implementations/IO/CommonFileSystem.cs @@ -216,6 +216,48 @@ namespace MediaBrowser.Common.Implementations.IO return new FileStream(path, mode, access, share); } + + /// + /// Swaps the files. + /// + /// The file1. + /// The file2. + public void SwapFiles(string file1, string file2) + { + var temp1 = Path.GetTempFileName(); + var temp2 = Path.GetTempFileName(); + + // Copying over will fail against hidden files + RemoveHiddenAttribute(file1); + RemoveHiddenAttribute(file2); + + File.Copy(file1, temp1, true); + File.Copy(file2, temp2, true); + + File.Copy(temp1, file2, true); + File.Copy(temp2, file1, true); + + File.Delete(temp1); + File.Delete(temp2); + } + + /// + /// Removes the hidden attribute. + /// + /// The path. + private void RemoveHiddenAttribute(string path) + { + var currentFile = new FileInfo(path); + + // This will fail if the file is hidden + if (currentFile.Exists) + { + if ((currentFile.Attributes & FileAttributes.Hidden) == FileAttributes.Hidden) + { + currentFile.Attributes &= ~FileAttributes.Hidden; + } + } + } } /// -- cgit v1.2.3