[longomatch] Make the Latest Version URL configurable by Addins.



commit bac741da3293823f053a91d37947c805ece0da8f
Author: Xavi Artigas <xartigas fluendo com>
Date:   Fri Apr 10 13:40:00 2015 +0200

    Make the Latest Version URL configurable by Addins.

 LongoMatch.Core/Common/Constants.cs    |    2 ++
 LongoMatch.Core/Config.cs              |    6 ++++++
 LongoMatch.Services/UpdatesNotifier.cs |   21 +++++----------------
 3 files changed, 13 insertions(+), 16 deletions(-)
---
diff --git a/LongoMatch.Core/Common/Constants.cs b/LongoMatch.Core/Common/Constants.cs
index 9ece14c..d962486 100644
--- a/LongoMatch.Core/Common/Constants.cs
+++ b/LongoMatch.Core/Common/Constants.cs
@@ -76,6 +76,8 @@ Xavier Queralt Mateu (ca)";
 
                public const string WEBSITE = "http://www.longomatch.com";;
 
+               public const string LATEST_VERSION_URL = "http://oneplay-cdn.fluendo.com/latest.json";;
+
                public const string MANUAL = "http://www.longomatch.com/documentation/manual.html";;
 
                #if HAVE_GTK
diff --git a/LongoMatch.Core/Config.cs b/LongoMatch.Core/Config.cs
index 0f8aa3c..c28f91a 100644
--- a/LongoMatch.Core/Config.cs
+++ b/LongoMatch.Core/Config.cs
@@ -107,6 +107,7 @@ namespace LongoMatch
                        Copyright = Constants.COPYRIGHT;
                        License = Constants.LICENSE;
                        SoftwareName = Constants.SOFTWARE_NAME;
+                       LatestVersionURL = Constants.LATEST_VERSION_URL;
                }
 
                public static void Save ()
@@ -277,6 +278,11 @@ namespace LongoMatch
                        set;
                }
 
+               static public string LatestVersionURL {
+                       get;
+                       set;
+               }
+
                static public Image FieldBackground {
                        get {
                                return new Image (Path.Combine (Config.ImagesDir, 
Constants.FIELD_BACKGROUND));
diff --git a/LongoMatch.Services/UpdatesNotifier.cs b/LongoMatch.Services/UpdatesNotifier.cs
index 57b87b7..95807c8 100644
--- a/LongoMatch.Services/UpdatesNotifier.cs
+++ b/LongoMatch.Services/UpdatesNotifier.cs
@@ -21,7 +21,6 @@ namespace LongoMatch.Services
                readonly Version currentVersion;
                Version latestVersion;
 
-               const string UPDATE_INFO_URL="http://oneplay-cdn.fluendo.com/latest.json";;
                string tempFile;
                string downloadURL;
 
@@ -40,33 +39,24 @@ namespace LongoMatch.Services
                void FetchNewVersion() {
                        var wb = new WebClient();
                        try {
-                               wb.DownloadFile(UPDATE_INFO_URL,tempFile);
+                               wb.DownloadFile(Config.LatestVersionURL,tempFile);
                                var fileStream = new FileStream(tempFile, FileMode.Open);
                                var sr = new StreamReader (fileStream);
                                JObject latestObject = JsonConvert.DeserializeObject<JObject> (sr.ReadToEnd 
());
                                fileStream.Close ();
+                               Log.InformationFormat ("UpdatesNotifier: Got latest version from {0}",
+                                       Config.LatestVersionURL);
 
                                latestVersion = new Version (latestObject["version"].Value<string> ());
                                downloadURL = latestObject["url"].Value<string> ();
                        }
                        catch(Exception ex) {
-                               Log.Warning("Error processing version file: " + UPDATE_INFO_URL);
+                               Log.Warning("Error processing version file: " + Config.LatestVersionURL);
                                Log.Exception (ex);
                                latestVersion = currentVersion;
                        }
                }
 
-               bool ConectionExists() {
-                       try {
-                               Dns.GetHostEntry("oneplay-cdn.fluendo.com");
-                               return true;
-                       }
-                       catch {
-                               latestVersion = currentVersion;
-                               return false;
-                       }
-               }
-
                bool IsOutDated() {
                        if(latestVersion.Major > currentVersion.Major)
                                return true;
@@ -78,8 +68,7 @@ namespace LongoMatch.Services
                }
 
                void CheckForUpdates() {
-                       if(ConectionExists())
-                               FetchNewVersion();
+                       FetchNewVersion();
                        Log.InformationFormat ("UpdatesNotifier: Current version is {0} and latest available 
is {1}",
                                currentVersion, latestVersion);
                        if(IsOutDated()) {


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]