check invalid file name

This commit is contained in:
PoChangSu 2020-06-25 13:42:54 +09:00
parent 1457b9c125
commit 3ef81b2c8e
2 changed files with 68 additions and 1 deletions

View File

@ -1,4 +1,5 @@
using System.IO;
using System.Text.RegularExpressions;
using UnityEngine;
namespace UniGLTF
@ -63,6 +64,8 @@ namespace UniGLTF
};
public static string EscapeFilePath(this string path)
{
path = Regex.Replace(path, @"[\u0000-\u001F\u007F]", "+");
foreach(var x in EscapeChars)
{
path = path.Replace(x, '+');

View File

@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Linq;
using UniGLTF;
using UnityEditor;
using UnityEngine;
@ -92,6 +93,8 @@ namespace VRM
public bool RemoveVertexColor = false;
#endregion
private const int MAX_LENGTH = 64;
public struct Validation
{
/// <summary>
@ -190,7 +193,7 @@ namespace VRM
if (ReduceBlendshape && Source.GetComponent<VRMBlendShapeProxy>() == null)
{
yield return Validation.Error("ReduceBlendshapeSize is need VRMBlendShapeProxy, you need to convert to VRM once.");
yield return Validation.Error("ReduceBlendshapeSize needs VRMBlendShapeProxy. You need to convert to VRM once.");
}
var vertexColor = Source.GetComponentsInChildren<SkinnedMeshRenderer>().Any(x => x.sharedMesh.colors.Length > 0);
@ -228,6 +231,67 @@ namespace VRM
yield return Validation.Warning(string.Format("unknown material '{0}' is used. this will export as `Standard` fallback", material.shader.name));
}
foreach (var material in materials)
{
if (material.name.Length > MAX_LENGTH)
yield return Validation.Error(string.Format("FileName '{0}' is too long. ", material.name));
}
var textureNameList = new List<string>();
foreach (var material in materials)
{
var shader = material.shader;
int propertyCount = ShaderUtil.GetPropertyCount(shader);
for (int i = 0; i < propertyCount; i++)
{
if (ShaderUtil.GetPropertyType(shader, i) == ShaderUtil.ShaderPropertyType.TexEnv)
{
if ((material.GetTexture(ShaderUtil.GetPropertyName(shader, i)) != null))
{
var textureName = material.GetTexture(ShaderUtil.GetPropertyName(shader, i)).name;
if (!textureNameList.Contains(textureName))
textureNameList.Add(textureName);
}
}
}
}
foreach (var textureName in textureNameList)
{
if (textureName.Length > MAX_LENGTH)
yield return Validation.Error(string.Format("FileName '{0}' is too long. ", textureName));
}
var vrmMeta = Source.GetComponent<VRMMeta>();
if (vrmMeta != null)
{
if (vrmMeta.Meta != null)
{
if (vrmMeta.Meta.Thumbnail != null)
{
var thumbnailName = vrmMeta.Meta.Thumbnail.name;
if (thumbnailName.Length > MAX_LENGTH)
yield return Validation.Error(string.Format("FileName '{0}' is too long. ", thumbnailName));
}
}
}
var meshFilters = Source.GetComponentsInChildren<MeshFilter>();
var meshesName = meshFilters.Select(x => x.sharedMesh.name).Distinct();
foreach (var meshName in meshesName)
{
if (meshName.Length > MAX_LENGTH)
yield return Validation.Error(string.Format("FileName '{0}' is too long. ", meshName));
}
var skinnedmeshRenderers = Source.GetComponentsInChildren<SkinnedMeshRenderer>();
var skinnedmeshesName = skinnedmeshRenderers.Select(x => x.sharedMesh.name).Distinct();
foreach (var skinnedmeshName in skinnedmeshesName)
{
if (skinnedmeshName.Length > MAX_LENGTH)
yield return Validation.Error(string.Format("FileName '{0}' is too long. ", skinnedmeshName));
}
}
/// <summary>