Terraria.ModLoader.ModCompile.Build C# (CSharp) Method

Build() private static method

private static Build ( BuildingMod mod, IBuildStatus status ) : bool
mod BuildingMod
status IBuildStatus
return bool
        private static bool Build(BuildingMod mod, IBuildStatus status) {
            byte[] winDLL = null;
            byte[] monoDLL = null;
            byte[] winPDB = null;
            if (mod.properties.noCompile) {
                winDLL = monoDLL = ReadIfExists(Path.Combine(mod.path, "All.dll"));
                winPDB = ReadIfExists(Path.Combine(mod.path, "All.pdb"));

                if (winDLL == null) {
                    winDLL = ReadIfExists(Path.Combine(mod.path, "Windows.dll"));
                    monoDLL = ReadIfExists(Path.Combine(mod.path, "Mono.dll"));
                    winPDB = ReadIfExists(Path.Combine(mod.path, "Windows.pdb"));
                }

                if (winDLL == null || monoDLL == null) {
                    ErrorLogger.LogDllBuildError(mod.path);
                    return false;
                }
            }
            else {
                var refMods = FindReferencedMods(mod.properties);
                if (refMods == null)
                    return false;

                if (Program.LaunchParameters.ContainsKey("-eac")) {
                    if (!windows) {
                        ErrorLogger.LogBuildError("Edit and continue is only supported on windows");
                        return false;
                    }

                    try {
                        status.SetStatus("Loading pre-compiled Windows.dll with edit and continue support");
                        var winPath = Program.LaunchParameters["-eac"];
                        var pdbPath = Path.ChangeExtension(winPath, "pdb");
                        winDLL = File.ReadAllBytes(winPath);
                        winPDB = File.ReadAllBytes(pdbPath);
                        mod.properties.editAndContinue = true;
                    }
                    catch (Exception e) {
                        ErrorLogger.LogBuildError("Failed to load pre-compiled edit and continue dll "+e);
                        return false;
                    }
                }
                else {
                    status.SetStatus("Compiling " + mod.Name + " for Windows...");
                    status.SetProgress(0, 2);
                    CompileMod(mod, refMods, true, ref winDLL, ref winPDB);
                }

                status.SetStatus("Compiling " + mod.Name + " for Mono...");
                status.SetProgress(1, 2);
                CompileMod(mod, refMods, false, ref monoDLL, ref winPDB);//the pdb reference won't actually be written to
                if (winDLL == null || monoDLL == null)
                    return false;
            }

            if (!VerifyName(mod.Name, winDLL) || !VerifyName(mod.Name, monoDLL))
                return false;

            status.SetStatus("Building "+mod.Name+"...");
            status.SetProgress(0, 1);

            mod.modFile.AddFile("Info", mod.properties.ToBytes());

            if (Equal(winDLL, monoDLL)) {
                mod.modFile.AddFile("All.dll", winDLL);
                if (winPDB != null) mod.modFile.AddFile("All.pdb", winPDB);
            }
            else {
                mod.modFile.AddFile("Windows.dll", winDLL);
                mod.modFile.AddFile("Mono.dll", monoDLL);
                if (winPDB != null) mod.modFile.AddFile("Windows.pdb", winPDB);
            }

            foreach (var resource in Directory.GetFiles(mod.path, "*", SearchOption.AllDirectories)) {
                var relPath = resource.Substring(mod.path.Length + 1);
                if (mod.properties.ignoreFile(relPath) ||
                        relPath == "build.txt" ||
                        !mod.properties.includeSource && Path.GetExtension(resource) == ".cs" ||
                        Path.GetFileName(resource) == "Thumbs.db")
                    continue;

                mod.modFile.AddFile(relPath, File.ReadAllBytes(resource));
            }

            WAVCacheIO.ClearCache(mod.Name);

            mod.modFile.Save();
            EnableMod(mod.modFile);
            return true;
        }

Same methods

ModCompile::Build ( string modFolder, IBuildStatus status ) : bool

Usage Example

Exemplo n.º 1
0
        internal static void BuildModCommandLine(string modFolder)
        {
            // Once we get to this point, the application is guaranteed to exit
            var lockFile = AcquireConsoleBuildLock();

            try
            {
                var modCompile = new ModCompile(new ConsoleBuildStatus());
                if (!modCompile.Build(modFolder))
                {
                    Environment.Exit(1);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                Environment.Exit(1);
            }
            finally
            {
                lockFile.Close();
            }
            // Mod was built with success, exit code 0 indicates success.
            Environment.Exit(0);
        }
All Usage Examples Of Terraria.ModLoader.ModCompile::Build