@@ -252,7 +252,7 @@ private static string DefaultIntegrationSavePath {
252
252
}
253
253
}
254
254
255
- private static string GetVendorLocationFromEnv ( string env )
255
+ private static string GetMayaLocationFromEnvironmentVariable ( string env )
256
256
{
257
257
string result = null ;
258
258
@@ -270,7 +270,7 @@ private static string GetVendorLocationFromEnv(string env)
270
270
//Remove any extra slashes on the end
271
271
//Maya would accept a single slash in either direction, so we should be able to
272
272
location = location . Replace ( "\\ " , "/" ) ;
273
- location . TrimEnd ( '/' ) ;
273
+ location = location . TrimEnd ( '/' ) ;
274
274
275
275
if ( Application . platform == RuntimePlatform . WindowsEditor )
276
276
{
@@ -281,22 +281,29 @@ private static string GetVendorLocationFromEnv(string env)
281
281
{
282
282
//We can assume our path is: /Applications/Autodesk/maya2017/Maya.app/Contents
283
283
//So we need to go up three folders.
284
+ Debug . Log ( string . Format ( "parsing location {0}" , location ) ) ;
285
+
284
286
285
287
var appFolder = Directory . GetParent ( location ) ;
286
288
if ( appFolder != null )
287
289
{
290
+ Debug . Log ( string . Format ( "parsing appFolder {0}" , appFolder . ToString ( ) ) ) ;
288
291
var versionFolder = Directory . GetParent ( appFolder . ToString ( ) ) ;
289
292
if ( versionFolder != null )
290
293
{
291
294
var autoDeskFolder = Directory . GetParent ( versionFolder . ToString ( ) ) ;
295
+ Debug . Log ( string . Format ( "parsing versionFolder {0}" , versionFolder . ToString ( ) ) ) ;
292
296
if ( autoDeskFolder != null )
293
297
{
298
+ Debug . Log ( string . Format ( "return autoDeskFolder {0}" , autoDeskFolder . ToString ( ) ) ) ;
299
+
294
300
result = autoDeskFolder . ToString ( ) ;
295
301
}
296
302
}
297
303
}
298
304
}
299
305
306
+ Debug . Log ( string . Format ( "found location {0}" , result ) ) ;
300
307
return result ;
301
308
}
302
309
@@ -349,7 +356,7 @@ public static string[] DCCVendorLocations
349
356
result = GetDefaultVendorLocations ( ) ;
350
357
}
351
358
352
- var additionalLocation = GetVendorLocationFromEnv ( "MAYA_LOCATION" ) ;
359
+ var additionalLocation = GetMayaLocationFromEnvironmentVariable ( "MAYA_LOCATION" ) ;
353
360
354
361
if ( ! string . IsNullOrEmpty ( additionalLocation ) )
355
362
{
@@ -457,7 +464,7 @@ public void ClearDCCOptionNames()
457
464
/// Will always take any Maya version over any 3ds Max version.
458
465
///
459
466
/// Returns the index of the most recent program in the list of dccOptionNames
460
- ///
467
+ /// Returns -1 on error.
461
468
/// </summary>
462
469
public int GetPreferredDCCApp ( )
463
470
{
@@ -466,33 +473,41 @@ public int GetPreferredDCCApp()
466
473
return - 1 ;
467
474
}
468
475
469
- int newestDCCVersionIndex = - 1 ;
476
+ int result = - 1 ;
470
477
int newestDCCVersionNumber = - 1 ;
471
478
472
479
for ( int i = 0 ; i < dccOptionNames . Count ; i ++ )
473
480
{
481
+ Debug . Log ( string . Format ( "check name for version : {0}" , dccOptionNames [ i ] ) ) ;
482
+
474
483
int versionToCheck = FindDCCVersion ( dccOptionNames [ i ] ) ;
475
484
if ( versionToCheck == - 1 )
476
485
{
486
+ if ( dccOptionNames [ i ] == "MAYA_LOCATION" )
487
+ return i ;
488
+
477
489
continue ;
478
490
}
479
491
if ( versionToCheck > newestDCCVersionNumber )
480
492
{
481
- newestDCCVersionIndex = i ;
493
+ result = i ;
482
494
newestDCCVersionNumber = versionToCheck ;
483
495
}
484
496
else if ( versionToCheck == newestDCCVersionNumber )
485
497
{
486
- int selection = ChoosePreferredDCCApp ( newestDCCVersionIndex , i ) ;
498
+ int selection = ChoosePreferredDCCApp ( result , i ) ;
487
499
if ( selection == i )
488
500
{
489
- newestDCCVersionIndex = i ;
501
+ result = i ;
490
502
newestDCCVersionNumber = FindDCCVersion ( dccOptionNames [ i ] ) ;
491
503
}
492
504
}
493
505
}
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 ;
496
511
}
497
512
/// <summary>
498
513
/// 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)
529
544
/// <returns> the year/version OR -1 if the year could not be parsed </returns>
530
545
private static int FindDCCVersion ( string AppName )
531
546
{
532
- if ( AppName == null )
547
+ if ( string . IsNullOrEmpty ( AppName ) )
533
548
{
534
549
return - 1 ;
535
550
}
536
-
537
- int version ;
551
+ AppName = AppName . Trim ( ) ;
552
+ if ( string . IsNullOrEmpty ( AppName ) )
553
+ return - 1 ;
554
+
538
555
string [ ] piecesArray = AppName . Split ( ' ' ) ;
539
- if ( piecesArray . Length == 0 )
556
+ if ( piecesArray . Length < 2 )
540
557
{
541
558
return - 1 ;
542
559
}
543
560
//Get the number, which is always the last chunk separated by a space.
544
561
string number = piecesArray [ piecesArray . Length - 1 ] ;
545
562
563
+ int version ;
546
564
if ( int . TryParse ( number , out version ) )
547
565
{
548
566
return version ;
@@ -566,11 +584,14 @@ private static int FindDCCVersion(string AppName)
566
584
/// If MAYA_LOCATION is set, add this to the list as well.
567
585
/// </summary>
568
586
private static void FindDCCInstalls ( ) {
569
- var dccOptionName = instance . dccOptionNames ;
570
- var dccOptionPath = instance . dccOptionPaths ;
587
+ var dccOptionNames = instance . dccOptionNames ;
588
+ var dccOptionPaths = instance . dccOptionPaths ;
571
589
590
+ // find dcc installation from vendor locations
572
591
for ( int i = 0 ; i < DCCVendorLocations . Length ; i ++ )
573
592
{
593
+ Debug . Log ( "checking vendor location for installs " + DCCVendorLocations [ i ] ) ;
594
+
574
595
if ( ! Directory . Exists ( DCCVendorLocations [ i ] ) )
575
596
{
576
597
// no autodesk products installed
@@ -580,14 +601,16 @@ private static void FindDCCInstalls() {
580
601
// either the newest version, or the exact version we wanted.
581
602
var adskRoot = new System . IO . DirectoryInfo ( DCCVendorLocations [ i ] ) ;
582
603
foreach ( var productDir in adskRoot . GetDirectories ( ) )
583
- {
604
+ {
605
+ Debug . Log ( "product " + productDir . FullName ) ;
606
+
584
607
var product = productDir . Name ;
585
608
586
609
// Only accept those that start with 'maya' in either case.
587
610
if ( product . StartsWith ( "maya" , StringComparison . InvariantCultureIgnoreCase ) ) {
588
611
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 ) ) ;
591
614
continue ;
592
615
}
593
616
@@ -603,23 +626,21 @@ private static void FindDCCInstalls() {
603
626
continue ;
604
627
}
605
628
606
- dccOptionPath . Add ( exePath ) ;
607
- dccOptionName . Add ( maxOptionName ) ;
629
+ dccOptionPaths . Add ( exePath ) ;
630
+ dccOptionNames . Add ( maxOptionName ) ;
608
631
}
609
632
}
610
633
}
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 ) )
613
639
{
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" ) ;
622
642
}
643
+
623
644
instance . selectedDCCApp = instance . GetPreferredDCCApp ( ) ;
624
645
}
625
646
@@ -647,7 +668,7 @@ public static string GetFirstValidVendorLocation()
647
668
/// </summary>
648
669
/// <returns>The maya exe path.</returns>
649
670
/// <param name="location">Location of Maya install.</param>
650
- private static string GetMayaExePath ( string location )
671
+ private static string GetMayaExePathFromLocation ( string location )
651
672
{
652
673
switch ( Application . platform ) {
653
674
case RuntimePlatform . WindowsEditor :
@@ -727,7 +748,7 @@ public enum DCCType { Maya, Max };
727
748
public static void AddDCCOption ( string newOption , DCCType dcc ) {
728
749
if ( Application . platform == RuntimePlatform . OSXEditor && dcc == DCCType . Maya ) {
729
750
// on OSX we get a path ending in .app, which is not quite the exe
730
- newOption = GetMayaExePath ( newOption ) ;
751
+ newOption = GetMayaExePathFromLocation ( newOption ) ;
731
752
}
732
753
733
754
var dccOptionPaths = instance . dccOptionPaths ;
0 commit comments