Пример #1
0
        /// <summary>
        /// Add a fileName to Perforce then submit it.
        /// Used for testing
        /// </summary>
        /// <param name="vsFileName">The file name to add then submit.</param>
        /// <param name="message">The first line of the P4 command result if no error, else the error message.</param>
        /// <returns>false if error (see message)</returns>
        public bool AddAndSubmitFile(string vsFileName, out string message)
        {
            // Need to do this for unit testing, or we get NullReferenceException in P4API
            Connect();
            Disconnect();

            Perforce.P4.Changelist cl = null;
            try
            {
                cl = _p4Repository.NewChangelist();
            }
            catch (NullReferenceException ex)
            {
                Trace.WriteLine(String.Format("P4Service.AddAndSubmitFile: {0}", ex.Message));
            }

            Perforce.P4.P4CommandResult recordSet;
            string p4FileName = GetP4FileName(vsFileName);
            bool   result     = SendCommand("add", out message, out recordSet, "-c", cl.Id.ToString(), p4FileName);

            if (!result)
            {
                return(false);
            }

            Perforce.P4.SubmitResults unparsedRecordset = null;
            try
            {
                unparsedRecordset = cl.Submit(_p4Options);
            }
            catch (Perforce.P4.P4Exception ex)
            {
                message = HandleRunUnParsedExceptionError(ex);
                return(false);
            }
            return(true);
        }
Пример #2
0
        public void OnNewModuleCreated(ModuleData InNewModuleData)
        {
            //Create a new Filespec list for potential checkouts
            List <Perforce.P4.FileSpec> NewFiles = new List <Perforce.P4.FileSpec>();

            ModuleView NewModuleView = new ModuleView(InNewModuleData);

            NewModuleView.Dock = DockStyle.Top;

            ModuleViewPanel.Controls.Add(NewModuleView);
            ProjectWorker.AddModuleToProxy(InNewModuleData);

            try
            {
                ZipFile.ExtractToDirectory(ProjectWorker.EmptyModuleFiles, Path.Combine(ProjectWorker.SourceDirectory, "Runtime"));

                string NewDirectoryName = Path.Combine(ProjectWorker.SourceDirectory, InNewModuleData.Type, InNewModuleData.Name);

                Directory.Move(Path.Combine(ProjectWorker.SourceDirectory, "Runtime", EmptyModuleToken), NewDirectoryName);

                string[] Files = Directory.GetFiles(NewDirectoryName);

                foreach (string CurrFile in Files)
                {
                    string text = File.ReadAllText(CurrFile);
                    text = text.Replace(EmptyModuleToken, InNewModuleData.Name);
                    File.WriteAllText(CurrFile, text);

                    string NewFileName = CurrFile.Replace(EmptyModuleToken, InNewModuleData.Name);
                    System.IO.File.Move(CurrFile, NewFileName);

                    Perforce.P4.FileSpec NewFileSpec = new Perforce.P4.FileSpec(new Perforce.P4.LocalPath(NewFileName));
                    NewFiles.Add(NewFileSpec);
                }

                if (InNewModuleData.Type == "Runtime")
                {
                    string[]      PrimaryBuildFileContents = File.ReadAllLines(ProjectWorker.PrimaryGameplayBuildFile);
                    List <string> ContentsAsList           = new List <string>();
                    ContentsAsList = PrimaryBuildFileContents.ToList <string>();

                    //Existing PrivateDependancy block
                    int InjectionIndex = ContentsAsList.FindIndex(
                        delegate(string Line)
                    {
                        return(Line.Contains(@"PrivateDependencyModuleNames"));
                    });

                    if (InjectionIndex > -1)
                    {
                        if (ContentsAsList[InjectionIndex + 1].Contains(@"{"))
                        {
                            InjectionIndex++;
                        }

                        //Add one to add the line after the injection index
                        ContentsAsList.Insert(InjectionIndex + 1, '\u0022' + InNewModuleData.Name + '\u0022' + ",");
                    }
                    else
                    {
                        int StartOfConstructorLine = ContentsAsList.FindIndex(
                            delegate(string Line)
                        {
                            return(Line.Contains(@"public " + ProjectWorker.PrimaryModuleName));
                        });

                        if (StartOfConstructorLine > -1)
                        {
                            if (ContentsAsList[StartOfConstructorLine + 1].Contains(@"{"))
                            {
                                StartOfConstructorLine++;
                            }

                            ContentsAsList.Insert(StartOfConstructorLine + 1, @"PrivateDependencyModuleNames.AddRange(new string[]");
                            ContentsAsList.Insert(StartOfConstructorLine + 2, @"{");
                            ContentsAsList.Insert(StartOfConstructorLine + 3, '\u0022' + InNewModuleData.Name + '\u0022' + ",");
                            ContentsAsList.Insert(StartOfConstructorLine + 4, @"});");
                        }
                    }

                    System.IO.FileInfo PrimaryBuildFileInfo = new System.IO.FileInfo(ProjectWorker.PrimaryGameplayBuildFile);
                    PrimaryBuildFileInfo.IsReadOnly = false;
                    File.WriteAllLines(ProjectWorker.PrimaryGameplayBuildFile, ContentsAsList.ToArray());
                }

                System.IO.FileInfo ProjectFileInfo = new System.IO.FileInfo(ProjectWorker.ProjectFile);
                ProjectFileInfo.IsReadOnly = false;
                SaveProject();

                //Create a CL for our new files
                if (ProjectWorker.ConnectedRepo != null)
                {
                    Perforce.P4.Changelist NewChangelist = new Perforce.P4.Changelist();
                    NewChangelist.Type        = ChangeListType.Restricted;
                    NewChangelist.Description = "[Modules] Created " + InNewModuleData.Name + " module";
                    Perforce.P4.Changelist CreatedChangelist = ProjectWorker.ConnectedRepo.CreateChangelist(NewChangelist);

                    Perforce.P4.Options EditOptions = new Perforce.P4.Options();
                    EditOptions["-c"] = String.Format("{0}", CreatedChangelist.Id);
                    ProjectWorker.ConnectedRepo.Connection.Client.AddFiles(EditOptions, NewFiles.ToArray());

                    ProjectWorker.ConnectedRepo.Connection.Client.EditFiles(EditOptions, new Perforce.P4.FileSpec[]
                    {
                        new Perforce.P4.LocalPath(ProjectWorker.ProjectFile.Replace("//", "/")),
                        new Perforce.P4.LocalPath(ProjectWorker.PrimaryGameplayBuildFile.Replace("//", "/"))
                    });
                }
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
            }
        }