66
77using Octokit ;
88using System . Diagnostics ;
9+ using System . Net ;
910
1011namespace 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 ( )
0 commit comments