Skip to content

Commit

Permalink
Better version parsing.
Browse files Browse the repository at this point in the history
  • Loading branch information
TBXin committed May 18, 2016
1 parent e601600 commit d5bc048
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions src/NFirmwareEditor/Managers/UpdatesManager.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Globalization;
using System.Threading;
using JetBrains.Annotations;
using NLog;
Expand Down Expand Up @@ -39,9 +40,29 @@ public ReleaseInfo CheckForUpdates()
{
s_logger.Info("Checking for updates...");
var latestRelease = GitHubApi.GetLatestRelease();
if (latestRelease == null || string.Equals(m_currentVersion, latestRelease.Tag) || latestRelease.Assets.Length == 0)
if (latestRelease == null || latestRelease.Assets.Length == 0)
{
s_logger.Info("No updates available.");
s_logger.Info("No updates found.");
return null;
}

float currentVersion;
float newVersion;

var v1 = float.TryParse(m_currentVersion, NumberStyles.Float, CultureInfo.InvariantCulture, out currentVersion);
var v2 = float.TryParse(latestRelease.Tag, NumberStyles.Float, CultureInfo.InvariantCulture, out newVersion);

if (v1 == false || v2 == false)
{
if (string.Equals(m_currentVersion, latestRelease.Tag))
{
s_logger.Info("Your are using latest version (string checking).");
return null;
}
}
else if (currentVersion >= newVersion)
{
s_logger.Info("Your are using latest version (float checking).");
return null;
}

Expand Down

0 comments on commit d5bc048

Please sign in to comment.