diff --git a/nanoFirmwareFlasher.Library/JLinkCli.cs b/nanoFirmwareFlasher.Library/JLinkCli.cs index 3a1b8503..d2453f85 100644 --- a/nanoFirmwareFlasher.Library/JLinkCli.cs +++ b/nanoFirmwareFlasher.Library/JLinkCli.cs @@ -280,47 +280,18 @@ public ExitCodes ExecuteFlashBinFiles( Console.ForegroundColor = ConsoleColor.White; - return ExitCodes.OK; - } - - private ExitCodes ProcessFilePaths(IList files, List shadowFiles) - { - // J-Link can't handle diacritc chars - // developer note: reported to Segger (Case: 60276735) and can be removed if this is fixed/improved - foreach (string binFile in files) + // be nice and clean up shadow files + try { - // make sure path is absolute - var binFilePath = Utilities.MakePathAbsolute( - Environment.CurrentDirectory, - binFile); - - // check file existence - if (!File.Exists(binFilePath)) + foreach (string shadowFile in shadowFiles) { - return ExitCodes.E5004; - } - - if (!binFilePath.IsNormalized(NormalizationForm.FormD) - || binFilePath.Contains(' ')) - { - var tempFile = Path.Combine( - Environment.GetEnvironmentVariable("TEMP", EnvironmentVariableTarget.Machine), - Path.GetFileName(binFilePath)); - - // copy file to shadow file - File.Copy( - binFilePath, - tempFile, - true); - - shadowFiles.Add(tempFile); - } - else - { - // copy file to shadow list - shadowFiles.Add(binFile); + File.Delete(shadowFile); } } + catch (Exception) + { + // ignore any exception here + } return ExitCodes.OK; } @@ -450,10 +421,23 @@ public ExitCodes ExecuteFlashHexFiles( Console.ForegroundColor = ConsoleColor.White; + // be nice and clean up shadow files + try + { + foreach (string shadowFile in shadowFiles) + { + File.Delete(shadowFile); + } + } + catch (Exception) + { + // ignore any exception here + } + return ExitCodes.OK; } - public void ShowCLIOutput(string cliOutput) + internal void ShowCLIOutput(string cliOutput) { // show CLI output, if verbosity is diagnostic if (Verbosity == VerbosityLevel.Diagnostic) @@ -536,5 +520,47 @@ internal static string RunJLinkCLI(string cmdFile, string arguments = null) return jlinkCli.StandardOutput.ReadToEnd(); } + + private ExitCodes ProcessFilePaths(IList files, List shadowFiles) + { + // J-Link can't handle diacritc chars + // developer note: reported to Segger (Case: 60276735) and can be removed if this is fixed/improved + foreach (string binFile in files) + { + // make sure path is absolute + var binFilePath = Utilities.MakePathAbsolute( + Environment.CurrentDirectory, + binFile); + + // check file existence + if (!File.Exists(binFilePath)) + { + return ExitCodes.E5004; + } + + if (!binFilePath.IsNormalized(NormalizationForm.FormD) + || binFilePath.Contains(' ')) + { + var tempFile = Path.Combine( + Environment.GetEnvironmentVariable("TEMP", EnvironmentVariableTarget.Machine), + Path.GetFileName(binFilePath)); + + // copy file to shadow file + File.Copy( + binFilePath, + tempFile, + true); + + shadowFiles.Add(tempFile); + } + else + { + // copy file to shadow list + shadowFiles.Add(binFilePath); + } + } + + return ExitCodes.OK; + } } }