Skip to content
This repository was archived by the owner on May 19, 2021. It is now read-only.

Commit 953ecf7

Browse files
committed
add more error checking to update checker, use TLS12 (suddenly windows requires it), update powershell script to use TLS12 also,
1 parent 96b1a38 commit 953ecf7

File tree

4 files changed

+37
-21
lines changed

4 files changed

+37
-21
lines changed

Diff for: UnityLauncher/Form1.Designer.cs

+16-13
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: UnityLauncher/Form1.cs

+3-4
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ public partial class Form1 : Form
2020
const string contextRegRoot = "Software\\Classes\\Directory\\Background\\shell";
2121
const string launcherArgumentsFile = "LauncherArguments.txt";
2222
const string githubReleaseAPICheckURL = "https://api.github.com/repos/unitycoder/unitylauncher/releases/latest";
23-
const string githubReleasesURL = "https://github.com/unitycoder/UnityLauncher/releases";
23+
const string githubReleasesLinkURL = "https://github.com/unitycoder/UnityLauncher/releases";
2424

2525
bool isDownloadUnityList = false;
26-
string previousGitRelease = null;
26+
string previousGitRelease = "0";
2727

2828

2929
public Form1()
@@ -107,7 +107,6 @@ void Start()
107107
// subscribe to columnwidthchange event, so that can save column sizes
108108
this.gridRecent.ColumnWidthChanged += new System.Windows.Forms.DataGridViewColumnEventHandler(this.gridRecent_ColumnWidthChanged);
109109

110-
111110
// get previous version build info string
112111
// this string is release tag for latest release when this app was compiled
113112
using (Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("UnityLauncher." + "PreviousVersion.txt"))
@@ -1113,7 +1112,7 @@ void CheckUpdates()
11131112
DialogResult dialogResult = MessageBox.Show("Update " + result + " is available, open download page?", "UnityLauncher - Check Update", MessageBoxButtons.YesNo);
11141113
if (dialogResult == DialogResult.Yes) // open download page
11151114
{
1116-
Tools.OpenURL(githubReleasesURL);
1115+
Tools.OpenURL(githubReleasesLinkURL);
11171116
}
11181117
}
11191118
else

Diff for: UnityLauncher/Tools.cs

+17-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
using System.Net;
88
using System.Text;
99
using System.Text.RegularExpressions;
10-
using System.Threading.Tasks;
1110
using System.Windows.Forms;
1211

1312
namespace UnityLauncherTools
@@ -336,9 +335,19 @@ public static string CheckUpdates(string githubReleaseURL, string previousGitRel
336335
string result = null;
337336
using (WebClient client = new WebClient())
338337
{
338+
// apparently this is now required..otherwise: "The request was aborted: Could not create SSL/TLS secure channel"
339+
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
340+
339341
// fetch current release info
340342
client.Headers.Add("user-agent", "MuskBrowser");
341343
string json = client.DownloadString(githubReleaseURL);
344+
345+
if (json.IndexOf('{') != 0)
346+
{
347+
// invalid json
348+
return result;
349+
}
350+
342351
var arr = json.Split(new string[] { "\"tag_name\":" }, StringSplitOptions.None);
343352

344353
// have tagname
@@ -349,9 +358,14 @@ public static string CheckUpdates(string githubReleaseURL, string previousGitRel
349358
if (arr2.Length > 1)
350359
{
351360
var currentlyAvailableLatestReleaseTag = arr2[1];
361+
352362
// compare online version with build in release version, return github version if different from embedded version
353-
if (Math.Abs(float.Parse(currentlyAvailableLatestReleaseTag)-float.Parse(previousGitRelease))>0.1f)
354-
// if (currentlyAvailableLatestReleaseTag != previousGitRelease)
363+
float previous = 0;
364+
float current = 0;
365+
if (float.TryParse(previousGitRelease, out previous) == false) return result;
366+
if (float.TryParse(currentlyAvailableLatestReleaseTag, out current) == false) return result;
367+
368+
if (Math.Abs(previous - current) > 0.1f)
355369
{
356370
result = currentlyAvailableLatestReleaseTag;
357371
Console.WriteLine("update available: [" + currentlyAvailableLatestReleaseTag + "] / [" + previousGitRelease + "]");

Diff for: UnityLauncher/UnityLauncher.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,6 @@
132132
</ItemGroup>
133133
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
134134
<PropertyGroup>
135-
<PreBuildEvent>powershell.exe -command "$web = New-Object System.Net.WebClient;$web.Headers['User-Agent'] = 'DefinitelyBrowser';$results = $web.DownloadString('https://api.github.com/repos/unitycoder/unitylauncher/releases/latest');$results = $results | ConvertFrom-Json;$results = $results | select -expand tag_name;echo $results | Out-File $(ProjectDir)PreviousVersion.txt;"</PreBuildEvent>
135+
<PreBuildEvent>powershell.exe -command "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12;$web = New-Object System.Net.WebClient;$web.Headers['User-Agent'] = 'DefinitelyBrowser';$results = $web.DownloadString('https://api.github.com/repos/unitycoder/unitylauncher/releases/latest');$results = $results | ConvertFrom-Json;$results = $results | select -expand tag_name;echo $results | Out-File $(ProjectDir)PreviousVersion.txt;"</PreBuildEvent>
136136
</PropertyGroup>
137137
</Project>

0 commit comments

Comments
 (0)