Skip to content

Commit 2c23d33

Browse files
authored
Merge pull request #1101 from PlayEveryWare/fix/cli-arguments
fix: Complete application of command line arguments from the Epic Games Launcher
2 parents 3cbfcde + b2426ba commit 2c23d33

File tree

2 files changed

+87
-22
lines changed

2 files changed

+87
-22
lines changed

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,13 @@ public static bool IsNullOrEmpty(SandboxId sandboxId)
101101
return IsNullOrEmpty(sandboxId._value);
102102
}
103103

104+
public static SandboxId FromString(string sandboxString)
105+
{
106+
SandboxId retVal = default;
107+
retVal.Value = sandboxString;
108+
return retVal;
109+
}
110+
104111
/// <summary>
105112
/// Indicates whether the sandbox id is empty. A sandbox id is empty if
106113
/// either the underlying value is null or empty, or if the underlying

com.playeveryware.eos/Runtime/Core/EOSManager.cs

Lines changed: 80 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -491,40 +491,98 @@ private void InitializeOverlay(IEOSCoroutineOwner coroutineOwner)
491491
});
492492
}
493493

494-
private void ConfigureCommandLineOptions()
494+
/// <summary>
495+
/// This function applies any command line arguments that may have
496+
/// been provided to the application from the Epic Games Launcher.
497+
/// </summary>
498+
private void ApplyCommandLineArguments()
495499
{
496-
// TODO: Make more complete the support for command line arguments.
497-
var epicArgs = GetCommandLineArgsFromEpicLauncher();
500+
EpicLauncherArgs epicArgs = GetCommandLineArgsFromEpicLauncher();
498501

499-
if (string.IsNullOrWhiteSpace(epicArgs.epicSandboxID))
502+
// If neither the sandbox id nor the deployment id have been specified on the command line, the application of the arguments can stop here.
503+
if (string.IsNullOrEmpty(epicArgs.epicSandboxID) && string.IsNullOrEmpty(epicArgs.epicDeploymentID))
500504
{
501505
return;
502506
}
503507

504-
var definedProductionEnvironments = Config.Get<ProductConfig>().Environments;
505-
bool sandboxOverridden = false;
506-
foreach (Named<SandboxId> sandbox in definedProductionEnvironments.Sandboxes)
508+
ProductConfig productConfig = Config.Get<ProductConfig>();
509+
510+
if (!string.IsNullOrEmpty(epicArgs.epicSandboxID))
507511
{
508-
if (sandbox.Value.ToString() != epicArgs.epicSandboxID.ToLower())
512+
bool sandboxDefined = false;
513+
SandboxId sandboxFromCommandLine = SandboxId.FromString(epicArgs.epicSandboxID);
514+
foreach (var namedSandbox in productConfig.Environments.Sandboxes)
509515
{
510-
continue;
516+
if (namedSandbox.Value.Equals(sandboxFromCommandLine))
517+
{
518+
Debug.Log($"{namedSandbox} selected as sandbox.");
519+
sandboxDefined = true;
520+
break;
521+
}
511522
}
512523

513-
PlatformManager.GetPlatformConfig().deployment.SandboxId = sandbox.Value;
514-
sandboxOverridden = true;
515-
Debug.Log($"SandboxID was overridden to be \"{sandbox.Value}\" by a command line parameter.");
516-
break;
524+
PlatformManager.GetPlatformConfig().deployment.SandboxId = sandboxFromCommandLine;
525+
526+
if (!sandboxDefined)
527+
{
528+
Debug.LogWarning(
529+
$"Sandbox Id \"{sandboxFromCommandLine}\" was " +
530+
$"provided on the command line, but was not " +
531+
$"found in the product config. Attempting to use " +
532+
$"it regardless.");
533+
}
517534
}
518535

519-
if (!sandboxOverridden)
536+
if (!string.IsNullOrEmpty(epicArgs.epicDeploymentID))
520537
{
521-
Debug.LogWarning(
522-
$"The SandboxID " +
523-
$"\"{epicArgs.epicSandboxID}\" specified by " +
524-
$"command line argument is not a valid id. " +
525-
$"Defaulting to SandboxID " +
526-
$"\"{PlatformManager.GetPlatformConfig().deployment.SandboxId}\" " +
527-
$"defined in the configuration.");
538+
bool deploymentDefined = false;
539+
540+
foreach (var namedDeployment in productConfig.Environments.Deployments)
541+
{
542+
// Check for equality regardless of case - and
543+
// regardless of whether the dashes are included in the
544+
// Guid for the purposes of comparison.
545+
if (namedDeployment.Value.DeploymentId.ToString().Equals(epicArgs.epicDeploymentID,
546+
StringComparison.OrdinalIgnoreCase) ||
547+
namedDeployment.Value.DeploymentId.ToString("N").Equals(epicArgs.epicDeploymentID,
548+
StringComparison.OrdinalIgnoreCase))
549+
{
550+
Debug.Log($"{namedDeployment} selected as deployment.");
551+
deploymentDefined = true;
552+
break;
553+
}
554+
}
555+
556+
// NOTE: An empty guid is known to cause the EOS SDK to fail
557+
// to initialize - however in the native code when
558+
// this same operation is done, no check is performed
559+
// on whether the Guid is a valid Guid. This
560+
// implementation has been written to provide
561+
// verisimilitude with the native implementation on
562+
// Windows. Regardless - a warning is logged here -
563+
// despite the fact that it could be arguably be
564+
// logged as an error.
565+
if (!Guid.TryParse(epicArgs.epicDeploymentID, out Guid deploymentFromCommandLine))
566+
{
567+
Debug.LogWarning(
568+
$"ERROR: Invalid Guid " +
569+
$"\"{epicArgs.epicDeploymentID}\" for Deployment " +
570+
$"Id was provided on the command line. EOS SDK " +
571+
$"will almost certainly fail to initialize.");
572+
573+
deploymentFromCommandLine = Guid.Empty;
574+
}
575+
576+
PlatformManager.GetPlatformConfig().deployment.DeploymentId = deploymentFromCommandLine;
577+
578+
if (!deploymentFromCommandLine.Equals(Guid.Empty) && !deploymentDefined)
579+
{
580+
Debug.LogWarning(
581+
$"Deployment \"{deploymentFromCommandLine}\" was " +
582+
$"provided on the command line, but was not " +
583+
$"found in the product config. Attempting to use " +
584+
$"it regardless.");
585+
}
528586
}
529587
}
530588

@@ -560,7 +618,7 @@ public void Init(IEOSCoroutineOwner coroutineOwner, string configFileName = null
560618
InitializeLogLevels();
561619
#endif
562620

563-
ConfigureCommandLineOptions();
621+
ApplyCommandLineArguments();
564622

565623
Result initResult = InitializePlatformInterface();
566624

0 commit comments

Comments
 (0)