Exemplo n.º 1
0
        /// <summary>
        /// Launches a DontShowAgainDialog if it is needed.
        /// </summary>
        /// <param name="serviceProvider">An associated serviceprovider.</param>
        /// <param name="messageText">The text the dilaog box will contain.</param>
        /// <param name="helpTopic">The associated help topic.</param>
        /// <param name="button">The default button.</param>
        /// <param name="registryKey">The registry key that serves for persisting the not show again value.</param>
        /// <returns>A Dialog result.</returns>
        internal static DialogResult LaunchDontShowAgainDialog(IServiceProvider serviceProvider, string messageText, string helpTopic, DefaultButton button, string registryKey)
        {
            if (String.IsNullOrEmpty(registryKey))
            {
                throw new ArgumentException(SR.GetString(SR.ParameterCannotBeNullOrEmpty, CultureInfo.CurrentUICulture), "registryKey");
            }

            DialogResult result = DialogResult.OK;

            bool dontShowAgain = ReadDontShowAgainValue(registryKey);

            if (!dontShowAgain)
            {
                DontShowAgainDialog dialog = new DontShowAgainDialog(serviceProvider, messageText, helpTopic, button);
                result = dialog.ShowDialog();

                // Now write to the registry the value.
                if (dialog.DontShowAgainValue)
                {
                    WriteDontShowAgainValue(registryKey, 1);
                }
            }

            return(result);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Checks if the project location is secure. If it is not then it will launch a dialog box prompting the user to acknowledge that the project location is not secure.
        /// </summary>
        /// <param name="location">The location to check</param>
        /// <returns>true if it is secure, false otherwise.</returns>
        private bool IsProjectLocationSecure(string location)
        {
            if (!Utilities.IsProjectLocationSecure(location))
            {
                if (Utilities.IsShellInCommandLineMode(this.Site) || Utilities.IsInAutomationFunction(this.Site))
                {
                    return(false);
                }

                string errorMessage = String.Format(CultureInfo.CurrentCulture, SR.GetString(SR.ProjectLocationNotTrusted, CultureInfo.CurrentUICulture), Environment.NewLine, Path.GetDirectoryName(location));
                return(DontShowAgainDialog.LaunchDontShowAgainDialog(this.Site, errorMessage, ProjectFolderFotSecureHelp, DontShowAgainDialog.DefaultButton.OK, DontShowProjectSecurityWarningAgain) == DialogResult.OK);
            }

            return(true);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Launches a DontShowAgainDialog if it is needed.
        /// </summary>
        /// <param name="serviceProvider">An associated serviceprovider.</param>
        /// <param name="messageText">The text the dilaog box will contain.</param>
        /// <param name="helpTopic">The associated help topic.</param>
        /// <param name="button">The default button.</param>
        /// <param name="registryKey">The registry key that serves for persisting the not show again value.</param>
        /// <returns>A Dialog result.</returns>
        internal static DialogResult LaunchDontShowAgainDialog(IServiceProvider serviceProvider, string messageText, string helpTopic, DefaultButton button, string registryKey)
        {
            if(String.IsNullOrEmpty(registryKey))
            {
                throw new ArgumentException(SR.GetString(SR.ParameterCannotBeNullOrEmpty, CultureInfo.CurrentUICulture), "registryKey");
            }

            DialogResult result = DialogResult.OK;

            bool dontShowAgain = ReadDontShowAgainValue(registryKey);

            if(!dontShowAgain)
            {
                DontShowAgainDialog dialog = new DontShowAgainDialog(serviceProvider, messageText, helpTopic, button);
                result = dialog.ShowDialog();

                // Now write to the registry the value.
                if(dialog.DontShowAgainValue)
                {
                    WriteDontShowAgainValue(registryKey, 1);
                }
            }

            return result;
        }
Exemplo n.º 4
0
        /// <summary>
        /// Initialize the nested hierarhy node.
        /// </summary>
        /// <param name="fileName">The file name of the nested project.</param>
        /// <param name="destination">The location of the nested project.</param>
        /// <param name="projectName">The name of the project.</param>
        /// <param name="createFlags">The nested project creation flags </param>
        /// <remarks>This methos should be called just after a NestedProjectNode object is created.</remarks>
        public virtual void Init(string fileName, string destination, string projectName, __VSCREATEPROJFLAGS createFlags)
        {
            if (String.IsNullOrEmpty(fileName))
            {
                throw new ArgumentException(SR.GetString(SR.ParameterCannotBeNullOrEmpty, CultureInfo.CurrentUICulture), "fileName");
            }

            if (String.IsNullOrEmpty(destination))
            {
                throw new ArgumentException(SR.GetString(SR.ParameterCannotBeNullOrEmpty, CultureInfo.CurrentUICulture), "destination");
            }

            this.projectName = Path.GetFileName(fileName);
            this.projectPath = Path.Combine(destination, this.projectName);

            // get the IVsSolution interface from the global service provider
            IVsSolution solution = this.GetService(typeof(IVsSolution)) as IVsSolution;

            Debug.Assert(solution != null, "Could not get the IVsSolution object from the services exposed by this project");
            if (solution == null)
            {
                throw new InvalidOperationException();
            }

            // Get the project type guid from project element
            string typeGuidString     = this.ItemNode.GetMetadataAndThrow(ProjectFileConstants.TypeGuid, new InvalidOperationException());
            Guid   projectFactoryGuid = Guid.Empty;

            if (!String.IsNullOrEmpty(typeGuidString))
            {
                projectFactoryGuid = new Guid(typeGuidString);
            }

            // Get the project factory.
            IVsProjectFactory projectFactory;

            ErrorHandler.ThrowOnFailure(solution.GetProjectFactory((uint)0, new Guid[] { projectFactoryGuid }, fileName, out projectFactory));

            this.CreateProjectDirectory();

            //Create new project using factory
            int    cancelled;
            Guid   refiid     = NativeMethods.IID_IUnknown;
            IntPtr projectPtr = IntPtr.Zero;

            // For a nested project the creation at unsafe location is governed by the parent project since the nested project will end up in the cone of the parent project.
            bool dontShowAgain = DontShowAgainDialog.ReadDontShowAgainValue(ProjectFactory.DontShowProjectSecurityWarningAgain);

            try
            {
                DontShowAgainDialog.WriteDontShowAgainValue(ProjectFactory.DontShowProjectSecurityWarningAgain, 1);
                ErrorHandler.ThrowOnFailure(projectFactory.CreateProject(fileName, destination, projectName, (uint)createFlags, ref refiid, out projectPtr, out cancelled));

                if (projectPtr != IntPtr.Zero)
                {
                    this.nestedHierarchy = Marshal.GetTypedObjectForIUnknown(projectPtr, typeof(IVsHierarchy)) as IVsHierarchy;
                    Debug.Assert(this.nestedHierarchy != null, "Nested hierarchy could not be created");
                    Debug.Assert(cancelled == 0);
                }
            }
            finally
            {
                if (projectPtr != IntPtr.Zero)
                {
                    // We created a new instance of the project, we need to call release to decrement the ref count
                    // the RCW (this.nestedHierarchy) still has a reference to it which will keep it alive
                    Marshal.Release(projectPtr);
                }

                // Revert back the old value that security questions about unsafe location are stil asked if that was the value.
                if (!dontShowAgain)
                {
                    DontShowAgainDialog.WriteDontShowAgainValue(ProjectFactory.DontShowProjectSecurityWarningAgain, 0);
                }
            }

            if (cancelled != 0 && this.nestedHierarchy == null)
            {
                ErrorHandler.ThrowOnFailure(VSConstants.OLE_E_PROMPTSAVECANCELLED);
            }

            // Link into the nested VS hierarchy.
            ErrorHandler.ThrowOnFailure(this.nestedHierarchy.SetProperty(VSConstants.VSITEMID_ROOT, (int)__VSHPROPID.VSHPROPID_ParentHierarchy, this.ProjectMgr));
            ErrorHandler.ThrowOnFailure(this.nestedHierarchy.SetProperty(VSConstants.VSITEMID_ROOT, (int)__VSHPROPID.VSHPROPID_ParentHierarchyItemid, (object)(int)this.ID));

            this.LockRDTEntry();

            this.ConnectPropertyNotifySink();
        }