private void BuildModulePanel() { ModuleViewPanel.Controls.Clear(); ModuleViewsLayout.Enabled = true; foreach (ModuleData Data in ProjectWorker.Proxy.Modules) { ModuleView NewModuleView = new ModuleView(Data); NewModuleView.Dock = DockStyle.Top; ModuleViewPanel.Controls.Add(NewModuleView); ModuleViewPanel.Update(); } }
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); } }