Пример #1
0
        /// <summary>
        /// The invoke handler passed to this object's QuickBuildMenuCommand, called by the base OleMenuCommand when an item is clicked
        /// </summary>
        private void OnInvokedDynamicItem(object sender, EventArgs args)
        {
            var MenuCommand = (QuickBuildMenuCommand)sender;

            // Get the project clicked in the solution explorer by accessing the current selection and converting to a Project if possible.
            IntPtr             HierarchyPtr, SelectionContainerPtr;
            uint               ProjectItemId;
            IVsMultiItemSelect MultiItemSelect;

            UnrealVSPackage.Instance.SelectionManager.GetCurrentSelection(out HierarchyPtr, out ProjectItemId, out MultiItemSelect, out SelectionContainerPtr);
            if (HierarchyPtr == null)
            {
                return;
            }

            IVsHierarchy SelectedHierarchy = Marshal.GetTypedObjectForIUnknown(HierarchyPtr, typeof(IVsHierarchy)) as IVsHierarchy;

            if (SelectedHierarchy == null)
            {
                return;
            }

            var SelectedProject = Utils.HierarchyObjectToProject(SelectedHierarchy);

            if (SelectedProject == null)
            {
                return;
            }

            // Builds the selected project with the clicked platform and config
            Utils.ExecuteProjectBuild(SelectedProject, MenuCommand.Text, PlaformName, BatchBuilderToolControl.BuildJob.BuildJobType.Build, null, null);
        }
Пример #2
0
        /// Called when 'BuildStartupProject' button is clicked
        void BuildStartupProjectButtonHandler(object Sender, EventArgs Args)
        {
            // Grab the current startup project
            IVsHierarchy ProjectHierarchy;

            UnrealVSPackage.Instance.SolutionBuildManager.get_StartupProject(out ProjectHierarchy);
            if (ProjectHierarchy != null)
            {
                var StartupProject = Utils.HierarchyObjectToProject(ProjectHierarchy);

                if (StartupProject != null)
                {
                    // Get the active solution configuration
                    var ActiveConfiguration =
                        (SolutionConfiguration2)UnrealVSPackage.Instance.DTE.Solution.SolutionBuild.ActiveConfiguration;
                    var SolutionConfiguration = ActiveConfiguration.Name;
                    var SolutionPlatform      = ActiveConfiguration.PlatformName;

                    // Combine the active solution configuration and platform into a string that Visual Studio
                    // can use to build the startup project (e.g. "Release|x64")
                    var BuildPlatformAndConfiguration = SolutionConfiguration + "|" + SolutionPlatform;

                    // Make sure the Output window is visible
                    UnrealVSPackage.Instance.DTE.ExecuteCommand("View.Output");

                    // Kick off the build!
                    UnrealVSPackage.Instance.DTE.Solution.SolutionBuild.BuildProject(
                        BuildPlatformAndConfiguration,
                        StartupProject.UniqueName,
                        WaitForBuildToFinish: false);
                }
            }
        }
        private void CommitCommandLineText(string CommandLine)
        {
            string FullCommandLine = CommandLine;

            IVsHierarchy ProjectHierarchy;

            UnrealVSPackage.Instance.SolutionBuildManager.get_StartupProject(out ProjectHierarchy);
            if (ProjectHierarchy != null)
            {
                var SelectedStartupProject = Utils.HierarchyObjectToProject(ProjectHierarchy);

                if (SelectedStartupProject != null)
                {
                    // for "Game" projects automatically remove the game project filename from the start of the command line
                    var ActiveConfiguration = (SolutionConfiguration2)UnrealVSPackage.Instance.DTE.Solution.SolutionBuild.ActiveConfiguration;
                    if (UnrealVSPackage.Instance.IsUE4Loaded && Utils.IsGameProject(SelectedStartupProject) && Utils.HasUProjectCommandLineArg(ActiveConfiguration.Name))
                    {
                        string UProjectFileName = Utils.GetUProjectFileName(SelectedStartupProject);
                        if (FullCommandLine.Trim().StartsWith(UProjectFileName, StringComparison.InvariantCultureIgnoreCase))
                        {
                            VsShellUtilities.ShowMessageBox(ServiceProvider.GlobalProvider,
                                                            string.Format("INFORMATION: The project filename {0} has been removed from the command line because it is included automatically for 'Game' projects.", UProjectFileName),
                                                            "UnrealVS",
                                                            OLEMSGICON.OLEMSGICON_INFO,
                                                            OLEMSGBUTTON.OLEMSGBUTTON_OK,
                                                            OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST);
                        }
                        else if (FullCommandLine.Trim().StartsWith(SelectedStartupProject.Name, StringComparison.OrdinalIgnoreCase))
                        {
                            VsShellUtilities.ShowMessageBox(ServiceProvider.GlobalProvider,
                                                            string.Format("INFORMATION: The project name {0} has been removed from the command line because it is included automatically for 'Game' projects.", SelectedStartupProject.Name),
                                                            "UnrealVS",
                                                            OLEMSGICON.OLEMSGICON_INFO,
                                                            OLEMSGBUTTON.OLEMSGBUTTON_OK,
                                                            OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST);
                        }
                        else
                        {
                            FullCommandLine = UProjectFileName + " " + FullCommandLine;
                        }
                    }

                    var CommandLineArgumentsProperty = GetProjectCommandLineProperty(SelectedStartupProject);

                    if (CommandLineArgumentsProperty != null)
                    {
                        Utils.SetPropertyValue(CommandLineArgumentsProperty, FullCommandLine);
                    }
                }
            }

            CommitCommandLineToMRU(CommandLine);
        }
Пример #4
0
        private void CommitCommandLineText(string CommandLine)
        {
            IVsHierarchy ProjectHierarchy;

            if (UnrealVSPackage.Instance.SolutionBuildManager.get_StartupProject(out ProjectHierarchy) == VSConstants.S_OK && ProjectHierarchy != null)
            {
                Project SelectedStartupProject = Utils.HierarchyObjectToProject(ProjectHierarchy);
                if (SelectedStartupProject != null)
                {
                    Configuration SelectedConfiguration = SelectedStartupProject.ConfigurationManager.ActiveConfiguration;
                    if (SelectedConfiguration != null)
                    {
                        IVsBuildPropertyStorage PropertyStorage = ProjectHierarchy as IVsBuildPropertyStorage;
                        if (PropertyStorage != null)
                        {
                            string FullCommandLine = CommandLine;

                            // for "Game" projects automatically remove the game project filename from the start of the command line
                            var ActiveConfiguration = (SolutionConfiguration2)UnrealVSPackage.Instance.DTE.Solution.SolutionBuild.ActiveConfiguration;
                            if (UnrealVSPackage.Instance.IsUE4Loaded && Utils.IsGameProject(SelectedStartupProject) && Utils.HasUProjectCommandLineArg(ActiveConfiguration.Name))
                            {
                                string AutoPrefix = Utils.GetAutoUProjectCommandLinePrefix(SelectedStartupProject);
                                if (FullCommandLine.IndexOf(Utils.UProjectExtension, StringComparison.OrdinalIgnoreCase) < 0 &&
                                    string.Compare(FullCommandLine, SelectedStartupProject.Name, StringComparison.OrdinalIgnoreCase) != 0 &&
                                    !FullCommandLine.StartsWith(SelectedStartupProject.Name + " ", StringComparison.OrdinalIgnoreCase))
                                {
                                    // Committed command line does not specify a .uproject
                                    FullCommandLine = AutoPrefix + " " + FullCommandLine;
                                }
                            }

                            // Get the project kind. C++ projects store the debugger arguments differently to other project types.
                            string ProjectKind = SelectedStartupProject.Kind;

                            // Update the property
                            string ProjectConfigurationName = String.Format("{0}|{1}", SelectedConfiguration.ConfigurationName, SelectedConfiguration.PlatformName);
                            if (String.Equals(ProjectKind, "{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}", StringComparison.InvariantCultureIgnoreCase))
                            {
                                PropertyStorage.SetPropertyValue("LocalDebuggerCommandArguments", ProjectConfigurationName, (uint)_PersistStorageType.PST_USER_FILE, FullCommandLine);
                            }
                            else
                            {
                                PropertyStorage.SetPropertyValue("StartArguments", ProjectConfigurationName, (uint)_PersistStorageType.PST_USER_FILE, FullCommandLine);
                            }
                        }
                    }
                }
            }

            CommitCommandLineToMRU(CommandLine);
        }
Пример #5
0
        int IVsSolutionEvents.OnBeforeCloseProject(IVsHierarchy pHierarchy, int fRemoved)
        {
            // This function is called after a Visual Studio project is closed

            // Get the actual Project object from the IVsHierarchy object that was supplied
            var ClosedProject = Utils.HierarchyObjectToProject(pHierarchy);

            if (ClosedProject != null && OnProjectClosed != null)
            {
                OnProjectClosed(ClosedProject);
            }

            return(VSConstants.S_OK);
        }
Пример #6
0
        int IVsSolutionEvents.OnAfterOpenProject(IVsHierarchy pHierarchy, int fAdded)
        {
            // This function is called after a Visual Studio project is opened (or a new project is created.)

            // Get the actual Project object from the IVsHierarchy object that was supplied
            var OpenedProject = Utils.HierarchyObjectToProject(pHierarchy);

            if (OpenedProject != null && OnProjectOpened != null)
            {
                OnProjectOpened(OpenedProject);
            }

            return(VSConstants.S_OK);
        }
Пример #7
0
        /// <summary>
        /// Returns a string to display in the command-line combo box, based on project state
        /// </summary>
        /// <returns>String to display</returns>
        private string MakeCommandLineComboText()
        {
            string Text = "";

            IVsHierarchy ProjectHierarchy;

            UnrealVSPackage.Instance.SolutionBuildManager.get_StartupProject(out ProjectHierarchy);
            if (ProjectHierarchy != null)
            {
                var SelectedStartupProject = Utils.HierarchyObjectToProject(ProjectHierarchy);

                if (SelectedStartupProject != null)
                {
                    var CommandLineArgumentsProperty = GetProjectCommandLineProperty(SelectedStartupProject);

                    if (CommandLineArgumentsProperty != null)
                    {
                        var CommandLineArguments = (string)CommandLineArgumentsProperty.Value;

                        // for "Game" projects automatically remove the game project filename from the start of the command line
                        var ActiveConfiguration = (SolutionConfiguration2)UnrealVSPackage.Instance.DTE.Solution.SolutionBuild.ActiveConfiguration;
                        if (UnrealVSPackage.Instance.IsUE4Loaded && Utils.IsGameProject(SelectedStartupProject) && Utils.HasUProjectCommandLineArg(ActiveConfiguration.Name))
                        {
                            var AutoPrefix = Utils.GetAutoUProjectCommandLinePrefix(SelectedStartupProject);

                            if (!string.IsNullOrEmpty(AutoPrefix))
                            {
                                if (CommandLineArguments.Trim().StartsWith(AutoPrefix, StringComparison.OrdinalIgnoreCase))
                                {
                                    CommandLineArguments = CommandLineArguments.Trim().Substring(AutoPrefix.Length).Trim();
                                }
                                //else if (CommandLineArguments.Trim().StartsWith(SelectedStartupProject.Name + " ", StringComparison.OrdinalIgnoreCase))
                                //{
                                //	CommandLineArguments = CommandLineArguments.Trim().Substring(SelectedStartupProject.Name.Length + 1).Trim();
                                //}
                            }
                        }

                        Text = CommandLineArguments;
                    }
                    else
                    {
                        Text = InvalidProjectString;
                    }
                }
            }

            return(Text);
        }
Пример #8
0
        /// <summary>
        /// Returns a string to display in the command-line combo box, based on project state
        /// </summary>
        /// <returns>String to display</returns>
        private string MakeCommandLineComboText()
        {
            string Text = "";

            IVsHierarchy ProjectHierarchy;

            if (UnrealVSPackage.Instance.SolutionBuildManager.get_StartupProject(out ProjectHierarchy) == VSConstants.S_OK && ProjectHierarchy != null)
            {
                Project SelectedStartupProject = Utils.HierarchyObjectToProject(ProjectHierarchy);
                if (SelectedStartupProject != null)
                {
                    Configuration SelectedConfiguration = SelectedStartupProject.ConfigurationManager.ActiveConfiguration;
                    if (SelectedConfiguration != null)
                    {
                        IVsBuildPropertyStorage PropertyStorage = ProjectHierarchy as IVsBuildPropertyStorage;
                        if (PropertyStorage != null)
                        {
                            // Query the property store for the debugger arguments
                            string ConfigurationName = String.Format("{0}|{1}", SelectedConfiguration.ConfigurationName, SelectedConfiguration.PlatformName);
                            if (PropertyStorage.GetPropertyValue("LocalDebuggerCommandArguments", ConfigurationName, (uint)_PersistStorageType.PST_USER_FILE, out Text) != VSConstants.S_OK)
                            {
                                if (PropertyStorage.GetPropertyValue("StartArguments", ConfigurationName, (uint)_PersistStorageType.PST_USER_FILE, out Text) != VSConstants.S_OK)
                                {
                                    Text = "";
                                }
                            }

                            // for "Game" projects automatically remove the game project filename from the start of the command line
                            var ActiveConfiguration = (SolutionConfiguration2)UnrealVSPackage.Instance.DTE.Solution.SolutionBuild.ActiveConfiguration;
                            if (UnrealVSPackage.Instance.IsUE4Loaded && Utils.IsGameProject(SelectedStartupProject) && Utils.HasUProjectCommandLineArg(ActiveConfiguration.Name))
                            {
                                string AutoPrefix = Utils.GetAutoUProjectCommandLinePrefix(SelectedStartupProject);
                                if (!string.IsNullOrEmpty(AutoPrefix))
                                {
                                    if (Text.Trim().StartsWith(AutoPrefix, StringComparison.OrdinalIgnoreCase))
                                    {
                                        Text = Text.Trim().Substring(AutoPrefix.Length).Trim();
                                    }
                                }
                            }
                        }
                    }
                }
            }

            return(Text);
        }
		/// <summary>
		/// Returns a string to display in the startup project combo box, based on project state
		/// </summary>
		/// <returns>String to display</returns>
		private string MakeStartupProjectComboText()
		{
			string Text = "";

			// Switch to this project!
			IVsHierarchy ProjectHierarchy;
			UnrealVSPackage.Instance.SolutionBuildManager.get_StartupProject( out ProjectHierarchy );
			if( ProjectHierarchy != null )
			{
				var Project = Utils.HierarchyObjectToProject(ProjectHierarchy);
				if (Project != null)
				{
					Text = Project.Name;
				}
			}

			return Text;
		}
Пример #10
0
        public int OnActiveProjectCfgChange(IVsHierarchy pIVsHierarchy)
        {
            // This function is called after a Visual Studio project has its active config changed

            // Check whether the project is the current startup project
            IVsHierarchy StartupProjectHierarchy;

            SolutionBuildManager.get_StartupProject(out StartupProjectHierarchy);
            if (StartupProjectHierarchy != null && StartupProjectHierarchy == pIVsHierarchy)
            {
                // Get the actual Project object from the IVsHierarchy object that was supplied
                var Project = Utils.HierarchyObjectToProject(pIVsHierarchy);
                if (Project != null && OnStartupProjectConfigChanged != null)
                {
                    OnStartupProjectConfigChanged(Project);
                }
            }
            return(VSConstants.S_OK);
        }
Пример #11
0
        int IVsSelectionEvents.OnElementValueChanged(uint elementid, object varValueOld, object varValueNew)
        {
            // This function is called when selection changes in various Visual Studio tool windows
            // and sub-systems.

            // Handle startup project changes
            if (elementid == (uint)VSConstants.VSSELELEMID.SEID_StartupProject)
            {
                // If we are registered to a project hierarchy for events, unregister
                var OldStartupProjectHierarchy = (IVsHierarchy)varValueOld;
                if (OldStartupProjectHierarchy != null && ProjectHierarchyEventsHandle != 0)
                {
                    OldStartupProjectHierarchy.UnadviseHierarchyEvents(ProjectHierarchyEventsHandle);
                    ProjectHierarchyEventsHandle = 0;
                }

                Project NewStartupProject = null;

                // Incoming hierarchy object could be null (if no startup project is set yet, or during shutdown.)
                var NewStartupProjectHierarchy = (IVsHierarchy)varValueNew;
                if (NewStartupProjectHierarchy != null)
                {
                    // Get the actual Project object from the IVsHierarchy object that was supplied
                    NewStartupProject = Utils.HierarchyObjectToProject(NewStartupProjectHierarchy);

                    if (NewStartupProject != null)
                    {
                        // Register for events from the project
                        NewStartupProjectHierarchy.AdviseHierarchyEvents(this, out ProjectHierarchyEventsHandle);
                    }
                }

                if (NewStartupProject != null)
                {
                    OnStartupProjectChanged(NewStartupProject);
                }
            }

            return(VSConstants.S_OK);
        }
Пример #12
0
        private void CommitCommandLineText(string CommandLine)
        {
            IVsHierarchy ProjectHierarchy;

            UnrealVSPackage.Instance.SolutionBuildManager.get_StartupProject(out ProjectHierarchy);
            if (ProjectHierarchy != null)
            {
                var SelectedStartupProject = Utils.HierarchyObjectToProject(ProjectHierarchy);

                if (SelectedStartupProject != null)
                {
                    var CommandLineArgumentsProperty = GetProjectCommandLineProperty(SelectedStartupProject);

                    if (CommandLineArgumentsProperty != null)
                    {
                        string FullCommandLine = CommandLine;

                        // for "Game" projects automatically remove the game project filename from the start of the command line
                        var ActiveConfiguration = (SolutionConfiguration2)UnrealVSPackage.Instance.DTE.Solution.SolutionBuild.ActiveConfiguration;
                        if (UnrealVSPackage.Instance.IsUE4Loaded && Utils.IsGameProject(SelectedStartupProject) && Utils.HasUProjectCommandLineArg(ActiveConfiguration.Name))
                        {
                            var AutoPrefix = Utils.GetAutoUProjectCommandLinePrefix(SelectedStartupProject);

                            if (FullCommandLine.IndexOf(Utils.UProjectExtension, StringComparison.OrdinalIgnoreCase) < 0 &&
                                string.Compare(FullCommandLine, SelectedStartupProject.Name, StringComparison.OrdinalIgnoreCase) != 0 &&
                                !FullCommandLine.StartsWith(SelectedStartupProject.Name + " ", StringComparison.OrdinalIgnoreCase))
                            {
                                // Committed command line does not specify a .uproject
                                FullCommandLine = AutoPrefix + " " + FullCommandLine;
                            }
                        }

                        Utils.SetPropertyValue(CommandLineArgumentsProperty, FullCommandLine);
                    }
                }
            }

            CommitCommandLineToMRU(CommandLine);
        }
Пример #13
0
        bool TryCompileSingleFile()
        {
            DTE DTE = UnrealVSPackage.Instance.DTE;

            // Activate the output window
            Window Window = DTE.Windows.Item(EnvDTE.Constants.vsWindowKindOutput);

            Window.Activate();
            OutputWindow OutputWindow = Window.Object as OutputWindow;

            // Try to find the 'Build' window
            OutputWindowPane BuildOutputPane = null;

            foreach (OutputWindowPane Pane in OutputWindow.OutputWindowPanes)
            {
                if (Pane.Guid.ToUpperInvariant() == "{1BD8A850-02D1-11D1-BEE7-00A0C913D1F8}")
                {
                    BuildOutputPane = Pane;
                    break;
                }
            }
            if (BuildOutputPane == null)
            {
                return(false);
            }

            // If there's already a build in progress, offer to cancel it
            if (ChildProcess != null && !ChildProcess.HasExited)
            {
                if (MessageBox.Show("Cancel current compile?", "Compile in progress", MessageBoxButtons.YesNo) == DialogResult.Yes)
                {
                    KillChildProcess();
                    BuildOutputPane.OutputString("1>  Build cancelled.\r\n");
                }
                return(true);
            }

            // Check we've got a file open
            if (DTE.ActiveDocument == null)
            {
                return(false);
            }

            // Grab the current startup project
            IVsHierarchy ProjectHierarchy;

            UnrealVSPackage.Instance.SolutionBuildManager.get_StartupProject(out ProjectHierarchy);
            if (ProjectHierarchy == null)
            {
                return(false);
            }
            Project StartupProject = Utils.HierarchyObjectToProject(ProjectHierarchy);

            if (StartupProject == null)
            {
                return(false);
            }
            Microsoft.VisualStudio.VCProjectEngine.VCProject VCStartupProject = StartupProject.Object as Microsoft.VisualStudio.VCProjectEngine.VCProject;
            if (VCStartupProject == null)
            {
                return(false);
            }

            // Get the active configuration for the startup project
            Configuration ActiveConfiguration     = StartupProject.ConfigurationManager.ActiveConfiguration;
            string        ActiveConfigurationName = String.Format("{0}|{1}", ActiveConfiguration.ConfigurationName, ActiveConfiguration.PlatformName);

            Microsoft.VisualStudio.VCProjectEngine.VCConfiguration ActiveVCConfiguration = VCStartupProject.Configurations.Item(ActiveConfigurationName);
            if (ActiveVCConfiguration == null)
            {
                return(false);
            }

            // Get the NMake settings for this configuration
            Microsoft.VisualStudio.VCProjectEngine.VCNMakeTool ActiveNMakeTool = ActiveVCConfiguration.Tools.Item("VCNMakeTool");
            if (ActiveNMakeTool == null)
            {
                return(false);
            }

            // Save all the open documents
            DTE.ExecuteCommand("File.SaveAll");

            // Check it's a cpp file
            string FileToCompile = DTE.ActiveDocument.FullName;

            if (!FileToCompile.EndsWith(".c", StringComparison.InvariantCultureIgnoreCase) && !FileToCompile.EndsWith(".cpp", StringComparison.InvariantCultureIgnoreCase))
            {
                MessageBox.Show("Invalid file extension for single-file compile.", "Invalid Extension", MessageBoxButtons.OK);
                return(true);
            }

            // If there's already a build in progress, don't let another one start
            if (DTE.Solution.SolutionBuild.BuildState == vsBuildState.vsBuildStateInProgress)
            {
                if (MessageBox.Show("Cancel current compile?", "Compile in progress", MessageBoxButtons.YesNo) == DialogResult.Yes)
                {
                    DTE.ExecuteCommand("Build.Cancel");
                }
                return(true);
            }

            // Make sure any existing build is stopped
            KillChildProcess();

            // Set up the output pane
            BuildOutputPane.Activate();
            BuildOutputPane.Clear();
            BuildOutputPane.OutputString(String.Format("1>------ Build started: Project: {0}, Configuration: {1} {2} ------\r\n", StartupProject.Name, ActiveConfiguration.ConfigurationName, ActiveConfiguration.PlatformName));
            BuildOutputPane.OutputString(String.Format("1>  Compiling {0}\r\n", FileToCompile));

            // Set up event handlers
            DTE.Events.BuildEvents.OnBuildBegin += BuildEvents_OnBuildBegin;

            // Create a delegate for handling output messages
            DataReceivedEventHandler OutputHandler = (Sender, Args) => { if (Args.Data != null)
                                                                         {
                                                                             BuildOutputPane.OutputString("1>  " + Args.Data + "\r\n");
                                                                         }
            };

            // Get the build command line and escape any environment variables that we use
            string BuildCommandLine = ActiveNMakeTool.BuildCommandLine;

            BuildCommandLine = BuildCommandLine.Replace("$(SolutionDir)", Path.GetDirectoryName(UnrealVSPackage.Instance.SolutionFilepath).TrimEnd(Path.DirectorySeparatorChar) + Path.DirectorySeparatorChar);
            BuildCommandLine = BuildCommandLine.Replace("$(ProjectName)", VCStartupProject.Name);

            // Spawn the new process
            ChildProcess = new System.Diagnostics.Process();
            ChildProcess.StartInfo.FileName               = Path.Combine(Environment.SystemDirectory, "cmd.exe");
            ChildProcess.StartInfo.Arguments              = String.Format("/C {0} -singlefile=\"{1}\"", BuildCommandLine, FileToCompile);
            ChildProcess.StartInfo.WorkingDirectory       = Path.GetDirectoryName(StartupProject.FullName);
            ChildProcess.StartInfo.UseShellExecute        = false;
            ChildProcess.StartInfo.RedirectStandardOutput = true;
            ChildProcess.StartInfo.RedirectStandardError  = true;
            ChildProcess.StartInfo.CreateNoWindow         = true;
            ChildProcess.OutputDataReceived              += OutputHandler;
            ChildProcess.ErrorDataReceived += OutputHandler;
            ChildProcess.Start();
            ChildProcess.BeginOutputReadLine();
            ChildProcess.BeginErrorReadLine();
            return(true);
        }
Пример #14
0
        private void CommitCommandLineText(string CommandLine)
        {
            IVsHierarchy ProjectHierarchy;

            if (UnrealVSPackage.Instance.SolutionBuildManager.get_StartupProject(out ProjectHierarchy) == VSConstants.S_OK && ProjectHierarchy != null)
            {
                Project SelectedStartupProject = Utils.HierarchyObjectToProject(ProjectHierarchy);
                if (SelectedStartupProject != null)
                {
                    Configuration SelectedConfiguration = SelectedStartupProject.ConfigurationManager.ActiveConfiguration;
                    if (SelectedConfiguration != null)
                    {
                        IVsBuildPropertyStorage PropertyStorage = ProjectHierarchy as IVsBuildPropertyStorage;
                        if (PropertyStorage != null)
                        {
                            string FullCommandLine = CommandLine;

                            // for "Game" projects automatically remove the game project filename from the start of the command line
                            var ActiveConfiguration = (SolutionConfiguration2)UnrealVSPackage.Instance.DTE.Solution.SolutionBuild.ActiveConfiguration;
                            if (UnrealVSPackage.Instance.IsUE4Loaded && Utils.IsGameProject(SelectedStartupProject) && Utils.HasUProjectCommandLineArg(ActiveConfiguration.Name))
                            {
                                string AutoPrefix = Utils.GetAutoUProjectCommandLinePrefix(SelectedStartupProject);
                                if (FullCommandLine.IndexOf(Utils.UProjectExtension, StringComparison.OrdinalIgnoreCase) < 0 &&
                                    string.Compare(FullCommandLine, SelectedStartupProject.Name, StringComparison.OrdinalIgnoreCase) != 0 &&
                                    !FullCommandLine.StartsWith(SelectedStartupProject.Name + " ", StringComparison.OrdinalIgnoreCase))
                                {
                                    // Committed command line does not specify a .uproject
                                    FullCommandLine = AutoPrefix + " " + FullCommandLine;
                                }
                            }

                            // Get the project platform name.
                            string ProjectPlatformName = SelectedConfiguration.PlatformName;
                            if (ProjectPlatformName == "Any CPU")
                            {
                                ProjectPlatformName = "AnyCPU";
                            }

                            // Get the project kind. C++ projects store the debugger arguments differently to other project types.
                            string ProjectKind = SelectedStartupProject.Kind;

                            // Update the property
                            string ProjectConfigurationName = String.Format("{0}|{1}", SelectedConfiguration.ConfigurationName, ProjectPlatformName);
                            if (String.Equals(ProjectKind, "{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}", StringComparison.InvariantCultureIgnoreCase))
                            {
                                List <string> ExtraFields = Utils.GetExtraDebuggerCommandArguments(ProjectPlatformName, SelectedStartupProject);

                                if (FullCommandLine.Length == 0)
                                {
                                    PropertyStorage.RemoveProperty("LocalDebuggerCommandArguments", ProjectConfigurationName, (uint)_PersistStorageType.PST_USER_FILE);
                                    PropertyStorage.RemoveProperty("RemoteDebuggerCommandArguments", ProjectConfigurationName, (uint)_PersistStorageType.PST_USER_FILE);
                                    foreach (string ExtraField in ExtraFields)
                                    {
                                        PropertyStorage.RemoveProperty(ExtraField, ProjectConfigurationName, (uint)_PersistStorageType.PST_USER_FILE);
                                    }
                                }
                                else
                                {
                                    PropertyStorage.SetPropertyValue("LocalDebuggerCommandArguments", ProjectConfigurationName, (uint)_PersistStorageType.PST_USER_FILE, FullCommandLine);
                                    PropertyStorage.SetPropertyValue("RemoteDebuggerCommandArguments", ProjectConfigurationName, (uint)_PersistStorageType.PST_USER_FILE, FullCommandLine);
                                    foreach (string ExtraField in ExtraFields)
                                    {
                                        PropertyStorage.SetPropertyValue(ExtraField, ProjectConfigurationName, (uint)_PersistStorageType.PST_USER_FILE, FullCommandLine);
                                    }
                                }
                            }
                            else
                            {
                                // For some reason, have to update C# projects this way, otherwise the properties page doesn't update. Conversely, SelectedConfiguration.Properties is always null for C++ projects in VS2017.
                                if (SelectedConfiguration.Properties != null)
                                {
                                    foreach (Property Property in SelectedConfiguration.Properties)
                                    {
                                        if (Property.Name.Equals("StartArguments", StringComparison.InvariantCultureIgnoreCase))
                                        {
                                            Property.Value = FullCommandLine;
                                            break;
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }

            CommitCommandLineToMRU(CommandLine);
        }