Exemplo n.º 1
1
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="items">List of updates to show</param>
        /// <param name="applicationIcon">The icon</param>
        /// <param name="separatorTemplate">HTML template for every single note. Use {0} = Version. {1} = Date. {2} = Note Body</param>
        /// <param name="headAddition">Additional text they will inserted into HTML Head. For Stylesheets.</param>
        public NetSparkleForm(Sparkle sparkle, NetSparkleAppCastItem[] items, Icon applicationIcon = null, string separatorTemplate = "", string headAddition = "")
        {
            _sparkle = sparkle;
            _updates = items;

            SeparatorTemplate =
                !string.IsNullOrEmpty(separatorTemplate) ?
                separatorTemplate :
                "<div style=\"border: #ccc 1px solid;\"><div style=\"background: {3}; padding: 5px;\"><span style=\"float: right; display:float;\">{1}</span>{0}</div><div style=\"padding: 5px;\">{2}</div></div><br>";

            InitializeComponent();

            // init ui
            try
            {
                NetSparkleBrowser.AllowWebBrowserDrop = false;
                NetSparkleBrowser.AllowNavigation = false;
            }
            catch (Exception ex)
            {
                Debug.WriteLine("Error in browser init: " + ex.Message);
            }

            NetSparkleAppCastItem item = items[0];

            lblHeader.Text = lblHeader.Text.Replace("APP", item.AppName);
            lblInfoText.Text = lblInfoText.Text.Replace("APP", item.AppName + " " + item.Version);
            lblInfoText.Text = lblInfoText.Text.Replace("OLDVERSION", getVersion(new Version(item.AppVersionInstalled)));

            if (items.Length == 0)
            {
                RemoveReleaseNotesControls();
            }
            else
            {
                NetSparkleAppCastItem latestVersion = _updates.OrderByDescending(p => p.Version).FirstOrDefault();

                StringBuilder sb = new StringBuilder("<html><head><meta http-equiv='Content-Type' content='text/html;charset=UTF-8'>" + headAddition + "</head><body>");
                foreach (NetSparkleAppCastItem castItem in items)
                {
                    sb.Append(string.Format(SeparatorTemplate,
                                            castItem.Version,
                                            castItem.PublicationDate.ToString("dd MMM yyyy"),
                                            GetReleaseNotes(castItem),
                                            latestVersion.Version.Equals(castItem.Version) ? "#ABFF82" : "#AFD7FF"));
                }
                sb.Append("</body>");

                string releaseNotes = sb.ToString();
                NetSparkleBrowser.DocumentText = releaseNotes;
            }

            if (applicationIcon != null)
            {
                imgAppIcon.Image = new Icon(applicationIcon, new Size(48, 48)).ToBitmap();
                Icon = applicationIcon;
            }

            TopMost = false;
        }
Exemplo n.º 2
0
        public void UpdateData(NetSparkleAppCastItem item, Image appIcon, Icon windowIcon, bool forceUpdate = false)
        {
            _currentItem = item;

            var resources = new System.ComponentModel.ComponentResourceManager(typeof(NetSparkleForm));
            resources.ApplyResources(this.lblHeader, "lblHeader");
            resources.ApplyResources(this.lblInfoText, "lblInfoText");

            lblHeader.Text = lblHeader.Text.Replace("APP", item.AppName);
            lblInfoText.Text = lblInfoText.Text.Replace("APP", item.AppName + " " + item.Version);
            lblInfoText.Text = lblInfoText.Text.Replace("OLDVERSION", item.AppVersionInstalled);

            if (item.ReleaseNotesLink != null && item.ReleaseNotesLink.Length > 0)
                NetSparkleBrowser.Navigate(item.ReleaseNotesLink);
            else
                RemoveReleaseNotesControls();

            if (appIcon != null)
                imgAppIcon.Image = appIcon;

            if (windowIcon != null)
                Icon = windowIcon;

            if (forceUpdate)
            {
                skipButton.Visible = false;
                buttonRemind.Visible = false;
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="item"></param>
        /// <param name="appIcon"></param>
        /// <param name="windowIcon"></param>
        public NetSparkleForm(NetSparkleAppCastItem item, Image appIcon, Icon windowIcon)
        {            
            InitializeComponent();
            
            // init ui 
            try
            {
                NetSparkleBrowser.AllowWebBrowserDrop = false;
                NetSparkleBrowser.AllowNavigation = false;
            }
            catch (Exception)
            { }
            
            _currentItem = item;

            lblHeader.Text = lblHeader.Text.Replace("APP", item.AppName);
            lblInfoText.Text = lblInfoText.Text.Replace("APP", item.AppName + " " + item.Version);
            lblInfoText.Text = lblInfoText.Text.Replace("OLDVERSION", item.AppVersionInstalled);

            if (!string.IsNullOrEmpty(item.ReleaseNotesLink) )
                NetSparkleBrowser.Navigate(item.ReleaseNotesLink);
            else            
                RemoveReleaseNotesControls();            

            if (appIcon != null)
                imgAppIcon.Image = appIcon;

            if (windowIcon != null)
                Icon = windowIcon;

            this.TopMost = true;
        }
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="sparkle">the sparkle instance</param>
        /// <param name="item"></param>
        /// <param name="appIcon">application icon</param>
        /// <param name="windowIcon">window icon</param>
        /// <param name="Unattend"><c>true</c> if this is an unattended install</param>
        public NetSparkleDownloadProgress(Sparkle sparkle, NetSparkleAppCastItem item, Image appIcon, Icon windowIcon, Boolean Unattend)
        {
            InitializeComponent();

            if (appIcon != null)
                imgAppIcon.Image = appIcon;

            if (windowIcon != null)
                Icon = windowIcon;

            // store the item
            _sparkle = sparkle;
            _item = item;
            //_referencedAssembly = referencedAssembly;
            _unattend = Unattend;

            // init ui
            btnInstallAndReLaunch.Visible = false;
            lblHeader.Text = lblHeader.Text.Replace("APP", item.AppName + " " + item.Version);
            progressDownload.Maximum = 100;
            progressDownload.Minimum = 0;
            progressDownload.Step = 1;

            // show the right 
            Size = new Size(Size.Width, 107);
            lblSecurityHint.Visible = false;
        }
Exemplo n.º 5
0
        private static NetSparkleAppCastItem ReadAppCast(XmlReader reader,
                                                         NetSparkleAppCastItem latestVersion, string installedVersion)
        {
            NetSparkleAppCastItem currentItem = null;

            // The fourth segment of the version number is ignored by Windows Installer:
            var installedVersionV = new Version(installedVersion);
            var installedVersionWithoutFourthSegment = new Version(installedVersionV.Major, installedVersionV.Minor,
                                                                   installedVersionV.Build);

            while (reader.Read())
            {
                if (reader.NodeType == XmlNodeType.Element)
                {
                    switch (reader.Name)
                    {
                        case itemNode:
                            {
                                currentItem = new NetSparkleAppCastItem();
                                break;
                            }
                        case releaseNotesLinkNode:
                            {
                                currentItem.ReleaseNotesLink = reader.ReadString().Trim();
                                break;
                            }
                        case enclosureNode:
                            {
                                var deltaFrom = reader.GetAttribute(deltaFromAttribute);
                                if (deltaFrom == null || deltaFrom == installedVersionWithoutFourthSegment.ToString())
                                {
                                    currentItem.Version = reader.GetAttribute(versionAttribute);
                                    currentItem.DownloadLink = reader.GetAttribute(urlAttribute);
                                    currentItem.DSASignature = reader.GetAttribute(dasSignature);
                                }
                                break;
                            }
                    }
                }
                else if (reader.NodeType == XmlNodeType.EndElement)
                {
                    switch (reader.Name)
                    {
                        case itemNode:
                            {
                                if (latestVersion == null)
                                    latestVersion = currentItem;
                                else if (currentItem.CompareTo(latestVersion) > 0)
                                {
                                    latestVersion = currentItem;
                                }
                                break;
                            }
                    }
                }
            }
            return latestVersion;
        }
 /// <summary>
 /// Show 'toast' window to notify new version is available
 /// </summary>
 /// <param name="updates">Appcast updates</param>
 /// <param name="applicationIcon">Icon to use in window</param>
 /// <param name="clickHandler">handler for click</param>
 public virtual void ShowToast(NetSparkleAppCastItem[] updates, Icon applicationIcon, Action<NetSparkleAppCastItem[]> clickHandler)
 {
     var toast = new ToastNotifier
         {
             Image =
                 {
                     Image = applicationIcon != null ? applicationIcon.ToBitmap() : Resources.software_update_available1
                 }
         };
     toast.ToastClicked += (sender, args) => clickHandler(updates); // TODO: this is leak
     toast.Show(Resources.DefaultNetSparkleUIFactory_ToastMessage, Resources.DefaultNetSparkleUIFactory_ToastCallToAction, 5);
 }
Exemplo n.º 7
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="item"></param>
        /// <param name="applicationIcon"></param>
        public NetSparkleForm(NetSparkleAppCastItem item, Icon applicationIcon)
        {
            InitializeComponent();

            // init ui
            try
            {
                NetSparkleBrowser.AllowWebBrowserDrop = false;
                NetSparkleBrowser.AllowNavigation = false;
            }
            catch (Exception ex)
            {
                Debug.WriteLine("Error in browser init: " + ex.Message);
            }

            _currentItem = item;

            lblHeader.Text = lblHeader.Text.Replace("APP", item.AppName);
            lblInfoText.Text = lblInfoText.Text.Replace("APP", item.AppName + " " + item.Version);
            lblInfoText.Text = lblInfoText.Text.Replace("OLDVERSION", item.AppVersionInstalled);

            if (!string.IsNullOrEmpty(item.ReleaseNotesLink))
            {

                if (new List<string>(new[]{".md",".mkdn",".mkd",".markdown"}).Contains(Path.GetExtension(item.ReleaseNotesLink).ToLower()))
                {
                    try
                    {
                        ShowMarkdownReleaseNotes(item);
                    }
                    catch (Exception)
                    {
            #if DEBUG
                        throw;
            #else
                        NetSparkleBrowser.Navigate(item.ReleaseNotesLink); //just show it raw
            #endif
                    }

                }
                else
                {
                    NetSparkleBrowser.Navigate(item.ReleaseNotesLink);
                }
            }
            else
                RemoveReleaseNotesControls();

            imgAppIcon.Image = applicationIcon.ToBitmap();
            Icon = applicationIcon;

            TopMost = true;
        }
Exemplo n.º 8
0
        private void bckWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            // get the config
            NetSparkleConfiguration config = _sparkle.GetApplicationConfig();

            // check for updats
            NetSparkleAppCastItem latestVersion = null;
            Boolean bUpdateRequired             = Sparkle.UpdateStatus.UpdateAvailable == _sparkle.GetUpdateStatus(config, out latestVersion);

            // save the result
            SparkleRequestedUpdate = bUpdateRequired;
            LatesVersion           = latestVersion;
        }
        private void bckWorker_DoWork(object sender, DoWorkEventArgs e)
        {            
            // get the config
            NetSparkleConfiguration config = _sparkle.GetApplicationConfig();

            // check for updats
            NetSparkleAppCastItem latestVersion;
            Boolean bUpdateRequired = _sparkle.IsUpdateRequired(config, out latestVersion);
                                
            // save the result
            SparkleRequestedUpdate = bUpdateRequired;
            this.latestVersion = latestVersion;
        }
Exemplo n.º 10
0
 /// <summary>
 /// Show 'toast' window to notify new version is available
 /// </summary>
 /// <param name="item">Appcast item</param>
 /// <param name="applicationIcon">Icon to use in window</param>
 /// <param name="clickHandler">handler for click</param>
 public virtual void ShowToast(NetSparkleAppCastItem item, Icon applicationIcon, EventHandler clickHandler)
 {
     var toast = new ToastNotifier
         {
             Tag = item,
             Image =
                 {
                     Image = applicationIcon.ToBitmap()
                 }
         };
     toast.ToastClicked += clickHandler;
     toast.Show(Resources.DefaultNetSparkleUIFactory_ToastMessage, Resources.DefaultNetSparkleUIFactory_ToastCallToAction, 5);
 }
        private void bckWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            // get the config
            NetSparkleConfiguration config = _sparkle.GetApplicationConfig();

            // check for updats
            NetSparkleAppCastItem latestVersion;
            Boolean bUpdateRequired = _sparkle.IsUpdateRequired(config, out latestVersion);

            // save the result
            SparkleRequestedUpdate = bUpdateRequired;
            this.latestVersion     = latestVersion;
        }
Exemplo n.º 12
0
        private void bckWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            // get the config
            NetSparkleConfiguration config = _sparkle.GetApplicationConfig();

            // check for updats
            NetSparkleAppCastItem latestVersion = null;
            Boolean bUpdateRequired = Sparkle.UpdateStatus.UpdateAvailable == _sparkle.GetUpdateStatus(config, out latestVersion);

            // save the result
            SparkleRequestedUpdate = bUpdateRequired;
            LatesVersion = latestVersion;
        }
Exemplo n.º 13
0
        private void bgworkerUpdate_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            NetSparkleAppCastItem lastVersion = e.Result as NetSparkleAppCastItem;

            if (lastVersion != null)
            {
                m_autoUpdator.ShowUpdateNeededUI(lastVersion);
            }
            else
            {
                MessageBox.Show(I18n.L.T("AlreadyUpdated"));
            }

            btnUpdate.Enabled = true;
            btnUpdate.Text    = I18n.L.T("CheckForUpdates");
        }
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="item"></param>
        /// <param name="applicationIcon">Your application Icon</param>
        public NetSparkleDownloadProgress(NetSparkleAppCastItem item, Icon applicationIcon)
        {
            InitializeComponent();

            imgAppIcon.Image = applicationIcon.ToBitmap();
            Icon = applicationIcon;

            // init ui
            btnInstallAndReLaunch.Visible = false;
            lblHeader.Text = lblHeader.Text.Replace("APP", item.AppName + " " + item.Version);
            downloadProgressLbl.Text = "";
            progressDownload.Maximum = 100;
            progressDownload.Minimum = 0;
            progressDownload.Step = 1;

            FormClosing += NetSparkleDownloadProgress_FormClosing;
        }
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="item"></param>
        /// <param name="applicationIcon">Your application Icon</param>
        public NetSparkleDownloadProgress(NetSparkleAppCastItem item, Icon applicationIcon)
        {
            InitializeComponent();

            imgAppIcon.Image = applicationIcon.ToBitmap();
            Icon = applicationIcon;

            // init ui
            btnInstallAndReLaunch.Visible = false;
            lblHeader.Text = lblHeader.Text.Replace("APP", item.AppName + " " + item.Version);
            progressDownload.Maximum = 100;
            progressDownload.Minimum = 0;
            progressDownload.Step = 1;

            // show the right
            Size = new Size(Size.Width, 107);
            lblSecurityHint.Visible = false;
        }
        public NetSparkleDownloadProgress(Sparkle sparkle, NetSparkleAppCastItem item, String referencedAssembly, Image appIcon, Icon windowIcon, Boolean Unattend)
        {
            InitializeComponent();

            if (appIcon != null)
                imgAppIcon.Image = appIcon;

            if (windowIcon != null)
                Icon = windowIcon;

            // store the item
            _sparkle = sparkle;
            _item = item;
            _referencedAssembly = referencedAssembly;
            _unattend = Unattend;

            // init ui
            btnInstallAndReLaunch.Visible = false;
            lblHeader.Text = lblHeader.Text.Replace("APP", item.AppName + " " + item.Version);
            progressDownload.Maximum = 100;
            progressDownload.Minimum = 0;
            progressDownload.Step = 1;

            // show the right
            Size = new Size(Size.Width, 107);
            lblSecurityHint.Visible = false;

            // get the filename of the download lin
            String[] segments = item.DownloadLink.Split('/');
            String fileName = segments[segments.Length - 1];

            // get temp path
            _tempName = Environment.ExpandEnvironmentVariables("%temp%\\" + fileName);

            // start async download
            WebClient Client = new WebClient();
            Client.DownloadProgressChanged += Client_DownloadProgressChanged;
            Client.DownloadFileCompleted += Client_DownloadFileCompleted;

            Uri url = new Uri(item.DownloadLink);

            Client.DownloadFileAsync(url, _tempName);
        }
Exemplo n.º 17
0
        public static bool CheckDSA(Sparkle sparkle, NetSparkleAppCastItem item, String tempName)
        {
            Boolean bDSAOk = false;

            // check if we have a dsa signature in appcast
            if (item.DSASignature == null || item.DSASignature.Length == 0)
            {
                sparkle.ReportDiagnosticMessage("No DSA check needed");
                bDSAOk = true;
            }
            else
            {
                // report
                sparkle.ReportDiagnosticMessage("Performing DSA check");

                // get the assembly
                if (File.Exists(tempName))
                {
                    // check if the file was downloaded successfully
                    String absolutePath = Path.GetFullPath(tempName);
                    if (!File.Exists(absolutePath))
                        throw new FileNotFoundException();

                    // get the assembly reference from which we start the update progress
                    // only from this trusted assembly the public key can be used
                    Assembly refassembly = System.Reflection.Assembly.GetEntryAssembly();
                    if (refassembly != null)
                    {
                        // Check if we found the public key in our entry assembly
                        if (NetSparkleDSAVerificator.ExistsPublicKey("NetSparkle_DSA.pub"))
                        {
                            // check the DSA Code and modify the back color
                            NetSparkleDSAVerificator dsaVerifier = new NetSparkleDSAVerificator("NetSparkle_DSA.pub");
                            bDSAOk = dsaVerifier.VerifyDSASignature(item.DSASignature, tempName);
                        }
                    }
                }
            }

            return bDSAOk;
        }
Exemplo n.º 18
0
 /// <summary>
 /// This method shows the update ui and allows to perform the 
 /// update process
 /// </summary>
 /// <param name="currentItem">the item to show the UI for</param>
 public void ShowUpdateNeededUI(NetSparkleAppCastItem currentItem)
 {
     if (this.UserWindow == null)
     {
         // create the form
         this.UserWindow = new NetSparkleForm(currentItem, ApplicationIcon, ApplicationWindowIcon);
     }
     this.UserWindow.CurrentItem = currentItem;
     if (this.HideReleaseNotes)
     {
         this.UserWindow.HideReleaseNotes();
     }
     // clear if already set.
     this.UserWindow.UserResponded -= new EventHandler(OnUserWindowUserResponded);
     this.UserWindow.UserResponded += new EventHandler(OnUserWindowUserResponded);
     this.UserWindow.Show();
 }
Exemplo n.º 19
0
        /// <summary>
        /// This method checks if an update is required. During this process the appcast
        /// will be downloaded and checked against the reference assembly. Ensure that
        /// the calling process has access to the internet and read access to the 
        /// reference assembly. This method is also called from the background loops.
        /// </summary>
        /// <param name="config">the configuration</param>
        /// <param name="latestVersion">returns the latest version</param>
        /// <returns><c>true</c> if an update is required</returns>
        public bool IsUpdateRequired(NetSparkleConfiguration config, out NetSparkleAppCastItem latestVersion)
        {
            // report
            ReportDiagnosticMessage("Downloading and checking appcast");

            // init the appcast
            NetSparkleAppCast cast = new NetSparkleAppCast(_AppCastUrl, config);

            // check if any updates are available
            try
            {
                latestVersion = cast.GetLatestVersion();
            }
            catch (Exception e)
            {
                // show the exeception message
                ReportDiagnosticMessage("Error during app cast download: " + e.Message);

                // just null the version info
                latestVersion = null;
            }

            if (latestVersion == null)
            {
                ReportDiagnosticMessage("No version information in app cast found");
                return false;
            }
            else
            {
                ReportDiagnosticMessage("Lastest version on the server is " + latestVersion.Version);
            }

            // set the last check time
            ReportDiagnosticMessage("Touch the last check timestamp");
            config.TouchCheckTime();

            // check if the available update has to be skipped
            if (latestVersion.Version.Equals(config.SkipThisVersion))
            {
                ReportDiagnosticMessage("Latest update has to be skipped (user decided to skip version " + config.SkipThisVersion + ")");
                return false;
            }

            // check if the version will be the same then the installed version
            Version v1 = new Version(config.InstalledVersion);
            Version v2 = new Version(latestVersion.Version);

            if (v2 <= v1)
            {
                ReportDiagnosticMessage("Installed version is valid, no update needed (" + config.InstalledVersion + ")");
                return false;
            }

            // ok we need an update
            return true;
        }
Exemplo n.º 20
0
 /// <summary>
 /// Updates from appcast
 /// </summary>
 /// <param name="currentItem">the current (top-most) item in the app-cast</param>
 private void Update(NetSparkleAppCastItem currentItem)
 {
     if (currentItem != null)
     {
         // show the update ui
         if (EnableSilentMode)
         {
             InitDownloadAndInstallProcess(currentItem);
         }
         else
         {
             ShowUpdateNeededUI(currentItem);
         }
     }
 }
Exemplo n.º 21
0
        /// <summary>
        /// This method checks if an update is required. During this process the appcast
        /// will be downloaded and checked against the reference assembly. Ensure that
        /// the calling process has access to the internet and read access to the 
        /// reference assembly. This method is also called from the background loops.
        /// </summary>
        /// <param name="config">the configuration</param>
        /// <param name="updates">list of available updates sorted decreasing</param>
        /// <returns><c>true</c> if an update is required</returns>
        public UpdateStatus GetUpdateStatus(NetSparkleConfiguration config, out NetSparkleAppCastItem[] updates)
        {
            // report
            ReportDiagnosticMessage("Downloading and checking appcast");

            // init the appcast
            NetSparkleAppCast cast = new NetSparkleAppCast(_appCastUrl, config);
            cast.Read();

            // check if any updates are available
            try
            {
                updates = cast.GetUpdates();
            }
            catch (Exception e)
            {
                // show the exception message 
                ReportDiagnosticMessage("Error during app cast download: " + e.Message);

                // just null the version info
                updates = null;
            }

            if (updates == null)
            {
                ReportDiagnosticMessage("No version information in app cast found");
                return UpdateStatus.CouldNotDetermine;
            }

            // set the last check time
            ReportDiagnosticMessage("Touch the last check timestamp");
            config.TouchCheckTime();

            // check if the version will be the same then the installed version
            if (updates.Length == 0)
            {
                ReportDiagnosticMessage("Installed version is valid, no update needed (" + config.InstalledVersion + ")");
                return UpdateStatus.UpdateNotAvailable;
            }
            ReportDiagnosticMessage("Latest version on the server is " + updates[0].Version);

            // check if the available update has to be skipped
            if (updates[0].Version.Equals(config.SkipThisVersion))
            {
                ReportDiagnosticMessage("Latest update has to be skipped (user decided to skip version " + config.SkipThisVersion + ")");
                return UpdateStatus.UserSkipped;
            }

            // ok we need an update
            return UpdateStatus.UpdateAvailable;
        }
Exemplo n.º 22
0
 /// <summary>
 /// This method shows the update ui and allows to perform the 
 /// update process
 /// </summary>
 /// <param name="updates">updates to show UI for</param>
 public void ShowUpdateNeededUI(NetSparkleAppCastItem[] updates)
 {
     if (_useNotificationToast)
     {
         UIFactory.ShowToast(updates, _applicationIcon, OnToastClick);
     }
     else
     {
         ShowUpdateNeededUIInner(updates);
     }
 }
Exemplo n.º 23
0
 private void OnToastClick(NetSparkleAppCastItem[] updates)
 {
     ShowUpdateNeededUIInner(updates);
 }
Exemplo n.º 24
0
        private void Parse(XmlReader reader)
        {
            NetSparkleAppCastItem currentItem = null;

            while (reader.Read())
            {
                if (reader.NodeType == XmlNodeType.Element)
                {
                    switch (reader.Name)
                    {
                        case itemNode:
                            currentItem = new NetSparkleAppCastItem()
                            {
                                AppVersionInstalled = _config.InstalledVersion,
                                AppName = _config.ApplicationName
                            };
                            break;
                        case releaseNotesLinkNode:
                            if (currentItem != null)
                            {
                                currentItem.ReleaseNotesLink = reader.ReadString().Trim();
                            }
                            break;
                        case enclosureNode:
                            if (currentItem != null)
                            {
                                currentItem.Version = reader.GetAttribute(versionAttribute);
                                currentItem.DownloadLink = reader.GetAttribute(urlAttribute);
                                currentItem.DSASignature = reader.GetAttribute(dsaSignature);
                            }
                            break;
                        case pubDateNode:
                            if (currentItem != null)
                            {
                                string dt = reader.ReadString().Trim();
                                try
                                {
                                    currentItem.PublicationDate = DateTime.ParseExact(dt, "ddd, dd MMM yyyy HH:mm:ss zzz", System.Globalization.CultureInfo.InvariantCulture);
                                }
                                catch (FormatException ex)
                                {
                                    Debug.WriteLine("Cannot parse item datetime " + dt + " with message " + ex.Message);
                                }
                            }
                            break;
                    }
                }
                else if (reader.NodeType == XmlNodeType.EndElement)
                {
                    switch (reader.Name)
                    {
                        case itemNode:
                            _items.Add(currentItem);
                            break;
                    }
                }
            }

            // sort versions reserve order
            _items.Sort((item1, item2) => -1 * item1.CompareTo(item2));
        }
Exemplo n.º 25
0
        private void ShowUpdateNeededUIInner(NetSparkleAppCastItem[] updates)
        {
            if (UserWindow != null)
            {
                // remove old user window
                UserWindow.UserResponded -= OnUserWindowUserResponded;
            }

            // create the form
            UserWindow = UIFactory.CreateSparkleForm(updates, _applicationIcon);

            if (HideReleaseNotes)
            {
                UserWindow.HideReleaseNotes();
            }

            // clear if already set.
            UserWindow.UserResponded += OnUserWindowUserResponded;
            UserWindow.Show();
        }
Exemplo n.º 26
0
        public NetSparkleAppCastItem GetLatestVersion()
        {
            NetSparkleAppCastItem latestVersion = null;

            try
            {
                // build a http web request stream
                WebRequest request = HttpWebRequest.Create(_castUrl);

                // request the cast and build the stream
                WebResponse response = request.GetResponse();

                Stream inputstream = response.GetResponseStream();

                NetSparkleAppCastItem currentItem = null;

                XmlTextReader reader = new XmlTextReader(inputstream);
                while(reader.Read())
                {
                    if ( reader.NodeType == XmlNodeType.Element)
                    {
                        switch(reader.Name)
                        {
                            case itemNode:
                                {
                                    currentItem = new NetSparkleAppCastItem();
                                    break;
                                }
                            case releaseNotesLinkNode:
                                {
                                    currentItem.ReleaseNotesLink = reader.ReadString();
                                    currentItem.ReleaseNotesLink = currentItem.ReleaseNotesLink.Trim('\n');
                                    break;
                                }
                            case enclosureNode:
                                {
                                    currentItem.Version = reader.GetAttribute(versionAttribute);
                                    currentItem.DownloadLink = reader.GetAttribute(urlAttribute);
                                    currentItem.DSASignature = reader.GetAttribute(dasSignature);

                                    break;
                                }
                        }
                    }
                    else if (reader.NodeType == XmlNodeType.EndElement)
                    {
                        switch (reader.Name)
                        {
                            case itemNode:
                                {
                                    if (latestVersion == null)
                                        latestVersion = currentItem;
                                    else if (currentItem.CompareTo(latestVersion) > 0 )
                                    {
                                            latestVersion = currentItem;
                                    }
                                    break;
                                }
                        }
                    }
                }

                // add some other attributes
                latestVersion.AppName = _config.ApplicationName;
                latestVersion.AppVersionInstalled = _config.InstalledVersion;
            }
            catch (Exception)
            {

            }

            // go ahead
            return latestVersion;
        }
Exemplo n.º 27
0
        private void ShowUpdateNeededUIInner(NetSparkleAppCastItem currentItem)
        {
            if (UserWindow == null)
            {
                // create the form
                UserWindow = UIFactory.CreateSparkleForm(currentItem, _applicationIcon);
            }

            UserWindow.CurrentItem = currentItem;
            if (HideReleaseNotes)
            {
                UserWindow.HideReleaseNotes();
            }

            // clear if already set.
            UserWindow.UserResponded -= OnUserWindowUserResponded;
            UserWindow.UserResponded += OnUserWindowUserResponded;
            UserWindow.Show();
        }
Exemplo n.º 28
0
        /// <summary>
        /// Starts the download process
        /// </summary>
        /// <param name="item">the appcast item to download</param>
        private void InitDownloadAndInstallProcess(NetSparkleAppCastItem item)
        {
            // get the filename of the download lin
            string[] segments = item.DownloadLink.Split('/');
            string fileName = segments[segments.Length - 1];

            // get temp path
            _downloadTempFileName = Environment.ExpandEnvironmentVariables("%temp%\\" + fileName);
            if (this.ProgressWindow == null)
            {
                this.ProgressWindow = new NetSparkleDownloadProgress(this, item, ApplicationIcon, ApplicationWindowIcon, EnableSilentMode);
            }
            else
            {
                this.ProgressWindow.InstallAndRelaunch -= new EventHandler(OnProgressWindowInstallAndRelaunch);
            }

            this.ProgressWindow.TempFileName = _downloadTempFileName;
            this.ProgressWindow.InstallAndRelaunch += new EventHandler(OnProgressWindowInstallAndRelaunch);

            // set up the download client
            // start async download
            if (_webDownloadClient != null)
            {
                _webDownloadClient.DownloadProgressChanged -= new DownloadProgressChangedEventHandler(this.ProgressWindow.OnClientDownloadProgressChanged);
                _webDownloadClient.DownloadFileCompleted -= new AsyncCompletedEventHandler(OnWebDownloadClientDownloadFileCompleted);
                _webDownloadClient = null;
            }

            _webDownloadClient = new WebClient();
            _webDownloadClient.UseDefaultCredentials = true;
            _webDownloadClient.DownloadProgressChanged += new DownloadProgressChangedEventHandler(this.ProgressWindow.OnClientDownloadProgressChanged);
            _webDownloadClient.DownloadFileCompleted += new AsyncCompletedEventHandler(OnWebDownloadClientDownloadFileCompleted);

            Uri url = new Uri(item.DownloadLink);
            _webDownloadClient.DownloadFileAsync(url, _downloadTempFileName);

            this.ProgressWindow.ShowDialog();
        }
Exemplo n.º 29
0
 private void ShowMarkdownReleaseNotes(NetSparkleAppCastItem item)
 {
     string contents;
     if (item.ReleaseNotesLink.StartsWith("file://")) //handy for testing
     {
         contents = File.ReadAllText(item.ReleaseNotesLink.Replace("file://", ""));
     }
     else
     {
         using (var webClient = new WebClient())
         {
             contents = webClient.DownloadString(item.ReleaseNotesLink);
         }
     }
     var md = new MarkdownSharp.Markdown();
     _htmlTempFile = TempFile.WithExtension("htm");
     File.WriteAllText(_htmlTempFile.Path, md.Transform(contents));
     NetSparkleBrowser.Navigate(_htmlTempFile.Path);
 }
Exemplo n.º 30
0
        private string GetReleaseNotes(NetSparkleAppCastItem item)
        {
            // at first try to use embedded description
            if (!string.IsNullOrEmpty(item.Description))
            {
                // check for markdown
                Regex containsHtmlRegex = new Regex(@"<\s*([^ >]+)[^>]*>.*?<\s*/\s*\1\s*>");
                if (containsHtmlRegex.IsMatch(item.Description))
                {
                    return item.Description;
                }
                else
                {
                    var md = new MarkdownSharp.Markdown();
                    var temp = md.Transform(item.Description);
                    return temp;
                }
            }

            // no embedded so try to get external
            if (string.IsNullOrEmpty(item.ReleaseNotesLink))
            {
                return null;
            }

            // download release note
            string notes = DownloadReleaseNotes(item.ReleaseNotesLink);
            if (string.IsNullOrEmpty(notes))
            {
                return null;
            }

            // check dsa of release notes
            if (!string.IsNullOrEmpty(item.ReleaseNotesDSASignature))
            {
                if (_sparkle.DSAVerificator.VerifyDSASignatureOfString(item.ReleaseNotesDSASignature, notes) == ValidationResult.Invalid)
                    return null;
            }

            // process release notes
            var extension = Path.GetExtension(item.ReleaseNotesLink);
            if (extension != null && MarkDownExtension.Contains(extension.ToLower()))
            {
                try
                {
                    var md = new MarkdownSharp.Markdown();
                    notes = md.Transform(notes);
                }
                catch (Exception ex)
                {
                    Debug.WriteLine("Error parsing MarkDown syntax: " + ex.Message);
                }
            }
            return notes;
        }
Exemplo n.º 31
0
        /// <summary>
        /// Updates from appcast
        /// </summary>
        /// <param name="updates">updates to be installed</param>
        private void Update(NetSparkleAppCastItem[] updates)
        {
            if (updates == null)
                return;

            // show the update ui
            if (EnableSilentMode)
            {
                InitDownloadAndInstallProcess(updates[0]); // install only latest
            }
            else
            {
                ShowUpdateNeededUI(updates);
            }
        }
Exemplo n.º 32
0
        /// <summary>
        /// Starts the download process
        /// </summary>
        /// <param name="item">the appcast item to download</param>
        private void InitDownloadAndInstallProcess(NetSparkleAppCastItem item)
        {
            // get the filename of the download lin
            string[] segments = item.DownloadLink.Split('/');
            string fileName = segments[segments.Length - 1];

            // get temp path
            _downloadTempFileName = Path.Combine(Path.GetTempPath(), fileName);
            if (ProgressWindow == null)
            {
                ProgressWindow = UIFactory.CreateProgressWindow(item, _applicationIcon);
            }
            else
            {
                ProgressWindow.InstallAndRelaunch -= OnProgressWindowInstallAndRelaunch;
            }

            ProgressWindow.InstallAndRelaunch += OnProgressWindowInstallAndRelaunch;
            
            // set up the download client
            // start async download
            if (_webDownloadClient != null)
            {
                _webDownloadClient.DownloadProgressChanged -= ProgressWindow.OnClientDownloadProgressChanged;
                _webDownloadClient.DownloadFileCompleted -= OnWebDownloadClientDownloadFileCompleted;
                _webDownloadClient = null;
            }

            _webDownloadClient = new WebClient {
                UseDefaultCredentials = true,
                Proxy = { Credentials = CredentialCache.DefaultNetworkCredentials },
            };
            _webDownloadClient.DownloadProgressChanged += ProgressWindow.OnClientDownloadProgressChanged;
            _webDownloadClient.DownloadFileCompleted += OnWebDownloadClientDownloadFileCompleted;

            Uri url = new Uri(item.DownloadLink);
            _webDownloadClient.DownloadFileAsync(url, _downloadTempFileName);

            ProgressWindow.ShowDialog();
        }
Exemplo n.º 33
0
 /// <summary>
 /// This method shows the update ui and allows to perform the 
 /// update process
 /// </summary>
 /// <param name="currentItem">the item to show the UI for</param>
 /// <param name="useNotificationToast"> </param>
 public void ShowUpdateNeededUI(NetSparkleAppCastItem currentItem, bool useNotificationToast)
 {
     if (useNotificationToast)
     {
         UIFactory.ShowToast(currentItem, _applicationIcon, OnToastClick);
     }
     else
     {
         ShowUpdateNeededUIInner(currentItem);
     }
 }