예제 #1
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);
        }