Skip to content

Commit

Permalink
replaced logic of update with RestSharp, had to switch security on gi…
Browse files Browse the repository at this point in the history
…thub api request
  • Loading branch information
Stefan Ruepp committed Apr 30, 2018
1 parent 681d1a1 commit 2ecadd3
Show file tree
Hide file tree
Showing 7 changed files with 204 additions and 27 deletions.
4 changes: 4 additions & 0 deletions EveChatNotifier/App_Readme/Spring.Rest.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Spring.NET REST Client Framework
--------------------------------
Download full package with sources, documentation and examples at
http://www.springframework.net/rest/
22 changes: 15 additions & 7 deletions EveChatNotifier/EveChatNotifier.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@
<OutputType>WinExe</OutputType>
<RootNamespace>EveChatNotifier</RootNamespace>
<AssemblyName>EveChatNotifier</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
Expand All @@ -20,6 +21,7 @@
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
Expand All @@ -29,26 +31,31 @@
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<PropertyGroup>
<ApplicationIcon>preferences_desktop_notification_bell.ico</ApplicationIcon>
</PropertyGroup>
<ItemGroup>
<Reference Include="AutoUpdater.NET, Version=1.4.6.0, Culture=neutral, PublicKeyToken=942f95247e354701, processorArchitecture=MSIL">
<HintPath>..\packages\Autoupdater.NET.Official.1.4.6\lib\net40\AutoUpdater.NET.dll</HintPath>
<Reference Include="AutoUpdater.NET, Version=1.4.9.0, Culture=neutral, PublicKeyToken=501435c91b35f4bc, processorArchitecture=MSIL">
<HintPath>..\packages\Autoupdater.NET.Official.1.4.9\lib\net40\AutoUpdater.NET.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Win32.TaskScheduler, Version=2.7.2.0, Culture=neutral, PublicKeyToken=c416bc1b32d97233, processorArchitecture=MSIL">
<HintPath>..\packages\TaskScheduler.2.7.2\lib\net40\Microsoft.Win32.TaskScheduler.dll</HintPath>
<Reference Include="Microsoft.Win32.TaskScheduler, Version=2.8.1.0, Culture=neutral, PublicKeyToken=c416bc1b32d97233, processorArchitecture=MSIL">
<HintPath>..\packages\TaskScheduler.2.8.1\lib\net40\Microsoft.Win32.TaskScheduler.dll</HintPath>
</Reference>
<Reference Include="NAudio, Version=1.8.4.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\NAudio.1.8.4\lib\net35\NAudio.dll</HintPath>
</Reference>
<Reference Include="Newtonsoft.Json, Version=10.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.10.0.3\lib\net40\Newtonsoft.Json.dll</HintPath>
<Reference Include="Newtonsoft.Json, Version=11.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.11.0.2\lib\net40\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="RestSharp, Version=106.2.2.0, Culture=neutral, PublicKeyToken=598062e77f915f75, processorArchitecture=MSIL">
<HintPath>..\packages\RestSharp.106.2.2\lib\net452\RestSharp.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Transactions" />
<Reference Include="System.Web" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
Expand All @@ -66,6 +73,7 @@
<Compile Include="Cleanup.cs" />
<Compile Include="Extensions.cs" />
<Compile Include="GithubUpdater\GithubRelease.cs" />
<Compile Include="GithubUpdater\GithubReleaseRestSharp.cs" />
<Compile Include="GithubUpdater\GithubUpdateCheck.cs" />
<Compile Include="GithubUpdater\UpdaterXml.cs" />
<Compile Include="IdleDetector\LastInput.cs" />
Expand Down
89 changes: 89 additions & 0 deletions EveChatNotifier/GithubUpdater/GithubReleaseRestSharp.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace EveChatNotifier.GithubUpdater
{
public class GithubReleaseRestSharp
{
public string url { get; set; }
public string assets_url { get; set; }
public string upload_url { get; set; }
public string html_url { get; set; }
public int id { get; set; }
public string tag_name { get; set; }
public string target_commitish { get; set; }
public string name { get; set; }
public bool draft { get; set; }
public Author author { get; set; }
public bool prerelease { get; set; }
public DateTime created_at { get; set; }
public DateTime published_at { get; set; }
public List<Asset> assets { get; set; }
public string tarball_url { get; set; }
public string zipball_url { get; set; }
public string body { get; set; }
}

public class Author
{
public string login { get; set; }
public int id { get; set; }
public string avatar_url { get; set; }
public string gravatar_id { get; set; }
public string url { get; set; }
public string html_url { get; set; }
public string followers_url { get; set; }
public string following_url { get; set; }
public string gists_url { get; set; }
public string starred_url { get; set; }
public string subscriptions_url { get; set; }
public string organizations_url { get; set; }
public string repos_url { get; set; }
public string events_url { get; set; }
public string received_events_url { get; set; }
public string type { get; set; }
public bool site_admin { get; set; }
}

public class Uploader
{
public string login { get; set; }
public int id { get; set; }
public string avatar_url { get; set; }
public string gravatar_id { get; set; }
public string url { get; set; }
public string html_url { get; set; }
public string followers_url { get; set; }
public string following_url { get; set; }
public string gists_url { get; set; }
public string starred_url { get; set; }
public string subscriptions_url { get; set; }
public string organizations_url { get; set; }
public string repos_url { get; set; }
public string events_url { get; set; }
public string received_events_url { get; set; }
public string type { get; set; }
public bool site_admin { get; set; }
}

public class Asset
{
public string url { get; set; }
public int id { get; set; }
public string name { get; set; }
public object label { get; set; }
public Uploader uploader { get; set; }
public string content_type { get; set; }
public string state { get; set; }
public int size { get; set; }
public int download_count { get; set; }
public DateTime created_at { get; set; }
public DateTime updated_at { get; set; }
public string browser_download_url { get; set; }
}
}
93 changes: 84 additions & 9 deletions EveChatNotifier/GithubUpdater/GithubUpdateCheck.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using AutoUpdaterDotNET;
using RestSharp;
using System;
using System.Collections.Generic;
using System.IO;
Expand All @@ -25,22 +26,96 @@ public static void UpdateUsingLocalXmlFile(string gitUserName, string repoName)

try
{
wc.DownloadStringCompleted += Wc_DownloadStringCompleted;
wc.Headers.Add("user-agent", repoName);
wc.DownloadStringAsync(new Uri(string.Format(@"https://api.github.com/repos/{0}/{1}/releases/latest", gitUserName, repoName)));
// no idea why but we need to fallback to TSL1.2 in order to retrieve github information ...
//ServicePointManager.ServerCertificateValidationCallback += (sender, certificate, chain, sslPolicyErrors) => true;
//ServicePointManager.Expect100Continue = true;
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;

Uri reqUri = new Uri(string.Format(@"http://api.github.com/repos/{0}/{1}/releases/latest", gitUserName, repoName));

RestClient client = new RestClient(@"https://api.github.com");
RestRequest request = new RestRequest("repos/{username}/{reponame}/releases/latest", Method.GET);
request.AddUrlSegment("username", gitUserName);
request.AddUrlSegment("reponame", repoName);
request.AddHeader("user-agent", repoName);
request.RequestFormat = DataFormat.Json;
request.JsonSerializer = new RestSharp.Serializers.JsonSerializer();

client.ExecuteAsync<GithubUpdater.GithubReleaseRestSharp>(request, (response) =>
{
if(response.IsSuccessful)
{
RestReleaseCheck(response.Data);
}
else
{
Logging.WriteLine(string.Format("Unable to start update procedure:{0}{1}", Environment.NewLine, response.ErrorMessage));
}
});
}
catch (Exception ex)
{
Logging.WriteLine(string.Format("Unable to start async version check:{0}{1}", Environment.NewLine, ex.ToString()));
}
}

/// <summary>
/// start auto update after download
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private static void Wc_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
/// <summary>
/// RestSharp update detection
/// </summary>
/// <param name="release"></param>
private static void RestReleaseCheck(GithubUpdater.GithubReleaseRestSharp release)
{
try
{
// generate update information object
UpdaterXml.item update = new UpdaterXml.item();
update.url = release.assets.Where(w => w.browser_download_url.EndsWith(".zip", StringComparison.OrdinalIgnoreCase)).First().browser_download_url;
update.version = release.tag_name;
update.changelog = releaseUrl;
update.mandatory = false;

// generate xml file
string updateUrl = null;
do
{
updateUrl = System.IO.Path.Combine(System.IO.Path.GetTempPath(), string.Format("{0}.xml", Guid.NewGuid().ToString("N")));
} while (System.IO.File.Exists(updateUrl));

// add file to cleanup job
Cleanup.GetInstance().FilesToDelete.AddIfNotExist<string>(updateUrl);

// serialize to file
using (TextWriter writer = new StreamWriter(updateUrl, false))
{
XmlSerializer serializer = new XmlSerializer(typeof(UpdaterXml.item));
serializer.Serialize(writer, update);
writer.Close();
}

// start update procedure
if (Properties.Settings.Default.CheckForUpdates)
{
Logging.WriteLine("AutoUpdater feature enabled - checking for update in the background.");

AutoUpdater.ShowRemindLaterButton = true;
AutoUpdater.ReportErrors = false;
AutoUpdater.Mandatory = false;
AutoUpdater.ShowSkipButton = true;
AutoUpdater.Start(updateUrl);
}
}
catch(Exception ex)
{
Logging.WriteLine(string.Format("Unable to start update procedure:{0}{1}", Environment.NewLine, ex.ToString()));
}
}

/// <summary>
/// start auto update after download
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private static void Wc_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
{
try
{
Expand Down
4 changes: 2 additions & 2 deletions EveChatNotifier/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
// Sie können alle Werte angeben oder Standardwerte für die Build- und Revisionsnummern verwenden,
// übernehmen, indem Sie "*" eingeben:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("2.8.8.0")]
[assembly: AssemblyFileVersion("2.8.8.0")]
[assembly: AssemblyVersion("2.9.0.0")]
[assembly: AssemblyFileVersion("2.9.0.0")]
12 changes: 6 additions & 6 deletions EveChatNotifier/app.config
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<?xml version="1.0" encoding="utf-8" ?>
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
<section name="EveChatNotifier.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
<sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<section name="EveChatNotifier.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false"/>
</sectionGroup>
<sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
<section name="EveChatNotifier.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
<sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<section name="EveChatNotifier.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false"/>
</sectionGroup>
</configSections>
<userSettings>
Expand Down Expand Up @@ -112,4 +112,4 @@
</setting>
</EveChatNotifier.Properties.Settings>
</applicationSettings>
</configuration>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2"/></startup></configuration>
7 changes: 4 additions & 3 deletions EveChatNotifier/packages.config
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Autoupdater.NET.Official" version="1.4.6" targetFramework="net40" />
<package id="Autoupdater.NET.Official" version="1.4.9" targetFramework="net40" requireReinstallation="true" />
<package id="NAudio" version="1.8.4" targetFramework="net40" />
<package id="Newtonsoft.Json" version="10.0.3" targetFramework="net40" />
<package id="TaskScheduler" version="2.7.2" targetFramework="net40" />
<package id="Newtonsoft.Json" version="11.0.2" targetFramework="net40" requireReinstallation="true" />
<package id="RestSharp" version="106.2.2" targetFramework="net452" />
<package id="TaskScheduler" version="2.8.1" targetFramework="net40" requireReinstallation="true" />
<package id="Tulpep.NotificationWindow" version="1.1.25" targetFramework="net40" />
</packages>

0 comments on commit 2ecadd3

Please sign in to comment.