declared & forced runs of cs mods

This commit is contained in:
Oiltanker
2022-05-14 01:43:17 +03:00
parent 3c84a5a1a5
commit f2ca5fa57d
@@ -10,6 +10,7 @@ using System.Runtime.Loader;
using System.Reflection.PortableExecutable; using System.Reflection.PortableExecutable;
using System.Reflection.Metadata; using System.Reflection.Metadata;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using System.Xml.Linq;
namespace Barotrauma namespace Barotrauma
{ {
@@ -34,13 +35,42 @@ namespace Barotrauma
Assembly = null; 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() public void SearchFolders()
{ {
foreach(ContentPackage cp in ContentPackageManager.EnabledPackages.All) var paths = new List<string>();
foreach (var cp in ContentPackageManager.AllPackages)
{ {
var path = Path.GetDirectoryName(cp.Path); var path = $"{Path.GetFullPath(Path.GetDirectoryName(cp.Path)).Replace('\\','/')}/";
RunFolder(path); if (GetRunType(cp, path) != RunType.None) paths.Add(path);
} }
paths.ForEach(p => RunFolder(p));
} }
public bool HasSources { get => sources.Count > 0; } public bool HasSources { get => sources.Count > 0; }
@@ -164,26 +194,7 @@ namespace Barotrauma
private static string[] DirSearch(string sDir) private static string[] DirSearch(string sDir)
{ {
List<string> files = new List<string>(); return Directory.GetFiles(sDir, "*.cs", SearchOption.AllDirectories);
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();
} }
public void Clear() public void Clear()