Warn on startup if .yaml files detected. (#3764)

This commit is contained in:
Pieter-Jan Briers
2023-02-11 22:12:27 +01:00
committed by GitHub
parent de20ad8a8f
commit 0d8032e3df
6 changed files with 72 additions and 1 deletions

View File

@@ -49,6 +49,7 @@ END TEMPLATE-->
* SDL2 backend now handles quit events (⌘+Q on macOS).
* SDL2 backend now logs video driver backend used on initialization.
* The engine will now warn on startup if `*.yaml` files are found in resources, as this most likely indicates an accident.
### Internal

View File

@@ -130,12 +130,26 @@ namespace Robust.Client
// Call Init in game assemblies.
_modLoader.BroadcastRunLevel(ModRunLevel.PreInit);
_modLoader.BroadcastRunLevel(ModRunLevel.Init);
// Start bad file extensions check after content init,
// in case content screws with the VFS.
var checkBadExtensions = ProgramShared.CheckBadFileExtensions(
_resourceCache,
_configurationManager,
_logManager.GetSawmill("res"));
_resourceCache.PreloadTextures();
_networkManager.Initialize(false);
_configurationManager.SetupNetworking();
_serializer.Initialize();
_inputManager.Initialize();
_console.Initialize();
// Make sure this is done before we try to load prototypes,
// avoid any possibility of race conditions causing the check to not finish
// before prototype load.
ProgramShared.FinishCheckBadFileExtensions(checkBadExtensions);
_prototypeManager.Initialize();
_prototypeManager.LoadDirectory(new ResourcePath("/EnginePrototypes/"));
_prototypeManager.LoadDirectory(Options.PrototypeDirectory);

View File

@@ -338,11 +338,24 @@ namespace Robust.Server
// Call Init in game assemblies.
_modLoader.BroadcastRunLevel(ModRunLevel.Init);
// Start bad file extensions check after content init,
// in case content screws with the VFS.
var checkBadExtensions = ProgramShared.CheckBadFileExtensions(
_resources,
_config,
_log.GetSawmill("res"));
_entityManager.Initialize();
_mapManager.Initialize();
_serialization.Initialize();
// Make sure this is done before we try to load prototypes,
// avoid any possibility of race conditions causing the check to not finish
// before prototype load and maybe break something.
ProgramShared.FinishCheckBadFileExtensions(checkBadExtensions);
// because of 'reasons' this has to be called after the last assembly is loaded
// otherwise the prototypes will be cleared
_prototype.Initialize();

View File

@@ -1215,6 +1215,15 @@ namespace Robust.Shared
public static readonly CVarDef<bool> ResPrototypeReloadWatch =
CVarDef.Create("res.prototype_reload_watch", true, CVar.CLIENTONLY);
/// <summary>
/// If true, do a warning check at startup for probably-erroneous file extensions like <c>.yaml</c> in resources.
/// </summary>
/// <remarks>
/// This check is always skipped on <c>FULL_RELEASE</c>.
/// </remarks>
public static readonly CVarDef<bool> ResCheckBadFileExtensions =
CVarDef.Create("res.check_bad_file_extensions", true);
/*
* DEBUG
*/

View File

@@ -1,8 +1,13 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Threading.Tasks;
using Robust.Shared.Configuration;
using Robust.Shared.Console;
using Robust.Shared.ContentPack;
using Robust.Shared.Log;
using Robust.Shared.Timing;
using Robust.Shared.Utility;
namespace Robust.Shared;
@@ -70,4 +75,29 @@ internal static class ProgramShared
res.MountContentPack(diskPath);
}
}
internal static Task CheckBadFileExtensions(IResourceManager res, IConfigurationManager cfg, ISawmill sawmill)
{
#if FULL_RELEASE
return Task.CompletedTask;
#else
if (!cfg.GetCVar(CVars.ResCheckBadFileExtensions))
return Task.CompletedTask;
// Run on thread pool to avoid slowing down init.
return Task.Run(() =>
{
foreach (var file in res.ContentFindFiles("/"))
{
if (file.Extension == "yaml")
sawmill.Warning($"{file} has extension \".yaml\". Robust only loads .yml files by convention, file will be ignored for prototypes and similar.");
}
});
#endif
}
internal static void FinishCheckBadFileExtensions(Task task)
{
task.Wait();
}
}

View File

@@ -653,7 +653,9 @@ namespace Robust.UnitTesting
("log.runtimelog", "false"),
(CVars.SysWinTickPeriod.Name, "-1"),
(CVars.SysGCCollectStart.Name, "false"),
(RTCVars.FailureLogLevel.Name, (Options?.FailureLogLevel ?? RTCVars.FailureLogLevel.DefaultValue).ToString())
(RTCVars.FailureLogLevel.Name, (Options?.FailureLogLevel ?? RTCVars.FailureLogLevel.DefaultValue).ToString()),
(CVars.ResCheckBadFileExtensions.Name, "false")
});
server.ContentStart = Options?.ContentStart ?? false;
@@ -827,6 +829,8 @@ namespace Robust.UnitTesting
(RTCVars.FailureLogLevel.Name, (Options?.FailureLogLevel ?? RTCVars.FailureLogLevel.DefaultValue).ToString()),
(CVars.ResPrototypeReloadWatch.Name, "false"),
(CVars.ResCheckBadFileExtensions.Name, "false")
});
GameLoop = new IntegrationGameLoop(DependencyCollection.Resolve<IGameTiming>(),