Skip to content

Commit

Permalink
Check all release and take the correct one depending if beta or relea…
Browse files Browse the repository at this point in the history
…se. See #58
  • Loading branch information
Antoine Aflalo committed Jan 1, 2016
1 parent 1eda84c commit 8ca0eef
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 19 deletions.
2 changes: 1 addition & 1 deletion SoundSwitch/Framework/Updater/GitHubRelease.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public class Asset

public override string ToString()
{
return $"tag_name: {tag_name}, name: {name}, prerelease: {prerelease}";
return $"(tag_name: {tag_name}, name: {name}, prerelease: {prerelease})";
}
}
}
56 changes: 39 additions & 17 deletions SoundSwitch/Framework/Updater/UpdateChecker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@
********************************************************************/

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Windows.Forms;
Expand Down Expand Up @@ -53,28 +55,48 @@ private void DownloadStringCompleted(object sender, DownloadStringCompletedEvent
return;
}

var serverRelease = JsonConvert.DeserializeObject<GitHubRelease>(e.Result);
if (serverRelease.prerelease)
var serverRelease = JsonConvert.DeserializeObject<List<GitHubRelease>>(e.Result);
if (!serverRelease.Any(ProcessRelease))
{
AppLogger.Log.Warn("The version found is a pre release: ", serverRelease);
if (!Beta)
return;
AppLogger.Log.Info("No new Version found ", string.Join("\n", serverRelease));
}
var version = new Version(serverRelease.tag_name.Substring(1));
var changelog = Regex.Split(serverRelease.body, "\r\n|\r|\n");
try
}

private bool ProcessRelease(GitHubRelease serverRelease)
{
using (AppLogger.Log.InfoCall())
{
var installer = serverRelease.assets.First(asset => asset.name.EndsWith(".exe"));
var release = new Release(version, installer, serverRelease.name);
release.Changelog.AddRange(changelog);
if (version > AppVersion)
AppLogger.Log.Info("Checking version: ", serverRelease);
if (serverRelease.prerelease && !Beta)
{
UpdateAvailable?.Invoke(this, new NewReleaseEvent(release));
AppLogger.Log.Info("Pre-release and not in Beta Mode.");
return false;
}
}
catch (Exception ex)
{
AppLogger.Log.Error("Exception while getting release ", ex);

if (!serverRelease.prerelease && Beta)
{
AppLogger.Log.Info("Release and in Beta Mode.");
return false;
}

var version = new Version(serverRelease.tag_name.Substring(1));
var changelog = Regex.Split(serverRelease.body, "\r\n|\r|\n");
try
{
if (version > AppVersion)
{
var installer = serverRelease.assets.First(asset => asset.name.EndsWith(".exe"));
var release = new Release(version, installer, serverRelease.name);
release.Changelog.AddRange(changelog);
UpdateAvailable?.Invoke(this, new NewReleaseEvent(release));
return true;
}
}
catch (Exception ex)
{
AppLogger.Log.Error("Exception while getting release ", ex);
}
return false;
}
}

Expand Down
2 changes: 1 addition & 1 deletion SoundSwitch/Model/AppModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ private void InitUpdateChecker()
{
WindowsAPIAdapter.HotKeyPressed += HandleHotkeyPress;
_updateChecker = new IntervalUpdateChecker(
new Uri("https://api.github.com/repos/Belphemur/SoundSwitch/releases/latest"),
new Uri("https://api.github.com/repos/Belphemur/SoundSwitch/releases"),
AppConfigs.Configuration.UpdateCheckInterval, AppConfigs.Configuration.SubscribedBetaVersion);
_updateChecker.UpdateAvailable += (sender, @event) => NewVersionReleased?.Invoke(this, @event);
_updateChecker.CheckForUpdate();
Expand Down

0 comments on commit 8ca0eef

Please sign in to comment.