Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
Alois-xx committed Jan 21, 2022
2 parents b8971eb + 7f9a103 commit 0585b1a
Showing 1 changed file with 26 additions and 23 deletions.
49 changes: 26 additions & 23 deletions ETWController/Screenshots/ScreenshotRecorder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,34 +91,37 @@ private ImageCodecInfo GetEncoder(ImageFormat format)

internal static void ClearFiles(string screenshotDirectory, int keepNewestNFiles=0)
{
// Delete old files from previous runs
foreach (var jpg in Directory.GetFiles(screenshotDirectory, "*.jpg")
.Select(x=> new FileInfo(x))
.OrderByDescending(x=>x.CreationTime)
.Skip(keepNewestNFiles))
if (Directory.Exists(screenshotDirectory))
{
try
// Delete old files from previous runs
foreach (var jpg in Directory.GetFiles(screenshotDirectory, "*.jpg")
.Select(x => new FileInfo(x))
.OrderByDescending(x => x.CreationTime)
.Skip(keepNewestNFiles))
{
File.Delete(jpg.FullName);
}
catch (Exception ex)
{
Trace.TraceError($"Could not delete screenshot file {jpg} because of {ex}");
try
{
File.Delete(jpg.FullName);
}
catch (Exception ex)
{
Trace.TraceError($"Could not delete screenshot file {jpg} because of {ex}");
}
}
}

// Ensure that all files in screenshot directory are deleted so no old remanents
// are kept in newere traces if screenshot capture is turned off
string report = Path.Combine(screenshotDirectory, HtmlReportGenerator.HtmlReportFileName);
if (File.Exists(report))
{
try
{
File.Delete(report);
}
catch (Exception ex)
// Ensure that all files in screenshot directory are deleted so no old remanents
// are kept in newere traces if screenshot capture is turned off
string report = Path.Combine(screenshotDirectory, HtmlReportGenerator.HtmlReportFileName);
if (File.Exists(report))
{
Trace.TraceError($"Could not delete report file {report} because of {ex}");
try
{
File.Delete(report);
}
catch (Exception ex)
{
Trace.TraceError($"Could not delete report file {report} because of {ex}");
}
}
}
}
Expand Down

0 comments on commit 0585b1a

Please sign in to comment.