Skip to content

Commit

Permalink
Old firmware files are now cleaned up.
Browse files Browse the repository at this point in the history
  • Loading branch information
shane-powell committed Jan 5, 2021
1 parent a407fc7 commit 7b20ca4
Showing 1 changed file with 32 additions and 4 deletions.
36 changes: 32 additions & 4 deletions ViewModels/AppViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ public enum FlashTool

private readonly string dfuPath = @$"{Environment.CurrentDirectory}\bin\firmware.dfu";

private readonly string unzipFolderPath = @$"{Environment.CurrentDirectory}\bin";

private readonly List<string> possibleDfuseLocations = new List<string>() { $@"{Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86)}\STMicroelectronics\Software\", $@"{Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles)}\STMicroelectronics\Software\" };

private bool dfuseFound = false;
Expand Down Expand Up @@ -204,6 +206,8 @@ public AppViewModel()

this.commandLineTools = new CommandLineTools(this.ProcessCommandLineMessage, null);

this.CleanUpFirmwareFiles();

//GetLatestFirmwareAsync();
GetAllFirmwareAsync();
}
Expand Down Expand Up @@ -262,10 +266,7 @@ private void FlashFirmware(object obj)

private void DownloadFirmware(object obj)
{
if (File.Exists(DownloadPath))
{
File.Delete(DownloadPath);
}
CleanUpFirmwareFiles();

if (this.targetAsset != null)
{
Expand All @@ -276,6 +277,33 @@ private void DownloadFirmware(object obj)
}
}

private void CleanUpFirmwareFiles()
{
if (File.Exists(DownloadPath))
{
try
{
File.Delete(DownloadPath);
}
catch (Exception e)
{
MessageBox.Show("Unable to clear old firmware download. Are the file(s) in use?");
}
}

if (Directory.Exists(unzipFolderPath))
{
try
{
Directory.Delete(unzipFolderPath, true);
}
catch (Exception e)
{
MessageBox.Show("Unable to clear old firmware download. Are the file(s) in use?");
}
}
}

private async Task GetLatestFirmwareAsync()
{
this.InterfaceEnabled = false;
Expand Down

0 comments on commit 7b20ca4

Please sign in to comment.