diff --git a/nanoFirmwareFlasher/CloudsmithPackageInfo.cs b/nanoFirmwareFlasher/CloudsmithPackageInfo.cs index 1c277c4b..104046c0 100644 --- a/nanoFirmwareFlasher/CloudsmithPackageInfo.cs +++ b/nanoFirmwareFlasher/CloudsmithPackageInfo.cs @@ -16,5 +16,8 @@ internal class CloudsmithPackageInfo [JsonProperty("cdn_url")] public string DownloadUrl { get; set; } + + [JsonProperty("name")] + public string TargetName { get; set; } } } diff --git a/nanoFirmwareFlasher/Esp32Operations.cs b/nanoFirmwareFlasher/Esp32Operations.cs index 54a5c21c..569cb5f8 100755 --- a/nanoFirmwareFlasher/Esp32Operations.cs +++ b/nanoFirmwareFlasher/Esp32Operations.cs @@ -167,7 +167,7 @@ internal static async System.Threading.Tasks.Task UpdateFirmwareAsync if (fitCheck) { - if (targetName.Contains("ESP32_WROOM_32_V3") && + if (targetName.EndsWith("REV3") && (esp32Device.ChipName.Contains("revision 0") || esp32Device.ChipName.Contains("revision 1") || esp32Device.ChipName.Contains("revision 2"))) diff --git a/nanoFirmwareFlasher/FirmwarePackage.cs b/nanoFirmwareFlasher/FirmwarePackage.cs index 4f58bcef..fc844f7b 100644 --- a/nanoFirmwareFlasher/FirmwarePackage.cs +++ b/nanoFirmwareFlasher/FirmwarePackage.cs @@ -219,46 +219,68 @@ protected async System.Threading.Tasks.Task DownloadAndExtractAsync() string responseBody = await response.Content.ReadAsStringAsync(); + bool targetNotFound = false; + // check for empty array if (responseBody == "[]") { - if (Verbosity >= VerbosityLevel.Normal) + targetNotFound = true; + } + else + { + // parse response + List packageInfo = JsonConvert.DeserializeObject>(responseBody); + + // if no specific version was requested, use latest available + if (string.IsNullOrEmpty(_fwVersion)) { - Console.ForegroundColor = ConsoleColor.White; - Console.WriteLine(""); - Console.Write($"Trying to find {_targetName} in community targets repository..."); + _fwVersion = packageInfo.ElementAt(0).Version; + // grab download URL + downloadUrl = packageInfo.ElementAt(0).DownloadUrl; + } + else + { + //get the download Url from the Cloudsmith Package info + // addition check if the cloudsmith json return empty json + if(packageInfo is null || packageInfo.Count == 0) + { + return ExitCodes.E9005; + } + else + { + downloadUrl = packageInfo.Where(w => w.Version == _fwVersion).Select(s => s.DownloadUrl).FirstOrDefault(); + } } - // try with community targets - - requestUri = $"{_cloudsmithPackages}/{_communityTargetsRepo}/?page=1&query=^{_targetName}$ {fwVersion}"; + // sanity check for target name matching requested + if(packageInfo.ElementAt(0).TargetName != _targetName) + { + targetNotFound = true; + } + } - response = await _cloudsmithClient.GetAsync(requestUri); + if(targetNotFound) + { + // can't find this target - responseBody = await response.Content.ReadAsStringAsync(); + Console.WriteLine(""); - if (responseBody == "[]") + if (Verbosity >= VerbosityLevel.Normal) { - // can't find this target + // output helpful message + Console.ForegroundColor = ConsoleColor.Red; + Console.WriteLine(""); + Console.WriteLine("*************************** ERROR **************************"); + Console.WriteLine("Couldn't find this target in our Cloudsmith repositories!"); + Console.WriteLine("To list the available targets use this option --listtargets."); + Console.WriteLine("************************************************************"); Console.WriteLine(""); - if (Verbosity >= VerbosityLevel.Normal) - { - // output helpful message - Console.ForegroundColor = ConsoleColor.Yellow; - - Console.WriteLine(""); - Console.WriteLine("*************************** ERROR **************************"); - Console.WriteLine("Couldn't find this target in our Cloudsmith repositories!"); - Console.WriteLine("To list the available targets use this option --listtargets."); - Console.WriteLine("************************************************************"); - Console.WriteLine(""); - - Console.ForegroundColor = ConsoleColor.White; - } - return ExitCodes.E9005; + Console.ForegroundColor = ConsoleColor.White; } + + return ExitCodes.E9005; } if (Verbosity >= VerbosityLevel.Normal) @@ -268,30 +290,6 @@ protected async System.Threading.Tasks.Task DownloadAndExtractAsync() Console.ForegroundColor = ConsoleColor.White; } - // parse response - List packageInfo = JsonConvert.DeserializeObject>(responseBody); - - // if no specific version was requested, use latest available - if (string.IsNullOrEmpty(_fwVersion)) - { - _fwVersion = packageInfo.ElementAt(0).Version; - // grab download URL - downloadUrl = packageInfo.ElementAt(0).DownloadUrl; - } - else - { - //get the download Url from the Cloudsmith Package info - // addition check if the cloudsmith json return empty json - if(packageInfo is null || packageInfo.Count == 0) - { - return ExitCodes.E9005; - } - else - { - downloadUrl = packageInfo.Where(w => w.Version == _fwVersion).Select(s => s.DownloadUrl).FirstOrDefault(); - } - } - // set exposed property Version = _fwVersion;