protected override void Initialize() { base.Initialize(); Instance = this; AutoBuilding = GetAutoBuilding(); { Shell = GetService(typeof(IVsShell)) as IVsShell; object value; Shell.GetProperty((int)__VSSPROPID.VSSPROPID_IsInCommandLineMode, out value); CommandLineMode = (bool)value; } RegisterProjectFactory(new ProjectFactory()); RegisterProjectFactory(new ProjectFactoryOld()); if (!CommandLineMode) { InstallDirectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); ResourcesDirectory = Path.Combine(InstallDirectory, "Resources"); DTE2 = (EnvDTE80.DTE2)GetService(typeof(EnvDTE.DTE)); DTEEvents = DTE.Events.DTEEvents; IVsSolution = GetService(typeof(SVsSolution)) as IVsSolution; IVsSolution4 = GetService(typeof(SVsSolution)) as IVsSolution4; UIShell = Instance.GetService(typeof(SVsUIShell)) as IVsUIShell; MonitorSelection = GetGlobalService(typeof(SVsShellMonitorSelection)) as IVsMonitorSelection; // // Update the InstallDir this was previously used in project imports, but is still usefull if you // need to detect the extension install dir. // Registry.SetValue(IceBuilderKey, string.Format("InstallDir.{0}", DTE.Version), InstallDirectory, RegistryValueKind.String); Assembly assembly = null; if (DTE.Version.StartsWith("11.0")) { assembly = Assembly.LoadFrom(Path.Combine(ResourcesDirectory, "IceBuilder.VS2012.dll")); } else if (DTE.Version.StartsWith("12.0")) { assembly = Assembly.LoadFrom(Path.Combine(ResourcesDirectory, "IceBuilder.VS2013.dll")); } else if (DTE.Version.StartsWith("14.0")) { assembly = Assembly.LoadFrom(Path.Combine(ResourcesDirectory, "IceBuilder.VS2015.dll")); } else { assembly = Assembly.LoadFrom(Path.Combine(ResourcesDirectory, "IceBuilder.VS2017.dll")); } VCUtil = assembly.GetType("IceBuilder.VCUtilI").GetConstructor(new Type[] { }).Invoke( new object[] { }) as VCUtil; NuGet = assembly.GetType("IceBuilder.NuGetI").GetConstructor(new Type[] { }).Invoke( new object[] { }) as IceBuilder.NuGet; NuGet.OnNugetBatchEnd(PackageInstalled); ProjectManagerFactory = assembly.GetType("IceBuilder.ProjectManagerFactoryI").GetConstructor(new Type[] { }).Invoke( new object[] { }) as IVsProjectManagerFactory; RunningDocumentTableEventHandler = new RunningDocumentTableEventHandler( GetService(typeof(SVsRunningDocumentTable)) as IVsRunningDocumentTable); Builder = new Builder(GetService(typeof(SVsBuildManagerAccessor)) as IVsBuildManagerAccessor2); // // Subscribe to solution events. // SolutionEventHandler = new SolutionEventHandler(); SolutionEventHandler.BeginTrack(); DocumentEventHandler = new DocumentEventHandler( GetService(typeof(SVsTrackProjectDocuments)) as IVsTrackProjectDocuments2); DocumentEventHandler.BeginTrack(); FileTracker = new GeneratedFileTracker(); BuildEvents = DTE2.Events.BuildEvents; BuildEvents.OnBuildBegin += BuildEvents_OnBuildBegin; BuildEvents.OnBuildDone += BuildEvents_OnBuildDone; } }
protected override void Initialize() { base.Initialize(); Instance = this; { Shell = GetService(typeof(IVsShell)) as IVsShell; object value; Shell.GetProperty((int)__VSSPROPID.VSSPROPID_IsInCommandLineMode, out value); CommandLineMode = (bool)value; } this.RegisterProjectFactory(new ProjectFactory()); if (!CommandLineMode) { ResourcesDirectory = Path.Combine( Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "Resources"); // // Copy required target, property and task files // String dataDir = Path.Combine(Environment.GetEnvironmentVariable("LOCALAPPDATA"), "ZeroC", "IceBuilder"); if (!Directory.Exists(dataDir)) { Directory.CreateDirectory(dataDir); } foreach (String f in new String[] { "IceBuilder.Common.props", "IceBuilder.Cpp.props", "Ice.3.6.0.Cpp.props", "IceBuilder.Cpp.targets", "IceBuilder.Cpp.xml", "IceBuilder.CSharp.props", "IceBuilder.CSharp.targets", "IceBuilder.Tasks.dll" }) { if (!File.Exists(Path.Combine(dataDir, f))) { File.Copy(Path.Combine(ResourcesDirectory, f), Path.Combine(dataDir, f)); } else { byte[] data1 = File.ReadAllBytes(Path.Combine(ResourcesDirectory, f)); byte[] data2 = File.ReadAllBytes(Path.Combine(dataDir, f)); if (!data1.SequenceEqual(data2)) { File.Copy(Path.Combine(ResourcesDirectory, f), Path.Combine(dataDir, f), true); } } } DTE2 = (EnvDTE80.DTE2)GetService(typeof(EnvDTE.DTE)); DTEEvents = DTE.Events.DTEEvents; IVsSolution = GetService(typeof(SVsSolution)) as IVsSolution; IVsSolution4 = GetService(typeof(SVsSolution)) as IVsSolution4; UIShell = Package.Instance.GetService(typeof(SVsUIShell)) as IVsUIShell; MonitorSelection = GetGlobalService(typeof(SVsShellMonitorSelection)) as IVsMonitorSelection; // Add our command handlers for menu (commands must exist in the .vsct file) OleMenuCommandService mcs = GetService(typeof(IMenuCommandService)) as OleMenuCommandService; if (null != mcs) { // Create the command for the menu item. CommandID menuCommandAddID = new CommandID(GuidList.IceBuilderCommandsGUI, (int)PkgCmdIDList.AddIceBuilder); OleMenuCommand menuItemAdd = new OleMenuCommand(AddIceBuilderToProject, menuCommandAddID); menuItemAdd.Enabled = false; mcs.AddCommand(menuItemAdd); menuItemAdd.BeforeQueryStatus += addIceBuilder_BeforeQueryStatus; CommandID menuCommanRemoveID = new CommandID(GuidList.IceBuilderCommandsGUI, (int)PkgCmdIDList.RemoveIceBuilder); OleMenuCommand menuItemRemove = new OleMenuCommand(RemoveIceBuilderFromProject, menuCommanRemoveID); menuItemRemove.Enabled = false; mcs.AddCommand(menuItemRemove); menuItemRemove.BeforeQueryStatus += removeIceBuilder_BeforeQueryStatus; } // // If IceHome isn't set or is set to an invlid location, try to // locate the latest version installed and use that. // Version version = null; Version latest = null; String iceHome = null; bool updateIceHome = true; try { if (File.Exists(Path.Combine(GetIceHome(), "bin", "slice2cpp.exe")) || File.Exists(Path.Combine(GetIceHome(), "cpp", "bin", "slice2cpp.exe"))) { updateIceHome = false; } } catch (ArgumentException) { } if (updateIceHome) { using (RegistryKey key = Registry.LocalMachine.OpenSubKey(@"Software\ZeroC")) { if (key != null) { foreach (String name in key.GetSubKeyNames()) { using (RegistryKey subKey = key.OpenSubKey(name)) { if (subKey == null) { continue; } object value = subKey.GetValue("InstallDir"); if (value == null) { continue; } String installDir = value.ToString(); try { if (!File.Exists(Path.Combine(installDir, "bin", "slice2cpp.exe"))) { continue; } } catch (ArgumentException) { // Could happen if install dir is null or has invalid characters continue; } try { version = Version.Parse(GetSliceCompilerVersion(installDir)); } catch (System.Exception) { continue; } if (version.Build == 51) { // Ignore beta version continue; } if (version < new Version(3, 6, 0)) { //We require 3.6.0 or greatest continue; } if (!name.Equals( String.Format("Ice {0}.{1}.{2}", version.Major, version.Minor, version.Build))) { continue; } latest = (latest == null) ? version : (latest > version) ? latest : version; if (latest.Equals(version)) { iceHome = installDir; } } } } } if (iceHome != null) { SetIceHome(iceHome); } else { // // Postpone the setting of Ice home until the add-in has been removed. // if (!File.Exists(AddinPath)) { if (MessageBox.Show( "The selected Ice home directory does not exist or is not " + "an Ice installation. Please provide a correct Ice home directory.", "Ice Builder - Incorrect Ice home", MessageBoxButtons.OKCancel, MessageBoxIcon.Information) == DialogResult.OK) { DTEEvents.OnStartupComplete += ShowIceOptionsPage; } } } } Assembly assembly = null; if (DTE.Version.StartsWith("11.0")) { assembly = Assembly.LoadFrom(Path.Combine(ResourcesDirectory, "IceBuilder.VS2012.dll")); } else if (DTE.Version.StartsWith("12.0")) { assembly = Assembly.LoadFrom(Path.Combine(ResourcesDirectory, "IceBuilder.VS2013.dll")); } else { assembly = Assembly.LoadFrom(Path.Combine(ResourcesDirectory, "IceBuilder.VS2015.dll")); } VCUtil = assembly.GetType("IceBuilder.VCUtilI").GetConstructor(new Type[] { }).Invoke( new object[] { }) as VCUtil; RunningDocumentTableEventHandler = new RunningDocumentTableEventHandler( GetService(typeof(SVsRunningDocumentTable)) as IVsRunningDocumentTable); Builder = new Builder(GetService(typeof(SVsBuildManagerAccessor)) as IVsBuildManagerAccessor2); // // Subscribe to solution events. // SolutionEventHandler = new SolutionEventHandler(); SolutionEventHandler.BeginTrack(); DocumentEventHandler = new DocumentEventHandler( GetService(typeof(SVsTrackProjectDocuments)) as IVsTrackProjectDocuments2); DocumentEventHandler.BeginTrack(); FileTracker = new GeneratedFileTracker(); BuildEvents = DTE2.Events.BuildEvents; BuildEvents.OnBuildBegin += BuildEvents_OnBuildBegin; BuildEvents.OnBuildDone += BuildEvents_OnBuildDone; if (File.Exists(AddinPath)) { DTEEvents.OnStartupComplete += AddinRemoval; } } }
protected override void Initialize() { base.Initialize(); Instance = this; { Shell = GetService(typeof(IVsShell)) as IVsShell; object value; Shell.GetProperty((int)__VSSPROPID.VSSPROPID_IsInCommandLineMode, out value); CommandLineMode = (bool)value; } this.RegisterProjectFactory(new ProjectFactory()); if (!CommandLineMode) { ResourcesDirectory = Path.Combine( Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "Resources"); // // Copy required target, property and task files // String dataDir = Path.Combine(Environment.GetEnvironmentVariable("LOCALAPPDATA"), "ZeroC", "IceBuilder"); if (!Directory.Exists(dataDir)) { Directory.CreateDirectory(dataDir); } foreach (String f in new String[] { "IceBuilder.Common.props", "IceBuilder.Cpp.props", "IceBuilder.Cpp.targets", "IceBuilder.Cpp.xml", "IceBuilder.CSharp.props", "IceBuilder.CSharp.targets", "IceBuilder.Tasks.dll" }) { if (!File.Exists(Path.Combine(dataDir, f))) { File.Copy(Path.Combine(ResourcesDirectory, f), Path.Combine(dataDir, f)); } else { byte[] data1 = File.ReadAllBytes(Path.Combine(ResourcesDirectory, f)); byte[] data2 = File.ReadAllBytes(Path.Combine(dataDir, f)); if (!data1.SequenceEqual(data2)) { File.Copy(Path.Combine(ResourcesDirectory, f), Path.Combine(dataDir, f), true); } } } DTE2 = (EnvDTE80.DTE2)GetService(typeof(EnvDTE.DTE)); DTEEvents = DTE.Events.DTEEvents; IVsSolution = GetService(typeof(SVsSolution)) as IVsSolution; IVsSolution4 = GetService(typeof(SVsSolution)) as IVsSolution4; UIShell = Package.Instance.GetService(typeof(SVsUIShell)) as IVsUIShell; MonitorSelection = GetGlobalService(typeof(SVsShellMonitorSelection)) as IVsMonitorSelection; // Add our command handlers for menu (commands must exist in the .vsct file) OleMenuCommandService mcs = GetService(typeof(IMenuCommandService)) as OleMenuCommandService; if (null != mcs) { // Create the command for the menu item. CommandID menuCommandAddID = new CommandID(GuidList.IceBuilderCommandsGUI, (int)PkgCmdIDList.AddIceBuilder); OleMenuCommand menuItemAdd = new OleMenuCommand(AddIceBuilderToProject, menuCommandAddID); menuItemAdd.Enabled = false; mcs.AddCommand(menuItemAdd); menuItemAdd.BeforeQueryStatus += addIceBuilder_BeforeQueryStatus; CommandID menuCommanRemoveID = new CommandID(GuidList.IceBuilderCommandsGUI, (int)PkgCmdIDList.RemoveIceBuilder); OleMenuCommand menuItemRemove = new OleMenuCommand(RemoveIceBuilderFromProject, menuCommanRemoveID); menuItemRemove.Enabled = false; mcs.AddCommand(menuItemRemove); menuItemRemove.BeforeQueryStatus += removeIceBuilder_BeforeQueryStatus; } // // If IceHome isn't set or is set to an invlid location, try to // locate the latest version installed and use that. // Version version = null; Version latest = null; String iceHome = null; bool updateIceHome = true; try { if (File.Exists(Path.Combine(GetIceHome(), "bin", "slice2cpp.exe")) || File.Exists(Path.Combine(GetIceHome(), "cpp", "bin", "slice2cpp.exe"))) { updateIceHome = false; } } catch (ArgumentException) { } if(updateIceHome) { using (RegistryKey key = Registry.LocalMachine.OpenSubKey(@"Software\ZeroC")) { if (key != null) { foreach (String name in key.GetSubKeyNames()) { using (RegistryKey subKey = key.OpenSubKey(name)) { if(subKey == null) { continue; } object value = subKey.GetValue("InstallDir"); if (value == null) { continue; } String installDir = value.ToString(); try { if (!File.Exists(Path.Combine(installDir, "bin", "slice2cpp.exe"))) { continue; } } catch (ArgumentException) { // Could happen if install dir is null or has invalid characters continue; } try { version = Version.Parse(GetSliceCompilerVersion(installDir)); } catch (System.Exception) { continue; } if (version.Build == 51) { // Ignore beta version continue; } if (version < new Version(3, 6, 0)) { //We require 3.6.0 or greatest continue; } if (!name.Equals( String.Format("Ice {0}.{1}.{2}", version.Major, version.Minor, version.Build))) { continue; } latest = (latest == null) ? version : (latest > version) ? latest : version; if (latest.Equals(version)) { iceHome = installDir; } } } } } if (iceHome != null) { SetIceHome(iceHome); } else { if (MessageBox.Show( "The selected Ice home directory does not exist or is not " + "an Ice installation. Please provide a correct Ice home directory.", "Ice Builder - Incorrect Ice home", MessageBoxButtons.OKCancel, MessageBoxIcon.Information) == DialogResult.OK) { DTEEvents.OnStartupComplete += ShowIceOptionsPage; } } } Assembly assembly = null; if (DTE.Version.StartsWith("11.0")) { assembly = Assembly.LoadFrom(Path.Combine(ResourcesDirectory, "IceBuilder.VS2012.dll")); } else if (DTE.Version.StartsWith("12.0")) { assembly = Assembly.LoadFrom(Path.Combine(ResourcesDirectory, "IceBuilder.VS2013.dll")); } else { assembly = Assembly.LoadFrom(Path.Combine(ResourcesDirectory, "IceBuilder.VS2015.dll")); } VCUtil = assembly.GetType("IceBuilder.VCUtilI").GetConstructor(new Type[] { }).Invoke( new object[] { }) as VCUtil; RunningDocumentTableEventHandler = new RunningDocumentTableEventHandler( GetService(typeof(SVsRunningDocumentTable)) as IVsRunningDocumentTable); Builder = new Builder(GetService(typeof(SVsBuildManagerAccessor)) as IVsBuildManagerAccessor2); // // Subscribe to solution events. // SolutionEventHandler = new SolutionEventHandler(); SolutionEventHandler.BeginTrack(); DocumentEventHandler = new DocumentEventHandler( GetService(typeof(SVsTrackProjectDocuments)) as IVsTrackProjectDocuments2); DocumentEventHandler.BeginTrack(); FileTracker = new GeneratedFileTracker(); BuildEvents = DTE2.Events.BuildEvents; BuildEvents.OnBuildBegin += BuildEvents_OnBuildBegin; BuildEvents.OnBuildDone += BuildEvents_OnBuildDone; DTEEvents.OnStartupComplete += AddinRemoval; } }
protected override async Task InitializeAsync(CancellationToken cancel, IProgress <Microsoft.VisualStudio.Shell.ServiceProgressData> progress) { Instance = this; await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); AutoBuilding = GetAutoBuilding(); object value = null; { Shell = await GetServiceAsync(typeof(IVsShell)) as IVsShell; if (Shell == null) { throw new PackageInitializationException("Error initializing Shell"); } Shell.GetProperty((int)__VSSPROPID.VSSPROPID_IsInCommandLineMode, out value); CommandLineMode = (bool)value; } if (!CommandLineMode) { InstallDirectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); ResourcesDirectory = Path.Combine(InstallDirectory, "Resources"); DTE2 = await GetServiceAsync(typeof(EnvDTE.DTE)) as EnvDTE80.DTE2; if (DTE2 == null) { throw new PackageInitializationException("Error initializing DTE2"); } DTEEvents = DTE.Events.DTEEvents; IVsSolution = await GetServiceAsync(typeof(SVsSolution)) as IVsSolution; if (IVsSolution == null) { throw new PackageInitializationException("Error initializing IVsSolution"); } IVsSolution4 = await GetServiceAsync(typeof(SVsSolution)) as IVsSolution4; if (IVsSolution4 == null) { throw new PackageInitializationException("Error initializing IVsSolution4"); } UIShell = await GetServiceAsync(typeof(SVsUIShell)) as IVsUIShell; if (UIShell == null) { throw new PackageInitializationException("Error initializing UIShell"); } MonitorSelection = await GetServiceAsync(typeof(SVsShellMonitorSelection)) as IVsMonitorSelection; if (MonitorSelection == null) { throw new PackageInitializationException("Error initializing MonitorSelection"); } // // Update the InstallDir this was previously used in project imports, but is still usefull if you // need to detect the extension install dir. // Registry.SetValue(IceBuilderKey, string.Format("InstallDir.{0}", DTE.Version), InstallDirectory, RegistryValueKind.String); Assembly assembly = null; if (DTE.Version.StartsWith("14.0")) { assembly = Assembly.LoadFrom(Path.Combine(ResourcesDirectory, "IceBuilder.VS2015.dll")); } else if (DTE.Version.StartsWith("15.0")) { assembly = Assembly.LoadFrom(Path.Combine(ResourcesDirectory, "IceBuilder.VS2017.dll")); } else { assembly = Assembly.LoadFrom(Path.Combine(ResourcesDirectory, "IceBuilder.VS2019.dll")); } var factory = assembly.GetType("IceBuilder.ProjectHelperFactoryI").GetConstructor(new Type[] { }).Invoke( new object[] { }) as IVsProjectHelperFactory; VCUtil = factory.VCUtil; NuGet = factory.NuGet; ProjectHelper = factory.ProjectHelper; ProjectFactoryHelperInstance.Init(VCUtil, NuGet, ProjectHelper); NuGet.OnNugetBatchEnd(PackageInstalled); RunningDocumentTableEventHandler = new RunningDocumentTableEventHandler( await GetServiceAsync(typeof(SVsRunningDocumentTable)) as IVsRunningDocumentTable); Builder = new Builder(await GetServiceAsync(typeof(SVsBuildManagerAccessor)) as IVsBuildManagerAccessor2); // // Subscribe to solution events. // SolutionEventHandler = new SolutionEventHandler(); SolutionEventHandler.BeginTrack(); DocumentEventHandler = new DocumentEventHandler( await GetServiceAsync(typeof(SVsTrackProjectDocuments)) as IVsTrackProjectDocuments2); DocumentEventHandler.BeginTrack(); BuildEvents = DTE2.Events.BuildEvents; BuildEvents.OnBuildBegin += BuildEvents_OnBuildBegin; BuildEvents.OnBuildDone += BuildEvents_OnBuildDone; } await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); RegisterProjectFactory(new ProjectFactory()); RegisterProjectFactory(new ProjectFactoryOld()); value = null; IVsSolution.GetProperty((int)__VSPROPID.VSPROPID_IsSolutionOpen, out value); if ((bool)value) { RunningDocumentTableEventHandler.BeginTrack(); InitializeProjects(DTEUtil.GetProjects()); } }