-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
75 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<configuration> | ||
<startup> | ||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/> | ||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2"/> | ||
</startup> | ||
</configuration> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,10 @@ | ||
using SteamShutdown.Actions; | ||
using Newtonsoft.Json; | ||
using SteamShutdown.Actions; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Diagnostics; | ||
using System.IO; | ||
using System.Net.Http; | ||
using System.Windows.Forms; | ||
|
||
namespace SteamShutdown | ||
|
@@ -21,9 +23,20 @@ static class SteamShutdown | |
[STAThread] | ||
static void Main() | ||
{ | ||
if (!EnsureSingleInstance()) return; | ||
|
||
AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException; | ||
if (!EnsureSingleInstance()) return; | ||
if (IsUpdateAvailable()) | ||
{ | ||
DialogResult dr = MessageBox.Show( | ||
"Do you want to update now?", | ||
"New version available", | ||
MessageBoxButtons.YesNo, | ||
MessageBoxIcon.Question); | ||
if (dr == DialogResult.Yes) | ||
{ | ||
Process.Start("https://github.com/akorb/SteamShutdown/releases/latest"); | ||
} | ||
} | ||
|
||
Application.EnableVisualStyles(); | ||
Application.SetCompatibleTextRenderingDefault(false); | ||
|
@@ -65,5 +78,43 @@ private static void CurrentDomain_UnhandledException(object sender, UnhandledExc | |
MessageBox.Show("Please send me the log file on GitHub or via E-Mail ([email protected])" + Environment.NewLine + | ||
"You find the log file on your Dekstop.", "An Error occured"); | ||
} | ||
|
||
private static bool IsUpdateAvailable() | ||
{ | ||
try | ||
{ | ||
// Usually HttpClient should stay alive over the whole application lifetime | ||
// but since we know we'll never require network access again after this function, | ||
// dispose it. | ||
using (HttpClient client = new HttpClient()) | ||
{ | ||
Uri ur = new Uri("https://api.github.com/repos/akorb/steamshutdown/releases/latest"); | ||
// Add an Accept header for JSON format. | ||
client.DefaultRequestHeaders.Accept.ParseAdd("application/json"); | ||
// User-Agent is necessary for the GitHub api | ||
client.DefaultRequestHeaders.UserAgent.ParseAdd("Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:79.0) Gecko/20100101 Firefox/79.0"); | ||
|
||
// Blocking call. Program will wait here until a response is received or a timeout occurs. | ||
HttpResponseMessage response = client.GetAsync(ur).Result; | ||
if (response.IsSuccessStatusCode && response.Content.Headers.ContentType.MediaType == "application/json") | ||
{ | ||
// Parse the response body. | ||
string text = response.Content.ReadAsStringAsync().Result; | ||
dynamic json = JsonConvert.DeserializeObject(text); | ||
string tag = json.tag_name; | ||
// Use trim (char based) instead of substring (index based) to allow to leave the 'v' in later tag names | ||
Version serverVersion = new Version(tag.TrimStart('v')); | ||
Version currentVersion = new Version(Application.ProductVersion); | ||
return serverVersion > currentVersion; | ||
} | ||
} | ||
} | ||
catch | ||
{ | ||
// Runs into catch for example if there is no internet connection available. | ||
// No further handling necessary since checking for an update is just a bonus. | ||
} | ||
return false; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<packages> | ||
<package id="ILMerge" version="3.0.40" targetFramework="net40" /> | ||
<package id="Newtonsoft.Json" version="12.0.3" targetFramework="net40" /> | ||
<package id="ILMerge" version="3.0.41" targetFramework="net472" /> | ||
<package id="Newtonsoft.Json" version="12.0.3" targetFramework="net472" /> | ||
</packages> |