commit 049333d29587d9d92865bc2867424010b7f15585
Author: Panagiotis Kanavos <pkanavos@gmail.com>
Date:   Wed Mar 7 17:57:29 2012 +0200

    Converted NetSparkle project to .NET 4 Client Profile
    Threading fixes for NetSparkle
    Added configurable versioninfo.xml url

diff --git a/trunk/NetSparkle/NetSparkle.cs b/trunk/NetSparkle/NetSparkle.cs
index 589b6b8..9be1464 100644
--- a/trunk/NetSparkle/NetSparkle.cs
+++ b/trunk/NetSparkle/NetSparkle.cs
@@ -5,6 +5,7 @@ using System.Text;
 using System.ComponentModel;
 using System.Threading;
 using System.Net;
+using System.Windows;
 using System.Windows.Forms;
 using System.Drawing;
 using System.Runtime.InteropServices;
@@ -12,6 +13,7 @@ using System.Management;
 using System.Diagnostics;
 using System.Security.Cryptography.X509Certificates;
 using System.Net.Security;
+using Point = System.Drawing.Point;
 
 namespace AppLimit.NetSparkle
 {
@@ -437,6 +439,7 @@ namespace AppLimit.NetSparkle
         /// <param name="currentItem"></param>
         public void ShowUpdateNeededUI(NetSparkleAppCastItem currentItem)
         {
+
             // create the form
             NetSparkleForm frm = new NetSparkleForm(currentItem, ApplicationIcon, ApplicationWindowIcon);
 
@@ -445,6 +448,7 @@ namespace AppLimit.NetSparkle
 
             if (HideReleaseNotes)
                 frm.RemoveReleaseNotesControls();
+
             
             // show it
             DialogResult dlgResult = frm.ShowDialog();
diff --git a/trunk/NetSparkle/NetSparkle2010.csproj b/trunk/NetSparkle/NetSparkle2010.csproj
index 9485e31..3f858c7 100644
--- a/trunk/NetSparkle/NetSparkle2010.csproj
+++ b/trunk/NetSparkle/NetSparkle2010.csproj
@@ -61,6 +61,11 @@
     <AssemblyOriginatorKeyFile>pithos.snk</AssemblyOriginatorKeyFile>
   </PropertyGroup>
   <ItemGroup>
+    <Reference Include="log4net">
+      <HintPath>..\Libraries\log4net.dll</HintPath>
+    </Reference>
+    <Reference Include="PresentationCore" />
+    <Reference Include="PresentationFramework" />
     <Reference Include="System" />
     <Reference Include="System.Core">
       <RequiredTargetFramework>3.5</RequiredTargetFramework>
@@ -68,6 +73,7 @@
     <Reference Include="System.Drawing" />
     <Reference Include="System.Management" />
     <Reference Include="System.Windows.Forms" />
+    <Reference Include="System.Xaml" />
     <Reference Include="System.Xml.Linq">
       <RequiredTargetFramework>3.5</RequiredTargetFramework>
     </Reference>
@@ -76,6 +82,7 @@
     </Reference>
     <Reference Include="System.Data" />
     <Reference Include="System.Xml" />
+    <Reference Include="WindowsBase" />
   </ItemGroup>
   <ItemGroup>
     <Compile Include="AssemblyInfo.cs" />
diff --git a/trunk/NetSparkle/NetSparkleMainWindows.cs b/trunk/NetSparkle/NetSparkleMainWindows.cs
index d8c2a57..92a3a09 100644
--- a/trunk/NetSparkle/NetSparkleMainWindows.cs
+++ b/trunk/NetSparkle/NetSparkleMainWindows.cs
@@ -4,23 +4,23 @@ using System.ComponentModel;
 using System.Data;
 using System.Drawing;
 using System.Linq;
+using System.Reflection;
 using System.Text;
 using System.Windows.Forms;
 using System.IO;
+using log4net;
 
 namespace AppLimit.NetSparkle
 {
     public partial class NetSparkleMainWindows : Form, IDisposable
     {
-        private StreamWriter sw = null;
+        private static readonly ILog Log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
 
         public NetSparkleMainWindows()
         {
             // init ui
             InitializeComponent();
 
-            // init logfile
-            sw = File.CreateText(Path.Combine(Environment.ExpandEnvironmentVariables("%temp%"), "NetSparkle.log"));
         }
 
         public void Report(String message)
@@ -45,11 +45,7 @@ namespace AppLimit.NetSparkle
         {
             try
             {
-                // write 
-                sw.WriteLine(msg);
-
-                // flush
-                sw.Flush();
+                Log.Info(msg);
             } catch(Exception)
             {
 
@@ -60,11 +56,6 @@ namespace AppLimit.NetSparkle
 
         void IDisposable.Dispose()
         {
-            // flush again
-            sw.Flush();
-
-            // close the stream
-            sw.Dispose();
 
             // close the base
             base.Dispose();
diff --git a/trunk/Pithos.Client.WPF/App.xaml.cs b/trunk/Pithos.Client.WPF/App.xaml.cs
index f87b11f..4105bfe 100644
--- a/trunk/Pithos.Client.WPF/App.xaml.cs
+++ b/trunk/Pithos.Client.WPF/App.xaml.cs
@@ -75,13 +75,6 @@ namespace Pithos.Client.WPF
             AppDomain.CurrentDomain.UnhandledException += OnUnhandledException;
             TaskScheduler.UnobservedTaskException += OnUnobservedException;
 
-            //_sparkle = new Sparkle(Settings.Default.UpdateUrl);
-            //_sparkle.updateDetected += OnUpdateDetected;
-            //_sparkle.ShowDiagnosticWindow = true;
-            
-            //Must delay opening the upgrade window
-            //to avoid Windows Messages sent by the TaskbarIcon
-            //TaskEx.Delay(5000).ContinueWith(_=>_sparkle.StartLoop(true,true),TaskScheduler.FromCurrentSynchronizationContext());
 
             //Fix incorrect proxy settings by switching to default proxy, if the proxy server settings is empty
             if (Settings.Default.UseManualProxy && String.IsNullOrWhiteSpace(Settings.Default.ProxyServer))
diff --git a/trunk/Pithos.Client.WPF/Configuration/PithosSettings.cs b/trunk/Pithos.Client.WPF/Configuration/PithosSettings.cs
index d35db40..38d38fd 100644
--- a/trunk/Pithos.Client.WPF/Configuration/PithosSettings.cs
+++ b/trunk/Pithos.Client.WPF/Configuration/PithosSettings.cs
@@ -120,12 +120,7 @@ namespace Pithos.Client.WPF.Configuration
 
         public AccountsCollection Accounts
         {
-            get
-            {
-                if (_settings.Accounts==null)
-                    _settings.Accounts=new AccountsCollection();
-                return _settings.Accounts;
-            }
+            get { return _settings.Accounts ?? (_settings.Accounts = new AccountsCollection()); }
             set { _settings.Accounts = value; }
         }
 
@@ -221,6 +216,21 @@ namespace Pithos.Client.WPF.Configuration
             set { _settings.HashingParallelism = value; }
         }
 
+        public string UpdateUrl
+        {
+            get { return _settings.UpdateUrl; }
+        }
+
+        public bool UpdateDiagnostics
+        {
+            get { return _settings.UpdateDiagnostics; }
+        }
+
+        public TimeSpan UpdateCheckInterval
+        {
+            get { return _settings.UpdateCheckInterval; }
+        }
+
         public void Save()
         {
             _settings.Save();
diff --git a/trunk/Pithos.Client.WPF/Pithos.Client.WPF.csproj b/trunk/Pithos.Client.WPF/Pithos.Client.WPF.csproj
index 641c76c..79af7bb 100644
--- a/trunk/Pithos.Client.WPF/Pithos.Client.WPF.csproj
+++ b/trunk/Pithos.Client.WPF/Pithos.Client.WPF.csproj
@@ -469,6 +469,10 @@
       <Project>{C45218F8-09E7-4F57-85BC-5D8D2AC736A3}</Project>
       <Name>ParallelExtensionsExtras</Name>
     </ProjectReference>
+    <ProjectReference Include="..\NetSparkle\NetSparkle2010.csproj">
+      <Project>{74635A21-2BAD-4522-AB95-E3E5703CD301}</Project>
+      <Name>NetSparkle2010</Name>
+    </ProjectReference>
     <ProjectReference Include="..\NotifyIconWpf\NotifyIconWpf.csproj">
       <Project>{7AC63864-7638-41C4-969C-D3197EF2BED9}</Project>
       <Name>NotifyIconWpf</Name>
diff --git a/trunk/Pithos.Client.WPF/Properties/AssemblyInfo.cs b/trunk/Pithos.Client.WPF/Properties/AssemblyInfo.cs
index 945c458..818091b 100644
--- a/trunk/Pithos.Client.WPF/Properties/AssemblyInfo.cs
+++ b/trunk/Pithos.Client.WPF/Properties/AssemblyInfo.cs
@@ -93,5 +93,5 @@ using System.Windows;
 // You can specify all the values or you can default the Build and Revision Numbers 
 // by using the '*' as shown below:
 // [assembly: AssemblyVersion("1.0.*")]
-[assembly: AssemblyVersion("0.7.0.0")]
+[assembly: AssemblyVersion("0.7.20305.0")]
 [assembly: AssemblyFileVersionAttribute("0.7.20305.0")]
diff --git a/trunk/Pithos.Client.WPF/Properties/Settings.Designer.cs b/trunk/Pithos.Client.WPF/Properties/Settings.Designer.cs
index f74fa75..29fcc1b 100644
--- a/trunk/Pithos.Client.WPF/Properties/Settings.Designer.cs
+++ b/trunk/Pithos.Client.WPF/Properties/Settings.Designer.cs
@@ -322,11 +322,35 @@ namespace Pithos.Client.WPF.Properties {
         [global::System.Configuration.ApplicationScopedSettingAttribute()]
         [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
         [global::System.Configuration.SpecialSettingAttribute(global::System.Configuration.SpecialSetting.WebServiceUrl)]
-        [global::System.Configuration.DefaultSettingValueAttribute("file:///E:/Projects/PITHOS/Source/Pithos/trunk/Pithos.AppCast/versioninfo.xml")]
+        [global::System.Configuration.DefaultSettingValueAttribute("https://github.com/pkanavos/PithosUpdateTest/raw/master/versioninfo.xml")]
         public string UpdateUrl {
             get {
                 return ((string)(this["UpdateUrl"]));
             }
         }
+        
+        [global::System.Configuration.UserScopedSettingAttribute()]
+        [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
+        [global::System.Configuration.DefaultSettingValueAttribute("False")]
+        public bool UpdateDiagnostics {
+            get {
+                return ((bool)(this["UpdateDiagnostics"]));
+            }
+            set {
+                this["UpdateDiagnostics"] = value;
+            }
+        }
+        
+        [global::System.Configuration.UserScopedSettingAttribute()]
+        [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
+        [global::System.Configuration.DefaultSettingValueAttribute("24.00:00:00")]
+        public global::System.TimeSpan UpdateCheckInterval {
+            get {
+                return ((global::System.TimeSpan)(this["UpdateCheckInterval"]));
+            }
+            set {
+                this["UpdateCheckInterval"] = value;
+            }
+        }
     }
 }
diff --git a/trunk/Pithos.Client.WPF/Properties/Settings.settings b/trunk/Pithos.Client.WPF/Properties/Settings.settings
index f4adf7d..7359f43 100644
--- a/trunk/Pithos.Client.WPF/Properties/Settings.settings
+++ b/trunk/Pithos.Client.WPF/Properties/Settings.settings
@@ -81,7 +81,13 @@
       <Value Profile="(Default)">00:01:00</Value>
     </Setting>
     <Setting Name="UpdateUrl" Type="(Web Service URL)" Scope="Application">
-      <Value Profile="(Default)">file:///E:/Projects/PITHOS/Source/Pithos/trunk/Pithos.AppCast/versioninfo.xml</Value>
+      <Value Profile="(Default)">https://github.com/pkanavos/PithosUpdateTest/raw/master/versioninfo.xml</Value>
+    </Setting>
+    <Setting Name="UpdateDiagnostics" Type="System.Boolean" Scope="User">
+      <Value Profile="(Default)">False</Value>
+    </Setting>
+    <Setting Name="UpdateCheckInterval" Type="System.TimeSpan" Scope="User">
+      <Value Profile="(Default)">24.00:00:00</Value>
     </Setting>
   </Settings>
 </SettingsFile>
\ No newline at end of file
diff --git a/trunk/Pithos.Client.WPF/Shell/ShellView.xaml b/trunk/Pithos.Client.WPF/Shell/ShellView.xaml
index be1aa75..da421d5 100644
--- a/trunk/Pithos.Client.WPF/Shell/ShellView.xaml
+++ b/trunk/Pithos.Client.WPF/Shell/ShellView.xaml
@@ -102,6 +102,7 @@
                             <Image Source="/Pithos.Client.WPF;component/Images/About.ico" />
                         </MenuItem.Icon>
                     </MenuItem>
+                    <MenuItem  Header="Check For Upgrade" x:Name="CheckForUpgrade" cal:Message.Attach="CheckForUpgrade"/>
                     <MenuItem x:Name="GoToSiteRootMenu"  cal:Message.Attach="[Event MouseLeftButtonUp]=[Action GoToSite()]"
                               cal:Action.TargetWithoutContext="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=MenuItem, AncestorLevel=1}, Path=DataContext}" >
                         <MenuItem.HeaderTemplate>
diff --git a/trunk/Pithos.Client.WPF/Shell/ShellViewModel.cs b/trunk/Pithos.Client.WPF/Shell/ShellViewModel.cs
index ded5171..fd4cf83 100644
--- a/trunk/Pithos.Client.WPF/Shell/ShellViewModel.cs
+++ b/trunk/Pithos.Client.WPF/Shell/ShellViewModel.cs
@@ -50,6 +50,7 @@ using System.ServiceModel;
 using System.Threading.Tasks;
 using System.Windows;
 using System.Windows.Controls.Primitives;
+using AppLimit.NetSparkle;
 using Caliburn.Micro;
 using Hardcodet.Wpf.TaskbarNotification;
 using Pithos.Client.WPF.Configuration;
@@ -179,14 +180,33 @@ namespace Pithos.Client.WPF {
 		{
 			base.OnActivate();
 
-			
+            _sparkle = new Sparkle(Settings.UpdateUrl);
+            _sparkle.updateDetected += OnUpgradeDetected;
+            _sparkle.ShowDiagnosticWindow = Settings.UpdateDiagnostics;
+
+            //Must delay opening the upgrade window
+            //to avoid Windows Messages sent by the TaskbarIcon
+            TaskEx.Delay(5000).ContinueWith(_=>
+                Execute.OnUIThread(()=> _sparkle.StartLoop(true,true,Settings.UpdateCheckInterval)));
+
 
 			StartMonitoring();                    
 		}
 
+	    private void OnUpgradeDetected(object sender, UpdateDetectedEventArgs e)
+	    {
+	        Log.InfoFormat("Update detected {0}",e.LatestVersion);
+	    }
 
+        public void CheckForUpgrade()
+        {
+            _sparkle.StopLoop();
+            _sparkle.Dispose();
+            _sparkle=new Sparkle(Settings.UpdateUrl);
+            _sparkle.StartLoop(true,true,Settings.UpdateCheckInterval);
+        }
 
-		private async void StartMonitoring()
+	    private async void StartMonitoring()
 		{
 			try
 			{
@@ -831,8 +851,9 @@ namespace Pithos.Client.WPF {
 
 
 		private bool _pollStarted;
+	    private Sparkle _sparkle;
 
-		//SMELL: Doing so much work for notifications in the shell is wrong
+	    //SMELL: Doing so much work for notifications in the shell is wrong
 		//The notifications should be moved to their own view/viewmodel pair
 		//and different templates should be used for different message types
 		//This will also allow the addition of extra functionality, eg. actions
diff --git a/trunk/Pithos.Client.WPF/app.config b/trunk/Pithos.Client.WPF/app.config
index bded901..9d9bfc3 100644
--- a/trunk/Pithos.Client.WPF/app.config
+++ b/trunk/Pithos.Client.WPF/app.config
@@ -87,6 +87,12 @@
    <setting name="StartupDelay" serializeAs="String">
     <value>00:01:00</value>
    </setting>
+   <setting name="UpdateDiagnostics" serializeAs="String">
+    <value>False</value>
+   </setting>
+   <setting name="UpdateCheckInterval" serializeAs="String">
+    <value>24.00:00:00</value>
+   </setting>
   </Pithos.Client.WPF.Properties.Settings>
 	</userSettings>
 	<connectionStrings>
@@ -120,7 +126,7 @@
     <value>https://pithos.dev.grnet.gr</value>
    </setting>
    <setting name="UpdateUrl" serializeAs="String">
-    <value>file:///E:/Projects/PITHOS/Source/Pithos/trunk/Pithos.AppCast/versioninfo.xml</value>
+    <value>https://github.com/pkanavos/PithosUpdateTest/raw/master/versioninfo.xml</value>
    </setting>
   </Pithos.Client.WPF.Properties.Settings>
 	</applicationSettings>
