3 #if SILICONSTUDIO_PLATFORM_WINDOWS_DESKTOP
5 using System.Diagnostics;
8 namespace SiliconStudio.Core.IO
10 public class TemporaryDirectory : IDisposable
12 private readonly
string directoryPath;
14 public TemporaryDirectory()
15 : this(Guid.NewGuid().ToString().Substring(0, 8))
19 public TemporaryDirectory(
string path)
21 this.directoryPath = Path.GetFullPath(path);
23 if (Directory.Exists(
this.directoryPath))
25 throw new InvalidOperationException(
string.Format(
"Directory {0} already exists.", path));
28 Directory.CreateDirectory(this.directoryPath);
31 public string DirectoryPath
33 get {
return directoryPath; }
38 DeleteDirectory(directoryPath);
41 public static void DeleteDirectory(
string directoryPath)
45 if (!Directory.Exists(directoryPath))
48 string.Format(
"Directory '{0}' is missing and can't be removed.",
54 string[] files = Directory.GetFiles(directoryPath);
55 string[] dirs = Directory.GetDirectories(directoryPath);
57 foreach (
string file
in files)
59 File.SetAttributes(file, FileAttributes.Normal);
63 foreach (
string dir
in dirs)
70 File.SetAttributes(directoryPath, FileAttributes.Normal);
71 Directory.Delete(directoryPath,
false);
75 Trace.WriteLine(string.Format(
"{0}The directory '{1}' could not be deleted!" +
76 "{0}Most of the time, this is due to an external process accessing the files in the temporary repositories created during the test runs, and keeping a handle on the directory, thus preventing the deletion of those files." +
77 "{0}Known and common causes include:" +
78 "{0}- Windows Search Indexer (go to the Indexing Options, in the Windows Control Panel, and exclude the bin folder of LibGit2Sharp.Tests)" +
79 "{0}- Antivirus (exclude the bin folder of LibGit2Sharp.Tests from the paths scanned by your real-time antivirus){0}",
80 Environment.NewLine, Path.GetFullPath(directoryPath)));