diff --git a/Duplicati/Library/Utility/TempFile.cs b/Duplicati/Library/Utility/TempFile.cs index 4031f4a63..2baaba334 100644 --- a/Duplicati/Library/Utility/TempFile.cs +++ b/Duplicati/Library/Utility/TempFile.cs @@ -28,9 +28,14 @@ namespace Duplicati.Library.Utility /// public class TempFile : IDisposable { + /// + /// The prefix applied to all temporary files + /// + public static string APPLICATION_PREFIX = System.Reflection.Assembly.GetEntryAssembly().FullName.Substring(0, 3).ToLower() + "-"; + private string m_path; private bool m_protect; - + #if DEBUG //In debug mode, we track the creation of temporary files, and encode the generating method into the name private static object m_lock = new object(); @@ -67,13 +72,32 @@ namespace Duplicati.Library.Utility m_fileTrace.Add(s, st); return s; } - + #else private static string GenerateUniqueName() { - return Guid.NewGuid().ToString(); + return APPLICATION_PREFIX + Guid.NewGuid().ToString(); } #endif + + /// + /// Gets all temporary files found in the current tempdir, that matches the application prefix + /// + /// The application temp files. + public static IEnumerable GetApplicationTempFiles() + { + return System.IO.Directory.GetFiles(TempFolder.SystemTempPath, APPLICATION_PREFIX + "*"); + } + + /// + /// Attempts to delete all temporary files for this application + /// + public static void RemoveAllApplicationTempFiles() + { + foreach(var s in GetApplicationTempFiles()) + try { System.IO.File.Delete(s); } + catch { } + } public TempFile() : this(System.IO.Path.Combine(TempFolder.SystemTempPath, GenerateUniqueName()))