Skip to content

Commit fc02a24

Browse files
author
AJubrey
committed
[CHANGED] we now preserve the environment variables during unit tests
[CHANGED] we now check that the default locations for the vendor locations are valid before using them [CHANGED] we check that the DCC location exists AFTER making sure it is formatted correctly (slashes in correct directions) [CHANGED] made safer the process during which we parse the given string from askMayaVersion()
1 parent 257557b commit fc02a24

File tree

2 files changed

+50
-7
lines changed

2 files changed

+50
-7
lines changed

Assets/FbxExporters/Editor/FbxExportSettings.cs

Lines changed: 38 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -264,14 +264,14 @@ private static string GetMayaLocationFromEnvironmentVariable(string env)
264264
if (string.IsNullOrEmpty(location))
265265
return null;
266266

267-
if (!Directory.Exists(location))
268-
return null;
269-
270267
//Remove any extra slashes on the end
271268
//Maya would accept a single slash in either direction, so we should be able to
272269
location = location.Replace("\\", "/");
273270
location = location.TrimEnd('/');
274271

272+
if (!Directory.Exists(location))
273+
return null;
274+
275275
if (Application.platform == RuntimePlatform.WindowsEditor)
276276
{
277277
//If we are on Windows, we need only go up one location to get to the "Autodesk" folder.
@@ -327,9 +327,32 @@ private static HashSet<string> GetCustomVendorLocations()
327327
private static HashSet<string> GetDefaultVendorLocations()
328328
{
329329
if (Application.platform == RuntimePlatform.WindowsEditor)
330-
return new HashSet<string>() { "C:/Program Files/Autodesk", "D:/Program Files/Autodesk" };
330+
{
331+
HashSet<string> windowsDefaults = new HashSet<string>() { "C:/Program Files/Autodesk", "D:/Program Files/Autodesk" };
332+
HashSet<string> existingDirectories = new HashSet<string>();
333+
foreach (string path in windowsDefaults)
334+
{
335+
if (Directory.Exists(path))
336+
{
337+
existingDirectories.Add(path);
338+
}
339+
}
340+
return existingDirectories;
341+
342+
}
331343
else if (Application.platform == RuntimePlatform.OSXEditor)
332-
return new HashSet<string>() { "/Applications/Autodesk" };
344+
{
345+
HashSet<string> MacOSDefaults = new HashSet<string>() { "/Applications/Autodesk" };
346+
HashSet<string> existingDirectories = new HashSet<string>();
347+
foreach (string path in MacOSDefaults)
348+
{
349+
if (Directory.Exists(path))
350+
{
351+
existingDirectories.Add(path);
352+
}
353+
}
354+
return existingDirectories;
355+
}
333356

334357
throw new NotImplementedException();
335358
}
@@ -807,10 +830,18 @@ static string AskMayaVersion(string exePath) {
807830
// Output is like: Maya 2018, Cut Number 201706261615
808831
// We want the stuff after 'Maya ' and before the comma.
809832
// (Uni-31601) less brittle! Consider also the mel command "about -version".
833+
if (string.IsNullOrEmpty(resultString))
834+
{
835+
return null;
836+
}
837+
838+
resultString = resultString.Trim();
810839
var commaIndex = resultString.IndexOf(',');
811-
if (!string.IsNullOrEmpty(resultString.Trim()))
840+
841+
if (commaIndex != -1)
812842
{
813-
return resultString.Substring(0, commaIndex).Substring("Maya ".Length);
843+
const int versionStart = 5; // length of "Maya "
844+
return resultString.Length > versionStart ? resultString.Substring(0, commaIndex).Substring(versionStart) : null;
814845
}
815846
else
816847
{

Assets/FbxExporters/Editor/UnitTests/FbxExportSettingsTest.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ namespace FbxExporters.UnitTests
1010
public class FbxExportSettingsTest : ExporterTestBase{
1111
ExportSettings m_originalSettings;
1212

13+
//For resetting environment variables:
14+
string originalVendorLocation = null;
15+
string originalMayaLocation = null;
16+
1317
// We read two private fields for the test.
1418
static System.Reflection.FieldInfo s_InstanceField; // static
1519
static System.Reflection.FieldInfo s_SavePathField; // member
@@ -356,6 +360,10 @@ public void VendorLocationInstallationTest1()
356360
//TearDown
357361
public void VendorLocations_TearDown(List<string> vendorInstallFolders)
358362
{
363+
//Put the environment variables back to what they were originally
364+
System.Environment.SetEnvironmentVariable("UNITY_FBX_3DAPP_VENDOR_LOCATIONS", originalVendorLocation);
365+
System.Environment.SetEnvironmentVariable("MAYA_LOCATION", originalMayaLocation);
366+
359367
//Clean up vendor location(s)
360368
foreach (var vendorLocation in vendorInstallFolders)
361369
{
@@ -412,6 +420,10 @@ public void SetEnvironmentVariables(string vendorLocation, string mayaLocationPa
412420

413421
public void VendorLocations_Setup(List<string> paths)
414422
{
423+
//Preserve our environment variables for later
424+
originalVendorLocation = System.Environment.GetEnvironmentVariable("UNITY_FBX_3DAPP_VENDOR_LOCATIONS");
425+
originalMayaLocation = System.Environment.GetEnvironmentVariable("MAYA_LOCATION");
426+
415427
foreach (var pathToExe in paths)
416428
{
417429
//make the directory

0 commit comments

Comments
 (0)