Browse Source

Keep track of temp files and try to clean in QueryClose (if VS does not shut down cleanly obviously files will be left over)

pull/3205/head
Christoph Wille 1 year ago
parent
commit
d2221783ba
  1. 18
      ILSpy.AddIn.Shared/ILSpyAddInPackage.cs
  2. 8
      ILSpy.AddIn.Shared/ILSpyInstance.cs

18
ILSpy.AddIn.Shared/ILSpyAddInPackage.cs

@ -97,6 +97,24 @@ namespace ICSharpCode.ILSpy.AddIn @@ -97,6 +97,24 @@ namespace ICSharpCode.ILSpy.AddIn
OpenReferenceCommand.Register(this);
OpenCodeItemCommand.Register(this);
}
protected override int QueryClose(out bool canClose)
{
var tempFiles = ILSpyInstance.TempFiles;
while (tempFiles.TryPop(out var filename))
{
try
{
System.IO.File.Delete(filename);
}
catch (Exception)
{
}
}
return base.QueryClose(out canClose);
}
#endregion
public void ShowMessage(string format, params object[] items)

8
ILSpy.AddIn.Shared/ILSpyInstance.cs

@ -1,4 +1,5 @@ @@ -1,4 +1,5 @@
using System.Collections.Generic;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
@ -20,8 +21,9 @@ namespace ICSharpCode.ILSpy.AddIn @@ -20,8 +21,9 @@ namespace ICSharpCode.ILSpy.AddIn
class ILSpyInstance
{
readonly ILSpyParameters parameters;
internal static readonly ConcurrentStack<string> TempFiles = new ConcurrentStack<string>();
readonly ILSpyParameters parameters;
public ILSpyInstance(ILSpyParameters parameters = null)
{
this.parameters = parameters;
@ -55,6 +57,8 @@ namespace ICSharpCode.ILSpy.AddIn @@ -55,6 +57,8 @@ namespace ICSharpCode.ILSpy.AddIn
string filepath = Path.GetTempFileName();
File.WriteAllText(filepath, assemblyArguments);
TempFiles.Push(filepath);
argumentsToPass = $"@\"{filepath}\"";
}

Loading…
Cancel
Save