Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do a directory existing check before we check for internet. #401

Merged
merged 2 commits into from
Nov 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/dotnet.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
name: Meadow.CLI
env:
CLI_RELEASE_VERSION: 1.4.2.0
CLI_RELEASE_VERSION: 1.4.4.0
IDE_TOOLS_RELEASE_VERSION: 1.4.0
MEADOW_OS_VERSION: 1.4.0.3
MEADOW_OS_VERSION: 1.5.0.4
VS_MAC_2019_VERSION: 8.10
VS_MAC_2022_VERSION: 17.5

Expand Down
2 changes: 1 addition & 1 deletion Meadow.CLI.Core/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace Meadow.CLI.Core
{
public static class Constants
{
public const string CLI_VERSION = "1.4.2.0";
public const string CLI_VERSION = "1.4.4.0";
public const ushort HCOM_PROTOCOL_PREVIOUS_VERSION_NUMBER = 0x0006;
public const ushort HCOM_PROTOCOL_CURRENT_VERSION_NUMBER = 0x0007; // Used for transmission
public const string WILDERNESS_LABS_USB_VID = "2E6A";
Expand Down
45 changes: 16 additions & 29 deletions Meadow.CLI.Core/Managers/DownloadManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -118,33 +118,25 @@ bool CreateFolder(string path, bool eraseIfExists)
return true;
}

static bool IsPassingThroughDefaultGateway()
//ToDo rename this method - DownloadOSAsync?
public async Task DownloadOsBinaries(string? version = null, bool force = false, CancellationToken cancellationToken = default)
{
NetworkInterface[] networkInterfaces = NetworkInterface.GetAllNetworkInterfaces();

foreach (NetworkInterface networkInterface in networkInterfaces)
string local_path;
if (!string.IsNullOrEmpty(version))
{
if (networkInterface.OperationalStatus == OperationalStatus.Up)
{
GatewayIPAddressInformationCollection gateways = networkInterface.GetIPProperties().GatewayAddresses;
local_path = Path.Combine(FirmwareDownloadsFilePathRoot, version);

if (gateways.Count > 0)
{
// If any network interface has a gateway, you are likely passing through a gateway.
return true;
}
if (!force
&& Directory.Exists(local_path)
&& Directory.EnumerateFiles(local_path).Any())
{
_logger.LogInformation($"Meadow OS version {version} was previously downloaded to: {local_path}.{Environment.NewLine}");
return;
}
}

return false;
}


//ToDo rename this method - DownloadOSAsync?
public async Task DownloadOsBinaries(string? version = null, bool force = false, CancellationToken cancellationToken = default)
{
// Check if there is an active internet connection
if (!NetworkInterface.GetIsNetworkAvailable() && IsPassingThroughDefaultGateway())
if (!NetworkInterface.GetIsNetworkAvailable())
{
_logger.LogError($"No internet connection! Cannot download Meadow OS version {version}. Please retry once an internet connection is available.{Environment.NewLine}");
return;
Expand All @@ -171,19 +163,14 @@ public async Task DownloadOsBinaries(string? version = null, bool force = false,
//we'll write latest.txt regardless of version if it doesn't exist
File.WriteAllText(Path.Combine(FirmwareDownloadsFilePathRoot, "latest.txt"), release.Version);

string local_path;

if (string.IsNullOrWhiteSpace(version))
{
local_path = Path.Combine(FirmwareDownloadsFilePathRoot, release.Version);
version = release.Version;
}
else
{
local_path = Path.Combine(FirmwareDownloadsFilePathRoot, version);
}

if (CreateFolder(local_path, force) == false)
local_path = Path.Combine(FirmwareDownloadsFilePathRoot, version);

if (!CreateFolder(local_path, force) && Directory.EnumerateFiles(local_path).Any())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah this is interesting ... at least validate there's one file. Part of me wonders if we just remove the "force" and always overwrite. I wonder if we're providing any value with the force flag? (something to chat about at least)

{
_logger.LogInformation($"Meadow OS version {version} was previously downloaded to: {local_path}.{Environment.NewLine}");
return;
Expand Down Expand Up @@ -412,4 +399,4 @@ private void CleanPath(string path)
}
}
}
}
}
2 changes: 1 addition & 1 deletion Meadow.CLI.Core/Meadow.CLI.Core.6.0.0.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<LangVersion>preview</LangVersion>
<Nullable>enable</Nullable>
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
<Version>1.4.2.0</Version>
<Version>1.4.4.0</Version>
</PropertyGroup>

<PropertyGroup>
Expand Down
2 changes: 1 addition & 1 deletion Meadow.CLI.Core/Meadow.CLI.Core.Classic.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<LangVersion>preview</LangVersion>
<Nullable>enable</Nullable>
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
<Version>1.4.0.0</Version>
<Version>1.4.4.0</Version>
</PropertyGroup>

<PropertyGroup>
Expand Down
2 changes: 1 addition & 1 deletion Meadow.CLI.Core/Meadow.CLI.Core.VS2019.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<LangVersion>preview</LangVersion>
<Nullable>enable</Nullable>
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
<Version>1.4.2.0</Version>
<Version>1.4.4.0</Version>
</PropertyGroup>

<PropertyGroup>
Expand Down
2 changes: 1 addition & 1 deletion Meadow.CLI.Core/Meadow.CLI.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<LangVersion>preview</LangVersion>
<Nullable>enable</Nullable>
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
<Version>1.4.2.0</Version>
<Version>1.4.4.0</Version>
</PropertyGroup>

<PropertyGroup>
Expand Down
2 changes: 1 addition & 1 deletion Meadow.CLI/Meadow.CLI.Classic.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<Authors>Peter Moody, Adrian Stevens, Brian Kim, Pete Garafano, Dominique Louis</Authors>
<Company>Wilderness Labs, Inc</Company>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<PackageVersion>1.4.2.0</PackageVersion>
<PackageVersion>1.4.4.0</PackageVersion>
<Platforms>AnyCPU</Platforms>
<PackageProjectUrl>http://developer.wildernesslabs.co/Meadow/Meadow.Foundation/</PackageProjectUrl>
<PackageIcon>icon.png</PackageIcon>
Expand Down
2 changes: 1 addition & 1 deletion Meadow.CLI/Meadow.CLI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<Authors>Peter Moody, Adrian Stevens, Brian Kim, Pete Garafano, Dominique Louis</Authors>
<Company>Wilderness Labs, Inc</Company>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<PackageVersion>1.4.0.0</PackageVersion>
<PackageVersion>1.4.4.0</PackageVersion>
<Platforms>AnyCPU</Platforms>
<PackageProjectUrl>http://developer.wildernesslabs.co/Meadow/Meadow.Foundation/</PackageProjectUrl>
<PackageIcon>icon.png</PackageIcon>
Expand Down