private bool Build(BuildingMod mod) { status.SetMod(mod.Name); status.SetStatus(Language.GetTextValue("tModLoader.Building", mod.Name)); byte[] winDLL = null; byte[] monoDLL = null; byte[] pdb = null; byte[] mdb = null; if (mod.properties.noCompile) { winDLL = monoDLL = ReadIfExists(Path.Combine(mod.path, "All.dll")); pdb = ReadIfExists(Path.Combine(mod.path, "All.pdb")); mdb = ReadIfExists(Path.Combine(mod.path, "All.mdb")) ?? ReadIfExists(Path.Combine(mod.path, "All.dll.mdb")); if (winDLL == null) { winDLL = ReadIfExists(Path.Combine(mod.path, "Windows.dll")); monoDLL = ReadIfExists(Path.Combine(mod.path, "Mono.dll")); pdb = ReadIfExists(Path.Combine(mod.path, "Windows.pdb")); mdb = ReadIfExists(Path.Combine(mod.path, "Mono.mdb")) ?? ReadIfExists(Path.Combine(mod.path, "Mono.dll.mdb")); } if (winDLL == null || monoDLL == null) { var missing = new List <string> { "All.dll" }; if (winDLL == null) { missing.Add("Windows.dll"); } if (monoDLL == null) { missing.Add("Mono.dll"); } status.LogError(Language.GetTextValue("tModLoader.BuildErrorMissingDllFiles", string.Join(", ", missing))); return(false); } } else { List <LocalMod> refMods; try { refMods = FindReferencedMods(mod.properties); } catch (Exception e) { status.LogError(e.Message, e.InnerException); return(false); } CompileMod(mod, refMods, true, ref winDLL, ref pdb); if (winDLL == null) { return(false); } CompileMod(mod, refMods, false, ref monoDLL, ref mdb); if (monoDLL == null) { return(false); } } if (!VerifyName(mod.Name, winDLL) || !VerifyName(mod.Name, monoDLL)) { return(false); } if (Program.LaunchParameters.ContainsKey("-eac")) { if (!windows) { status.SetStatus(Language.GetTextValue("tModLoader.BuildWarningEACWindowsOnly")); } else if (pdb != null) { status.SetStatus(Language.GetTextValue("tModLoader.EnabledEAC")); mod.properties.editAndContinue = true; } } status.SetStatus(Language.GetTextValue("tModLoader.Packaging", mod)); status.SetProgress(0, 1); mod.modFile.AddFile("Info", mod.properties.ToBytes()); if (Equal(winDLL, monoDLL)) { mod.modFile.AddFile("All.dll", winDLL); if (pdb != null) { mod.modFile.AddFile("All.pdb", pdb); } if (mdb != null) { mod.modFile.AddFile("All.mdb", mdb); } } else { mod.modFile.AddFile("Windows.dll", winDLL); mod.modFile.AddFile("Mono.dll", monoDLL); if (pdb != null) { mod.modFile.AddFile("Windows.pdb", pdb); } if (mdb != null) { mod.modFile.AddFile("Mono.mdb", mdb); } } var resources = Directory.GetFiles(mod.path, "*", SearchOption.AllDirectories) .Where(res => !IgnoreResource(mod, res)) .ToList(); Parallel.ForEach(resources, resource => AddResource(mod, resource)); GetMod(mod.Name)?.File?.Close(); // if the mod is currently loaded, the file-handle needs to be released mod.modFile.Save(); mod.modFile.Close(); EnableMod(mod.Name); return(true); }
private bool Build(BuildingMod mod) { status.SetMod(mod.Name); status.SetStatus(Language.GetTextValue("tModLoader.Building", mod.Name)); 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) { var missing = new List <string> { "All.dll" }; if (winDLL == null) { missing.Add("Windows.dll"); } if (monoDLL == null) { missing.Add("Mono.dll"); } status.LogError(Language.GetTextValue("tModLoader.BuildErrorMissingDllFiles", string.Join(", ", missing))); return(false); } } else { List <LocalMod> refMods; try { refMods = FindReferencedMods(mod.properties); } catch (Exception e) { status.LogError(e.Message, e.InnerException); return(false); } if (Program.LaunchParameters.ContainsKey("-eac")) { if (!windows) { status.LogError(Language.GetTextValue("tModLoader.BuildErrorEACWindowsOnly")); return(false); } var winPath = Program.LaunchParameters["-eac"]; try { status.SetStatus(Language.GetTextValue("tModLoader.LoadingEAC")); var pdbPath = Path.ChangeExtension(winPath, "pdb"); winDLL = File.ReadAllBytes(winPath); winPDB = File.ReadAllBytes(pdbPath); mod.properties.editAndContinue = true; } catch (Exception e) { status.LogError(Language.GetTextValue("tModLoader.BuildErrorEACLoadFailed", winPath + "/.pdb"), e); return(false); } } else { status.SetStatus(Language.GetTextValue("tModLoader.CompilingWindows", mod)); status.SetProgress(0, 2); CompileMod(mod, refMods, true, ref winDLL, ref winPDB); } if (winDLL == null) { return(false); } status.SetStatus(Language.GetTextValue("tModLoader.CompilingMono", 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.Packaging", 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(".idea" + 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; } AddResource(mod.modFile, relPath, resource); } WAVCacheIO.ClearCache(mod.Name); GetMod(mod.Name)?.File?.Close(); // if the mod is currently loaded, the file-handle needs to be released mod.modFile.Save(); mod.modFile.Close(); EnableMod(mod.Name); return(true); }
public ModCompile(IBuildStatus status) { this.status = status; status.SetMod(null); UpdateReferencesFolder(); }
public ModCompile(IBuildStatus status) { this.status = status; status.SetMod(null); }