Skip to content

Commit

Permalink
Feature: Check for Pre-releases (#1574)
Browse files Browse the repository at this point in the history
* Feature: Check for Pre-releases

* Docs: Add #1574
  • Loading branch information
BornToBeRoot authored Oct 2, 2022
1 parent f1c809b commit 59ae473
Show file tree
Hide file tree
Showing 12 changed files with 110 additions and 26 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Source/NETworkManager.Localization/Resources/Strings.resx
Original file line number Diff line number Diff line change
Expand Up @@ -3221,4 +3221,7 @@ If not set, the default AWS CLI settings are used.</value>
<data name="AWSSessionManagerPluginIsNotInstalled" xml:space="preserve">
<value>AWS Session Manager Plugin is not installed!</value>
</data>
<data name="CheckForPreReleases" xml:space="preserve">
<value>Check for pre-releases</value>
</data>
</root>
15 changes: 15 additions & 0 deletions Source/NETworkManager.Settings/SettingsInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,21 @@ public bool Update_CheckForUpdatesAtStartup
}
}

private bool _update_CheckForPreReleases;
public bool Update_CheckForPreReleases
{
get => _update_CheckForPreReleases;
set
{
if (value == _update_CheckForPreReleases)
return;

_update_CheckForPreReleases = value;
OnPropertyChanged();
SettingsChanged = true;
}
}

// Profiles
private string _profiles_CustomProfilesLocation;
public string Profiles_CustomProfilesLocation
Expand Down
15 changes: 8 additions & 7 deletions Source/NETworkManager.Update/UpdateAvailableArgs.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using Octokit;
using System;

namespace NETworkManager.Update
{
Expand All @@ -8,17 +9,17 @@ namespace NETworkManager.Update
public class UpdateAvailableArgs : EventArgs
{
/// <summary>
/// Version of the program update.
/// Release of the program update.
/// </summary>
public Version Version { get; private set; }
public Release Release { get; private set; }

/// <summary>
/// Initializes a new instance of the <see cref="UpdateAvailableArgs"/> class and passes the <see cref="Version"/> as paramter.
/// Initializes a new instance of the <see cref="UpdateAvailableArgs"/> class and passes the <see cref="Release"/> as paramter.
/// </summary>
/// <param name="version">Version of the program update.</param>
public UpdateAvailableArgs(Version version)
/// <param name="release">Release of the program update.</param>
public UpdateAvailableArgs(Release release)
{
Version = version;
Release = release;
}
}
}
13 changes: 9 additions & 4 deletions Source/NETworkManager.Update/Updater.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,19 +58,24 @@ protected virtual void OnError()
/// <param name="userName">GitHub username like "BornToBeRoot".</param>
/// <param name="projectName">GitHub repository like "NETworkManager".</param>
/// <param name="currentVersion">Version like 1.2.0.0.</param>
public void CheckOnGitHub(string userName, string projectName, Version currentVersion)
public void CheckOnGitHub(string userName, string projectName, Version currentVersion, bool includePreRelease)
{
Task.Run(() =>
{
try
{
var client = new GitHubClient(new ProductHeaderValue(userName + "_" + projectName));

var latestVersion = new Version(client.Repository.Release.GetLatest(userName, projectName).Result.TagName);
Release release = null;

if (includePreRelease)
release = client.Repository.Release.GetAll(userName, projectName).Result[0];
else
release = client.Repository.Release.GetLatest(userName, projectName).Result;

// Compare versions (tag=2021.2.15.0, version=2021.2.15.0)
if (latestVersion > currentVersion)
OnUpdateAvailable(new UpdateAvailableArgs(latestVersion));
if (new Version(release.TagName) > currentVersion)
OnUpdateAvailable(new UpdateAvailableArgs(release));
else
OnNoUpdateAvailable();
}
Expand Down
2 changes: 1 addition & 1 deletion Source/NETworkManager/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
<mah:MetroWindow.RightWindowCommands>
<mah:WindowCommands ShowLastSeparator="False">
<StackPanel Orientation="Horizontal">
<Button Command="{Binding OpenWebsiteCommand}" Opacity="1" Visibility="{Binding IsUpdateAvailable, Converter={StaticResource BooleanToVisibilityCollapsedConverter}}" CommandParameter="{x:Static resources:Resources.NETworkManager_LatestReleaseUrl}" Cursor="Hand">
<Button Command="{Binding OpenWebsiteCommand}" Opacity="1" Visibility="{Binding IsUpdateAvailable, Converter={StaticResource BooleanToVisibilityCollapsedConverter}}" CommandParameter="{Binding UpdateReleaseUrl, Mode=OneWay, UpdateSourceTrigger=PropertyChanged}" Cursor="Hand">
<StackPanel Orientation="Horizontal">
<Rectangle Width="20" Height="20" Fill="{DynamicResource MahApps.Brushes.Accent}">
<Rectangle.OpacityMask>
Expand Down
17 changes: 16 additions & 1 deletion Source/NETworkManager/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,20 @@ public bool IsUpdateAvailable
}
}

private string _updateReleaseUrl;
public string UpdateReleaseUrl
{
get => _updateReleaseUrl;
set
{
if (value == _updateReleaseUrl)
return;

_updateReleaseUrl = value;
OnPropertyChanged();
}
}

private ICollectionView _profileFiles;
public ICollectionView ProfileFiles
{
Expand Down Expand Up @@ -1162,7 +1176,7 @@ private void CheckForUpdates()

updater.UpdateAvailable += Updater_UpdateAvailable;
updater.Error += Updater_Error;
updater.CheckOnGitHub(Properties.Resources.NETworkManager_GitHub_User, Properties.Resources.NETworkManager_GitHub_Repo, AssemblyManager.Current.Version);
updater.CheckOnGitHub(Properties.Resources.NETworkManager_GitHub_User, Properties.Resources.NETworkManager_GitHub_Repo, AssemblyManager.Current.Version, SettingsManager.Current.Update_CheckForPreReleases);
}

private static void Updater_Error(object sender, EventArgs e)
Expand All @@ -1172,6 +1186,7 @@ private static void Updater_Error(object sender, EventArgs e)

private void Updater_UpdateAvailable(object sender, UpdateAvailableArgs e)
{
UpdateReleaseUrl = e.Release.Prerelease ? e.Release.HtmlUrl : Properties.Resources.NETworkManager_LatestReleaseUrl;
IsUpdateAvailable = true;
}
#endregion
Expand Down
36 changes: 26 additions & 10 deletions Source/NETworkManager/ViewModels/AboutViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@
using NETworkManager.Localization.Resources;
using NETworkManager.Utilities;
using NETworkManager.Documentation;
using NETworkManager.Properties;

namespace NETworkManager.ViewModels
{
public class AboutViewModel : ViewModelBase
{
#region Variables
public string Version => $"{Strings.Version} {AssemblyManager.Current.Version}";
public string DevelopedByText => string.Format(Strings.DevelopedAndMaintainedByX + " ", Properties.Resources.NETworkManager_GitHub_User);
public string DevelopedByText => string.Format(Strings.DevelopedAndMaintainedByX + " ", Resources.NETworkManager_GitHub_User);

private bool _isUpdateCheckRunning;
public bool IsUpdateCheckRunning
Expand All @@ -31,16 +32,16 @@ public bool IsUpdateCheckRunning
}
}

private bool _updateAvailable;
public bool UpdateAvailable
private bool _isUpdateAvailable;
public bool IsUpdateAvailable
{
get => _updateAvailable;
get => _isUpdateAvailable;
set
{
if (value == _updateAvailable)
if (value == _isUpdateAvailable)
return;

_updateAvailable = value;
_isUpdateAvailable = value;
OnPropertyChanged();
}
}
Expand All @@ -59,6 +60,20 @@ public string UpdateText
}
}

private string _updateReleaseUrl;
public string UpdateReleaseUrl
{
get => _updateReleaseUrl;
set
{
if (value == _updateReleaseUrl)
return;

_updateReleaseUrl = value;
OnPropertyChanged();
}
}

private bool _showUpdaterMessage;
public bool ShowUpdaterMessage
{
Expand Down Expand Up @@ -186,7 +201,7 @@ private void OpenLicenseFolderAction()
#region Methods
private void CheckForUpdates()
{
UpdateAvailable = false;
IsUpdateAvailable = false;
ShowUpdaterMessage = false;

IsUpdateCheckRunning = true;
Expand All @@ -197,17 +212,18 @@ private void CheckForUpdates()
updater.NoUpdateAvailable += Updater_NoUpdateAvailable;
updater.Error += Updater_Error;

updater.CheckOnGitHub(Properties.Resources.NETworkManager_GitHub_User, Properties.Resources.NETworkManager_GitHub_Repo, AssemblyManager.Current.Version);
updater.CheckOnGitHub(Resources.NETworkManager_GitHub_User, Resources.NETworkManager_GitHub_Repo, AssemblyManager.Current.Version, SettingsManager.Current.Update_CheckForPreReleases);
}
#endregion

#region Events
private void Updater_UpdateAvailable(object sender, UpdateAvailableArgs e)
{
UpdateText = string.Format(Strings.VersionxxIsAvailable, e.Version);
UpdateText = string.Format(Strings.VersionxxIsAvailable, e.Release.TagName);
UpdateReleaseUrl = e.Release.Prerelease ? e.Release.HtmlUrl : Resources.NETworkManager_LatestReleaseUrl;

IsUpdateCheckRunning = false;
UpdateAvailable = true;
IsUpdateAvailable = true;
}

private void Updater_NoUpdateAvailable(object sender, EventArgs e)
Expand Down
19 changes: 18 additions & 1 deletion Source/NETworkManager/ViewModels/SettingsUpdateViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using NETworkManager.Settings;
using NETworkManager.Utilities;

namespace NETworkManager.ViewModels
{
Expand All @@ -24,6 +23,23 @@ public bool CheckForUpdatesAtStartup
OnPropertyChanged();
}
}

private bool _checkForPreReleases;
public bool CheckForPreReleases
{
get => _checkForPreReleases;
set
{
if (value == _checkForPreReleases)
return;

if (!_isLoading)
SettingsManager.Current.Update_CheckForPreReleases = value;

_checkForPreReleases = value;
OnPropertyChanged();
}
}
#endregion

#region Constructor, LoadSettings
Expand All @@ -39,6 +55,7 @@ public SettingsUpdateViewModel()
private void LoadSettings()
{
CheckForUpdatesAtStartup = SettingsManager.Current.Update_CheckForUpdatesAtStartup;
CheckForPreReleases = SettingsManager.Current.Update_CheckForPreReleases;
}
#endregion
}
Expand Down
4 changes: 2 additions & 2 deletions Source/NETworkManager/Views/AboutView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,9 @@
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Button Grid.Column="0" x:Name="ButtonCheckForUpdates" HorizontalAlignment="Left" Command="{Binding CheckForUpdatesCommand}" IsEnabled="{Binding IsUpdateCheckRunning, Converter={StaticResource BooleanReverseConverter}}" Style="{StaticResource DefaultButton}" Content="{x:Static localization:Strings.CheckForUpdates}" />
<StackPanel Grid.Column="2" Orientation="Horizontal" Visibility="{Binding UpdateAvailable, Converter={StaticResource BooleanToVisibilityCollapsedConverter}}">
<StackPanel Grid.Column="2" Orientation="Horizontal" Visibility="{Binding IsUpdateAvailable, Converter={StaticResource BooleanToVisibilityCollapsedConverter}}">
<StackPanel.InputBindings>
<MouseBinding Gesture="LeftClick" Command="{Binding OpenWebsiteCommand}" CommandParameter="{x:Static resources:Resources.NETworkManager_LatestReleaseUrl}" />
<MouseBinding Gesture="LeftClick" Command="{Binding OpenWebsiteCommand}" CommandParameter="{Binding UpdateReleaseUrl, Mode=OneWay, UpdateSourceTrigger=PropertyChanged}" />
</StackPanel.InputBindings>
<Rectangle Width="20" Height="20" Fill="{DynamicResource MahApps.Brushes.Accent}">
<Rectangle.OpacityMask>
Expand Down
1 change: 1 addition & 0 deletions Source/NETworkManager/Views/SettingsUpdateView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,6 @@
</Rectangle.Resources>
</Rectangle>
</StackPanel>
<mahAppsControls:ToggleSwitch Header="{x:Static localization:Strings.CheckForPreReleases}" IsOn="{Binding CheckForPreReleases}" />
</StackPanel>
</UserControl>
2 changes: 2 additions & 0 deletions docs/Changelog/next-release.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ permalink: /Changelog/next-release
- Detect if PuTTY is installed at first run [#1542](https://github.com/BornToBeRoot/NETworkManager/pull/1542){:target="\_blank"}
- Discovery Protocol
- Add local connection & local interface to output [#1533](https://github.com/BornToBeRoot/NETworkManager/pull/1533){:target="\_blank"}
- Settings > Update
- Option to check for pre-releases added [#1574](https://github.com/BornToBeRoot/NETworkManager/pull/1574){:target="\_blank"}
- Profiles > Group Dialog
- Remove checkboxes in group dialog [#1530](https://github.com/BornToBeRoot/NETworkManager/pull/1530){:target="\_blank"}
- log4net added for error handling (Log file: `%LocalAppData%\NETworkManager\NETworkManager.log`) [#1539](https://github.com/BornToBeRoot/NETworkManager/pull/1539){:target="\_blank"}
Expand Down

0 comments on commit 59ae473

Please sign in to comment.