/// <summary> /// Modify the .uproject specific settings of this module /// </summary> /// <param name="mod"></param> public void SetUProjectSettings( UProjectModule mod ) { UProjectSettings = mod; }
/// <summary> /// Modify the .uproject specific settings of this module /// </summary> /// <param name="mod"></param> public void SetUProjectSettings(UProjectModule mod) { UProjectSettings = mod; }
private void addOrEditUprojectModule( string unrealProjectPath, string moduleName, UProjectModule settings ) { string json; try { json = File.ReadAllText(unrealProjectPath); } catch (Exception ex) { return; } JObject uproject = JObject.Parse(json); //Get the array of modules and try to find to find a matching one to update JArray moduleArray = (JArray)uproject["Modules"]; IEnumerator<JToken> e = moduleArray.GetEnumerator(); foreach (JToken moduleJson in moduleArray.Children().ToList()) { UProjectModule jsonConv = UProjectModule.LoadFromJObject(moduleJson); //If they're matching names, remove it from the array (we'll add it later) if (jsonConv.Name.Equals(settings.Name, StringComparison.InvariantCultureIgnoreCase)) { moduleJson.Remove(); break; } } //Add to the array moduleArray.Add(JToken.FromObject(settings)); //Write it out to the file File.WriteAllText(unrealProjectPath, uproject.ToString()); }
private void moduleToolStripMenuItem_Click(object sender, EventArgs e) { if (LoadedProject == null) return; NewModuleDialogue dialog = new NewModuleDialogue(ref ModuleDataSource); if ( dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK ) { if (LoadedProject.QueryNewModuleExists(dialog.ModuleName)) { DialogResult res = MessageBox.Show(string.Format("A module named \"{0}\" already exists. Continue?", dialog.ModuleName), "Module Already Exists", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation); if (res == System.Windows.Forms.DialogResult.No) { return; } } //Generate GO try { UProjectModule settings = null; if (dialog.ShouldWriteToProjectFile) { settings = new UProjectModule() { Name = dialog.ModuleName, LoadingPhase = dialog.LoadPhase, Type = dialog.Type, AdditionalDependencies = dialog.GetAdditionalDependencies() }; } //Generate the new module with the provided settings LoadedProject.GenerateNewModule(dialog.ModuleName, dialog.GetPublicDependencies(), dialog.GetPrivateDependencies(), settings); //Reload and select the module with the matching name reloadModules(dialog.ModuleName); } catch (Exception ex) { MessageBox.Show(ex.Message, "Error Generating Files", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
/// <summary> /// Generate a new module for your current project /// </summary> /// <param name="ModuleName">The name of the Unreal module to create</param> /// <param name="PublicDependencies"></param> /// <param name="PrivateDependencies"></param> /// <param name="settings"></param> public void GenerateNewModule(string ModuleName, string[] PublicDependencies, string[] PrivateDependencies, UProjectModule settings) { //Generate a brand new module string ModulePath = Path.Combine(SourcePath, ModuleName); string TemplatePath = Path.Combine(Directory.GetCurrentDirectory(), TemplateDir); Console.WriteLine("[GENERATE] Gathering file templates"); //Go through all the files in the /Templates/ folder, templatizing and generating them in the right place string[] Files = null; try { Files = Directory.GetFiles(TemplatePath, "*", SearchOption.AllDirectories); } catch (DirectoryNotFoundException ex) { } if (Files == null || Files.Length == 0) throw new FileNotFoundException("Templates folder was missing or empty!"); foreach (string Filename in Files) { //Replace the naming scheme string newFileName = Path.GetFileName(Filename).Replace(ModuleNameToken, ModuleName); //Get the path relative to the templates folder string relativePath = StringUtils.GetRelativePath(Path.GetDirectoryName(Filename), TemplatePath); string outputFilepath = Path.Combine(ModulePath, relativePath, newFileName); Console.WriteLine("[GENERATE] {0}", outputFilepath); //Generate the path string builtFile = generateFromTokens(Filename, ModuleName, PublicDependencies, PrivateDependencies); Directory.CreateDirectory(Path.GetDirectoryName(outputFilepath)); File.WriteAllText(outputFilepath, builtFile); } //Now, attempt to overwrite the *.uproject file with our new module entry //prepare your butts if (settings != null) { addOrEditUprojectModule(ProjectFile, ModuleName, settings); } Console.WriteLine("[GENERATE] Finished!"); }