const int VSSPROPID_ReleaseVersion = -9068; // VS 12+ internal static void Ensure(IAnkhServiceProvider context) { if (FullVersion.Major == 0) { // Use the old DTE api in an attempt to get the version Version ver; if (TryGetDteVersion(context, out ver)) { _vsVersion = ver; } } if (FullVersion.Major == 0) { string versionStr = null; // VS 2012 has a shell property IVsShell shell = context.GetService <IVsShell>(typeof(SVsShell)); if (shell != null) { object v; if (VSErr.Succeeded(shell.GetProperty(VSSPROPID_ReleaseVersion, out v))) { versionStr = v as string; } } if (!string.IsNullOrEmpty(versionStr)) { ParseVersion(versionStr); } } }
public ShellInitializedObservable([Import(ContractNames.Interop.IVsShell)] IVsShell shell) { this.shell = shell; initialized = new AsyncManualResetEvent(); object zombie; ErrorHandler.ThrowOnFailure(shell.GetProperty((int)__VSSPROPID.VSSPROPID_Zombie, out zombie)); var isZombie = (bool)zombie; observable = Observable.Create <ShellInitialized>(async o => { if (isZombie) { await initialized.WaitAsync(); } o.OnNext(data); o.OnCompleted(); return(Disposable.Empty); }); if (isZombie) { ErrorHandler.ThrowOnFailure(shell.AdviseShellPropertyChanges(this, out cookie)); } }
public bool IsRecording() { // If the property can not be retrieved it is assumed no macro is being recorded. VSRECORDSTATE recordState = VSRECORDSTATE.VSRECORDSTATE_OFF; // Retrieve the macro recording state. IVsShell vsShell = (IVsShell)Microsoft.VisualStudio.Shell.Package.GetGlobalService(typeof(SVsShell)); if (vsShell != null) { object var; if (ErrorHandler.Succeeded(vsShell.GetProperty((int)__VSSPROPID.VSSPROPID_RecordState, out var)) && null != var) { recordState = (VSRECORDSTATE)var; } } // If there is a change in the record state to OFF or ON we must either obtain // or release the macro recorder. if (recordState == VSRECORDSTATE.VSRECORDSTATE_ON && m_VsMacroRecorder == null) { // If this QueryService fails we no macro recording m_VsMacroRecorder = (IVsMacroRecorder)Microsoft.VisualStudio.Shell.Package.GetGlobalService(typeof(IVsMacroRecorder)); } else if (recordState == VSRECORDSTATE.VSRECORDSTATE_OFF && m_VsMacroRecorder != null) { // If the macro recording state has been switched off then we can release // the service. Note that if the state has become paused we take no action. Stop(); } return(m_VsMacroRecorder != null); }
/// <summary> /// Show error window if settings permit. /// </summary> public void BringToFrontIfSettingsPermit() { EnsureInitialized(); NuGetUIThreadHelper.JoinableTaskFactory.Run(async() => { await NuGetUIThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); IVsShell vsShell = await _asyncServiceProvider.GetServiceAsync <IVsShell>(); object propertyShowTaskListOnBuildEnd; int getPropertyReturnCode = vsShell.GetProperty((int)__VSSPROPID.VSSPROPID_ShowTasklistOnBuildEnd, out propertyShowTaskListOnBuildEnd); bool showErrorListOnBuildEnd = true; if (getPropertyReturnCode == VSConstants.S_OK) { if (bool.TryParse(propertyShowTaskListOnBuildEnd?.ToString(), out bool result)) { showErrorListOnBuildEnd = result; } } if (showErrorListOnBuildEnd) { // Give the error list focus. var vsErrorList = _errorList as IVsErrorList; vsErrorList?.BringToFront(); } }); }
protected override void OnInitialize() { base.OnInitialize(); GetService <SelectionContext>(typeof(ISelectionContext)).CmdUIContextChanged += OnCmdUIContextChanged; GetService <AnkhServiceEvents>().ThemeChanged += OnThemeChanged; IVsShell shell = GetService <IVsShell>(typeof(SVsShell)); if (shell != null) { object v; if (!VSErr.Succeeded(shell.GetProperty((int)__VSSPROPID.VSSPROPID_Zombie, out v))) { _zombie = false; } else { _zombie = (v is bool) && ((bool)v); } if (!VSErr.Succeeded(shell.AdviseShellPropertyChanges(this, out _shellPropsCookie))) { _shellPropsCookie = 0; } } // We might already have cached some stale values! foreach (CmdStateCacheItem i in _cookieMap.Values) { i.Reload(Monitor); } }
/// <summary> /// Gets the Static Analysis Tools directory /// </summary> private static string GetStaticAnalysisToolsDirectory(IServiceProvider provider) { if (s_staticAnalysisToolsDirectory == null) { string installDirectory = null; // Get the VS install directory IVsShell shell = (IVsShell)provider.GetService(typeof(IVsShell)); if (shell != null) { object value; if (shell.GetProperty((int)__VSSPROPID2.VSSPROPID_InstallRootDir, out value) == VSConstants.S_OK) { installDirectory = value as string; } } // If we failed to get the install directory through the shell service (this is possible if we are called // from the policy object and we are running in tf.exe and not devenv.exe), then just try to deduce the // install directory from the location of this assembly, which should be under common7\ide\privateassemblies if (string.IsNullOrEmpty(installDirectory)) { installDirectory = Path.GetFullPath(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), @"..\..\..\")); } s_staticAnalysisToolsDirectory = Path.Combine(installDirectory, @"Team Tools\Static Analysis Tools"); } return(s_staticAnalysisToolsDirectory); }
/// <summary> /// Retrieves the Devenv installation directory. /// </summary> private static string GetEnvironmentDirectoryLocation() { IVsShell shell = Microsoft.VisualStudio.Shell.Package.GetGlobalService(typeof(IVsShell)) as IVsShell; Debug.Assert(shell != null, "Could not retrieve the IVsShell service from the global service provider"); object installDirAsObject; // We do not want to throw. If we cannot set the solution related constants we set them to empty string. ErrorHandler.ThrowOnFailure(shell.GetProperty((int)__VSSPROPID.VSSPROPID_InstallDirectory, out installDirAsObject)); string installDir = ((string)installDirAsObject); if (String.IsNullOrEmpty(installDir)) { return(String.Empty); } // Ensure that we have traimnling backslash as this is done for the langproj macros too. if (installDir[installDir.Length - 1] != Path.DirectorySeparatorChar) { installDir += Path.DirectorySeparatorChar; } return(installDir); }
private void NavigateTutorialAnchor(string anchorName) { IVsShell shell = (IVsShell)GetService(typeof(SVsShell)); if (shell != null) { object value; shell.GetProperty((int)__VSSPROPID.VSSPROPID_InstallDirectory, out value); string installDir = (string)value; string tutorialsPath = Path.Combine(installDir, tutorialsRelativePath); if (File.Exists(tutorialsPath)) { if (!String.IsNullOrEmpty(anchorName)) { this.Navigate(tutorialsPath + "#" + anchorName); } else { this.Navigate(tutorialsPath); } } else { MessageBox.Show("The tutorials are missing from your installation. Please reinstall AddOn Studio for Multiverse Interface.", "AddOn Studio for Multiverse Interface", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
internal static IDictionary <string, IORMGenerator> GetORMGenerators(IServiceProvider serviceProvider) { Dictionary <string, IORMGenerator> generators = _ormGenerators; if (generators == null) { generators = new Dictionary <string, IORMGenerator>(); string registryRoot = null; try { IVsShell shell = serviceProvider.GetService(typeof(SVsShell)) as IVsShell; object registryRootObj; shell.GetProperty((int)__VSSPROPID.VSSPROPID_VirtualRegistryRoot, out registryRootObj); registryRoot = registryRootObj.ToString(); } catch (Exception ex) { // TODO: Localize message. ReportError("WARNING: Exception ocurred while trying to read registry root in ORMCustomTool:", ex); } if (registryRoot != null) { LoadGeneratorsFromRoot(Registry.CurrentUser, generators, registryRoot + "_Config"); } if (null != System.Threading.Interlocked.CompareExchange(ref _ormGenerators, generators, null)) { generators = _ormGenerators; } } return(generators); }
private object GetVirtualRegistryRoot() { // Note: A different way of getting the registry root IVsShell shell = (IVsShell)Package.GetGlobalService(typeof(SVsShell)); shell.GetProperty((int)__VSSPROPID.VSSPROPID_VirtualRegistryRoot, out object root); return(root); }
internal static bool IsInModalState(this IVsShell vsShell) { if (ErrorHandler.Failed(vsShell.GetProperty((int)__VSSPROPID4.VSSPROPID_IsModal, out object value)) || !(value is bool)) { return(false); } return((bool)value); }
Task <IStatusResponse> IStatusRequestHandler.GetStatusAsync() { vsShell.GetProperty((int)__VSSPROPID5.VSSPROPID_AppBrandName, out var ideName); ideName = ideName ?? "Microsoft Visual Studio"; vsSolution.GetProperty((int)__VSPROPID.VSPROPID_SolutionBaseName, out var ideInstance); ideInstance = ideInstance ?? ""; return(Task.FromResult <IStatusResponse>(new StatusResponse(ideName.ToString(), ideInstance.ToString()))); }
public static async Task <bool> IsInServerModeAsync(CancellationToken token) { await NuGetUIThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(token); IVsShell shell = await ServiceLocator.GetGlobalServiceAsync <SVsShell, IVsShell>(); return(shell.GetProperty((int)__VSSPROPID11.VSSPROPID_ShellMode, out object value) == VSConstants.S_OK && value is int shellMode && shellMode == (int)__VSShellMode.VSSM_Server); }
private bool zombieMode(IVsShell vsShell) { object initialised = false; var result = vsShell.GetProperty((int)__VSSPROPID4.VSSPROPID_ShellInitialized, out initialised); if (result == 0) { return((bool)initialised == false); } return(true); }
/// <summary> /// Gets the current running VS hive, such as "10.0" or "10.0Exp". /// </summary> public static string GetHive(this IVsShell shell) { var value = default(object); var hive = "10.0"; if (ErrorHandler.Succeeded(shell.GetProperty((int)__VSSPROPID.VSSPROPID_VirtualRegistryRoot, out value))) { hive = ((string)value).Replace(@"Software\Microsoft\VisualStudio\", string.Empty); } return(hive); }
public ShellInitializedNotification(IVsShell shell) { _shell = shell; _tcs = new TaskCompletionSource <object>(); ErrorHandler.ThrowOnFailure(_shell.AdviseShellPropertyChanges(this, out _cookie)); // Check again in case we raised with initialization object value; if (ErrorHandler.Succeeded(_shell.GetProperty((int)__VSSPROPID4.VSSPROPID_ShellInitialized, out value)) && CheckProperty((int)__VSSPROPID4.VSSPROPID_ShellInitialized, value)) { return; } if (ErrorHandler.Succeeded(_shell.GetProperty((int)__VSSPROPID6.VSSPROPID_ShutdownStarted, out value)) && CheckProperty((int)__VSSPROPID6.VSSPROPID_ShutdownStarted, value)) { return; } }
private string GetStaticAnalysisToolsDirectory(IServiceProvider serviceProvider) { string installDirectory = null; // Get the VS install directory IVsShell shell = (IVsShell)serviceProvider.GetService(typeof(IVsShell)); object value; Marshal.ThrowExceptionForHR(shell.GetProperty((int)__VSSPROPID2.VSSPROPID_InstallRootDir, out value)); installDirectory = (string)value; return(Path.Combine(installDirectory, "Team Tools", "Static Analysis Tools")); }
public static bool TryGetPropertyValue(this IVsShell shell, __VSSPROPID id, out IntPtr value) { var hresult = shell.GetProperty((int)id, out var objValue); if (ErrorHandler.Succeeded(hresult) && objValue != null) { value = (IntPtr.Size == 4) ? (IntPtr)(int)objValue : (IntPtr)(long)objValue; return(true); } value = default; return(false); }
/// <summary> /// BSTR. Directory where visual studio executable was installed. /// http://technet.microsoft.com/en-us/microsoft.visualstudio.shell.interop.__vsspropid%28v=vs.71%29.aspx /// </summary> /// <param name="ptr">stub.</param> /// <returns></returns> public static string GetDevEnvDir(this string ptr) { #if VSSDK_15_AND_NEW ThreadHelper.ThrowIfNotOnUIThread(); //TODO: upgrade to 15 #endif IVsShell shell = (IVsShell)Package.GetGlobalService(typeof(SVsShell)); shell.GetProperty((int)__VSSPROPID.VSSPROPID_InstallDirectory, out object dirObject); string dir = (string)dirObject; return(string.IsNullOrEmpty(dir) ? PropertyNames.UNDEFINED : dir.DirectoryPathFormat()); }
/// <summary> /// Checks whether the provider is invoked in command line mode /// </summary> public bool InCommandLineMode() { IVsShell shell = (IVsShell)GetService(typeof(SVsShell)); object pvar; if (shell.GetProperty((int)__VSSPROPID.VSSPROPID_IsInCommandLineMode, out pvar) == VSConstants.S_OK && (bool)pvar) { return(true); } return(false); }
public async Task <string?> GetRegistryRootAsync(ProjectSystem.VS.IVsService <IVsShell> vsShellService) { await _threadingService.SwitchToUIThread(); IVsShell shell = await vsShellService.GetValueAsync(); if (ErrorHandler.Succeeded(shell.GetProperty((int)__VSSPROPID.VSSPROPID_VirtualRegistryRoot, out object value))) { return(value as string); } return(null); }
public async Task <string?> GetLocalAppDataFolderAsync(ProjectSystem.VS.IVsService <IVsShell> vsShellService) { await _threadingService.SwitchToUIThread(); IVsShell shell = await vsShellService.GetValueAsync(); if (ErrorHandler.Succeeded(shell.GetProperty((int)__VSSPROPID4.VSSPROPID_LocalAppDataDir, out object value))) { return(value as string); } return(null); }
public async Task <string> GetLocalAppDataFolderAsync(IServiceProvider serviceProvider) { await _threadingService.SwitchToUIThread(); IVsShell shell = serviceProvider.GetService <IVsShell, SVsShell>(); if (ErrorHandler.Succeeded(shell.GetProperty((int)__VSSPROPID4.VSSPROPID_LocalAppDataDir, out object objDataFolder)) && objDataFolder is string appDataFolder) { return(appDataFolder); } return(null); }
/// <summary> /// Gets the version of Visual Studio. /// </summary> public async Task<Version?> GetVsVersionAsync() { await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); IVsShell shell = await VS.Services.GetShellAsync(); shell.GetProperty((int)__VSSPROPID5.VSSPROPID_ReleaseVersion, out object value); if (value is string raw) { return Version.Parse(raw.Split(' ')[0]); } return null; }
private string GetStaticAnalysisToolsDirectory() { // Get the VS install directory IVsShell shell = this.serviceProvider.GetService <SVsShell, IVsShell>(); Debug.Assert(shell != null, "IVsShell is expected"); object value; ErrorHandler.ThrowOnFailure(shell.GetProperty((int)__VSSPROPID2.VSSPROPID_InstallRootDir, out value)); string vsInstallDirectory = value as string; return(Path.Combine(vsInstallDirectory, DefaultVSRuleSetsFolder)); }
protected override void Initialize() { base.Initialize(); IVsShell shell = GetService(typeof(IVsShell)) as IVsShell; object value; shell.GetProperty((int)__VSSPROPID.VSSPROPID_IsInCommandLineMode, out value); if (!(bool)value) { string installDirectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); Registry.SetValue(@"HKEY_CURRENT_USER\Software\ZeroC\IceBuilder", "InstallDir.10.0", installDirectory, RegistryValueKind.String); } }
/// <summary> /// Creates anew instance of the <see cref="VsEnvironmentRenderCapabilities"/> class. /// </summary> private VsEnvironmentRenderCapabilities() { IVsShell service = ServiceProvider.GlobalProvider.GetService(typeof(SVsShell)) as IVsShell; if (service != null) { object obj2; if (Microsoft.VisualStudio.ErrorHandler.Succeeded(service.GetProperty(-9061, out obj2))) { this.VisualEffectsAllowed = (int)obj2; } service.AdviseShellPropertyChanges(this, out this.shellPropertyChangesCookie); } }
public void Setup() { object isReady; ErrorHandler.ThrowOnFailure(_shell.GetProperty((int)__VSSPROPID4.VSSPROPID_ShellInitialized, out isReady)); if ((bool)isReady) { _init(); } else { ErrorHandler.ThrowOnFailure(_shell.AdviseShellPropertyChanges(this, out _cookie)); } }
private void CheckVsStarted() { _vsShell.GetProperty((int)__VSSPROPID4.VSSPROPID_ShellInitialized, out var value); if (value is bool) { if ((bool)value) { _application.FireStarted(); } else { _vsShell.AdviseShellPropertyChanges(this, out _vsShellEventsCookie); } } }
/// <summary> /// Creates a new InfoBar in the main window. /// </summary> /// <param name="model">A model representing the text, icon, and actions of the InfoBar.</param> public async Task <InfoBar?> CreateAsync(InfoBarModel model) { await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); IVsShell shell = await VS.Services.GetShellAsync(); shell.GetProperty((int)__VSSPROPID7.VSSPROPID_MainWindowInfoBarHost, out object value); if (value is IVsInfoBarHost host) { return(new InfoBar(host, model)); } return(null); }
/// <summary> /// Initialization of the package; this method is called right after the package is sited, so this is the place /// where you can put all the initialization code that rely on services provided by VisualStudio. /// </summary> protected override void Initialize() { base.Initialize(); // 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 tool window CommandID toolwndCommandID = new CommandID(GuidList.guidProgressBarCmdSet, (int)PkgCmdIDList.cmdidProgressBar); MenuCommand menuToolWin = new MenuCommand(ShowToolWindow, toolwndCommandID); mcs.AddCommand(menuToolWin); } // Get shell object vsShell = ServiceProvider.GlobalProvider.GetService(typeof(SVsShell)) as IVsShell; if (vsShell != null) { // Initialize VisualEffects values, so themes can determine if various effects are supported by the environment object effectsAllowed; if (ErrorHandler.Succeeded(vsShell.GetProperty((int)__VSSPROPID4.VSSPROPID_VisualEffectsAllowed, out effectsAllowed))) { // VSSPROPID_VisualEffectsAllowed is a VT_I4 property, so casting to int should be safe Debug.Assert(effectsAllowed is int, "VSSPROPID_VisualEffectsAllowed should be of type int"); this.visualEffectsAllowed = (int)effectsAllowed; } else { Debug.Fail("Failed to get the VSSPROPID_VisualEffectsAllowed property value."); } // Subscribe to shell property changes to update VisualEffects values if the user modifies the settings vsShell.AdviseShellPropertyChanges(this, out shellPropertyChangesCookie); } // Get solution solution = ServiceProvider.GlobalProvider.GetService(typeof(SVsSolution)) as IVsSolution2; if (solution != null) { // Get count of any currently loaded projects object count; solution.GetProperty((int)__VSPROPID.VSPROPID_ProjectCount, out count); totalProjects = (int)count; // Register for solution events solution.AdviseSolutionEvents(this, out solutionEventsCookie); } // Get solution build manager sbm = ServiceProvider.GlobalProvider.GetService(typeof(SVsSolutionBuildManager)) as IVsSolutionBuildManager2; if (sbm != null) { sbm.AdviseUpdateSolutionEvents(this, out updateSolutionEventsCookie); } // Get tool window if (toolWindow == null) { toolWindow = this.FindToolWindow(typeof(BuildProgressToolWindow), 0, true) as BuildProgressToolWindow; } // Set initial value of EffectsEnabled in tool window toolWindow.EffectsEnabled = visualEffectsAllowed != 0; }