Skip to content

Commit

Permalink
Improvements in JLink operations (#280)
Browse files Browse the repository at this point in the history
  • Loading branch information
josesimoes committed Jun 18, 2024
1 parent b352eda commit e504cd8
Showing 1 changed file with 64 additions and 38 deletions.
102 changes: 64 additions & 38 deletions nanoFirmwareFlasher.Library/JLinkCli.cs
Original file line number Diff line number Diff line change
Expand Up @@ -280,47 +280,18 @@ public ExitCodes ExecuteFlashBinFiles(

Console.ForegroundColor = ConsoleColor.White;

return ExitCodes.OK;
}

private ExitCodes ProcessFilePaths(IList<string> files, List<string> 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;
}
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -536,5 +520,47 @@ internal static string RunJLinkCLI(string cmdFile, string arguments = null)

return jlinkCli.StandardOutput.ReadToEnd();
}

private ExitCodes ProcessFilePaths(IList<string> files, List<string> 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;
}
}
}

0 comments on commit e504cd8

Please sign in to comment.