Skip to content

Commit

Permalink
Fixed issue #1, slightly simplified IsUpdateCheckEnabled, removed unn…
Browse files Browse the repository at this point in the history
…ecessary replace
  • Loading branch information
BitesizedLion committed Dec 21, 2022
1 parent 5f07edf commit fe05484
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 57 deletions.
6 changes: 3 additions & 3 deletions App.config
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" />
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8"/>
</startup>
</configuration>
</configuration>
4 changes: 2 additions & 2 deletions Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.1.2.3")]
[assembly: AssemblyFileVersion("1.1.2.3")]
[assembly: AssemblyVersion("1.1.3.4")]
[assembly: AssemblyFileVersion("1.1.3.4")]
44 changes: 18 additions & 26 deletions Properties/Resources.Designer.cs

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

22 changes: 9 additions & 13 deletions Properties/Settings.Designer.cs

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

5 changes: 4 additions & 1 deletion TidalRPC.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<OutputType>WinExe</OutputType>
<RootNamespace>TidalRPC</RootNamespace>
<AssemblyName>TidalRPC</AssemblyName>
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<Deterministic>true</Deterministic>
Expand All @@ -27,6 +27,8 @@
<ApplicationVersion>1.0.0.%2a</ApplicationVersion>
<UseApplicationTrust>false</UseApplicationTrust>
<BootstrapperEnabled>true</BootstrapperEnabled>
<TargetFrameworkProfile />
<LangVersion>latest</LangVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
Expand Down Expand Up @@ -85,6 +87,7 @@
<Compile Include="Properties\Resources.Designer.cs">
<AutoGen>True</AutoGen>
<DependentUpon>Resources.resx</DependentUpon>
<DesignTime>True</DesignTime>
</Compile>
<None Include="packages.config" />
<None Include="Properties\Settings.settings">
Expand Down
29 changes: 17 additions & 12 deletions UpdateManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,24 @@ namespace TidalRPC
{
public static class UpdateManager
{
static bool updateDenied = false;
private static bool updateDenied = false;
private static bool updatePrompted = false;

// Method for checking if update checking is enabled
public static bool IsUpdateCheckEnabled()
{
string keyName = "SOFTWARE\\TidalRPC\\Settings";
string valueName = "CheckForUpdates";

using (RegistryKey key = Registry.CurrentUser.OpenSubKey(keyName))
{
if (key == null)
{
ToggleUpdateCheck(true);
return true;
}
using RegistryKey key = Registry.CurrentUser.OpenSubKey(keyName);

return (int)key.GetValue(valueName, 0) != 0;
if (key == null)
{
ToggleUpdateCheck(true);
return true;
}

return (int)key.GetValue(valueName, 0) != 0;
}

// Method for toggling update checking
Expand Down Expand Up @@ -58,31 +58,36 @@ public static async Task CheckForUpdates()

while (!updateDenied)
{
if (!IsUpdateCheckEnabled()) return;
if (!IsUpdateCheckEnabled() || updatePrompted) return;

// Fetch the latest release information from the GitHub API
HttpResponseMessage response = await client.GetAsync("https://api.github.com/repos/BitesizedLion/TidalRPC/releases/latest");

if (response.IsSuccessStatusCode)
{
string json = await response.Content.ReadAsStringAsync();
dynamic release = JsonConvert.DeserializeObject(json);
Version latestVersion = new Version(((string)release.tag_name).Replace("v", ""));
dynamic release = JsonConvert.DeserializeObject(json); // i know this is bad, it will be improved later

Version latestVersion = new Version(((string)release.tag_name));

// Compare the version numbers
if (latestVersion > currentVersion)
{
// Prompt the user to update
DialogResult result = MessageBox.Show("A new version of the software is available. Do you want to download it?", "Update Available", MessageBoxButtons.YesNo);

updatePrompted = true;

switch (result)
{
case DialogResult.Yes:
Process.Start((string)release.html_url); // Open the download URL in the default web browser
updatePrompted = false;
break;

case DialogResult.No:
updateDenied = true;
updatePrompted = false;
break;

}
Expand Down

0 comments on commit fe05484

Please sign in to comment.