44using AET . ModVerify . Reporting ;
55using AET . ModVerify . Settings ;
66using AET . ModVerify . Utilities ;
7+ using AET . ModVerify . Verifiers . Caching ;
78using Microsoft . Extensions . DependencyInjection ;
89using PG . StarWarsGame . Engine ;
910using PG . StarWarsGame . Files ;
@@ -43,36 +44,71 @@ public SingleModelVerifier(
4344
4445 public override void Verify ( string modelName , IReadOnlyCollection < string > contextInfo , CancellationToken token )
4546 {
47+ var cacheEntry = _cache ? . GetEntry ( modelName ) ;
48+ if ( cacheEntry ? . AlreadyVerified is true )
49+ {
50+ if ( ! cacheEntry . Value . AssetExists )
51+ {
52+ var error = VerificationError . Create (
53+ this ,
54+ VerifierErrorCodes . FileNotFound ,
55+ $ "Unable to find .ALO file '{ modelName } '",
56+ VerificationSeverity . Error ,
57+ contextInfo ,
58+ modelName ) ;
59+ AddError ( error ) ;
60+ }
61+ return ;
62+ }
4663
4764 var modelPath = BuildModelPath ( modelName ) ;
48- VerifyAlamoFile ( modelPath , contextInfo , token ) ;
65+ VerifyAlamoFile ( modelPath , contextInfo , token , out var modelExists ) ;
4966
50- foreach ( var textureError in _textureVerifier . VerifyErrors )
51- AddError ( textureError ) ;
52- }
53-
54- private void VerifyAlamoFile ( string modelPath , IReadOnlyCollection < string > contextInfo , CancellationToken token )
55- {
56- token . ThrowIfCancellationRequested ( ) ;
57-
58- var modelName = FileSystem . Path . GetFileName ( modelPath . AsSpan ( ) ) ;
59-
60- // We always want to report that a file was not found, so that error reports show all XRefs to the not found model.
61- if ( ! GameEngine . GameRepository . ModelRepository . FileExists ( modelPath ) )
67+ if ( ! modelExists )
6268 {
63- var modelNameString = modelName . ToString ( ) ;
6469 var error = VerificationError . Create (
6570 this ,
6671 VerifierErrorCodes . FileNotFound ,
67- $ "Unable to find .ALO file '{ modelNameString } '",
72+ $ "Unable to find .ALO file '{ modelName } '",
6873 VerificationSeverity . Error ,
6974 contextInfo ,
70- modelNameString ) ;
75+ modelName ) ;
7176 AddError ( error ) ;
7277 }
7378
74- if ( _cache ? . TryAddEntry ( modelName ) is false )
75- return ;
79+ _cache ? . TryAddEntry ( modelName , modelExists ) ;
80+
81+ foreach ( var textureError in _textureVerifier . VerifyErrors )
82+ AddError ( textureError ) ;
83+ }
84+
85+ public void VerifyModelOrParticle (
86+ IAloFile < IAloDataContent , AloFileInformation > aloFile ,
87+ IReadOnlyCollection < string > contextInfo ,
88+ CancellationToken token )
89+ {
90+ switch ( aloFile )
91+ {
92+ case IAloModelFile model :
93+ VerifyModel ( model , contextInfo , token ) ;
94+ break ;
95+ case IAloParticleFile particle :
96+ VerifyParticle ( particle , contextInfo ) ;
97+ break ;
98+ default :
99+ throw new InvalidOperationException ( "The data stream is neither a model nor particle." ) ;
100+ }
101+ }
102+
103+ private void VerifyAlamoFile (
104+ string modelPath ,
105+ IReadOnlyCollection < string > contextInfo ,
106+ CancellationToken token ,
107+ out bool modelExists )
108+ {
109+ token . ThrowIfCancellationRequested ( ) ;
110+
111+ modelExists = true ;
76112
77113 IAloFile < IAloDataContent , AloFileInformation > ? aloFile = null ;
78114 try
@@ -90,8 +126,13 @@ private void VerifyAlamoFile(string modelPath, IReadOnlyCollection<string> conte
90126 return ;
91127 }
92128
129+ // Because throwsException is true, we know that if aloFile is null,
130+ // the file does not exist
93131 if ( aloFile is null )
132+ {
133+ modelExists = false ;
94134 return ;
135+ }
95136
96137 VerifyModelOrParticle ( aloFile , contextInfo , token ) ;
97138 }
@@ -101,21 +142,6 @@ private void VerifyAlamoFile(string modelPath, IReadOnlyCollection<string> conte
101142 }
102143 }
103144
104- public void VerifyModelOrParticle ( IAloFile < IAloDataContent , AloFileInformation > aloFile , IReadOnlyCollection < string > contextInfo , CancellationToken token )
105- {
106- switch ( aloFile )
107- {
108- case IAloModelFile model :
109- VerifyModel ( model , contextInfo , token ) ;
110- break ;
111- case IAloParticleFile particle :
112- VerifyParticle ( particle , contextInfo ) ;
113- break ;
114- default :
115- throw new InvalidOperationException ( "The data stream is neither a model nor particle." ) ;
116- }
117- }
118-
119145 private void VerifyParticle ( IAloParticleFile file , IReadOnlyCollection < string > contextInfo )
120146 {
121147 foreach ( var texture in file . Content . Textures )
@@ -220,22 +246,21 @@ private void VerifyProxyExists(IPetroglyphFileHolder model, string proxy, IReadO
220246 var proxyPath = BuildModelPath ( proxyName ) ;
221247
222248 var modelFilePath = FileSystem . Path . GetGameStrippedPath ( Repository . Path . AsSpan ( ) , model . FilePath . AsSpan ( ) ) . ToString ( ) ;
249+
250+ VerifyAlamoFile ( proxyPath , [ ..contextInfo , modelFilePath ] , token , out var proxyExists ) ;
223251
224- if ( ! Repository . ModelRepository . FileExists ( proxyPath ) )
252+ if ( ! proxyExists )
225253 {
226254 var message = $ "Proxy particle '{ proxyName } ' not found for model '{ modelFilePath } '";
227255 var error = VerificationError . Create (
228256 this ,
229257 VerifierErrorCodes . FileNotFound ,
230- message ,
231- VerificationSeverity . Error ,
232- [ ..contextInfo , modelFilePath ] ,
258+ message ,
259+ VerificationSeverity . Error ,
260+ [ .. contextInfo , modelFilePath ] ,
233261 proxyName ) ;
234262 AddError ( error ) ;
235- return ;
236263 }
237-
238- VerifyAlamoFile ( proxyPath , [ ..contextInfo , modelFilePath ] , token ) ;
239264 }
240265
241266 private void VerifyShaderExists ( IPetroglyphFileHolder model , string shader , IReadOnlyCollection < string > contextInfo )
0 commit comments