9
9
using System . IO ;
10
10
using System . IO . Abstractions ;
11
11
using System . Linq ;
12
+ using System . Threading ;
12
13
using System . Threading . Tasks ;
13
14
using AET . ModVerify . Pipeline ;
14
- using AnakinRaW . CommonUtilities . SimplePipeline . Progress ;
15
+ using AET . ModVerifyTool . Reporting ;
16
+ using PG . StarWarsGame . Engine ;
15
17
16
18
namespace AET . ModVerifyTool ;
17
19
@@ -48,20 +50,68 @@ public async Task<int> RunApplication()
48
50
return 0 ;
49
51
}
50
52
51
- private async Task < IReadOnlyCollection < VerificationError > > Verify ( VerifyGameInstallationData installData )
53
+ private async Task < IReadOnlyCollection < VerificationError > > Verify ( VerifyInstallationInformation installInformation )
52
54
{
55
+ var gameEngineService = services . GetRequiredService < IPetroglyphStarWarsGameEngineService > ( ) ;
56
+ var engineErrorReporter = new ConcurrentGameEngineErrorReporter ( ) ;
57
+
58
+ IStarWarsGameEngine gameEngine ;
59
+
60
+ try
61
+ {
62
+ var initProgress = new Progress < string > ( ) ;
63
+ var initProgressReporter = new EngineInitializeProgressReporter ( initProgress ) ;
64
+
65
+ try
66
+ {
67
+ _logger ? . LogInformation ( $ "Creating Game Engine '{ installInformation . EngineType } '") ;
68
+ gameEngine = await gameEngineService . InitializeAsync (
69
+ installInformation . EngineType ,
70
+ installInformation . GameLocations ,
71
+ engineErrorReporter ,
72
+ initProgress ,
73
+ false ,
74
+ CancellationToken . None ) . ConfigureAwait ( false ) ;
75
+ _logger ? . LogInformation ( $ "Game Engine created") ;
76
+ }
77
+ finally
78
+ {
79
+ initProgressReporter . Dispose ( ) ;
80
+ }
81
+ }
82
+ catch ( Exception e )
83
+ {
84
+ _logger ? . LogError ( e , $ "Creating game engine failed: { e . Message } ") ;
85
+ throw ;
86
+ }
87
+
88
+ var progressReporter = new VerifyConsoleProgressReporter ( installInformation . Name ) ;
89
+
53
90
using var verifyPipeline = new GameVerifyPipeline (
54
- installData . EngineType ,
55
- installData . GameLocations ,
91
+ gameEngine ,
92
+ engineErrorReporter ,
56
93
settings . VerifyPipelineSettings ,
57
94
settings . GlobalReportSettings ,
58
- new VerifyConsoleProgressReporter ( ) ,
95
+ progressReporter ,
59
96
services ) ;
60
97
61
98
try
62
99
{
63
- _logger ? . LogInformation ( $ "Verifying '{ installData . Name } '...") ;
64
- await verifyPipeline . RunAsync ( ) . ConfigureAwait ( false ) ;
100
+ try
101
+ {
102
+ _logger ? . LogInformation ( $ "Verifying '{ installInformation . Name } '...") ;
103
+ await verifyPipeline . RunAsync ( ) . ConfigureAwait ( false ) ;
104
+ progressReporter . Report ( string . Empty , 1.0 ) ;
105
+ }
106
+ catch
107
+ {
108
+ progressReporter . ReportError ( "Verification failed" , null ) ;
109
+ throw ;
110
+ }
111
+ finally
112
+ {
113
+ progressReporter . Dispose ( ) ;
114
+ }
65
115
}
66
116
catch ( OperationCanceledException )
67
117
{
@@ -72,11 +122,8 @@ private async Task<IReadOnlyCollection<VerificationError>> Verify(VerifyGameInst
72
122
_logger ? . LogError ( e , $ "Verification failed: { e . Message } ") ;
73
123
throw ;
74
124
}
75
- finally
76
- {
77
- _logger ? . LogInformation ( "Finished verification" ) ;
78
- }
79
125
126
+ _logger ? . LogInformation ( "Finished verification" ) ;
80
127
return verifyPipeline . FilteredErrors ;
81
128
}
82
129
@@ -91,8 +138,7 @@ private async Task ReportErrors(IReadOnlyCollection<VerificationError> errors)
91
138
if ( errors . Any ( x => x . Severity >= settings . AppThrowsOnMinimumSeverity ) )
92
139
throw new GameVerificationException ( errors ) ;
93
140
}
94
-
95
-
141
+
96
142
private async Task WriteBaseline ( IEnumerable < VerificationError > errors , string baselineFile )
97
143
{
98
144
var baseline = new VerificationBaseline ( settings . GlobalReportSettings . MinimumReportSeverity , errors ) ;
@@ -106,16 +152,4 @@ private async Task WriteBaseline(IEnumerable<VerificationError> errors, string b
106
152
using var fs = _fileSystem . FileStream . New ( fullPath , FileMode . Create , FileAccess . Write , FileShare . None ) ;
107
153
await baseline . ToJsonAsync ( fs ) ;
108
154
}
109
- }
110
-
111
- public class VerifyConsoleProgressReporter : IVerifyProgressReporter
112
- {
113
- public void Report ( string progressText , double progress , ProgressType type , VerifyProgressInfo detailedProgress )
114
- {
115
- if ( type != VerifyProgress . ProgressType )
116
- return ;
117
-
118
-
119
- Console . WriteLine ( progressText ) ;
120
- }
121
155
}
0 commit comments