Esempio n. 1
0
 private void RaiseNewVersionExists(UpdateManifestInfo info)
 {
     if (NewVersionFound != null)
     {
         NewVersionFound(this, new UpdateEventArgs(info));
     }
 }
Esempio n. 2
0
        internal static bool ExtractDownloadedPackage(UpdateManifestInfo manifest)
        {
            try
            {
                string packageName = ExtractFileNameFromUri(manifest.UpdatePackageUri);
                string path        = GetDownloadDirectoryPath() + Path.DirectorySeparatorChar + packageName;

                string hash = CalculateHash(path);
                if (string.Equals(manifest.HashCode, hash, StringComparison.InvariantCulture))
                {
                    using (ZipFile zip = ZipFile.Read(path))
                    {
                        foreach (ZipEntry e in zip)
                        {
                            e.Extract(GetDownloadDirectoryPath(true), ExtractExistingFileAction.OverwriteSilently);  // overwrite == true
                        }
                    }

                    return(true);
                }
                else
                {
                    EventLogger.Instance.Add("Error: Hash doesn't match: " + hash);
                }
            }
            catch (Exception ex)
            {
                EventLogger.Instance.Add("Error: ExtractDownloadedPackage " + ex.Message);
            }

            return(false);
        }
Esempio n. 3
0
        internal static UpdateManifestInfo LoadManifestFile()
        {
            try
            {
                UpdateManifestInfo info = null;

                string manifestFileName = ExtractFileNameFromUri(Settings.Instance.UpdateUri);

                string path =
                    GetDownloadDirectoryPath() +
                    Path.DirectorySeparatorChar +
                    manifestFileName;

                if (File.Exists(path))
                {
                    XmlDocument doc = new System.Xml.XmlDocument();
                    doc.Load(path);

                    XmlNode details = doc.SelectSingleNode("UpdateDetails");
                    if (details != null && details.HasChildNodes)
                    {
                        info = new UpdateManifestInfo();

                        XmlNode node = details.SelectSingleNode("Version");
                        if (node != null)
                        {
                            info.UpdateVersion = node.InnerText;
                        }

                        node = details.SelectSingleNode("URL");
                        if (node != null)
                        {
                            info.UpdatePackageUri = node.InnerText;
                        }

                        node = details.SelectSingleNode("ChangeLog");
                        if (node != null)
                        {
                            info.ChangeLog = node.InnerText;
                        }

                        node = details.SelectSingleNode("HashCode");
                        if (node != null)
                        {
                            info.HashCode = node.InnerText;
                        }
                    }
                }

                return(info);
            }
            catch (Exception ex)
            {
                EventLogger.Instance.Add("Error: LoadManifestFile " + ex.Message);
            }

            return(null);
        }
Esempio n. 4
0
        // download latest updates
        private bool DownloadNewVersion(bool checkAutoDownloadFlag = false)
        {
            bool res = false;

            try
            {
                // There's already a new version ready to set up
                if (this.IsDownloadComplete)
                {
                    return(res);
                }

                // If an operation is being done, do not interfere
                UpdaterStatus state = (UpdaterStatus)this.state.Current;
                if ((state == UpdaterStatus.ManifestDownloadCompleted ||
                     state == UpdaterStatus.Idle))
                {
                    res = true;
                    UpdateManifestInfo info = GetNewVersionInfo();
                    if (info != null)
                    {
                        this.NewVersionDetails = info.ChangeLog;

                        if ((checkAutoDownloadFlag && Settings.Instance.AutoDownloadUpdate) ||
                            !checkAutoDownloadFlag)
                        {
                            EventLogger.Instance.Add("Found new version.");

                            this.state.Current = UpdaterStatus.DownloadingPackage;
                            res = this.downloader.BeginDownloadPackage(info);
                        }
                        else
                        {
                            EventLogger.Instance.Add("Found new version auto download is off. It'll not be downloaded.");
                        }
                    }

                    if ((UpdaterStatus)this.state.Current != UpdaterStatus.DownloadingPackage)
                    {
                        this.state.Current = UpdaterStatus.Idle;
                    }
                }
            }
            catch (Exception ex)
            {
                this.state.Current = UpdaterStatus.Idle;
                EventLogger.Instance.Add(ex.Message);
                res = false;
            }

            return(res);
        }
Esempio n. 5
0
        internal static void Cleanup(UpdateManifestInfo info)
        {
            try
            {
                string filename = GetManifestFilePath();
                File.Delete(filename);

                filename = GetPackageFilePath(info);
                File.Delete(filename);
            }
            catch (Exception ex)
            {
                EventLogger.Instance.Add("Error: Cleanup " + ex.Message);
            }
        }
Esempio n. 6
0
        private UpdateManifestInfo GetNewVersionInfo()
        {
            try
            {
                object tmpCurr = this.state.Current;
                this.state.Current = UpdaterStatus.CheckingVersion;

                UpdateManifestInfo info = GetManifestInfo();
                if (info == null)
                {
                    EventLogger.Instance.Add("Cannot get manifest file info. Version comparison failed.");
                }
                else
                {
                    System.Reflection.AssemblyName asm = ServiceIo.GetUpdateAssembly();

                    if (asm == null)
                    {
                        EventLogger.Instance.Add("Cannot get update application assembly. Version comparison failed.");
                    }
                    else
                    {
                        Version currentVersion = asm.Version;
                        Version latestVersion  = new Version(info.UpdateVersion);

                        if (latestVersion > currentVersion)
                        {
                            this.IsNewVersionAvailable = true;
                            RaiseNewVersionExists(info);
                            return(info);
                        }
                        else
                        {
                            this.IsNewVersionAvailable = false;
                        }
                    }
                }
                this.state.Current = tmpCurr;
            }
            catch (Exception ex)
            {
                //this.state.Current = UpdaterStatus.Idle;
                EventLogger.Instance.Add(ex.Message);
            }

            return(null);
        }
Esempio n. 7
0
        internal static string GetPackageFilePath(UpdateManifestInfo manifest)
        {
            try
            {
                string path     = GetDownloadDirectoryPath(true);
                string filename = ExtractFileNameFromUri(manifest.UpdatePackageUri);

                return(path +
                       System.IO.Path.DirectorySeparatorChar +
                       filename);
            }
            catch (Exception ex)
            {
                EventLogger.Instance.Add("Error: GetPackageFilePath " + ex.Message);
            }

            return(string.Empty);
        }
Esempio n. 8
0
        internal bool BeginDownloadPackage(UpdateManifestInfo manifest)
        {
            try
            {
                if ((DownloaderState)this.downloadState.Current == DownloaderState.DownloadingManifest ||
                    (DownloaderState)this.downloadState.Current == DownloaderState.DownloadingPackage)
                {
                    EventLogger.Instance.Add("Cannot download package. Downloader is already downloading.");
                    return(false);
                }

                if (manifest == null)
                {
                    return(false);
                }
                EventLogger.Instance.Add("Downloading package...");

                this.downloadState.Current = DownloaderState.DownloadingPackage;

                DownloadInfo inf = new DownloadInfo();
                inf.Manifest   = manifest;
                inf.DownloadId = (Int32)Downloadables.UpdatePackage;

                this.webClient.DownloadFileAsync(
                    new Uri(manifest.UpdatePackageUri),
                    ServiceIo.GetPackageFilePath(inf.Manifest),
                    inf);

                return(true);
            }
            catch (Exception ex)
            {
                this.downloadState.Current = DownloaderState.Idle;
                EventLogger.Instance.Add(ex.Message);
            }

            return(false);
        }
Esempio n. 9
0
 public UpdateEventArgs(UpdateManifestInfo info)
 {
 }