Skip to content

Commit e33b5d4

Browse files
committed
refactor verifierchain
1 parent bac693b commit e33b5d4

16 files changed

Lines changed: 86 additions & 68 deletions

src/ModVerify.CliApp/Properties/launchSettings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"profiles": {
33
"Verify": {
44
"commandName": "Project",
5-
"commandLineArgs": ""
5+
"commandLineArgs": "verify --offline"
66
},
77
"Verify (Interactive)": {
88
"commandName": "Project",

src/ModVerify/Reporting/Engine/EngineErrorReporterBase.cs

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,33 @@
66

77
namespace AET.ModVerify.Reporting.Engine;
88

9-
internal abstract class EngineErrorReporterBase<T>(IGameRepository gameRepository, IServiceProvider serviceProvider)
10-
: IGameVerifierInfo
9+
internal abstract class EngineErrorReporterBase<T> : IGameVerifierInfo
1110
{
12-
protected readonly IGameRepository GameRepository = gameRepository ?? throw new ArgumentNullException(nameof(gameRepository));
13-
protected readonly IServiceProvider ServiceProvider = serviceProvider ?? throw new ArgumentNullException(nameof(serviceProvider));
11+
protected readonly IGameRepository GameRepository;
12+
protected readonly IServiceProvider ServiceProvider;
1413

1514
public IGameVerifierInfo? Parent => null;
1615

16+
public IReadOnlyList<IGameVerifierInfo> VerifierChain { get; }
17+
1718
public string Name => GetType().FullName;
1819

1920
public abstract string FriendlyName { get; }
2021

22+
protected EngineErrorReporterBase(IGameRepository gameRepository, IServiceProvider serviceProvider)
23+
{
24+
GameRepository = gameRepository ?? throw new ArgumentNullException(nameof(gameRepository));
25+
ServiceProvider = serviceProvider ?? throw new ArgumentNullException(nameof(serviceProvider));
26+
VerifierChain = [this];
27+
}
28+
2129
public IEnumerable<VerificationError> GetErrors(IEnumerable<T> errors)
2230
{
2331
foreach (var error in errors)
2432
{
2533
var errorData = CreateError(error);
2634
yield return new VerificationError(
27-
errorData.Identifier, errorData.Message, [this], errorData.Context, errorData.Asset, errorData.Severity);
35+
errorData.Identifier, errorData.Message, this, errorData.Context, errorData.Asset, errorData.Severity);
2836
}
2937
}
3038

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
using AET.ModVerify.Verifiers;
2+
using AET.ModVerify.Verifiers.Utilities;
3+
using System.Collections.Generic;
24

35
namespace AET.ModVerify.Reporting;
46

57
internal sealed class RestoredVerifierInfo : IGameVerifierInfo
68
{
79
public IGameVerifierInfo? Parent { get; init; }
10+
11+
public IReadOnlyList<IGameVerifierInfo> VerifierChain => field ??= this.GetVerifierChain();
12+
813
public required string Name { get; init; }
914
public string FriendlyName => Name;
1015
}

src/ModVerify/Reporting/VerificationError.cs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,13 @@ public sealed class VerificationError : IEquatable<VerificationError>
2828
public VerificationError(
2929
string id,
3030
string message,
31-
IReadOnlyList<IGameVerifierInfo> verifiers,
31+
IGameVerifierInfo verifier,
3232
IEnumerable<string> contextEntries,
3333
string asset,
3434
VerificationSeverity severity)
3535
{
36+
if (verifier == null)
37+
throw new ArgumentNullException(nameof(verifier));
3638
if (contextEntries == null)
3739
throw new ArgumentNullException(nameof(contextEntries));
3840
if (asset is null)
@@ -41,7 +43,7 @@ public VerificationError(
4143

4244
Id = id;
4345
Message = message ?? throw new ArgumentNullException(nameof(message));
44-
VerifierChain = [.. verifiers];
46+
VerifierChain = verifier.VerifierChain;
4547
Severity = severity;
4648
ContextEntries = _contextEntries = [.. contextEntries];
4749
Asset = asset;
@@ -58,18 +60,18 @@ internal VerificationError(JsonVerificationError error)
5860
}
5961

6062
public static VerificationError Create(
61-
IReadOnlyList<IGameVerifierInfo> verifiers,
63+
IGameVerifierInfo verifier,
6264
string id,
6365
string message,
6466
VerificationSeverity severity,
6567
IEnumerable<string> context,
6668
string asset)
6769
{
68-
return new VerificationError(id, message, verifiers, context, asset, severity);
70+
return new VerificationError(id, message, verifier, context, asset, severity);
6971
}
7072

7173
public static VerificationError Create(
72-
IReadOnlyList<IGameVerifierInfo> verifiers,
74+
IGameVerifierInfo verifier,
7375
string id,
7476
string message,
7577
VerificationSeverity severity,
@@ -78,7 +80,7 @@ public static VerificationError Create(
7880
return new VerificationError(
7981
id,
8082
message,
81-
verifiers,
83+
verifier,
8284
[],
8385
asset,
8486
severity);

src/ModVerify/Verifiers/CommandBar/CommandBarVerifier.Components.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ private void VerifyCommandBarComponents()
1919
if (!occupiedComponentIds.TryGetValue(component.Id, out var alreadyOccupied))
2020
{
2121
AddError(VerificationError.Create(
22-
VerifierChain,
22+
this,
2323
CommandBarUnsupportedComponent,
2424
$"The CommandBar component '{component.Name}' is not supported by the game.",
2525
VerificationSeverity.Information,
@@ -32,7 +32,7 @@ private void VerifyCommandBarComponents()
3232

3333
if (alreadyOccupied)
3434
{
35-
AddError(VerificationError.Create(VerifierChain,
35+
AddError(VerificationError.Create(this,
3636
VerifierErrorCodes.Duplicate,
3737
$"The CommandBar component '{component.Name}' with ID '{component.Id}' already exists.",
3838
VerificationSeverity.Warning,
@@ -56,7 +56,7 @@ private void VerifyCommandBarModel(CommandBarBaseComponent component)
5656

5757
if (shellComponent.ModelPath is null)
5858
{
59-
AddError(VerificationError.Create(VerifierChain,
59+
AddError(VerificationError.Create(this,
6060
CommandBarShellNoModel, $"The CommandBarShellComponent '{component.Name}' has no model specified.",
6161
VerificationSeverity.Error, shellComponent.Name));
6262
return;
@@ -65,7 +65,7 @@ private void VerifyCommandBarModel(CommandBarBaseComponent component)
6565
var model = GameEngine.PGRender.LoadModelAndAnimations(shellComponent.ModelPath.AsSpan(), null);
6666
if (model is null)
6767
{
68-
AddError(VerificationError.Create(VerifierChain,
68+
AddError(VerificationError.Create(this,
6969
CommandBarShellNoModel, $"Could not find model '{shellComponent.ModelPath}' for CommandBarShellComponent '{component.Name}'.",
7070
VerificationSeverity.Error, [shellComponent.Name], shellComponent.ModelPath));
7171
return;
@@ -79,7 +79,7 @@ private void VerifyComponentBone(CommandBarBaseComponent component)
7979

8080
if (component.Bone == -1)
8181
{
82-
AddError(VerificationError.Create(VerifierChain,
82+
AddError(VerificationError.Create(this,
8383
CommandBarShellNoModel, $"The CommandBar component '{component.Name}' is not connected to a shell component.",
8484
VerificationSeverity.Warning, component.Name));
8585
}

src/ModVerify/Verifiers/CommandBar/CommandBarVerifier.Groups.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,14 @@ private void VerifyCommandBarShellsGroups()
2525
}
2626

2727
if (shellGroups.Count == 0)
28-
AddError(VerificationError.Create(VerifierChain,
28+
AddError(VerificationError.Create(this,
2929
CommandBarNoShellsGroup,
3030
$"No CommandBarGroup '{CommandBarConstants.ShellGroupName}' found.",
3131
VerificationSeverity.Error,
3232
"GameCommandBar"));
3333

3434
if (shellGroups.Count > 1)
35-
AddError(VerificationError.Create(VerifierChain,
35+
AddError(VerificationError.Create(this,
3636
CommandBarManyShellsGroup,
3737
$"Found more than one Shells CommandBarGroup. Mind that group names are case-sensitive. Correct name is '{CommandBarConstants.ShellGroupName}'",
3838
VerificationSeverity.Warning,
@@ -46,7 +46,7 @@ private void VerifyShellGroup(CommandBarComponentGroup shellGroup)
4646
var shellComponent = component as CommandBarShellComponent;
4747
if (shellComponent?.Type is not CommandBarComponentType.Shell)
4848
{
49-
AddError(VerificationError.Create(VerifierChain,
49+
AddError(VerificationError.Create(this,
5050
CommandBarNoShellsComponentInShellGroup,
5151
$"The CommandBar component '{component.Name}' is not a shell component, but part of the '{CommandBarConstants.ShellGroupName}' group.",
5252
VerificationSeverity.Warning, component.Name));

src/ModVerify/Verifiers/Commons/AudioFileVerifier.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public override void Verify(AudioFileInfo sampleInfo, IReadOnlyCollection<string
3636
if (sampleStream is null)
3737
{
3838
AddError(VerificationError.Create(
39-
VerifierChain,
39+
this,
4040
VerifierErrorCodes.FileNotFound,
4141
$"Audio file '{sampleString}' could not be found.",
4242
VerificationSeverity.Error,
@@ -72,7 +72,7 @@ public override void Verify(AudioFileInfo sampleInfo, IReadOnlyCollection<string
7272
if (format != WaveFormats.PCM)
7373
{
7474
AddError(VerificationError.Create(
75-
VerifierChain,
75+
this,
7676
VerifierErrorCodes.SampleNotPCM,
7777
$"Audio file '{sampleString}' has an invalid format '{format}'. Supported is {WaveFormats.PCM}",
7878
VerificationSeverity.Error,
@@ -83,7 +83,7 @@ public override void Verify(AudioFileInfo sampleInfo, IReadOnlyCollection<string
8383
if (channels > 1 && !sampleInfo.IsAmbient)
8484
{
8585
AddError(VerificationError.Create(
86-
VerifierChain,
86+
this,
8787
VerifierErrorCodes.SampleNotMono,
8888
$"Audio file '{sampleString}' is not mono audio.",
8989
VerificationSeverity.Information,
@@ -93,7 +93,7 @@ public override void Verify(AudioFileInfo sampleInfo, IReadOnlyCollection<string
9393
if (sampleRate > 48_000)
9494
{
9595
AddError(VerificationError.Create(
96-
VerifierChain,
96+
this,
9797
VerifierErrorCodes.InvalidSampleRate,
9898
$"Audio file '{sampleString}' has a too high sample rate of {sampleRate}. Maximum is 48.000Hz.",
9999
VerificationSeverity.Error,
@@ -104,7 +104,7 @@ public override void Verify(AudioFileInfo sampleInfo, IReadOnlyCollection<string
104104
if (bitPerSecondPerChannel > 16)
105105
{
106106
AddError(VerificationError.Create(
107-
VerifierChain,
107+
this,
108108
VerifierErrorCodes.InvalidBitsPerSeconds,
109109
$"Audio file '{sampleString}' has an invalid bit size of {bitPerSecondPerChannel}. Supported are 16bit.",
110110
VerificationSeverity.Error,

src/ModVerify/Verifiers/Commons/DuplicateVerifier.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public override void Verify(IDuplicateVerificationContext toVerify, IReadOnlyCol
3131
if (toVerify.HasDuplicates(crc32, out var entryNames, out var context, out var errorMessage))
3232
{
3333
AddError(VerificationError.Create(
34-
VerifierChain,
34+
this,
3535
VerifierErrorCodes.Duplicate,
3636
errorMessage,
3737
VerificationSeverity.Error,

src/ModVerify/Verifiers/Commons/ModelVerifier.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ private void VerifyAlamoFile(string modelPath, IReadOnlyCollection<string> conte
7272
{
7373
var modelNameString = modelName.ToString();
7474
var error = VerificationError.Create(
75-
VerifierChain,
75+
this,
7676
VerifierErrorCodes.FileNotFound,
7777
$"Unable to find .ALO file '{modelNameString}'",
7878
VerificationSeverity.Error,
@@ -95,7 +95,7 @@ private void VerifyAlamoFile(string modelPath, IReadOnlyCollection<string> conte
9595
{
9696
var aloFilePath = FileSystem.Path.GetGameStrippedPath(Repository.Path.AsSpan(), modelPath.AsSpan()).ToString();
9797
var message = $"'{aloFilePath}' is corrupted: {e.Message}";
98-
AddError(VerificationError.Create(VerifierChain, VerifierErrorCodes.FileCorrupt, message,
98+
AddError(VerificationError.Create(this, VerifierErrorCodes.FileCorrupt, message,
9999
VerificationSeverity.Critical, contextInfo, aloFilePath));
100100
return;
101101
}
@@ -139,7 +139,7 @@ private void VerifyParticle(IAloParticleFile file, IReadOnlyCollection<string> c
139139
{
140140
var particlePath = FileSystem.Path.GetGameStrippedPath(Repository.Path.AsSpan(), file.FilePath.AsSpan()).ToString();
141141
AddError(VerificationError.Create(
142-
VerifierChain,
142+
this,
143143
VerifierErrorCodes.InvalidFilePath,
144144
$"Invalid texture file name '{texture}' in particle '{particlePath}'",
145145
VerificationSeverity.Error,
@@ -154,7 +154,7 @@ private void VerifyParticle(IAloParticleFile file, IReadOnlyCollection<string> c
154154
{
155155
var particlePath = FileSystem.Path.GetGameStrippedPath(Repository.Path.AsSpan(), file.FilePath.AsSpan()).ToString();
156156
AddError(VerificationError.Create(
157-
VerifierChain,
157+
this,
158158
VerifierErrorCodes.InvalidParticleName,
159159
$"The particle name '{file.Content.Name}' does not match file name '{particlePath}'",
160160
VerificationSeverity.Error,
@@ -173,7 +173,7 @@ private void VerifyModel(IAloModelFile file, IReadOnlyCollection<string> context
173173
{
174174
var modelFilePath = FileSystem.Path.GetGameStrippedPath(Repository.Path.AsSpan(), file.FilePath.AsSpan()).ToString();
175175
AddError(VerificationError.Create(
176-
VerifierChain,
176+
this,
177177
VerifierErrorCodes.InvalidFilePath,
178178
$"Invalid texture file name '{texture}' in model '{modelFilePath}'",
179179
VerificationSeverity.Error,
@@ -191,7 +191,7 @@ private void VerifyModel(IAloModelFile file, IReadOnlyCollection<string> context
191191
var modelFilePath =
192192
FileSystem.Path.GetGameStrippedPath(Repository.Path.AsSpan(), file.FilePath.AsSpan()).ToString();
193193
AddError(VerificationError.Create(
194-
VerifierChain,
194+
this,
195195
VerifierErrorCodes.InvalidFilePath,
196196
$"Invalid shader file name '{shader}' in model '{modelFilePath}'",
197197
VerificationSeverity.Error,
@@ -210,7 +210,7 @@ private void VerifyModel(IAloModelFile file, IReadOnlyCollection<string> context
210210
var modelFilePath = FileSystem.Path
211211
.GetGameStrippedPath(Repository.Path.AsSpan(), file.FilePath.AsSpan()).ToString();
212212
AddError(VerificationError.Create(
213-
VerifierChain,
213+
this,
214214
VerifierErrorCodes.InvalidFilePath,
215215
$"Invalid proxy file name '{proxy}' for model '{modelFilePath}'",
216216
VerificationSeverity.Error,
@@ -238,7 +238,7 @@ private void VerifyProxyExists(IPetroglyphFileHolder model, string proxy, IReadO
238238
{
239239
var message = $"Proxy particle '{proxyName}' not found for model '{modelFilePath}'";
240240
var error = VerificationError.Create(
241-
VerifierChain,
241+
this,
242242
VerifierErrorCodes.FileNotFound,
243243
message,
244244
VerificationSeverity.Error,
@@ -261,7 +261,7 @@ private void VerifyShaderExists(IPetroglyphFileHolder model, string shader, IRea
261261
var modelFilePath = FileSystem.Path.GetGameStrippedPath(Repository.Path.AsSpan(), model.FilePath.AsSpan()).ToString();
262262
var message = $"Shader effect '{shader}' not found for model '{modelFilePath}'.";
263263
var error = VerificationError.Create(
264-
VerifierChain,
264+
this,
265265
VerifierErrorCodes.FileNotFound,
266266
message,
267267
VerificationSeverity.Error,

src/ModVerify/Verifiers/Commons/TextureVeifier.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public void Verify(ReadOnlySpan<char> textureName, IReadOnlyCollection<string> c
3939

4040
if (tooLongPath)
4141
{
42-
AddError(VerificationError.Create(VerifierChain, VerifierErrorCodes.FilePathTooLong,
42+
AddError(VerificationError.Create(this, VerifierErrorCodes.FilePathTooLong,
4343
$"Could not find texture '{pathString}' because the engine resolved a path that is too long.",
4444
VerificationSeverity.Error, contextInfo, pathString));
4545
return;
@@ -56,7 +56,7 @@ public void Verify(ReadOnlySpan<char> textureName, IReadOnlyCollection<string> c
5656

5757
messageBuilder.Append('.');
5858

59-
AddError(VerificationError.Create(VerifierChain, VerifierErrorCodes.FileNotFound,
59+
AddError(VerificationError.Create(this, VerifierErrorCodes.FileNotFound,
6060
messageBuilder.ToString(),
6161
VerificationSeverity.Error, contextInfo, pathString));
6262
}

0 commit comments

Comments
 (0)