Skip to content

Commit 3740f2f

Browse files
committed
fix: Auto Select Only Client Credential and Deployment During Migration
During migration, if there is only one Credential, select it. If there is only one Deployment, select it. Otherwise, log a warning noting that no Credential/Deployment was selected. Also log a warning if unable to find a matching deployment/client credential.
1 parent 58e52bd commit 3740f2f

File tree

1 file changed

+89
-10
lines changed

1 file changed

+89
-10
lines changed

com.playeveryware.eos/Runtime/Core/Config/PlatformConfig.cs

Lines changed: 89 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -418,26 +418,105 @@ protected virtual void MigrateNonOverrideableConfigValues(EOSConfig overrideValu
418418
ProductConfig productConfig = Get<ProductConfig>();
419419
string compDeploymentString = mainNonOverrideableConfig.deploymentID?.ToLower();
420420

421-
foreach(Named<Deployment> dep in productConfig.Environments.Deployments)
421+
// If the compDeploymentString is explicitly set, then seek that out and use it
422+
if (!string.IsNullOrEmpty(compDeploymentString))
422423
{
423-
if (!string.IsNullOrEmpty(compDeploymentString) && !compDeploymentString.Equals(dep.Value.DeploymentId.ToString("N").ToLowerInvariant()))
424+
Deployment? foundDeployment = null;
425+
426+
foreach (Named<Deployment> dep in productConfig.Environments.Deployments)
424427
{
425-
continue;
428+
if (!compDeploymentString.Equals(dep.Value.DeploymentId.ToString("N").ToLowerInvariant()))
429+
{
430+
continue;
431+
}
432+
433+
foundDeployment = dep.Value;
434+
break;
426435
}
427436

428-
deployment = dep.Value;
429-
break;
437+
// If we didn't find a matching deployment, log about it
438+
if (foundDeployment.HasValue)
439+
{
440+
deployment = foundDeployment.Value;
441+
}
442+
else
443+
{
444+
Debug.LogWarning($"The previous config explicitly identified "
445+
+ $"'{compDeploymentString}' as the Deployment GUID, but "
446+
+ "could not find a deployment with that id in the config. "
447+
+ "You must set the Deployment in the EOS Configuration window.");
448+
}
449+
}
450+
else if (productConfig.Environments.Deployments.Count == 1)
451+
{
452+
// If compDeploymentString wasn't explicitly set, and there was exactly
453+
// one defined deployment, then intuitively use that.
454+
455+
deployment = productConfig.Environments.Deployments[0].Value;
456+
Debug.Log($"The previous config did not explicitly define a " +
457+
$"deployment. There was one defined deployment, automatically " +
458+
$"selecting deployment name '{productConfig.Environments.Deployments[0].Name}' " +
459+
$"with id '{deployment.DeploymentId}'.");
460+
}
461+
else
462+
{
463+
// If there are multiple deployments, we can't auto select one.
464+
// The user will have to set one directly.
465+
Debug.LogWarning($"The previous config did not explicitly define " +
466+
$"a deployment for this platform, and there are more than " +
467+
$"one available deployments. You must sset the Deployment in" +
468+
$"the EOS Configuration window for this platform.");
430469
}
431470

432-
foreach (Named<EOSClientCredentials> creds in productConfig.Clients)
471+
string compClientString = mainNonOverrideableConfig.clientID?.ToLowerInvariant();
472+
// If the compClientString is explicitly set, then seek that out and use it
473+
if (!string.IsNullOrEmpty(compClientString))
433474
{
434-
if (!creds.Value.ClientId.Equals(mainNonOverrideableConfig.clientID))
475+
EOSClientCredentials foundCredentials = null;
476+
477+
foreach (Named<EOSClientCredentials> creds in productConfig.Clients)
435478
{
436-
continue;
479+
if (!compClientString.Equals(creds.Value.ClientId.ToLowerInvariant()))
480+
{
481+
continue;
482+
}
483+
484+
foundCredentials = creds.Value;
485+
break;
437486
}
438487

439-
clientCredentials = creds.Value;
440-
break;
488+
// If we didn't find a matching deployment, log about it
489+
if (foundCredentials != null)
490+
{
491+
clientCredentials = foundCredentials;
492+
}
493+
else
494+
{
495+
Debug.LogWarning($"The previous config explicitly identified "
496+
+ $"'{compClientString}' as the Client ID, but "
497+
+ "could not find client credentials with that id in the config. "
498+
+ "You must set the Client Credentials in the EOS Configuration window.");
499+
}
500+
}
501+
else if (productConfig.Clients.Count == 1)
502+
{
503+
// If compClientString wasn't explicitly set, and there was exactly
504+
// one defined client credential, then intuitively use that.
505+
506+
clientCredentials = productConfig.Clients[0].Value;
507+
Debug.Log($"The previous config did not explicitly define " +
508+
$"client credentials. There was one defined client credential, automatically " +
509+
$"selecting client credential name '{productConfig.Clients[0].Name}' " +
510+
$"with id '{clientCredentials.ClientId}'.");
511+
}
512+
else
513+
{
514+
// If there are multiple deployments, we can't auto select one.
515+
// The user will have to set one directly.
516+
Debug.LogWarning($"The previous config did not explicitly define " +
517+
$"client credentials for this platform, and there are more than " +
518+
$"one available client credentials. You must set the " +
519+
$"Client Credentials in the EOS Configuration window for this platform.");
441520
}
442521
}
443522

0 commit comments

Comments
 (0)