Exemplo n.º 1
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Updates all files that require an update.
        /// </summary>
        /// ------------------------------------------------------------------------------------
        private void UpdateFiles()
        {
            bool fAskedUserToExit = false;             // will be set to true as soon as we have asked user

            using (ProgressDialog dlg = new ProgressDialog())
            {
                dlg.ProgressBar.Maximum = m_FilesToUpdate.Length;
                dlg.Show();
                for (int i = 0; i < m_FilesToUpdate.Length && !dlg.ShouldCancel; i++)
                {
                    UpdateFile file = m_FilesToUpdate[i];
                    Trace.WriteLine(DateTime.Now + ": Installing " + file.Name);
                    dlg.InstallText = "Installing " + file.Name;

                    if (file.ExitVs && !fAskedUserToExit)
                    {
                        fAskedUserToExit = true;
                        CloseVs();
                    }

                    try
                    {
                        string extension = Path.GetExtension(file.Name).ToLower();
                        if (extension == ".msi" || extension == ".vsi" || extension == ".vsix")
                        {
                            // Install this file
                            Process process = new Process();
                            process.StartInfo.FileName       = Path.Combine(m_UpdatePath, file.Name);
                            process.StartInfo.CreateNoWindow = true;
                            process.StartInfo.Arguments      = "/quiet";
                            process.Start();
                            process.WaitForExit();
                            Trace.WriteLine(DateTime.Now + ": Exit code: " + process.ExitCode);
                        }
                        else if (extension == ".dll")
                        {
                            // Install in the GAC
                            string  fileName = Path.Combine(m_UpdatePath, file.Name);
                            Publish publish  = new Publish();
                            publish.GacInstall(fileName);
                            Trace.WriteLine(DateTime.Now + ": Installed in GAC");
                        }
                    }
                    catch (Exception e)
                    {
                        Trace.WriteLine(DateTime.Now + ": Got exception installing " +
                                        file.Name + ": " + e.Message);
                        // remove from list of updated files so that we try again
                        m_FileHash.Remove(file.Name);
                    }
                    dlg.ProgressBar.Increment(1);
                }

                RestartVisualStudio(dlg);
                dlg.Close();
            }
        }
Exemplo n.º 2
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Checks if updates are available
        /// </summary>
        /// <returns></returns>
        /// ------------------------------------------------------------------------------------
        private bool UpdatesAvailable()
        {
            XmlReader     reader     = XmlReader.Create(Path.Combine(m_UpdatePath, "Updates.xml"));
            XmlSerializer serializer = new XmlSerializer(typeof(UpdateDesc));
            UpdateDesc    updateDesc = (UpdateDesc)serializer.Deserialize(reader);

            reader.Close();

            ArrayList filesToUpdate = new ArrayList();

            for (int i = 0; i < updateDesc.files.Length; i++)
            {
                try
                {
                    UpdateFile file       = updateDesc.files[i];
                    string     hash       = ComputeHash(Path.Combine(m_UpdatePath, file.Name));
                    string     storedHash = (string)m_FileHash[file.Name];

                    if (hash != storedHash && (!file.Once || storedHash == null))
                    {
                        Trace.WriteLine(DateTime.Now.ToString() + ": Need to update " + file.Name);

                        if (!m_fFirstTime || !file.IgnoreFirstTime)
                        {
                            filesToUpdate.Add(file);
                        }
                        else
                        {
                            Trace.WriteLine(DateTime.Now.ToString() + "(Ignored due to " + (m_fFirstTime ? "/first)" : "file props)"));
                        }

                        // Store new hash value
                        m_FileHash[file.Name] = hash;
                    }
                }
                catch (Exception e)
                {
                    Trace.WriteLine(DateTime.Now.ToString() + ": Got exception " + e.Message);
                }
            }

            m_FilesToUpdate = new UpdateFile[filesToUpdate.Count];
            filesToUpdate.CopyTo(m_FilesToUpdate);
            return(m_FilesToUpdate.Length > 0);
        }
Exemplo n.º 3
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Checks if the version of Visual Studio specified in file.VSVersion is installed on
        /// this machine.
        /// </summary>
        /// <returns>Returns <c>true</c> if no specific VS version is specified or that version
        /// is installed, otherwise <c>false</c>.</returns>
        /// ------------------------------------------------------------------------------------
        private bool IncludeUpdate(UpdateFile file)
        {
            if (string.IsNullOrEmpty(file.VSVersion))
            {
                return(true);
            }

            bool fInclude = false;

            foreach (var vsversion in file.VSVersion.Split(','))
            {
                int version;
                switch (vsversion.Trim())
                {
                case "2005":
                    version = 8;
                    break;

                case "2008":
                    version = 9;
                    break;

                case "2010":
                    version = 10;
                    break;

                default:
                    Trace.WriteLine(DateTime.Now + ": Corrupt updates.xml file. Unknown VS version: " +
                                    file.VSVersion);
                    return(true);
                }
                // See http://www.mztools.com/articles/2008/MZ2008003.aspx on how to detect which VS
                // version is installed.
                var key = Registry.ClassesRoot.OpenSubKey(string.Format("VisualStudio.DTE.{0}.0", version));
                fInclude |= (key != null);
                if (key != null)
                {
                    key.Close();
                    break;
                }
            }
            return(fInclude);
        }
Exemplo n.º 4
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Updates all files that require an update.
        /// </summary>
        /// ------------------------------------------------------------------------------------
        private void UpdateFiles()
        {
            bool fAskedUserToExit = false;             // will be set to true as soon as we have asked user

            using (ProgressDialog dlg = new ProgressDialog())
            {
                dlg.ProgressBar.Maximum = m_FilesToUpdate.Length;
                dlg.Show();
                for (int i = 0; i < m_FilesToUpdate.Length && !dlg.ShouldCancel; i++)
                {
                    UpdateFile file = m_FilesToUpdate[i];
                    Trace.WriteLine(DateTime.Now.ToString() + ": Installing " + file.Name);
                    dlg.InstallText = "Installing " + file.Name;

                    if (file.ExitVs && !fAskedUserToExit)
                    {
                        fAskedUserToExit = true;
                        Process[] processes = Process.GetProcessesByName("devenv");
                        if (processes.Length > 0)
                        {
                            if (MessageBox.Show("Visual Studio needs to close before update can proceed",
                                                "Updates available", MessageBoxButtons.OKCancel) == DialogResult.OK)
                            {
                                ExitVs();
                            }
                            else
                            {
                                Trace.WriteLine(DateTime.Now.ToString() + ": Skipped closing Visual Studio by user's request");
                            }
                        }
                    }

                    try
                    {
                        string extension = Path.GetExtension(file.Name).ToLower();
                        if (extension == ".msi" || extension == ".vsi")
                        {
                            // Install this file
                            Process process = new Process();
                            process.StartInfo.FileName       = Path.Combine(m_UpdatePath, file.Name);
                            process.StartInfo.CreateNoWindow = true;
                            process.StartInfo.Arguments      = "/quiet";
                            process.Start();
                            process.WaitForExit();
                            Trace.WriteLine(DateTime.Now.ToString() + ": Exit code: " + process.ExitCode);
                        }
                        else if (extension == ".dll")
                        {
                            // Install in the GAC
                            string  fileName = Path.Combine(m_UpdatePath, file.Name);
                            Publish publish  = new Publish();
                            publish.GacInstall(fileName);
                            Trace.WriteLine(DateTime.Now.ToString() + ": Installed in GAC");
                        }
                    }
                    catch (Exception e)
                    {
                        Trace.WriteLine(DateTime.Now.ToString() + ": Got exception installing " +
                                        file.Name + ": " + e.Message);
                        // remove from list of updated files so that we try again
                        m_FileHash.Remove(file.Name);
                    }
                    dlg.ProgressBar.Increment(1);
                }

                RestartVisualStudio(dlg);
                dlg.Close();
            }
        }
Exemplo n.º 5
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Checks if the version of Visual Studio specified in file.VSVersion is installed on
        /// this machine.
        /// </summary>
        /// <returns>Returns <c>true</c> if no specific VS version is specified or that version
        /// is installed, otherwise <c>false</c>.</returns>
        /// ------------------------------------------------------------------------------------
        private bool IncludeUpdate(UpdateFile file)
        {
            if (string.IsNullOrEmpty(file.VSVersion))
                return true;

            bool fInclude = false;
            foreach (var vsversion in file.VSVersion.Split(','))
            {
                int version;
                switch (vsversion.Trim())
                {
                    case "2005":
                        version = 8;
                        break;
                    case "2008":
                        version = 9;
                        break;
                    case "2010":
                        version = 10;
                        break;
                    default:
                        Trace.WriteLine(DateTime.Now + ": Corrupt updates.xml file. Unknown VS version: " +
                                        file.VSVersion);
                        return true;
                }
                // See http://www.mztools.com/articles/2008/MZ2008003.aspx on how to detect which VS
                // version is installed.
                var key = Registry.ClassesRoot.OpenSubKey(string.Format("VisualStudio.DTE.{0}.0", version));
                fInclude |= (key != null);
                if (key != null)
                {
                    key.Close();
                    break;
                }
            }
            return fInclude;
        }