예제 #1
0
파일: Metadata.cs 프로젝트: zSnap/zSnap
        /// <summary>
        /// <para>
        /// Maps an <see cref="UpdateInfo"/> to a 
        /// <see cref="Tuple{T1, T2, T3}"/>.
        /// </para>
        /// </summary>
        /// <param name="info">
        /// The <see cref="UpdateInfo"/> to map to a tuple.
        /// </param>
        /// <returns>
        /// A three-tuple of <see cref="Uri"/>s, with the first item
        /// being the archive location, the second the installer location,
        /// and the third the release notes location.
        /// </returns>
        /// <exception cref="ArgumentException">
        /// Thrown if the <see cref="IsAvailable"/> property of
        /// <paramref name="info"/> is false.
        /// </exception>
        public static Tuple<Uri, Uri, Uri> Unmap(UpdateInfo info)
        {
            if (!info.IsAvailable)
            {
                throw new ArgumentException(
                    paramName:  nameof(info),
                    message:    "The provided UpdateInfo did not contain " +
                                "information to map to a Tuple<Uri, Uri, Uri>."
                    );
            }

            return Tuple.Create(
                item1: info.ArchiveLocation,
                item2: info.InstallerLocation,
                item3: info.ReleaseNotesLocation
                );
        }
예제 #2
0
파일: Metadata.cs 프로젝트: zSnap/zSnap
        /// <summary>
        /// <para>
        /// Checks whether an update is available for this version, and
        /// provides access information if one is available.
        /// </para>
        /// </summary>
        /// <param name="info">
        /// <para>
        /// The variable to which information about any available update
        /// is to be assigned.
        /// </para>
        /// </param>
        public static void CheckNewVersion(out UpdateInfo info)
        {
            // If there's no internet connection, we obviously can't check 
            // for an update using the internet.
            if (!Interop.InternetCheckConnection())
            {
                info = new UpdateInfo();
                return;
            }

            var uri = String.Join(
                String.Empty, UPDATE_CHECK_URI, "?hash=", VersionHash);
            var req = WebRequest.CreateHttp(uri);

            // Get the response, catching any exceptions if the request fails.
            var res = req.GetResponseSafe() as HttpWebResponse;

            // If the request fails, indicate that no update is available.
            if (res.StatusCode != HttpStatusCode.OK)
            {
                info = new UpdateInfo();
                return;
            }

            // The response we get should be some XML.
            var xpd = new XPathDocument(res.GetResponseStream());
            var update = xpd.CreateNavigator().SelectSingleNode("/data/update");

            // Is there an update available? If not, we return.
            bool isAvail;
            if (!bool.TryParse(update.GetAttribute("available", ""), out isAvail) ||
                !isAvail)
            {
                info = new UpdateInfo();
                return;
            }

            // Try and parse the URIs 
            Uri archive, installer, notes;
            if (!Uri.TryCreate(update.GetAttribute("archive", ""),
                               UriKind.Absolute,
                               out archive) ||
                !Uri.TryCreate(update.GetAttribute("install", ""),
                               UriKind.Absolute,
                               out installer) ||
                !Uri.TryCreate(update.GetAttribute("notes", ""),
                               UriKind.Absolute,
                               out notes))
            {
                info = new UpdateInfo();
                return;
            }

            // Return the retrieved URIs
            info = new UpdateInfo(archive, installer, notes);
        }