Browse Source

Wavefront format has issues with file names with spaces, but there's no need to check the whole path.

Fixes #70
Vicente Penades 5 years ago
parent
commit
3d3cd96c02

+ 5 - 1
src/SharpGLTF.Toolkit/IO/WavefrontWriter.cs

@@ -47,10 +47,12 @@ namespace SharpGLTF.IO
 
 
         public void WriteFiles(string filePath)
         public void WriteFiles(string filePath)
         {
         {
-            var dir = System.IO.Path.GetDirectoryName(filePath);
+            Guard.NotNullOrEmpty(filePath, nameof(filePath));
 
 
             var files = GetFiles(System.IO.Path.GetFileNameWithoutExtension(filePath));
             var files = GetFiles(System.IO.Path.GetFileNameWithoutExtension(filePath));
 
 
+            var dir = System.IO.Path.GetDirectoryName(filePath);
+
             foreach (var f in files)
             foreach (var f in files)
             {
             {
                 var fpath = System.IO.Path.Combine(dir, f.Key);
                 var fpath = System.IO.Path.Combine(dir, f.Key);
@@ -60,6 +62,8 @@ namespace SharpGLTF.IO
 
 
         public IReadOnlyDictionary<String, BYTES> GetFiles(string baseName)
         public IReadOnlyDictionary<String, BYTES> GetFiles(string baseName)
         {
         {
+            Guard.IsFalse(baseName.Any(c => char.IsWhiteSpace(c)), nameof(baseName), "Whitespace characters not allowed in filename");
+
             var files = new Dictionary<String, BYTES>();
             var files = new Dictionary<String, BYTES>();
 
 
             var materials = _WriteMaterials(files, baseName, _Mesh.Primitives.Select(item => item.Material));
             var materials = _WriteMaterials(files, baseName, _Mesh.Primitives.Select(item => item.Material));

+ 0 - 4
src/SharpGLTF.Toolkit/Schema2/MeshExtensions.cs

@@ -742,8 +742,6 @@ namespace SharpGLTF.Schema2
         public static void SaveAsWavefront(this ModelRoot model, string filePath)
         public static void SaveAsWavefront(this ModelRoot model, string filePath)
         {
         {
             Guard.NotNull(model, nameof(model));
             Guard.NotNull(model, nameof(model));
-            Guard.NotNullOrEmpty(filePath, nameof(filePath));
-            Guard.IsFalse(filePath.Any(c => char.IsWhiteSpace(c)), nameof(filePath), "Whitespace characters not allowed in filename");
 
 
             var wf = new IO.WavefrontWriter();
             var wf = new IO.WavefrontWriter();
             wf.AddModel(model);
             wf.AddModel(model);
@@ -753,8 +751,6 @@ namespace SharpGLTF.Schema2
         public static void SaveAsWavefront(this ModelRoot model, string filePath, Animation animation, float time)
         public static void SaveAsWavefront(this ModelRoot model, string filePath, Animation animation, float time)
         {
         {
             Guard.NotNull(model, nameof(model));
             Guard.NotNull(model, nameof(model));
-            Guard.NotNullOrEmpty(filePath, nameof(filePath));
-            Guard.IsFalse(filePath.Any(c => char.IsWhiteSpace(c)), nameof(filePath), "Whitespace characters not allowed in filename");
 
 
             var wf = new IO.WavefrontWriter();
             var wf = new IO.WavefrontWriter();
             wf.AddModel(model, animation, time);
             wf.AddModel(model, animation, time);