From f2ca5fa57d9981ad72abcc5910d9f113936070be Mon Sep 17 00:00:00 2001 From: Oiltanker Date: Sat, 14 May 2022 01:43:17 +0300 Subject: [PATCH] declared & forced runs of cs mods --- .../SharedSource/LuaCs/Cs/CsScriptLoader.cs | 59 +++++++++++-------- 1 file changed, 35 insertions(+), 24 deletions(-) diff --git a/Barotrauma/BarotraumaShared/SharedSource/LuaCs/Cs/CsScriptLoader.cs b/Barotrauma/BarotraumaShared/SharedSource/LuaCs/Cs/CsScriptLoader.cs index 9bb2c9d44..7c439129d 100644 --- a/Barotrauma/BarotraumaShared/SharedSource/LuaCs/Cs/CsScriptLoader.cs +++ b/Barotrauma/BarotraumaShared/SharedSource/LuaCs/Cs/CsScriptLoader.cs @@ -10,6 +10,7 @@ using System.Runtime.Loader; using System.Reflection.PortableExecutable; using System.Reflection.Metadata; using System.Text.RegularExpressions; +using System.Xml.Linq; namespace Barotrauma { @@ -34,13 +35,42 @@ namespace Barotrauma Assembly = null; } + private enum RunType { Standard, Forced, None }; + private RunType GetRunType(ContentPackage cp, string path) + { + if (!Directory.Exists(path + "CSharp")) return RunType.None; + + var isEnabled = ContentPackageManager.EnabledPackages.All.Contains(cp); + if (File.Exists(path + "CSharp/RunConfig.xml")) + { + var doc = XDocument.Load(File.Open(path + "CSharp/RunConfig.xml", FileMode.Open, FileAccess.Read)); + var elems = doc.Root.Elements().ToArray(); + var elem = elems.FirstOrDefault(e => e.Name.LocalName.Equals(LuaCsSetup.IsServer ? "Server" : (LuaCsSetup.IsClient ? "Client" : "None"), StringComparison.OrdinalIgnoreCase)); + + if (elem != null && Enum.TryParse(typeof(RunType), elem.Value, out object enumValue) && enumValue is RunType rtValue) + { + if (rtValue == RunType.Standard && isEnabled) LuaCsSetup.PrintCsMessage($"Standard run C# of {cp.Name}"); + else if (rtValue == RunType.Forced) LuaCsSetup.PrintCsMessage($"Forced run C# of {cp.Name}"); + return rtValue; + } + } + + if (isEnabled) + { + LuaCsSetup.PrintCsMessage($"Assumed run C# of {cp.Name}"); + return RunType.Standard; + } + else return RunType.None; + } public void SearchFolders() { - foreach(ContentPackage cp in ContentPackageManager.EnabledPackages.All) + var paths = new List(); + foreach (var cp in ContentPackageManager.AllPackages) { - var path = Path.GetDirectoryName(cp.Path); - RunFolder(path); - } + var path = $"{Path.GetFullPath(Path.GetDirectoryName(cp.Path)).Replace('\\','/')}/"; + if (GetRunType(cp, path) != RunType.None) paths.Add(path); + } + paths.ForEach(p => RunFolder(p)); } public bool HasSources { get => sources.Count > 0; } @@ -164,26 +194,7 @@ namespace Barotrauma private static string[] DirSearch(string sDir) { - List files = new List(); - - try - { - foreach (string f in Directory.GetFiles(sDir)) - { - files.Add(f); - } - - foreach (string d in Directory.GetDirectories(sDir)) - { - files.AddRange(DirSearch(d)); - } - } - catch (System.Exception excpt) - { - Console.WriteLine(excpt.Message); - } - - return files.ToArray(); + return Directory.GetFiles(sDir, "*.cs", SearchOption.AllDirectories); } public void Clear()