Length Parameter in enclosure

Nov 23, 2011 at 2:39 PM

Hi,

i ran into the problem that i had a typo in the appCast.

So i added following check into NetSparkleDownloadProcess.cs after modifying the sources at the bottom... 

System.IO.FileInfo info = new FileInfo(_tempName);
if
(info.Length > 0 &&_item.Length != info.Length)
{
_sparkle.ReportDiagnosticMessage("Filesize does not match specification: " + info.Length);
}

NetSparkleAppCaseItem.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AppLimit.NetSparkle
{
    public class NetSparkleAppCastItem : IComparable<NetSparkleAppCastItem>
    {
        public Int32 Length;

        public String AppName;
        public String AppVersionInstalled;

        public String Version;
        public String ReleaseNotesLink;
        public String DownloadLink;

        public String DSASignature;


        #region IComparable<NetSparkleAppCastItem> Members

        public int CompareTo(NetSparkleAppCastItem other)
        {
            Version v1 = new Version(this.Version);
            Version v2 = new Version(other.Version);

            return v1.CompareTo(v2);            
        }

        #endregion
    }    
}

NetSparkleAppCast.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Xml;
using System.Net;

namespace AppLimit.NetSparkle
{
    public class NetSparkleAppCast
    {
        private NetSparkleConfiguration _config;
        private String _castUrl;

        private const String itemNode = "item";
        private const String enclosureNode = "enclosure";
        private const String lengthNode = "length";
        private const String releaseNotesLinkNode = "sparkle:releaseNotesLink";
        private const String versionAttribute = "sparkle:version";
        private const String dasSignature = "sparkle:dsaSignature";
        private const String urlAttribute = "url";

        public bool UseDefaultCredentials { get; set; }

        public NetSparkleAppCast(String castUrl, NetSparkleConfiguration config)
        {
            _config = config;
            _castUrl = castUrl;
        }

        public NetSparkleAppCastItem GetLatestVersion()
        {
            NetSparkleAppCastItem latestVersion = null;

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

            // 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);
                                if (!Int32.TryParse(reader.GetAttribute(lengthNode), out currentItem.Length))
                                {
                                    currentItem.Length = -1;
                                }
                                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;

            // go ahead
            return latestVersion;
        }

    }
}

Coordinator
Nov 27, 2011 at 7:34 AM
Hi,

thanks a lot. I will add it to the code soon.

Dirk

Sent from my iPad

On 23.11.2011, at 16:39, nitarmat <notifications@codeplex.com> wrote:

From: nitarmat

Hi,

i ran into the problem that i had a typo in the appCast.

So i added following check into NetSparkleDownloadProcess.cs after modifying the sources at the bottom...

System.IO.FileInfo info = new FileInfo(_tempName);
if
(info.Length > 0 &&_item.Length != info.Length)
{
_sparkle.ReportDiagnosticMessage("Filesize does not match specification: " + info.Length);
}

NetSparkleAppCaseItem.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AppLimit.NetSparkle
{
    public class NetSparkleAppCastItem : IComparable<NetSparkleAppCastItem>
    {
        public Int32 Length;

        public String AppName;
        public String AppVersionInstalled;

        public String Version;
        public String ReleaseNotesLink;
        public String DownloadLink;

        public String DSASignature;


        #region IComparable<NetSparkleAppCastItem> Members

        public int CompareTo(NetSparkleAppCastItem other)
        {
            Version v1 = new Version(this.Version);
            Version v2 = new Version(other.Version);

            return v1.CompareTo(v2);            
        }

        #endregion
    }    
}

NetSparkleAppCast.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Xml;
using System.Net;

namespace AppLimit.NetSparkle
{
    public class NetSparkleAppCast
    {
        private NetSparkleConfiguration _config;
        private String _castUrl;

        private const String itemNode = "item";
        private const String enclosureNode = "enclosure";
        private const String lengthNode = "length";
        private const String releaseNotesLinkNode = "sparkle:releaseNotesLink";
        private const String versionAttribute = "sparkle:version";
        private const String dasSignature = "sparkle:dsaSignature";
        private const String urlAttribute = "url";

        public bool UseDefaultCredentials { get; set; }

        public NetSparkleAppCast(String castUrl, NetSparkleConfiguration config)
        {
            _config = config;
            _castUrl = castUrl;
        }

        public NetSparkleAppCastItem GetLatestVersion()
        {
            NetSparkleAppCastItem latestVersion = null;

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

            // 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);
                                if (!Int32.TryParse(reader.GetAttribute(lengthNode), out currentItem.Length))
                                {
                                    currentItem.Length = -1;
                                }
                                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;

            // go ahead
            return latestVersion;
        }

    }
}