[unity] Replaced full json parsing for version string in SkeletonDataCompatibility.GetVersionInfo() with lightweight regex variant (fallback to full parsing). Affects editor only, built binary always excluded GetVersionInfo() checks.

This commit is contained in:
Harald Csaszar 2020-04-01 15:18:34 +02:00
parent b566bfb0b9
commit fbcd00d41a

View File

@ -30,7 +30,10 @@
using System.Collections.Generic;
using System.IO;
using UnityEngine;
#if UNITY_EDITOR
using System.Globalization;
using System.Text.RegularExpressions;
#endif
namespace Spine.Unity {
@ -41,6 +44,7 @@ namespace Spine.Unity {
static readonly int[][] compatibleJsonVersions = { new[] { 3, 8, 0 } };
static bool wasVersionDialogShown = false;
static readonly Regex jsonVersionRegex = new Regex(@"""spine""\s*:\s*""([^""]+)""", RegexOptions.CultureInvariant);
#endif
public enum SourceType {
@ -92,23 +96,29 @@ namespace Spine.Unity {
}
}
else {
object obj = Json.Deserialize(new StringReader(asset.text));
if (obj == null) {
Debug.LogErrorFormat("'{0}' is not valid JSON.", asset.name);
return null;
Match match = jsonVersionRegex.Match(asset.text);
if (match != null) {
fileVersion.rawVersion = match.Groups[1].Value;
}
else {
object obj = Json.Deserialize(new StringReader(asset.text));
if (obj == null) {
Debug.LogErrorFormat("'{0}' is not valid JSON.", asset.name);
return null;
}
var root = obj as Dictionary<string, object>;
if (root == null) {
Debug.LogErrorFormat("'{0}' is not compatible JSON. Parser returned an incorrect type while parsing version info.", asset.name);
return null;
}
var root = obj as Dictionary<string, object>;
if (root == null) {
Debug.LogErrorFormat("'{0}' is not compatible JSON. Parser returned an incorrect type while parsing version info.", asset.name);
return null;
}
if (root.ContainsKey("skeleton")) {
var skeletonInfo = (Dictionary<string, object>)root["skeleton"];
object jv;
skeletonInfo.TryGetValue("spine", out jv);
fileVersion.rawVersion = jv as string;
if (root.ContainsKey("skeleton")) {
var skeletonInfo = (Dictionary<string, object>)root["skeleton"];
object jv;
skeletonInfo.TryGetValue("spine", out jv);
fileVersion.rawVersion = jv as string;
}
}
}