LogDllBuildError() static private method

static private LogDllBuildError ( string modDir ) : void
modDir string
return void
Exemplo n.º 1
0
        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(Language.GetTextValue("tModLoader.MSCompilingWindows", mod));
                    status.SetProgress(0, 2);
                    CompileMod(mod, refMods, true, ref winDLL, ref winPDB);
                }
                if (winDLL == null)
                {
                    return(false);
                }

                status.SetStatus(Language.GetTextValue("tModLoader.MSCompilingMono", mod));
                status.SetProgress(1, 2);
                CompileMod(mod, refMods, false, ref monoDLL, ref winPDB);                //the pdb reference won't actually be written to
                if (monoDLL == null)
                {
                    return(false);
                }
            }

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

            status.SetStatus(Language.GetTextValue("tModLoader.MSBuilding") + mod + "...");
            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" ||
                    relPath == ".gitattributes" ||
                    relPath == ".gitignore" ||
                    relPath.StartsWith(".git" + Path.DirectorySeparatorChar) ||
                    relPath.StartsWith(".vs" + Path.DirectorySeparatorChar) ||
                    relPath.StartsWith("bin" + Path.DirectorySeparatorChar) ||
                    relPath.StartsWith("obj" + Path.DirectorySeparatorChar) ||
                    !mod.properties.includeSource && sourceExtensions.Contains(Path.GetExtension(resource)) ||
                    Path.GetFileName(resource) == "Thumbs.db")
                {
                    continue;
                }

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

            WAVCacheIO.ClearCache(mod.Name);

            mod.modFile.Save();
            EnableMod(mod.modFile);
            ActivateExceptionReporting();
            ModLoader.isModder = true;
            return(true);
        }
Exemplo n.º 2
0
        internal static bool do_BuildMod(object threadContext)
        {
            Interface.buildMod.SetReading();
            BuildProperties properties = BuildProperties.ReadBuildFile(modToBuild);

            if (!CreateModReferenceDlls(properties))
            {
                if (!buildAll)
                {
                    Main.menuMode = Interface.errorMessageID;
                }
                return(false);
            }
            LoadReferences();
            Interface.buildMod.SetCompiling();
            byte[] windowsData;
            byte[] otherData;
            if (properties.noCompile)
            {
                string modDir = modToBuild + Path.DirectorySeparatorChar;
                if (File.Exists(modDir + "All.dll"))
                {
                    windowsData = File.ReadAllBytes(modDir + "All.dll");
                    otherData   = File.ReadAllBytes(modDir + "All.dll");
                }
                else if (File.Exists(modDir + "Windows.dll") && File.Exists(modDir + "Other.dll"))
                {
                    windowsData = File.ReadAllBytes(modDir + "Windows.dll");
                    otherData   = File.ReadAllBytes(modDir + "Other.dll");
                }
                else
                {
                    ErrorLogger.LogDllBuildError(modToBuild);
                    if (!buildAll)
                    {
                        Main.menuMode = Interface.errorMessageID;
                    }
                    return(false);
                }
            }
            else
            {
                windowsData = CompileMod(modToBuild, properties, true);
                otherData   = CompileMod(modToBuild, properties, false);
                if (windowsData == null || otherData == null)
                {
                    if (!buildAll)
                    {
                        Main.menuMode = Interface.errorMessageID;
                    }
                    return(false);
                }
            }
            Interface.buildMod.SetBuildText();
            string file = ModPath + Path.DirectorySeparatorChar + Path.GetFileName(modToBuild) + ".tmod";

            byte[]   propertiesData = properties.ToBytes();
            TmodFile modFile        = new TmodFile(file);

            using (MemoryStream memoryStream = new MemoryStream())
            {
                using (BinaryWriter writer = new BinaryWriter(memoryStream))
                {
                    writer.Write(propertiesData.Length);
                    writer.Write(propertiesData);
                    writer.Write(Path.GetFileName(modToBuild));
                    string[] resources = Directory.GetFiles(modToBuild, "*", SearchOption.AllDirectories);
                    foreach (string resource in resources)
                    {
                        if (Path.GetExtension(resource) == ".cs")
                        {
                            continue;
                        }
                        if (resource.Substring(modToBuild.Length + 1) == "build.txt")
                        {
                            continue;
                        }
                        string resourcePath = resource.Replace(ModSourcePath + Path.DirectorySeparatorChar, null);
                        resourcePath = resourcePath.Replace(Path.DirectorySeparatorChar, '/');
                        byte[] buffer = File.ReadAllBytes(resource);
                        writer.Write(resourcePath);
                        writer.Write(buffer.Length);
                        writer.Write(buffer);
                    }
                    writer.Write("end");
                    writer.Flush();
                    modFile.AddFile("Resources", memoryStream.ToArray());
                }
            }
            bool same = windowsData.Length == otherData.Length;

            if (same)
            {
                for (int k = 0; k < windowsData.Length; k++)
                {
                    if (windowsData[k] != otherData[k])
                    {
                        same = false;
                        break;
                    }
                }
            }
            if (same)
            {
                modFile.AddFile("All", windowsData);
            }
            else
            {
                modFile.AddFile("Windows", windowsData);
                modFile.AddFile("Other", otherData);
            }
            modFile.Save();
            EnableMod(file);
            if (!buildAll)
            {
                Main.menuMode = reloadAfterBuild ? Interface.reloadModsID : 0;
            }
            return(true);
        }