mirror of
https://github.com/vrm-c/UniVRM.git
synced 2026-09-13 14:29:38 -05:00
Merge pull request #2103 from ousttrue/fix/validate_no_sample_copy
Sample コピーが同一かどうかを確認する
This commit is contained in:
@@ -1,11 +1,30 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using UnityEngine;
|
||||
|
||||
namespace VRM
|
||||
{
|
||||
public static class VRMSampleCopy
|
||||
{
|
||||
struct CopyInfo
|
||||
{
|
||||
public string Src;
|
||||
public string Dst;
|
||||
|
||||
public CopyInfo(string src, string dst)
|
||||
{
|
||||
Src = src;
|
||||
Dst = dst;
|
||||
}
|
||||
}
|
||||
|
||||
static CopyInfo[] CopyList = new CopyInfo[]{
|
||||
new CopyInfo(Path.Combine(Application.dataPath, "VRM_Samples"), Path.Combine(Application.dataPath, "VRM/Samples~")),
|
||||
new CopyInfo(Path.Combine(Application.dataPath, "VRM10_Samples"), Path.Combine(Application.dataPath, "VRM10/Samples~")),
|
||||
new CopyInfo(Path.Combine(Application.dataPath, "UniGLTF_Samples"), Path.Combine(Application.dataPath, "UniGLTF/Samples~")),
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// Assets/VRM_Samples
|
||||
/// を
|
||||
@@ -24,9 +43,10 @@ namespace VRM
|
||||
/// </summary>
|
||||
public static void Execute()
|
||||
{
|
||||
Copy(Path.Combine(Application.dataPath, "VRM_Samples"), Path.Combine(Application.dataPath, "VRM/Samples~"));
|
||||
Copy(Path.Combine(Application.dataPath, "VRM10_Samples"), Path.Combine(Application.dataPath, "VRM10/Samples~"));
|
||||
Copy(Path.Combine(Application.dataPath, "UniGLTF_Samples"), Path.Combine(Application.dataPath, "UniGLTF/Samples~"));
|
||||
foreach (var info in CopyList)
|
||||
{
|
||||
Copy(info.Src, info.Dst);
|
||||
}
|
||||
}
|
||||
|
||||
static void Copy(string srcDir, string dstDir)
|
||||
@@ -61,5 +81,61 @@ namespace VRM
|
||||
throw new FileNotFoundException(src);
|
||||
}
|
||||
}
|
||||
|
||||
public static bool Validate()
|
||||
{
|
||||
return CopyList.All(x => _Validate(x.Src, x.Dst));
|
||||
}
|
||||
|
||||
static bool _Validate(string src, string dst)
|
||||
{
|
||||
if (Directory.Exists(src))
|
||||
{
|
||||
if (!Directory.Exists(dst))
|
||||
{
|
||||
Debug.LogError($"{dst} not exists");
|
||||
return false;
|
||||
|
||||
}
|
||||
var list = Directory.EnumerateFileSystemEntries(dst).Select(x => x.Substring(dst.Length + 1)).ToList();
|
||||
foreach (var child in Directory.EnumerateFileSystemEntries(src))
|
||||
{
|
||||
if (!_Validate(child, Path.Combine(dst, Path.GetFileName(child)).Replace("\\", "/")))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
var rel = child.Substring(src.Length + 1);
|
||||
list.Remove(rel);
|
||||
}
|
||||
if (list.Count > 0)
|
||||
{
|
||||
var remain = string.Join(",", list);
|
||||
Debug.LogError($"only dst: {remain}");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
else if (File.Exists(src))
|
||||
{
|
||||
// same file
|
||||
if (!File.Exists(dst))
|
||||
{
|
||||
Debug.LogError($"{dst} not exists");
|
||||
return false;
|
||||
}
|
||||
if (!File.ReadAllBytes(src).SequenceEqual(File.ReadAllBytes(dst)))
|
||||
{
|
||||
Debug.LogError($"{src} != {dst}");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
// throw new FileNotFoundException(src);
|
||||
Debug.LogError($"dir nor file");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -187,6 +187,11 @@ namespace VRM.DevOnly.PackageExporter
|
||||
|
||||
public static void CreateUnityPackages(string outputDir)
|
||||
{
|
||||
if (!VRMSampleCopy.Validate())
|
||||
{
|
||||
throw new Exception("SampleCopy is not same !");
|
||||
}
|
||||
|
||||
{
|
||||
var packages = new[]{
|
||||
// VRM
|
||||
|
||||
Reference in New Issue
Block a user