aboutsummaryrefslogtreecommitdiff
path: root/MediaBrowser.Common.Implementations/IO/CommonFileSystem.cs
diff options
context:
space:
mode:
authorLuke Pulverenti <luke.pulverenti@gmail.com>2013-12-19 16:51:32 -0500
committerLuke Pulverenti <luke.pulverenti@gmail.com>2013-12-19 16:51:32 -0500
commitcd859ac2e6d499ce2cdf531058e64a4c3402910f (patch)
treee453d21e99ef2d6aee7f5e4af668a69147b31dfd /MediaBrowser.Common.Implementations/IO/CommonFileSystem.cs
parente1e5d354345008e8d4ddc2dbbb99a68df4133280 (diff)
added IHasImages and IHasUserData
Diffstat (limited to 'MediaBrowser.Common.Implementations/IO/CommonFileSystem.cs')
-rw-r--r--MediaBrowser.Common.Implementations/IO/CommonFileSystem.cs42
1 files changed, 42 insertions, 0 deletions
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);
}
+
+ /// <summary>
+ /// Swaps the files.
+ /// </summary>
+ /// <param name="file1">The file1.</param>
+ /// <param name="file2">The file2.</param>
+ 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);
+ }
+
+ /// <summary>
+ /// Removes the hidden attribute.
+ /// </summary>
+ /// <param name="path">The path.</param>
+ 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;
+ }
+ }
+ }
}
/// <summary>