Skip to content

Commit dfc0e57

Browse files
committed
Partial async support in AppUpdater.MUVersion
Update TODO
1 parent 94d9336 commit dfc0e57

File tree

6 files changed

+72
-24
lines changed

6 files changed

+72
-24
lines changed

AppUpdater/MUVersion.cs

Lines changed: 62 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
using Octokit;
88
using System.Diagnostics;
9+
using System.Net;
910

1011
namespace AppUpdater
1112
{
@@ -22,39 +23,84 @@ public static Release LatestRelease
2223
}
2324
}
2425

25-
public static bool Init()
26+
public static async Task<Release> Init()
2627
{
27-
if(client == null)
28+
if (client == null)
2829
{
2930
Log.Write(LogLevel.EXPERT, true, "AppUpdater.MUVersion: Cannot create GithubClient object");
30-
return false;
31+
return null;
3132
}
3233

33-
Task<IReadOnlyList<Release>> releases = client.Repository.Release.GetAll("UAVXP", "MedocUpdates");
34-
if(releases == null)
34+
if(client.Repository == null)
3535
{
36-
Log.Write(LogLevel.EXPERT, true, "AppUpdater.MUVersion: Cannot get a release list from the Github. Probably Internet was down");
37-
return false;
36+
Log.Write(LogLevel.EXPERT, true, "AppUpdater.MUVersion: client.Repository == null");
37+
return null;
38+
}
39+
40+
if (client.Repository.Release == null)
41+
{
42+
Log.Write(LogLevel.EXPERT, true, "AppUpdater.MUVersion: client.Repository.Release == null");
43+
return null;
44+
}
45+
46+
// Fixes the "Could not create SSL/TLS secure channel." on Windows Server 2008 R2
47+
try
48+
{
49+
ServicePointManager.Expect100Continue = true;
50+
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls |
51+
SecurityProtocolType.Tls11 |
52+
SecurityProtocolType.Tls12 |
53+
SecurityProtocolType.Ssl3;
54+
}
55+
catch(Exception ex)
56+
{
57+
Log.Write(LogLevel.EXPERT, true, "AppUpdater.MUVersion: Cannot set the security protocol type - TLS/TLS1.1/TLS1.2/SSL3 probably not supported");
58+
return null;
3859
}
3960

40-
if(releases.Result == null)
61+
//IReadOnlyList<Release> releases = await client.Repository.Release.GetAll("UAVXP", "MedocUpdates");
62+
63+
Task<Release> release = client.Repository.Release.GetLatest("UAVXP", "MedocUpdates");
64+
//Release release = await client.Repository.Release.GetLatest("UAVXP", "MedocUpdates");
65+
if (release == null)
4166
{
42-
Log.Write(LogLevel.EXPERT, true, "AppUpdater.MUVersion: Probably, something wrong with the Github. Try to check for updates again later");
43-
return false;
67+
Log.Write(LogLevel.EXPERT, true, "AppUpdater.MUVersion: Cannot get a release list from the Github. Probably Internet was down");
68+
return null;
4469
}
4570

46-
if(releases.Result.Count <= 0)
71+
try
4772
{
48-
Log.Write(LogLevel.EXPERT, true, "AppUpdater.MUVersion: No releases at the Github repository");
49-
return false;
73+
//latestRelease = releases.Result[0];
74+
//latestRelease = releases[0];
75+
latestRelease = await release;
76+
//latestRelease = release;
77+
//latestRelease = release.Result;
5078
}
79+
catch(Exception ex)
80+
{
81+
Log.Write(LogLevel.EXPERT, true, "AppUpdater.MUVersion: latestRelease task failed\r\n" + ex.Message);
5182

52-
latestRelease = releases.Result[0];
83+
// FIXME: Ugly solution
84+
if(ex.InnerException != null)
85+
{
86+
Log.Write(LogLevel.EXPERT, true, "\t" + ex.InnerException.Message);
87+
88+
if (ex.InnerException.InnerException != null)
89+
{
90+
Log.Write(LogLevel.EXPERT, true, "\t" + ex.InnerException.InnerException.Message);
91+
92+
if (ex.InnerException.InnerException.InnerException != null)
93+
Log.Write(LogLevel.EXPERT, true, "\t" + ex.InnerException.InnerException.InnerException.Message);
94+
}
95+
}
96+
97+
return null;
98+
}
5399

54-
Log.Write( LogLevel.BASIC, true, String.Format("The latest release is tagged at {0} and is named {1}",
100+
Log.Write(LogLevel.BASIC, true, String.Format("The latest release is tagged at {0} and is named {1}",
55101
latestRelease.TagName, latestRelease.Name));
56102

57-
return true;
103+
return latestRelease;
58104
}
59105

60106
public static Version GetRemoteData()

AppUpdater/Program.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ namespace AppUpdater
1313
{
1414
class Program
1515
{
16-
static void Main(string[] args)
16+
static async Task Main(string[] args)
1717
{
1818
Log.Init();
1919
Log.Write("");
@@ -51,7 +51,7 @@ static void Main(string[] args)
5151
mainAppProcesses = Process.GetProcessesByName("MedocUpdates");
5252
}
5353

54-
if(!MUVersion.Init())
54+
if(await MUVersion.Init() == null)
5555
{
5656
Log.Write(LogLevel.NORMAL, "AppUpdater: Cannot retrieve the latest releases from Github. Check your Internet connection");
5757
return;

MedocUpdates/MedocUpdates.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
<HintPath>..\packages\HtmlAgilityPack.1.11.16\lib\Net45\HtmlAgilityPack.dll</HintPath>
6060
</Reference>
6161
<Reference Include="Newtonsoft.Json, Version=12.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
62-
<HintPath>..\packages\Newtonsoft.Json.12.0.2\lib\net45\Newtonsoft.Json.dll</HintPath>
62+
<HintPath>..\packages\Newtonsoft.Json.12.0.3\lib\net45\Newtonsoft.Json.dll</HintPath>
6363
</Reference>
6464
<Reference Include="Octokit, Version=0.36.0.0, Culture=neutral, processorArchitecture=MSIL">
6565
<HintPath>..\packages\Octokit.0.36.0\lib\net46\Octokit.dll</HintPath>

MedocUpdates/TODO.txt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,5 +83,7 @@ Localization
8383
+Change download progressbar color (or even hightlighted DownloadButton background)
8484
Changed DownloadButton background color to M.E.Doc's green
8585

86-
Make the app check it's updates periodically
87-
Also make a setting for it
86+
-Make the app check it's updates periodically
87+
Also make a setting for it
88+
89+
Redo all of the M.E.Doc update checking to async/await?

MedocUpdates/frmMUUpdates.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@ public int GetUpdateState()
3535
return this.remoteVersion.CompareTo(this.localVersion);
3636
}
3737

38-
private void frmMUUpdates_Load(object sender, EventArgs e)
38+
private async void frmMUUpdates_Load(object sender, EventArgs e)
3939
{
40-
if(!MUVersion.Init())
40+
if(await MUVersion.Init() == null)
4141
{
4242
Log.Write("frmMUUpdates: Cannot retrieve the latest releases from Github. Check your Internet connection");
4343
return;

MedocUpdates/packages.config

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<packages>
33
<package id="HtmlAgilityPack" version="1.11.16" targetFramework="net472" />
4-
<package id="Newtonsoft.Json" version="12.0.2" targetFramework="net472" />
4+
<package id="Newtonsoft.Json" version="12.0.3" targetFramework="net472" />
55
<package id="Octokit" version="0.36.0" targetFramework="net472" />
66
<package id="Ookii.Dialogs.WinForms" version="1.1.0" targetFramework="net472" />
77
<package id="Syroot.Windows.IO.KnownFolders" version="1.2.1" targetFramework="net472" />

0 commit comments

Comments
 (0)