.NET Format Style Fixes

This commit is contained in:
refringe
2025-06-18 17:09:20 +00:00
committed by Format Bot
parent ca0a7d6345
commit 6e01428b2b
774 changed files with 23507 additions and 40003 deletions
+11 -8
View File
@@ -5,15 +5,16 @@ namespace SPTarkov.Server.Logger;
public static class SptLoggerExtensions
{
public static IHostBuilder UseSptLogger(this IHostBuilder builder)
{
ArgumentNullException.ThrowIfNull(builder);
builder.ConfigureServices((_, collection) =>
{
collection.AddSptLogger();
});
builder.ConfigureServices(
(_, collection) =>
{
collection.AddSptLogger();
}
);
return builder;
}
@@ -22,10 +23,12 @@ public static class SptLoggerExtensions
{
ArgumentNullException.ThrowIfNull(collection);
collection.AddSingleton<ILoggerFactory>(sp =>
new SptLoggerProvider(sp.GetService<JsonUtil>(), sp.GetService<FileUtil>(), sp.GetService<SptLoggerQueueManager>()));
collection.AddSingleton<ILoggerFactory>(sp => new SptLoggerProvider(
sp.GetService<JsonUtil>(),
sp.GetService<FileUtil>(),
sp.GetService<SptLoggerQueueManager>()
));
return collection;
}
}
+6 -4
View File
@@ -5,13 +5,15 @@ using SPTarkov.Server.Core.Utils.Logger;
namespace SPTarkov.Server.Logger;
[Injectable]
public class SptLoggerProvider(JsonUtil jsonUtil, FileUtil fileUtil, SptLoggerQueueManager queueManager) : ILoggerProvider, ILoggerFactory
public class SptLoggerProvider(
JsonUtil jsonUtil,
FileUtil fileUtil,
SptLoggerQueueManager queueManager
) : ILoggerProvider, ILoggerFactory
{
private List<ILoggerProvider> loggerProviders = new();
public void Dispose()
{
}
public void Dispose() { }
public void AddProvider(ILoggerProvider provider)
{
+17 -5
View File
@@ -8,13 +8,19 @@ public class SptLoggerWrapper : ILogger
{
private readonly SptLogger<SptLoggerWrapper> _logger;
public SptLoggerWrapper(string category, JsonUtil jsonUtil, FileUtil fileUtil, SptLoggerQueueManager queueManager)
public SptLoggerWrapper(
string category,
JsonUtil jsonUtil,
FileUtil fileUtil,
SptLoggerQueueManager queueManager
)
{
_logger = new SptLogger<SptLoggerWrapper>(fileUtil, jsonUtil, queueManager);
_logger.OverrideCategory(category);
}
public IDisposable? BeginScope<TState>(TState state) where TState : notnull
public IDisposable? BeginScope<TState>(TState state)
where TState : notnull
{
return null;
}
@@ -24,7 +30,13 @@ public class SptLoggerWrapper : ILogger
return _logger.IsLogEnabled(ConvertLogLevel(logLevel));
}
public void Log<TState>(Microsoft.Extensions.Logging.LogLevel logLevel, EventId eventId, TState state, Exception? exception, Func<TState, Exception?, string> formatter)
public void Log<TState>(
Microsoft.Extensions.Logging.LogLevel logLevel,
EventId eventId,
TState state,
Exception? exception,
Func<TState, Exception?, string> formatter
)
{
var level = ConvertLogLevel(logLevel);
switch (level)
@@ -60,7 +72,7 @@ public class SptLoggerWrapper : ILogger
LogLevel.Warn => Microsoft.Extensions.Logging.LogLevel.Warning,
LogLevel.Error => Microsoft.Extensions.Logging.LogLevel.Error,
LogLevel.Fatal => Microsoft.Extensions.Logging.LogLevel.Critical,
_ => throw new ArgumentOutOfRangeException(nameof(level), level, null)
_ => throw new ArgumentOutOfRangeException(nameof(level), level, null),
};
}
@@ -74,7 +86,7 @@ public class SptLoggerWrapper : ILogger
Microsoft.Extensions.Logging.LogLevel.Warning => LogLevel.Warn,
Microsoft.Extensions.Logging.LogLevel.Error => LogLevel.Error,
Microsoft.Extensions.Logging.LogLevel.Critical => LogLevel.Fatal,
_ => throw new ArgumentOutOfRangeException(nameof(level), level, null)
_ => throw new ArgumentOutOfRangeException(nameof(level), level, null),
};
}
}
+25 -13
View File
@@ -53,18 +53,18 @@ public class ModDllLoader
/// <returns>SptMod</returns>
private static SptMod LoadMod(string path)
{
var result = new SptMod
{
Directory = path,
Assemblies = []
};
var result = new SptMod { Directory = path, Assemblies = [] };
var assemblyCount = 0;
foreach (var file in new DirectoryInfo(path).GetFiles()) // Only search top level
{
if (string.Equals(file.Extension, ".dll", StringComparison.OrdinalIgnoreCase))
{
assemblyCount++;
result.Assemblies.Add(AssemblyLoadContext.Default.LoadFromAssemblyPath(Path.GetFullPath(file.FullName)));
result.Assemblies.Add(
AssemblyLoadContext.Default.LoadFromAssemblyPath(
Path.GetFullPath(file.FullName)
)
);
}
}
@@ -77,14 +77,22 @@ public class ModDllLoader
if (result.ModMetadata == null)
{
throw new Exception($"Failed to load mod metadata for: {Path.GetFullPath(path)} \ndid you override `AbstractModMetadata`?");
throw new Exception(
$"Failed to load mod metadata for: {Path.GetFullPath(path)} \ndid you override `AbstractModMetadata`?"
);
}
if (result.ModMetadata?.Name == null || result.ModMetadata?.Author == null ||
result.ModMetadata?.Version == null || result.ModMetadata?.Licence == null ||
result.ModMetadata?.SptVersion == null)
if (
result.ModMetadata?.Name == null
|| result.ModMetadata?.Author == null
|| result.ModMetadata?.Version == null
|| result.ModMetadata?.Licence == null
|| result.ModMetadata?.SptVersion == null
)
{
throw new Exception($"The mod metadata for: {Path.GetFullPath(path)} is missing one of these properties: name, author, licence, version or sptVersion");
throw new Exception(
$"The mod metadata for: {Path.GetFullPath(path)} is missing one of these properties: name, author, licence, version or sptVersion"
);
}
return result;
@@ -105,11 +113,15 @@ public class ModDllLoader
{
foreach (var module in allAsmModules)
{
var modMetadata = module.GetTypes().SingleOrDefault(t => typeof(AbstractModMetadata).IsAssignableFrom(t));
var modMetadata = module
.GetTypes()
.SingleOrDefault(t => typeof(AbstractModMetadata).IsAssignableFrom(t));
if (result != null && modMetadata != null)
{
throw new Exception($"Duplicate mod metadata found for mod at path: {Path.GetFullPath(path)}");
throw new Exception(
$"Duplicate mod metadata found for mod at path: {Path.GetFullPath(path)}"
);
}
if (modMetadata != null)
+4 -2
View File
@@ -9,7 +9,9 @@ public class ModLoadOrder(ICloner cloner)
protected Dictionary<string, AbstractModMetadata> mods = new();
protected Dictionary<string, AbstractModMetadata> modsAvailable = new();
public Dictionary<string, AbstractModMetadata> SetModList(Dictionary<string, AbstractModMetadata> mods)
public Dictionary<string, AbstractModMetadata> SetModList(
Dictionary<string, AbstractModMetadata> mods
)
{
this.mods = mods;
modsAvailable = cloner.Clone(this.mods);
@@ -36,7 +38,7 @@ public class ModLoadOrder(ICloner cloner)
public List<string> GetLoadOrder()
{
return [..loadOrder.Keys];
return [.. loadOrder.Keys];
}
public HashSet<string> GetModsOnLoadBefore(string mod)
+71 -48
View File
@@ -16,7 +16,8 @@ public class ModValidator(
ISemVer semVer,
ModLoadOrder modLoadOrder,
JsonUtil jsonUtil,
FileUtil fileUtil)
FileUtil fileUtil
)
{
protected readonly string basepath = "user/mods/";
protected readonly string modOrderPath = "user/mods/order.json";
@@ -32,7 +33,9 @@ public class ModValidator(
{
ValidateMods(mods);
var sortedModLoadOrder = modLoadOrder.SetModList(imported.ToDictionary(m => m.Key, m => m.Value.ModMetadata));
var sortedModLoadOrder = modLoadOrder.SetModList(
imported.ToDictionary(m => m.Key, m => m.Value.ModMetadata)
);
var finalList = new List<SptMod>();
foreach (var orderMod in SortModsLoadOrder())
{
@@ -65,10 +68,7 @@ public class ModValidator(
logger.Info(localisationService.GetText("modloader-mod_order_missing"));
// Write file with empty order array to disk
fileUtil.WriteFile(modOrderPath, jsonUtil.Serialize(new ModOrder
{
Order = []
}));
fileUtil.WriteFile(modOrderPath, jsonUtil.Serialize(new ModOrder { Order = [] }));
}
else
{
@@ -138,7 +138,9 @@ public class ModValidator(
{
foreach (var missingMod in missingFromOrderJSON.Keys)
{
logger.Debug(localisationService.GetText("modloader-mod_order_missing_from_json", missingMod));
logger.Debug(
localisationService.GetText("modloader-mod_order_missing_from_json", missingMod)
);
}
}
@@ -147,10 +149,7 @@ public class ModValidator(
{
if (ShouldSkipMod(mod.ModMetadata))
{
logger.Warning(localisationService.GetText("modloader-skipped_mod", new
{
mod
}));
logger.Warning(localisationService.GetText("modloader-skipped_mod", new { mod }));
continue;
}
@@ -187,7 +186,7 @@ public class ModValidator(
foreach (var mod in modPackageData.Values)
{
var name = $"{mod.Author}-{mod.Name}";
groupedMods.Add(name, [..groupedMods.GetValueOrDefault(name) ?? [], mod]);
groupedMods.Add(name, [.. groupedMods.GetValueOrDefault(name) ?? [], mod]);
// if there's more than one entry for a given mod it means there's at least 2 mods with the same author and name trying to load.
if (groupedMods[name].Count > 1 && !skippedMods.Contains(name))
@@ -213,7 +212,6 @@ public class ModValidator(
return mods.Where(ValidMod).ToList();
}
/// <summary>
/// Is the passed in mod compatible with the running server version
/// </summary>
@@ -227,7 +225,9 @@ public class ModValidator(
// Error and prevent loading if sptVersion property is not a valid semver string
if (!(semVer.IsValid(mod.SptVersion) || semVer.IsValidRange(mod.SptVersion)))
{
logger.Error(localisationService.GetText("modloader-invalid_sptversion_field", modName));
logger.Error(
localisationService.GetText("modloader-invalid_sptversion_field", modName)
);
return false;
}
@@ -235,12 +235,15 @@ public class ModValidator(
if (!semVer.Satisfies(sptVersion, mod.SptVersion))
{
logger.Error(
localisationService.GetText("modloader-outdated_sptversion_field", new
{
modName,
modVersion = mod.Version,
desiredSptVersion = mod.SptVersion
})
localisationService.GetText(
"modloader-outdated_sptversion_field",
new
{
modName,
modVersion = mod.Version,
desiredSptVersion = mod.SptVersion,
}
)
);
return false;
@@ -274,12 +277,15 @@ public class ModValidator(
// Add mod to imported list
imported.Add(mod.ModMetadata.Name, mod);
logger.Info(
localisationService.GetText("modloader-loaded_mod", new
{
name = mod.ModMetadata.Name,
version = mod.ModMetadata.Version,
author = mod.ModMetadata.Author
})
localisationService.GetText(
"modloader-loaded_mod",
new
{
name = mod.ModMetadata.Name,
version = mod.ModMetadata.Version,
author = mod.ModMetadata.Author,
}
)
);
}
@@ -293,7 +299,10 @@ public class ModValidator(
return skippedMods.Contains($"{pkg.Author}-{pkg.Name}");
}
protected bool AreModDependenciesFulfilled(AbstractModMetadata pkg, Dictionary<string, AbstractModMetadata> loadedMods)
protected bool AreModDependenciesFulfilled(
AbstractModMetadata pkg,
Dictionary<string, AbstractModMetadata> loadedMods
)
{
if (pkg.ModDependencies == null)
{
@@ -309,11 +318,10 @@ public class ModValidator(
if (!loadedMods.ContainsKey(modDependency))
{
logger.Error(
localisationService.GetText("modloader-missing_dependency", new
{
mod = modName,
modDependency
})
localisationService.GetText(
"modloader-missing_dependency",
new { mod = modName, modDependency }
)
);
return false;
}
@@ -321,13 +329,16 @@ public class ModValidator(
if (!semVer.Satisfies(loadedMods[modDependency].Version, requiredVersion))
{
logger.Error(
localisationService.GetText("modloader-outdated_dependency", new
{
mod = modName,
modDependency,
currentVersion = loadedMods[modDependency].Version,
requiredVersion
})
localisationService.GetText(
"modloader-outdated_dependency",
new
{
mod = modName,
modDependency,
currentVersion = loadedMods[modDependency].Version,
requiredVersion,
}
)
);
return false;
}
@@ -336,7 +347,10 @@ public class ModValidator(
return true;
}
protected bool IsModCompatible(AbstractModMetadata mod, Dictionary<string, AbstractModMetadata> loadedMods)
protected bool IsModCompatible(
AbstractModMetadata mod,
Dictionary<string, AbstractModMetadata> loadedMods
)
{
var incompatbileModsList = mod.Incompatibilities;
if (incompatbileModsList == null)
@@ -350,12 +364,15 @@ public class ModValidator(
if (loadedMods.ContainsKey(incompatibleModName))
{
logger.Error(
localisationService.GetText("modloader-incompatible_mod_found", new
{
author = mod.Author,
name = mod.Name,
incompatibleModName
})
localisationService.GetText(
"modloader-incompatible_mod_found",
new
{
author = mod.Author,
name = mod.Name,
incompatibleModName,
}
)
);
return false;
}
@@ -374,7 +391,11 @@ public class ModValidator(
var modName = mod.ModMetadata.Name;
var modPath = GetModPath(modName);
var modIsCalledBepinEx = string.Equals(modName, "bepinex", StringComparison.OrdinalIgnoreCase);
var modIsCalledBepinEx = string.Equals(
modName,
"bepinex",
StringComparison.OrdinalIgnoreCase
);
var modIsCalledUser = string.Equals(modName, "user", StringComparison.OrdinalIgnoreCase);
var modIsCalledSrc = string.Equals(modName, "src", StringComparison.OrdinalIgnoreCase);
var modIsCalledDb = string.Equals(modName, "db", StringComparison.OrdinalIgnoreCase);
@@ -406,7 +427,9 @@ public class ModValidator(
if (!semVer.IsValid(config.Version))
{
logger.Error(localisationService.GetText("modloader-invalid_version_property", modName));
logger.Error(
localisationService.GetText("modloader-invalid_version_property", modName)
);
issue = true;
}
+18 -10
View File
@@ -20,7 +20,9 @@ public static class Program
// Some users don't know how to create a shortcut...
if (!IsRunFromInstallationFolder())
{
Console.WriteLine("You have not created a shortcut properly. Please hold alt when dragging to create a shortcut.");
Console.WriteLine(
"You have not created a shortcut properly. Please hold alt when dragging to create a shortcut."
);
await Task.Delay(-1);
return;
}
@@ -47,7 +49,9 @@ public static class Program
// update the loadedMods list with our validated sorted mods
loadedMods = sortedLoadedMods;
diHandler.AddInjectableTypesFromAssemblies(sortedLoadedMods.SelectMany(a => a.Assemblies));
diHandler.AddInjectableTypesFromAssemblies(
sortedLoadedMods.SelectMany(a => a.Assemblies)
);
}
diHandler.InjectAll();
@@ -65,9 +69,10 @@ public static class Program
{
// Convert to relative path
string relativeModPath = Path.GetRelativePath(
Directory.GetCurrentDirectory(),
mod.Directory
).Replace('\\', '/');
Directory.GetCurrentDirectory(),
mod.Directory
)
.Replace('\\', '/');
bundleLoader.AddBundles(relativeModPath);
}
@@ -85,7 +90,8 @@ public static class Program
await app.InitializeAsync();
// Run garbage collection now the server is ready to start
GCSettings.LargeObjectHeapCompactionMode = GCLargeObjectHeapCompactionMode.CompactOnce;
GCSettings.LargeObjectHeapCompactionMode =
GCLargeObjectHeapCompactionMode.CompactOnce;
GC.Collect(GC.MaxGeneration, GCCollectionMode.Aggressive, true, true);
await app.StartAsync();
@@ -128,8 +134,8 @@ public static class Program
diHandler.AddInjectableTypesFromAssembly(typeof(App).Assembly);
diHandler.InjectAll();
// register the mod validator components
var provider = builder.Services
.AddScoped(typeof(ISptLogger<ModValidator>), typeof(SptLogger<ModValidator>))
var provider = builder
.Services.AddScoped(typeof(ISptLogger<ModValidator>), typeof(SptLogger<ModValidator>))
.AddScoped(typeof(ISemVer), typeof(SemanticVersioningSemVer))
.AddSingleton<ModValidator>()
.AddSingleton<ModLoadOrder>()
@@ -165,10 +171,12 @@ public static class Program
private static bool IsRunFromInstallationFolder()
{
var dirFiles = Directory.GetFiles(Directory.GetCurrentDirectory());
var dirFiles = Directory.GetFiles(Directory.GetCurrentDirectory());
// This file is guaranteed to exist if ran from the correct location, even if the game does not exist here.
return dirFiles.Any(dirFile => dirFile.EndsWith("sptLogger.json") || dirFile.EndsWith("sptLogger.Development.json"));
return dirFiles.Any(dirFile =>
dirFile.EndsWith("sptLogger.json") || dirFile.EndsWith("sptLogger.Development.json")
);
}
[DllImport("kernel32.dll", SetLastError = true)]
+4 -10
View File
@@ -1,7 +1,5 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<Import Project="..\Build.props" />
<PropertyGroup>
<PackageId>SPTarkov.Server</PackageId>
<Authors>Single Player Tarkov</Authors>
@@ -17,29 +15,27 @@
<IsPackable>true</IsPackable>
<StaticWebAssetsEnabled>false</StaticWebAssetsEnabled>
</PropertyGroup>
<PropertyGroup Condition="'$(RuntimeIdentifier)' == 'win-x64'">
<AssemblyName>SPTarkov.Server</AssemblyName>
<ApplicationIcon>..\Libraries\SPTarkov.Server.Assets\SPT_Data\images\icon.ico</ApplicationIcon>
</PropertyGroup>
<PropertyGroup Condition="'$(RuntimeIdentifier)' == 'linux-x64'">
<AssemblyName>SPTarkov.Server.Linux</AssemblyName>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\Libraries\SPTarkov.Reflection\SPTarkov.Reflection.csproj" />
<ProjectReference Include="..\Libraries\SPTarkov.Server.Core\SPTarkov.Server.Core.csproj" />
<ProjectReference Include="..\Libraries\SPTarkov.Server.Assets\SPTarkov.Server.Assets.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="9.0.5" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="9.0.5" />
<PackageReference
Include="Microsoft.Extensions.DependencyInjection.Abstractions"
Version="9.0.5"
/>
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="9.0.5" />
<PackageReference Include="Microsoft.Extensions.Http" Version="9.0.5" />
</ItemGroup>
<ItemGroup>
<Content Include="Assets\**">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
@@ -52,9 +48,7 @@
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>
<ItemGroup>
<None Include="..\LICENSE" Pack="true" Visible="false" PackagePath="" />
</ItemGroup>
</Project>