/// <summary> /// Saves configuration to the file. /// </summary> public void StoreConfiguration() { try { if (!Directory.Exists(ConfigurationFolder)) { // create directory where configuration will be saved Directory.CreateDirectory(ConfigurationFolder); } using (FileStream writer = new FileStream(ConfigurationFilename, FileMode.Create)) { XmlSerializer serializer = new XmlSerializer(typeof(VcbCommandBarsConfiguration)); serializer.Serialize(writer, m_uiElementsConfigurations); } } catch (Exception exception) { ExceptionForm.Show(exception); } }
/// <summary> /// This function is the callback used to execute the command when the menu item is clicked. /// See the constructor to see how the menu item is associated with this function using /// OleMenuCommandService service and MenuCommand class. /// </summary> /// <param name="sender">Event sender.</param> /// <param name="e">Event args.</param> protected override void MenuItemCallback(object sender, EventArgs e) { base.PreMenuItemCallback(); try { ConfigurationForm configurationForm = new ConfigurationForm(); if (configurationForm.ShowDialog(new WindowAdapter(m_devEnvApplicationObject.MainWindow.HWnd)) == DialogResult.OK) { ConfigurationPersister.Instance.Configuration = configurationForm.GetConfiguration(); ConfigurationPersister.Instance.StoreConfiguration(); } } catch (Exception ex) { ExceptionForm.Show(new WindowAdapter(m_devEnvApplicationObject.MainWindow.HWnd), ex, "Error starting Versioning Controlled Build add-in"); } }
/// <summary> /// Reads configuration from the file. If file does not exists, /// creates default configuration. /// </summary> /// <returns></returns> private VcbCommandBarsConfiguration LoadConfiguration() { if (Directory.Exists(ConfigurationFolder)) { try { using (FileStream reader = new FileStream(ConfigurationFilename, FileMode.Open)) { XmlSerializer serializer = new XmlSerializer(typeof(VcbCommandBarsConfiguration)); return((VcbCommandBarsConfiguration)serializer.Deserialize(reader)); } } catch (FileNotFoundException) { } catch (Exception exception) { ExceptionForm.Show(exception); } } return(new VcbCommandBarsConfiguration()); }
/// <summary> /// Overrides <c>Install</c> method to save information on /// environments for which add-in has been installed. /// </summary> /// <param name="mySavedState"></param> public override void Install(IDictionary savedState) { #if DEBUG_SETUP System.Diagnostics.Debugger.Launch(); #endif base.Install(savedState); try { string targetDir = GetTargetDir(); Debug.Assert(targetDir != null && targetDir.Length > 0); AddInFileInstaller afi = new AddInFileInstaller(targetDir); bool permanentBars = (string)Context.Parameters["permanentbars"] == "1"; savedState.Add("permanentbars", permanentBars); bool allUsers = (string)Context.Parameters["allusers"] == "1"; bool installAddinFiles = (string)Context.Parameters["installaddinfiles"] == "1"; foreach (DevEnvironmentVersion devEnvironmentVersion in DevEnvironmentVersions) { if (IsDevEnvironmentInstalled(devEnvironmentVersion)) { savedState.Add(devEnvironmentVersion.LaunchCondition, true); // for XML registered addins, copy corresponding file and save their names // to delete them on uninstallation if (installAddinFiles && !devEnvironmentVersion.AddInIsComRegistered) { string addInFile = afi.Install(allUsers, devEnvironmentVersion.Version); savedState.Add(string.Format("{0}.AddInFile", devEnvironmentVersion.Version), addInFile); } } } } catch (Exception e) { ExceptionForm.Show(e, InstallErrorCaption); } }
/// <summary> /// Recurses sub project tree (e.g. for Enterprise template projects) /// searching for the largest version. /// </summary> /// <param name="projectItems"> /// Collection of <c>ProjectItems</c> to recurse. /// </param> private void RecurseSubProjectTree(ProjectItems parentProjectItems, ProjectInfo parentProjectInfo, int level) { level++; Debug.Assert(parentProjectItems != null); Debug.Assert(parentProjectInfo != null); try { foreach (ProjectItem projectItem in parentProjectItems) { try { Project subProject = projectItem.SubProject; if (subProject != null) { ProjectTypeInfo subProjectTypeInfo = ProjectTypeInfo.ProjectTypeInfos[subProject.Kind]; if (subProjectTypeInfo == ProjectTypeInfo.EnterpriseProject || subProjectTypeInfo == ProjectTypeInfo.SolutionFolder) { ProjectInfo subProjectInfo = new ProjectInfo(subProject.Name, subProject.Name, AppendBranchToPath(parentProjectInfo.UIPath, subProject.Name), subProjectTypeInfo, level); RecurseSubProjectTree(subProject.ProjectItems, subProjectInfo, level); parentProjectInfo.SubProjects.Add(subProjectInfo); } else if (subProjectTypeInfo == ProjectTypeInfo.SetupProject) { ProjectInfo pi = GetSetupInfo(subProject, parentProjectInfo.UIPath, subProjectTypeInfo, level); Debug.Assert(pi != null); Debug.Assert(m_allProjects != null); parentProjectInfo.SubProjects.Add(pi); } else if (subProjectTypeInfo != null) { ProjectInfo pi = GetProjectInfo(subProject, parentProjectInfo.UIPath, subProjectTypeInfo, level); Debug.Assert(pi != null); Debug.Assert(m_allProjects != null); parentProjectInfo.SubProjects.Add(pi); } } else { // folders do not have subprojects but only project items ProjectTypeInfo projectTypeInfo = ProjectTypeInfo.ProjectTypeInfos[projectItem.Kind]; if (projectTypeInfo == ProjectTypeInfo.VirtualFolder) { ProjectInfo subProjectInfo = new ProjectInfo(projectItem.Name, projectItem.Name, AppendBranchToPath(parentProjectInfo.UIPath, projectItem.Name), projectTypeInfo, level); RecurseSubProjectTree(projectItem.ProjectItems, subProjectInfo, level); if (subProjectInfo.SubProjects.Count > 0) { parentProjectInfo.SubProjects.Add(subProjectInfo); } } } } catch (NotImplementedException e) { Debug.WriteLine(e.ToString()); } } } catch (Exception e) { ExceptionForm.Show(new WindowAdapter(m_devEnvApplicationObject.MainWindow.HWnd), e, "Browsing Solution Error"); } }
public override void Uninstall(IDictionary mySavedState) { #if DEBUG_SETUP System.Diagnostics.Debugger.Launch(); #endif if (mySavedState != null) { try { // for permanent commandbars, toolbar and menu must be removed explicitely if (mySavedState.Contains("permanentbars") && (bool)mySavedState["permanentbars"] == true) { // collect a list of all IDEs for which add-in has been installed StringCollection devEnvironmentNames = new StringCollection(); foreach (DevEnvironmentVersion devEnvironmentVersion in DevEnvironmentVersions) { // check if toolbar was originally installed for the enviromnment, // if environment was started at all since add-in was installed and // if this environment still exists if (mySavedState.Contains(devEnvironmentVersion.LaunchCondition) && IsDevEnvironmentInstalled(devEnvironmentVersion)) { devEnvironmentNames.Add(devEnvironmentVersion.Name); } } if (devEnvironmentNames.Count > 0) { RemoveToolbarsForm.Show(devEnvironmentNames); foreach (DevEnvironmentVersion devEnvironmentVersion in DevEnvironmentVersions) { // remove permanent UI entries for selected environments only if (devEnvironmentNames.Contains(devEnvironmentVersion.Name)) { RemovePermamanentUI(devEnvironmentVersion); } } } } foreach (DevEnvironmentVersion devEnvironmentVersion in DevEnvironmentVersions) { // clean-up PreloadAddinState registry entries if (mySavedState.Contains(devEnvironmentVersion.LaunchCondition) && devEnvironmentVersion.AddInIsComRegistered && PreloadAddinStateExists(devEnvironmentVersion) && IsDevEnvironmentInstalled(devEnvironmentVersion)) { DeletePreloadAddinState(devEnvironmentVersion); mySavedState.Remove(devEnvironmentVersion.LaunchCondition); } } // delete AddIn files foreach (DevEnvironmentVersion devEnvironmentVersion in DevEnvironmentVersions) { string addinFileKey = string.Format("{0}.AddInFile", devEnvironmentVersion.Version); if (mySavedState.Contains(addinFileKey)) { string addInFilename = (string)mySavedState[addinFileKey]; File.Delete(addInFilename); } } } catch (Exception e) { ExceptionForm.Show(e, UnistallErrorCaption); } DeleteUiSettings(); if (RemoveConfigurationsForm.Show() == DialogResult.Yes) { DeleteConfigurations(); } } base.Uninstall(mySavedState); }