Skip to content

Commit 23b7046

Browse files
committed
fix: Correct implementation to not assume that the first deployment is defined correctly.
1 parent a00a4ef commit 23b7046

File tree

2 files changed

+29
-19
lines changed

2 files changed

+29
-19
lines changed

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

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ public class ProductConfig : Config
108108
/// process of setting the default deployment for the platforms.
109109
/// </summary>
110110
[JsonIgnore]
111-
private bool _deploymentDefined;
111+
private bool _deploymentDefinedWhenLoaded;
112112

113113
/// <summary>
114114
/// Used to store information about what platform configs have been
@@ -143,8 +143,10 @@ protected ProductConfig() : base("eos_product_config.json") { }
143143

144144
protected override void OnReadCompleted()
145145
{
146-
// This tracks whether there is a single deployment defined.
147-
_deploymentDefined = Environments.IsDeploymentDefined;
146+
// This tracks whether there is a single deployment defined. The
147+
// out parameter is discarded because it is not needed at this
148+
// juncture.
149+
_deploymentDefinedWhenLoaded = Environments.TryGetFirstDefinedNamedDeployment(out _);
148150
}
149151

150152
// This compile conditional is here because the OnWriteCompleted method
@@ -157,26 +159,26 @@ protected override void BeforeWrite()
157159
// If there is one deployment, and one sandbox, then make sure they
158160
// are linked to each other if the sandbox is not empty.
159161
// But only do this if they have been newly added
160-
if (!_deploymentDefined && Environments.Deployments.Count ==1 && Environments.Sandboxes.Count == 1 && !Environments.Sandboxes[0].Value.IsEmpty)
162+
if (!_deploymentDefinedWhenLoaded && Environments.Deployments.Count ==1 && Environments.Sandboxes.Count == 1 && !Environments.Sandboxes[0].Value.IsEmpty)
161163
{
162164
Environments.Deployments[0].Value.SandboxId = Environments.Sandboxes[0].Value;
163165
}
164166
}
165167

166168
protected override void OnWriteCompleted()
167169
{
170+
bool definedDeploymentExists =
171+
Environments.TryGetFirstDefinedNamedDeployment(out Named<Deployment> deploymentToSetPlatformsTo);
172+
168173
// If when the config was last read there was a deployment defined,
169174
// or there is not now one defined - then there is no need to try
170175
// and set the deployment values for each platform config.
171-
if (_deploymentDefined || !Environments.IsDeploymentDefined)
176+
if (_deploymentDefinedWhenLoaded ||
177+
!definedDeploymentExists)
172178
{
173179
return;
174180
}
175181

176-
// Select the first defined deployment as the deployment to set
177-
// platform configs to use.
178-
Named<Deployment> deploymentToSetPlatformsTo = Environments.Deployments[0];
179-
180182
List<PlatformManager.Platform> platformConfigsUpdated = new();
181183

182184
// For each platform for which configuration can be done

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

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -51,22 +51,30 @@ public ProductionEnvironments()
5151
}
5252

5353
/// <summary>
54-
/// Indicates whether there is at least one complete deployment defined.
54+
/// Tries to retrieve the first defined named deployment.
5555
/// </summary>
56-
public bool IsDeploymentDefined
56+
/// <param name="deployment">
57+
/// The first named deployment that has been determined to be defined.
58+
/// </param>
59+
/// <returns>
60+
/// True if there was a defined named deployment found, false otherwise.
61+
/// </returns>
62+
public bool TryGetFirstDefinedNamedDeployment(out Named<Deployment> deployment)
5763
{
58-
get
64+
deployment = null;
65+
66+
// Go through the deployments
67+
foreach (var dep in Deployments)
5968
{
60-
foreach (var deployment in Deployments)
69+
// If the deployment is complete then stop
70+
if (dep.Value.IsComplete)
6171
{
62-
if (deployment.Value.IsComplete)
63-
{
64-
return true;
65-
}
72+
deployment = dep;
73+
break;
6674
}
67-
68-
return false;
6975
}
76+
77+
return (deployment == null);
7078
}
7179

7280
/// <summary>

0 commit comments

Comments
 (0)