Skip to content

Commit

Permalink
Keep track of temp files and try to clean in QueryClose (if VS does n…
Browse files Browse the repository at this point in the history
…ot shut down cleanly obviously files will be left over)
  • Loading branch information
christophwille committed May 12, 2024
1 parent 6762dd6 commit d222178
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
18 changes: 18 additions & 0 deletions ILSpy.AddIn.Shared/ILSpyAddInPackage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,24 @@ protected override async Task InitializeAsync(CancellationToken cancellationToke
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)
Expand Down
8 changes: 6 additions & 2 deletions ILSpy.AddIn.Shared/ILSpyInstance.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -20,8 +21,9 @@ public ILSpyParameters(IEnumerable<string> assemblyFileNames, params string[] ar

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;
Expand Down Expand Up @@ -55,6 +57,8 @@ public void Start()
string filepath = Path.GetTempFileName();
File.WriteAllText(filepath, assemblyArguments);

TempFiles.Push(filepath);

argumentsToPass = $"@\"{filepath}\"";
}

Expand Down

0 comments on commit d222178

Please sign in to comment.