Skip to content

Commit 852451a

Browse files
committed
fix: Correct implementation so that improperly formatted Sandbox values are handled correctly.
1 parent 23b7046 commit 852451a

File tree

2 files changed

+44
-21
lines changed

2 files changed

+44
-21
lines changed

Assets/Plugins/Source/Editor/Utility/GUIEditorUtility.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -975,9 +975,9 @@ private static void RenderSandboxInputs(ref ProductionEnvironments value)
975975
}
976976

977977
item.Value.Value = RenderFieldWithHint(
978-
EditorGUI.TextField,
978+
EditorGUI.DelayedTextField,
979979
new Rect(currentX, rect.y, remainingWidth - 10f, rect.height),
980-
string.IsNullOrEmpty,
980+
SandboxId.IsNullOrEmpty,
981981
item.Value.Value,
982982
"Sandbox Id");
983983
},

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

Lines changed: 42 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -46,31 +46,55 @@ readonly get
4646
return;
4747
}
4848

49-
if (!Guid.TryParse(value, out _))
49+
// Store previous value
50+
string previousValue = _value;
51+
52+
// Set the value, and test for validity
53+
_value = value.ToLower();
54+
55+
// If the newly set value is valid, stop here.
56+
if (IsValid())
5057
{
51-
if (!Regex.IsMatch(value, PreProductionEnvironmentRegex))
52-
{
53-
throw new ArgumentException(
54-
"Value for SandboxId must either be " +
55-
"parseable to a Guid, or it must start with a " +
56-
"lowercase 'p', followed by a dash and thirty " +
57-
"letter characters.");
58-
}
58+
return;
5959
}
60-
else
60+
61+
// Otherwise, log a warning and return the value to what it was
62+
// before an attempt was made to change it.
63+
// TODO: Figure out how to have this manifest in the editor
64+
// window instead of just the log.
65+
string logMessage = $"Invalid SandboxId: \"{_value}\".";
66+
67+
// If the previous value wasn't null, then inform the user that
68+
// the value is being restored to the previous.
69+
if (previousValue != null)
6170
{
62-
// If the Guid was correctly parsed, then considering that
63-
// the EOS SDK prefers SandboxId to be lowercase without
64-
// dashes, do this just to be sure.
65-
value = value.Replace("-", "");
71+
logMessage += $"Restoring to previous value of \"{previousValue}\".";
6672
}
6773

68-
// Whether the value was correctly matched to the regex or it
69-
// was a Guid, it still should be lowercase.
70-
_value = value.ToLower();
74+
// Actually log the composed message.
75+
UnityEngine.Debug.LogWarning(logMessage);
76+
77+
_value = previousValue;
7178
}
7279
}
7380

81+
public bool IsValid()
82+
{
83+
return Guid.TryParse(_value, out _) ||
84+
Regex.IsMatch(_value, PreProductionEnvironmentRegex);
85+
}
86+
87+
public static bool IsNullOrEmpty(string sandboxString)
88+
{
89+
return String.IsNullOrEmpty(sandboxString) ||
90+
Guid.Empty.ToString("N").Equals(sandboxString);
91+
}
92+
93+
public static bool IsNullOrEmpty(SandboxId sandboxId)
94+
{
95+
return IsNullOrEmpty(sandboxId._value);
96+
}
97+
7498
/// <summary>
7599
/// Indicates whether the sandbox id is empty. A sandbox id is empty if
76100
/// either the underlying value is null or empty, or if the underlying
@@ -84,8 +108,7 @@ public readonly bool IsEmpty
84108
{
85109
get
86110
{
87-
return String.IsNullOrEmpty(_value) ||
88-
Guid.Empty.ToString("N").Equals(_value);
111+
return IsNullOrEmpty(this);
89112
}
90113
}
91114

0 commit comments

Comments
 (0)