[longomatch] Add Updates Notifier service.
- From: Andoni Morales Alastruey <amorales src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [longomatch] Add Updates Notifier service.
- Date: Fri, 17 Apr 2015 16:20:44 +0000 (UTC)
commit e561a64a2b20cf4d4d0d2ca4a940c9cf719673c4
Author: Xavi Artigas <xartigas fluendo com>
Date: Fri Apr 10 10:39:25 2015 +0200
Add Updates Notifier service.
The link in the popup message does not work yet.
Requires machine.config file to be available, which means that MONO_CFG_PATH has to be set on some OS.
LongoMatch.Services/LongoMatch.Services.csproj | 6 +-
LongoMatch.Services/UpdatesNotifier.cs | 94 ++++++++++++++++++++++++
po/POTFILES.in | 1 +
3 files changed, 100 insertions(+), 1 deletions(-)
---
diff --git a/LongoMatch.Services/LongoMatch.Services.csproj b/LongoMatch.Services/LongoMatch.Services.csproj
index 6eacc73..54f064a 100644
--- a/LongoMatch.Services/LongoMatch.Services.csproj
+++ b/LongoMatch.Services/LongoMatch.Services.csproj
@@ -44,6 +44,7 @@
<Compile Include="..\AssemblyInfo\AssemblyInfo.cs">
<Link>AssemblyInfo.cs</Link>
</Compile>
+ <Compile Include="UpdatesNotifier.cs" />
</ItemGroup>
<ItemGroup>
<Folder Include="..\" />
@@ -52,6 +53,9 @@
<Reference Include="System" />
<Reference Include="Mono.Posix" />
<Reference Include="System.Core" />
+ <Reference Include="Newtonsoft.Json, Version=4.5.0.0, Culture=neutral, PublicKeyToken=b9a188c8922137c6">
+ <Package>newtonsoft-json</Package>
+ </Reference>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\LongoMatch.Core\LongoMatch.Core.csproj">
@@ -68,4 +72,4 @@
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
-</Project>
\ No newline at end of file
+</Project>
diff --git a/LongoMatch.Services/UpdatesNotifier.cs b/LongoMatch.Services/UpdatesNotifier.cs
new file mode 100644
index 0000000..165c9f2
--- /dev/null
+++ b/LongoMatch.Services/UpdatesNotifier.cs
@@ -0,0 +1,94 @@
+//
+// Copyright (C) 2015 FLUENDO S.A.
+//
+
+using System;
+using System.IO;
+using System.Reflection;
+using System.Net;
+using System.Threading;
+using Newtonsoft.Json;
+using Newtonsoft.Json.Linq;
+using Mono.Unix;
+
+namespace LongoMatch.Services
+{
+
+
+ public class UpdatesNotifier
+ {
+ readonly Version actual;
+ Version update;
+
+ const string UPDATE_INFO_URL="http://oneplay-cdn.fluendo.com/latest.json";
+ string temp_file;
+ string downloadURL;
+
+ #region Constructors
+ public UpdatesNotifier()
+ {
+ actual = Assembly.GetExecutingAssembly().GetName().Version;
+ temp_file = Path.Combine(Config.HomeDir, "latest.json");
+
+ var thread = new Thread(new ThreadStart(CheckForUpdates));
+ thread.Start();
+ }
+ #endregion
+
+ #region Private methods
+ void FetchNewVersion() {
+ var wb = new WebClient();
+ try {
+ wb.DownloadFile(UPDATE_INFO_URL,temp_file);
+ var fileStream = new FileStream(temp_file, FileMode.Open);
+ var sr = new StreamReader (fileStream);
+ JObject latest = JsonConvert.DeserializeObject<JObject> (sr.ReadToEnd ());
+ fileStream.Close ();
+
+ update = new Version (latest["version"].Value<string> ());
+ downloadURL = latest["url"].Value<string> ();
+ }
+ catch(Exception ex) {
+ Console.WriteLine("Error downloading version file:\n"+ex);
+ update = actual;
+ }
+ }
+
+ bool ConectionExists() {
+ try {
+ Dns.GetHostEntry("oneplay-cdn.fluendo.com");
+ return true;
+ }
+ catch {
+ update = actual;
+ return false;
+ }
+ }
+
+ bool IsOutDated() {
+ if(update.Major > actual.Major)
+ return true;
+ if(update.Minor > actual.Minor)
+ return true;
+ if(update.Build > actual.Build)
+ return true;
+ return false;
+ }
+
+ void CheckForUpdates() {
+ if(ConectionExists())
+ FetchNewVersion();
+ if(update != null && IsOutDated()) {
+ Config.GUIToolkit.Invoke (delegate {
+ Config.GUIToolkit.InfoMessage (
+ string.Format (
+ Catalog.GetString("Version {0} is available!\n" +
+ "(You are using version {1})\n" +
+ "<a href=\"{2}/index.html\">Click here to get
it.</a>"),
+ update, actual, downloadURL));
+ });
+ }
+ }
+ #endregion
+ }
+}
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 9829c2d..910a12f 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -148,3 +148,4 @@ LongoMatch.Services/ProjectsManager.cs
LongoMatch.Services/RenderingJobsManager.cs
LongoMatch.Services/TemplatesService.cs
LongoMatch.Services/ToolsManager.cs
+LongoMatch.Services/UpdatesNotifier.cs
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]