From fbcd00d41af6785c4d45262ccdd16caa14a32dd1 Mon Sep 17 00:00:00 2001 From: Harald Csaszar Date: Wed, 1 Apr 2020 15:18:34 +0200 Subject: [PATCH] [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. --- .../Asset Types/SkeletonDataCompatibility.cs | 38 ++++++++++++------- 1 file changed, 24 insertions(+), 14 deletions(-) diff --git a/spine-unity/Assets/Spine/Runtime/spine-unity/Asset Types/SkeletonDataCompatibility.cs b/spine-unity/Assets/Spine/Runtime/spine-unity/Asset Types/SkeletonDataCompatibility.cs index 68b78f57c..d072a31c7 100644 --- a/spine-unity/Assets/Spine/Runtime/spine-unity/Asset Types/SkeletonDataCompatibility.cs +++ b/spine-unity/Assets/Spine/Runtime/spine-unity/Asset Types/SkeletonDataCompatibility.cs @@ -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; - 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; + 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)root["skeleton"]; - object jv; - skeletonInfo.TryGetValue("spine", out jv); - fileVersion.rawVersion = jv as string; + if (root.ContainsKey("skeleton")) { + var skeletonInfo = (Dictionary)root["skeleton"]; + object jv; + skeletonInfo.TryGetValue("spine", out jv); + fileVersion.rawVersion = jv as string; + } } }