Skip to content

Commit 3767a51

Browse files
committed
preview review changes - please test
1 parent cf0d1b1 commit 3767a51

File tree

1 file changed

+54
-33
lines changed

1 file changed

+54
-33
lines changed

Assets/FbxExporters/Editor/FbxExportSettings.cs

Lines changed: 54 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ private static string DefaultIntegrationSavePath {
252252
}
253253
}
254254

255-
private static string GetVendorLocationFromEnv(string env)
255+
private static string GetMayaLocationFromEnvironmentVariable(string env)
256256
{
257257
string result = null;
258258

@@ -270,7 +270,7 @@ private static string GetVendorLocationFromEnv(string env)
270270
//Remove any extra slashes on the end
271271
//Maya would accept a single slash in either direction, so we should be able to
272272
location = location.Replace("\\", "/");
273-
location.TrimEnd('/');
273+
location = location.TrimEnd('/');
274274

275275
if (Application.platform == RuntimePlatform.WindowsEditor)
276276
{
@@ -281,22 +281,29 @@ private static string GetVendorLocationFromEnv(string env)
281281
{
282282
//We can assume our path is: /Applications/Autodesk/maya2017/Maya.app/Contents
283283
//So we need to go up three folders.
284+
Debug.Log(string.Format("parsing location {0}",location));
285+
284286

285287
var appFolder = Directory.GetParent(location);
286288
if (appFolder != null)
287289
{
290+
Debug.Log(string.Format("parsing appFolder {0}",appFolder.ToString()));
288291
var versionFolder = Directory.GetParent(appFolder.ToString());
289292
if (versionFolder != null)
290293
{
291294
var autoDeskFolder = Directory.GetParent(versionFolder.ToString());
295+
Debug.Log(string.Format("parsing versionFolder {0}",versionFolder.ToString()));
292296
if (autoDeskFolder != null)
293297
{
298+
Debug.Log(string.Format("return autoDeskFolder {0}",autoDeskFolder.ToString()));
299+
294300
result = autoDeskFolder.ToString();
295301
}
296302
}
297303
}
298304
}
299305

306+
Debug.Log(string.Format("found location {0}",result));
300307
return result;
301308
}
302309

@@ -349,7 +356,7 @@ public static string[] DCCVendorLocations
349356
result = GetDefaultVendorLocations();
350357
}
351358

352-
var additionalLocation = GetVendorLocationFromEnv("MAYA_LOCATION");
359+
var additionalLocation = GetMayaLocationFromEnvironmentVariable("MAYA_LOCATION");
353360

354361
if (!string.IsNullOrEmpty(additionalLocation))
355362
{
@@ -457,7 +464,7 @@ public void ClearDCCOptionNames()
457464
/// Will always take any Maya version over any 3ds Max version.
458465
///
459466
/// Returns the index of the most recent program in the list of dccOptionNames
460-
///
467+
/// Returns -1 on error.
461468
/// </summary>
462469
public int GetPreferredDCCApp()
463470
{
@@ -466,33 +473,41 @@ public int GetPreferredDCCApp()
466473
return -1;
467474
}
468475

469-
int newestDCCVersionIndex = -1;
476+
int result = -1;
470477
int newestDCCVersionNumber = -1;
471478

472479
for (int i = 0; i < dccOptionNames.Count; i++)
473480
{
481+
Debug.Log(string.Format("check name for version : {0}", dccOptionNames[i]));
482+
474483
int versionToCheck = FindDCCVersion(dccOptionNames[i]);
475484
if (versionToCheck == -1)
476485
{
486+
if (dccOptionNames[i]=="MAYA_LOCATION")
487+
return i;
488+
477489
continue;
478490
}
479491
if (versionToCheck > newestDCCVersionNumber)
480492
{
481-
newestDCCVersionIndex = i;
493+
result = i;
482494
newestDCCVersionNumber = versionToCheck;
483495
}
484496
else if (versionToCheck == newestDCCVersionNumber)
485497
{
486-
int selection = ChoosePreferredDCCApp(newestDCCVersionIndex, i);
498+
int selection = ChoosePreferredDCCApp(result, i);
487499
if (selection == i)
488500
{
489-
newestDCCVersionIndex = i;
501+
result = i;
490502
newestDCCVersionNumber = FindDCCVersion(dccOptionNames[i]);
491503
}
492504
}
493505
}
494-
Debug.Assert(newestDCCVersionIndex >= -1 && newestDCCVersionIndex < dccOptionNames.Count);
495-
return newestDCCVersionIndex;
506+
507+
Debug.Log(string.Format("found index : {0} {1}", result, dccOptionNames.Count));
508+
Debug.Assert(result > -1 && result < dccOptionNames.Count);
509+
510+
return result;
496511
}
497512
/// <summary>
498513
/// Takes the index of two program names from dccOptionNames and chooses our preferred one based on the preference list
@@ -529,20 +544,23 @@ private int ChoosePreferredDCCApp(int optionA, int optionB)
529544
/// <returns> the year/version OR -1 if the year could not be parsed </returns>
530545
private static int FindDCCVersion(string AppName)
531546
{
532-
if (AppName == null)
547+
if (string.IsNullOrEmpty(AppName))
533548
{
534549
return -1;
535550
}
536-
537-
int version;
551+
AppName = AppName.Trim();
552+
if (string.IsNullOrEmpty(AppName))
553+
return -1;
554+
538555
string[] piecesArray = AppName.Split(' ');
539-
if (piecesArray.Length == 0)
556+
if (piecesArray.Length < 2)
540557
{
541558
return -1;
542559
}
543560
//Get the number, which is always the last chunk separated by a space.
544561
string number = piecesArray[piecesArray.Length - 1];
545562

563+
int version;
546564
if (int.TryParse(number, out version))
547565
{
548566
return version;
@@ -566,11 +584,14 @@ private static int FindDCCVersion(string AppName)
566584
/// If MAYA_LOCATION is set, add this to the list as well.
567585
/// </summary>
568586
private static void FindDCCInstalls() {
569-
var dccOptionName = instance.dccOptionNames;
570-
var dccOptionPath = instance.dccOptionPaths;
587+
var dccOptionNames = instance.dccOptionNames;
588+
var dccOptionPaths = instance.dccOptionPaths;
571589

590+
// find dcc installation from vendor locations
572591
for (int i = 0; i < DCCVendorLocations.Length; i++)
573592
{
593+
Debug.Log( "checking vendor location for installs " + DCCVendorLocations[i] );
594+
574595
if (!Directory.Exists(DCCVendorLocations[i]))
575596
{
576597
// no autodesk products installed
@@ -580,14 +601,16 @@ private static void FindDCCInstalls() {
580601
// either the newest version, or the exact version we wanted.
581602
var adskRoot = new System.IO.DirectoryInfo(DCCVendorLocations[i]);
582603
foreach (var productDir in adskRoot.GetDirectories())
583-
{
604+
{
605+
Debug.Log( "product " + productDir.FullName );
606+
584607
var product = productDir.Name;
585608

586609
// Only accept those that start with 'maya' in either case.
587610
if (product.StartsWith ("maya", StringComparison.InvariantCultureIgnoreCase)) {
588611
string version = product.Substring ("maya".Length);
589-
dccOptionPath.Add (GetMayaExePath (productDir.FullName.Replace ("\\", "/")));
590-
dccOptionName.Add (GetUniqueDCCOptionName(kMayaOptionName + version));
612+
dccOptionPaths.Add (GetMayaExePathFromLocation (productDir.FullName.Replace ("\\", "/")));
613+
dccOptionNames.Add (GetUniqueDCCOptionName(kMayaOptionName + version));
591614
continue;
592615
}
593616

@@ -603,23 +626,21 @@ private static void FindDCCInstalls() {
603626
continue;
604627
}
605628

606-
dccOptionPath.Add(exePath);
607-
dccOptionName.Add(maxOptionName);
629+
dccOptionPaths.Add(exePath);
630+
dccOptionNames.Add(maxOptionName);
608631
}
609632
}
610633
}
611-
var location = System.Environment.GetEnvironmentVariable("MAYA_LOCATION");
612-
if (!string.IsNullOrEmpty(location))
634+
635+
// add extra locations defined by special environment variables
636+
string location = GetMayaLocationFromEnvironmentVariable("MAYA_LOCATION");
637+
638+
if (!string.IsNullOrEmpty(location))
613639
{
614-
location = location.TrimEnd('/');
615-
string pathToAdd = GetMayaExePath(location.Replace("\\", "/"));
616-
//If this path is already a part of our list, don't add it
617-
if (!dccOptionPath.Contains(pathToAdd) && Directory.Exists(pathToAdd))
618-
{
619-
dccOptionPath.Add(pathToAdd);
620-
dccOptionName.Add("MAYA_LOCATION");
621-
}
640+
dccOptionPaths.Add(GetMayaExePathFromLocation(location));
641+
dccOptionNames.Add("MAYA_LOCATION");
622642
}
643+
623644
instance.selectedDCCApp = instance.GetPreferredDCCApp();
624645
}
625646

@@ -647,7 +668,7 @@ public static string GetFirstValidVendorLocation()
647668
/// </summary>
648669
/// <returns>The maya exe path.</returns>
649670
/// <param name="location">Location of Maya install.</param>
650-
private static string GetMayaExePath(string location)
671+
private static string GetMayaExePathFromLocation(string location)
651672
{
652673
switch (Application.platform) {
653674
case RuntimePlatform.WindowsEditor:
@@ -727,7 +748,7 @@ public enum DCCType { Maya, Max };
727748
public static void AddDCCOption(string newOption, DCCType dcc){
728749
if (Application.platform == RuntimePlatform.OSXEditor && dcc == DCCType.Maya) {
729750
// on OSX we get a path ending in .app, which is not quite the exe
730-
newOption = GetMayaExePath(newOption);
751+
newOption = GetMayaExePathFromLocation(newOption);
731752
}
732753

733754
var dccOptionPaths = instance.dccOptionPaths;

0 commit comments

Comments
 (0)