@@ -109,6 +109,16 @@ public async Task Run()
109
109
await writer . WriteAsync ( licenseContent ) ;
110
110
}
111
111
Console . WriteLine ( "Successfully obtained a Unity license!" ) ;
112
+
113
+ Console . WriteLine ( "Finalising license by running Unity..." ) ;
114
+ var finaliseResponse = await RunUnityToFinaliseLicense ( ) ;
115
+ if ( finaliseResponse . IsActivated )
116
+ {
117
+ Console . WriteLine ( "Successfully finalised Unity license!" ) ;
118
+ return ;
119
+ }
120
+
121
+ throw new InvalidOperationException ( "Unable to finalise Unity license!" ) ;
112
122
}
113
123
114
124
private string GenerateTxId ( )
@@ -133,6 +143,12 @@ private async Task<UnityLicenseStatusCheck> RunUnityAndCaptureMachineKeys()
133
143
ArgumentList =
134
144
{
135
145
"-quit" ,
146
+ "-batchmode" ,
147
+ "-username" ,
148
+ _request . Username ,
149
+ "-password" ,
150
+ _request . Password ,
151
+ "-force-free"
136
152
} ,
137
153
CustomBufferHandler = ( buffer ) =>
138
154
{
@@ -173,6 +189,42 @@ private async Task<UnityLicenseStatusCheck> RunUnityAndCaptureMachineKeys()
173
189
174
190
throw new InvalidOperationException ( "Unity didn't provide us with machine keys after 30 licensing attempts..." ) ;
175
191
}
192
+
193
+ private async Task < UnityLicenseStatusCheck > RunUnityToFinaliseLicense ( )
194
+ {
195
+ var executor = new UnityExecutor ( ) ;
196
+ for ( var i = 0 ; i < 30 ; i ++ )
197
+ {
198
+ var response = await executor . ExecuteAsync ( new UnityExecutorRequest
199
+ {
200
+ UnityExecutablePath = _request . UnityExecutablePath ,
201
+ ArgumentList =
202
+ {
203
+ "-quit" ,
204
+ "-batchmode" ,
205
+ "-username" ,
206
+ _request . Username ,
207
+ "-password" ,
208
+ _request . Password ,
209
+ "-force-free"
210
+ }
211
+ } ) ;
212
+
213
+ if ( response . Result == UnityExecutorResponseResult . Success )
214
+ {
215
+ return new UnityLicenseStatusCheck
216
+ {
217
+ IsActivated = true ,
218
+ } ;
219
+ }
220
+ else if ( response . Result == UnityExecutorResponseResult . Error )
221
+ {
222
+ throw new InvalidOperationException ( response . Output ) ;
223
+ }
224
+ }
225
+
226
+ throw new InvalidOperationException ( "Unity didn't provide us with machine keys after 30 licensing attempts..." ) ;
227
+ }
176
228
177
229
private class UnityLicenseStatusCheck
178
230
{
0 commit comments