Esempio n. 1
0
        public Update CheckForUpdates(IWebClientWrapper client)
        {
            string url = BrandingControl.getString("BRANDING_updaterURL");

            if (String.IsNullOrEmpty(url))
            {
                url = "https://pvupdates.vmd.citrix.com/updates.v2.tsv";
            }

            string identify = (string)getreg.GetReg("HKEY_LOCAL_MACHINE\\Software\\Citrix\\XenTools\\AutoUpdate", "Identify", "NO");

            if (identify.Equals("YES"))
            {
                url += "?id=" + uuid.Value.Substring(4);
            }

            if (update_url.Exists)
            {
                url = update_url.Value;
            }

            url = (string)getreg.GetReg("HKEY_LOCAL_MACHINE\\SOFTWARE\\Citrix\\XenTools", "update_url", url);

            if (String.IsNullOrEmpty(url))
            {
                session.Log("Update URL is Null or Empty");
                throw new ArgumentNullException("URL is empty");
            }
            session.Log("Checking URL: " + url + " for updates after: " + version.ToString());

            string contents = null;

            try
            {
                string userAgent = (string)getreg.GetReg("HKEY_LOCAL_MACHINE\\SOFTWARE\\Citrix\\XenTools\\AutoUpdate", "UserAgent", BrandingControl.getString("BRANDING_userAgent"));
                session.Log("This is my user agent : " + userAgent);
                client.AddHeader("User-Agent", userAgent);
                contents = client.DownloadString(url);
            }
            catch (Exception e)
            {
                session.Log("Download failed " + e.Message);
                throw;
            }
            if (String.IsNullOrEmpty(contents))
            {
                return(null);
            }

            string        arch    = (Win32Impl.Is64BitOS() && (!Win32Impl.IsWOW64())) ? "x64" : "x86";
            List <Update> updates = new List <Update>();

            foreach (string line in contents.Split(new char[] { '\n' }))
            {
                if (String.IsNullOrEmpty(line))
                {
                    continue;
                }
                try
                {
                    Update update = new Update(line);
                    session.Log("Update Entry " + update.ToString());
                    if (update.Arch != arch)
                    {
                        continue;
                    }
                    if (update.Version.CompareTo(version) <= 0)
                    {
                        continue;
                    }

                    updates.Add(update);
                }
                catch (Exception e)
                {
                    session.Log("Exception: " + e.Message);
                }
            }

            updates.Reverse();
            if (updates.Count > 0)
            {
                return(updates[0]);
            }

            session.Log("No updates found");
            return(null);
        }