Skip to content
This repository was archived by the owner on Apr 11, 2020. It is now read-only.

Commit dc24dc9

Browse files
committed
Try to fix licensing for subscriptions
1 parent e2f2e56 commit dc24dc9

File tree

2 files changed

+53
-1
lines changed

2 files changed

+53
-1
lines changed

UnityAutomaticLicensor/UnityExecutor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public async Task<UnityExecutorResponse> ExecuteAsync(UnityExecutorRequest reque
2929
}
3030
processStartInfo.ArgumentList.Add("-logFile");
3131
processStartInfo.ArgumentList.Add(logPath);
32-
processStartInfo.ArgumentList.Add("-projectPath");
32+
processStartInfo.ArgumentList.Add("-createProject");
3333
processStartInfo.ArgumentList.Add(temporaryDirectory);
3434
var process = Process.Start(processStartInfo);
3535

UnityAutomaticLicensor/UnityLicensor.cs

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,16 @@ public async Task Run()
109109
await writer.WriteAsync(licenseContent);
110110
}
111111
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!");
112122
}
113123

114124
private string GenerateTxId()
@@ -133,6 +143,12 @@ private async Task<UnityLicenseStatusCheck> RunUnityAndCaptureMachineKeys()
133143
ArgumentList =
134144
{
135145
"-quit",
146+
"-batchmode",
147+
"-username",
148+
_request.Username,
149+
"-password",
150+
_request.Password,
151+
"-force-free"
136152
},
137153
CustomBufferHandler = (buffer) =>
138154
{
@@ -173,6 +189,42 @@ private async Task<UnityLicenseStatusCheck> RunUnityAndCaptureMachineKeys()
173189

174190
throw new InvalidOperationException("Unity didn't provide us with machine keys after 30 licensing attempts...");
175191
}
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+
}
176228

177229
private class UnityLicenseStatusCheck
178230
{

0 commit comments

Comments
 (0)