Esempio n. 1
0
        public static string[] CreateProject(string projPath, GameCategory category)
        {
            Directory.CreateDirectory(Path.GetDirectoryName(projPath));
            var projName = Path.GetFileNameWithoutExtension(projPath);

            // Generate Project File
            FileGeneration fg = new FileGeneration();

            fg.AppendLine("<Project Sdk=\"Microsoft.NET.Sdk\">");
            using (new DepthWrapper(fg))
            {
                fg.AppendLine($"<PropertyGroup>");
                using (new DepthWrapper(fg))
                {
                    fg.AppendLine($"<OutputType>Exe</OutputType>");
                    fg.AppendLine($"<TargetFramework>netcoreapp3.1</TargetFramework>");
                }
                fg.AppendLine($"</PropertyGroup>");
                fg.AppendLine();

                fg.AppendLine($"<ItemGroup>");
                using (new DepthWrapper(fg))
                {
                    fg.AppendLine($"<PackageReference Include=\"Mutagen.Bethesda\" Version=\"{Versions.MutagenVersion}\" />");
                    fg.AppendLine($"<PackageReference Include=\"Mutagen.Bethesda.Synthesis\" Version=\"{Versions.SynthesisVersion}\" />");
                    fg.AppendLine($"<PackageReference Include=\"GitInfo\" Version=\"*\">");
                    using (new DepthWrapper(fg))
                    {
                        fg.AppendLine($"<PrivateAssets>all</PrivateAssets>");
                        fg.AppendLine($"<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>");
                    }
                    fg.AppendLine($"</PackageReference>");
                }
                fg.AppendLine($"</ItemGroup>");
                fg.AppendLine();
            }
            fg.AppendLine("</Project>");
            fg.Generate(projPath);

            // Generate Program.cs
            fg = new FileGeneration();
            fg.AppendLine("using System;");
            fg.AppendLine("using System.Collections.Generic;");
            fg.AppendLine("using System.Linq;");
            fg.AppendLine("using Mutagen.Bethesda;");
            fg.AppendLine("using Mutagen.Bethesda.Synthesis;");
            fg.AppendLine($"using Mutagen.Bethesda.{category};");
            fg.AppendLine();
            fg.AppendLine($"namespace {projName}");
            using (new BraceWrapper(fg))
            {
                fg.AppendLine($"public class Program");
                using (new BraceWrapper(fg))
                {
                    fg.AppendLine("public static int Main(string[] args)");
                    using (new BraceWrapper(fg))
                    {
                        fg.AppendLine($"return SynthesisPipeline.Instance.Patch<I{category}Mod, I{category}ModGetter>(");
                        using (new DepthWrapper(fg))
                        {
                            fg.AppendLine("args: args,");
                            fg.AppendLine("patcher: RunPatch,");
                            fg.AppendLine($"userPreferences: new {nameof(UserPreferences)}()");
                            using (new BraceWrapper(fg)
                            {
                                AppendParenthesis = true, AppendSemicolon = true
                            })
                            {
                                fg.AppendLine($"{nameof(UserPreferences.ActionsForEmptyArgs)} = new {nameof(RunDefaultPatcher)}()");
                                using (new BraceWrapper(fg))
                                {
                                    fg.AppendLine($"{nameof(RunDefaultPatcher.IdentifyingModKey)} = \"YourPatcher.esp\",");
                                    fg.AppendLine($"{nameof(RunDefaultPatcher.TargetRelease)} = {nameof(GameRelease)}.{category.DefaultRelease()},");
                                    fg.AppendLine($"{nameof(RunDefaultPatcher.BlockAutomaticExit)} = true,");
                                }
                            }
                        }
                    }
                    fg.AppendLine();

                    fg.AppendLine($"public static void RunPatch(SynthesisState<I{category}Mod, I{category}ModGetter> state)");
                    using (new BraceWrapper(fg))
                    {
                        fg.AppendLine($"//Your code here!");
                    }
                }
            }
            fg.Generate(Path.Combine(Path.GetDirectoryName(projPath) !, "Program.cs"));

            return(new string[]
            {
                projPath,
                Path.Combine(Path.GetDirectoryName(projPath) !, "Program.cs")
            });
        public static string[] CreateProject(string projPath, GameCategory category, bool insertOldVersion = false)
        {
            Directory.CreateDirectory(Path.GetDirectoryName(projPath) !);
            var projName = Path.GetFileNameWithoutExtension(projPath);

            // Generate Project File
            FileGeneration fg = new();

            fg.AppendLine("<Project Sdk=\"Microsoft.NET.Sdk\">");
            fg.AppendLine($"  <PropertyGroup>");
            fg.AppendLine($"    <OutputType>Exe</OutputType>");
            fg.AppendLine($"    <TargetFramework>net5.0</TargetFramework>");
            fg.AppendLine($"    <TargetPlatformIdentifier>Windows</TargetPlatformIdentifier>");
            fg.AppendLine($"  </PropertyGroup>");
            fg.AppendLine();
            fg.AppendLine($"  <ItemGroup>");
            fg.AppendLine($"    <PackageReference Include=\"Mutagen.Bethesda\" Version=\"{(insertOldVersion ? Versions.OldMutagenVersion : Versions.MutagenVersion)}\" />");
            fg.AppendLine($"    <PackageReference Include=\"Mutagen.Bethesda.Synthesis\" Version=\"{(insertOldVersion ? Versions.OldSynthesisVersion : Versions.SynthesisVersion)}\" />");
            fg.AppendLine($"  </ItemGroup>");
            fg.AppendLine("</Project>");
            fg.Generate(projPath);

            // Generate Program.cs
            fg = new FileGeneration();
            fg.AppendLine("using System;");
            fg.AppendLine("using System.Collections.Generic;");
            fg.AppendLine("using System.Linq;");
            fg.AppendLine("using Mutagen.Bethesda;");
            fg.AppendLine("using Mutagen.Bethesda.Synthesis;");
            fg.AppendLine($"using Mutagen.Bethesda.{category};");
            fg.AppendLine("using System.Threading.Tasks;");
            fg.AppendLine();
            fg.AppendLine($"namespace {projName}");
            using (new BraceWrapper(fg))
            {
                fg.AppendLine($"public class Program");
                using (new BraceWrapper(fg))
                {
                    fg.AppendLine("public static async Task<int> Main(string[] args)");
                    using (new BraceWrapper(fg))
                    {
                        fg.AppendLine($"return await SynthesisPipeline.Instance");
                        using (new DepthWrapper(fg))
                        {
                            fg.AppendLine($".AddPatch<I{category}Mod, I{category}ModGetter>(RunPatch)");
                            fg.AppendLine($".Run(args, new {nameof(RunPreferences)}()");
                            using (new BraceWrapper(fg)
                            {
                                AppendParenthesis = true, AppendSemicolon = true
                            })
                            {
                                fg.AppendLine($"{nameof(UserPreferences.ActionsForEmptyArgs)} = new {nameof(RunDefaultPatcher)}()");
                                using (new BraceWrapper(fg))
                                {
                                    fg.AppendLine($"{nameof(RunDefaultPatcher.IdentifyingModKey)} = \"YourPatcher.esp\",");
                                    fg.AppendLine($"{nameof(RunDefaultPatcher.TargetRelease)} = {nameof(GameRelease)}.{category.DefaultRelease()},");
                                }
                            }
                        }
                    }
                    fg.AppendLine();

                    fg.AppendLine($"public static void RunPatch({nameof(IPatcherState)}<I{category}Mod, I{category}ModGetter> state)");
                    using (new BraceWrapper(fg))
                    {
                        fg.AppendLine($"//Your code here!");
                    }
                }
            }
            fg.Generate(Path.Combine(Path.GetDirectoryName(projPath) !, "Program.cs"));

            return(new string[]
            {
                projPath,
                Path.Combine(Path.GetDirectoryName(projPath) !, "Program.cs")
            });
Esempio n. 3
0
        public string[] Create(
            GameCategory category,
            FilePath projPath,
            bool insertOldVersion  = false,
            string?targetFramework = null)
        {
            _FileSystem.Directory.CreateDirectory(projPath.Directory);
            var projName = projPath.NameWithoutExtension;

            // Generate Project File
            FileGeneration fg = new();

            fg.AppendLine("<Project Sdk=\"Microsoft.NET.Sdk\">");
            fg.AppendLine($"  <PropertyGroup>");
            fg.AppendLine($"    <OutputType>Exe</OutputType>");
            fg.AppendLine($"    <TargetFramework>{(targetFramework ?? "net6.0")}</TargetFramework>");
            fg.AppendLine($"    <TargetPlatformIdentifier>Windows</TargetPlatformIdentifier>");
            fg.AppendLine($"  </PropertyGroup>");
            fg.AppendLine();
            fg.AppendLine($"  <ItemGroup>");
            fg.AppendLine($"    <PackageReference Include=\"Mutagen.Bethesda\" Version=\"{(insertOldVersion ? Versions.OldMutagenVersion : Versions.MutagenVersion)}\" />");
            fg.AppendLine($"    <PackageReference Include=\"Mutagen.Bethesda.Synthesis\" Version=\"{(insertOldVersion ? Versions.OldSynthesisVersion : Versions.SynthesisVersion)}\" />");
            fg.AppendLine($"  </ItemGroup>");
            fg.AppendLine("</Project>");
            fg.Generate(projPath);

            // Generate Program.cs
            fg = new FileGeneration();
            fg.AppendLine("using System;");
            fg.AppendLine("using System.Collections.Generic;");
            fg.AppendLine("using System.Linq;");
            fg.AppendLine("using Mutagen.Bethesda;");
            fg.AppendLine("using Mutagen.Bethesda.Synthesis;");
            fg.AppendLine($"using Mutagen.Bethesda.{category};");
            fg.AppendLine("using System.Threading.Tasks;");
            fg.AppendLine();
            fg.AppendLine($"namespace {projName}");
            using (new BraceWrapper(fg))
            {
                fg.AppendLine($"public class Program");
                using (new BraceWrapper(fg))
                {
                    fg.AppendLine("public static async Task<int> Main(string[] args)");
                    using (new BraceWrapper(fg))
                    {
                        fg.AppendLine($"return await SynthesisPipeline.Instance");
                        using (new DepthWrapper(fg))
                        {
                            fg.AppendLine($".AddPatch<I{category}Mod, I{category}ModGetter>(RunPatch)");
                            fg.AppendLine($".SetTypicalOpen({nameof(GameRelease)}.{category.DefaultRelease()}, \"YourPatcher.esp\")");
                            fg.AppendLine($".Run(args);");
                        }
                    }
                    fg.AppendLine();

                    fg.AppendLine($"public static void RunPatch({nameof(IPatcherState)}<I{category}Mod, I{category}ModGetter> state)");
                    using (new BraceWrapper(fg))
                    {
                        fg.AppendLine($"//Your code here!");
                    }
                }
            }
            fg.Generate(Path.Combine(Path.GetDirectoryName(projPath) !, "Program.cs"));

            return(new string[]
            {
                projPath,
                Path.Combine(Path.GetDirectoryName(projPath) !, "Program.cs")
            });