From d85fadf2db1f836e09c9b1c61848dab895624435 Mon Sep 17 00:00:00 2001 From: ritorizo <41831966+ritorizo@users.noreply.github.com> Date: Wed, 8 Jan 2025 07:32:49 +0100 Subject: [PATCH] Look for ressources in the dirrectory of the environement (#2157) Co-authored-by: ritorizo Co-authored-by: wixoa --- DMCompiler/DMCompiler.cs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/DMCompiler/DMCompiler.cs b/DMCompiler/DMCompiler.cs index d386a8e69f..25f6e9a5f3 100644 --- a/DMCompiler/DMCompiler.cs +++ b/DMCompiler/DMCompiler.cs @@ -128,6 +128,9 @@ public void AddResourceDirectory(string dir) { preproc.IncludeFile(includeDir, fileName, false); } + // Adds the root of the DM project to FILE_DIR + compiler.AddResourceDirectory(Path.GetDirectoryName(files[0]) ?? "/"); + string compilerDirectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) ?? string.Empty; string dmStandardDirectory = Path.Join(compilerDirectory, "DMStandard"); @@ -139,7 +142,7 @@ public void AddResourceDirectory(string dir) { // Push the pragma config file to the tippy-top of the stack, super-duper prioritizing it, since it governs some compiler behaviour. string pragmaName; string pragmaDirectory; - if(Settings.PragmaFileOverride is not null) { + if (Settings.PragmaFileOverride is not null) { pragmaDirectory = Path.GetDirectoryName(Settings.PragmaFileOverride); pragmaName = Path.GetFileName(Settings.PragmaFileOverride); } else { @@ -147,7 +150,7 @@ public void AddResourceDirectory(string dir) { pragmaName = "DefaultPragmaConfig.dm"; } - if(!File.Exists(Path.Join(pragmaDirectory,pragmaName))) { + if (!File.Exists(Path.Join(pragmaDirectory, pragmaName))) { ForcedError($"Configuration file '{pragmaName}' not found."); return null; } @@ -336,7 +339,7 @@ private string SaveJson(List maps, string interfaceFile, string ou try { JsonSerializer.Serialize(outputFileHandle, compiledDream, - new JsonSerializerOptions() {DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingDefault}); + new JsonSerializerOptions() { DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingDefault }); return $"Saved to {outputFile}"; } catch (Exception e) { @@ -349,7 +352,7 @@ private string SaveJson(List maps, string interfaceFile, string ou public void DefineFatalErrors() { foreach (WarningCode code in Enum.GetValues()) { - if((int)code < 1_000) { + if ((int)code < 1_000) { Config.ErrorConfig[code] = ErrorLevel.Error; } } @@ -359,7 +362,7 @@ public void DefineFatalErrors() { /// This method also enforces the rule that all emissions with codes less than 1000 are mandatory errors. /// public void CheckAllPragmasWereSet() { - foreach(WarningCode code in Enum.GetValues()) { + foreach (WarningCode code in Enum.GetValues()) { if (!Config.ErrorConfig.ContainsKey(code)) { ForcedWarning($"Warning #{(int)code:d4} '{code.ToString()}' was never declared as error, warning, notice, or disabled."); Config.ErrorConfig.Add(code, ErrorLevel.Disabled);