@@ -313,52 +313,56 @@ private static string GetUniqueName(string name){
313
313
return uniqueName ;
314
314
}
315
315
316
- // <summary>
317
- //
318
- // Find the latest program available and make that the default choice.
319
- // Will always take any Maya version over any 3ds Max version.
320
- //
321
- // Returns the position of the most recent program in the list of dccOptionPaths
322
- //
323
- // </summary>
316
+ /// <summary>
317
+ ///
318
+ /// Find the latest program available and make that the default choice.
319
+ /// Will always take any Maya version over any 3ds Max version.
320
+ ///
321
+ /// Returns the position of the most recent program in the list of dccOptionPaths
322
+ ///
323
+ /// </summary>
324
324
public int FindMostRecentProgram ( )
325
325
{
326
326
int newestMayaVersion = - 1 ;
327
+ int savedMayaVersionNumber = 0 ;
327
328
int newestMaxVersion = - 1 ;
328
329
329
330
for ( int i = 0 ; i < instance . dccOptionPaths . Count ; i ++ )
330
331
{
331
332
if ( instance . dccOptionPaths [ i ] . ToLower ( ) . Contains ( "maya" ) )
332
333
{
333
334
if ( newestMayaVersion == - 1 )
335
+ {
334
336
newestMayaVersion = 0 ;
337
+ savedMayaVersionNumber = int . Parse ( AskMayaVersion ( instance . dccOptionPaths [ i ] ) ) ;
338
+ continue ;
339
+ }
335
340
336
341
//Check if the path we are considering is newer than the previously saved one
337
- if ( int . Parse ( AskMayaVersion ( instance . dccOptionPaths [ i ] ) ) > int . Parse ( AskMayaVersion ( instance . dccOptionPaths [ newestMayaVersion ] ) ) )
342
+ int versionToCheck ;
343
+ if ( int . TryParse ( AskMayaVersion ( instance . dccOptionPaths [ i ] ) , out versionToCheck ) )
338
344
{
339
- newestMayaVersion = i ;
345
+ if ( versionToCheck > savedMayaVersionNumber )
346
+ {
347
+ newestMayaVersion = i ;
348
+ savedMayaVersionNumber = versionToCheck ;
349
+ }
340
350
}
341
351
}
342
- else if ( instance . dccOptionPaths [ i ] . ToLower ( ) . Contains ( "max" ) )
352
+ else if ( instance . dccOptionPaths [ i ] . ToLower ( ) . Contains ( "max" ) && newestMayaVersion == - 1 )
343
353
{
344
354
if ( newestMaxVersion == - 1 )
355
+ {
345
356
newestMaxVersion = 0 ;
346
-
347
- //Isolate the number out of the path we are currently checking
348
- var nameCurrent = Path . GetFileName ( Path . GetDirectoryName ( instance . dccOptionPaths [ i ] ) ) . ToLower ( ) ;
349
- nameCurrent = nameCurrent . Replace ( "3ds max" , "" ) . Trim ( ) ;
350
-
351
- //Isolate the number out of the path that is the current best answer
352
- var nameNewest = Path . GetFileName ( Path . GetDirectoryName ( instance . dccOptionPaths [ newestMaxVersion ] ) ) . ToLower ( ) ;
353
- nameNewest = nameNewest . Replace ( "3ds max" , "" ) . Trim ( ) ;
357
+ continue ;
358
+ }
354
359
355
360
//Check if the path we are considering is newer than the previously saved one
356
- if ( int . Parse ( nameCurrent ) > int . Parse ( nameNewest ) )
361
+ if ( FindMaxVersion ( dccOptionPaths [ i ] ) > FindMaxVersion ( dccOptionPaths [ newestMaxVersion ] ) )
357
362
{
358
363
newestMaxVersion = i ;
359
364
}
360
365
361
-
362
366
}
363
367
364
368
}
@@ -376,6 +380,28 @@ public int FindMostRecentProgram()
376
380
return 0 ;
377
381
}
378
382
383
+ /// <summary>
384
+ /// Finds the 3ds Max version based off of the title of the application
385
+ /// </summary>
386
+ /// <param name="path"></param>
387
+ /// <returns> the year/version OR -1 if the year could not be parsed </returns>
388
+ private static int FindMaxVersion ( string path )
389
+ {
390
+ var fileName = Path . GetFileName ( Path . GetDirectoryName ( path ) ) . ToLower ( ) ;
391
+ fileName = fileName . Replace ( "3ds max" , "" ) . Trim ( ) ;
392
+
393
+ int version ;
394
+
395
+ if ( int . TryParse ( fileName , out version ) )
396
+ {
397
+ return version ;
398
+ }
399
+ else
400
+ {
401
+ return - 1 ;
402
+ }
403
+ }
404
+
379
405
/// <summary>
380
406
/// Find Maya and 3DsMax installations at default install path.
381
407
/// Add results to given dictionary.
@@ -576,10 +602,8 @@ public static string GetMaxOptionName(string exePath){
576
602
}
577
603
578
604
public static bool IsEarlierThanMax2017 ( string exePath ) {
579
- var name = Path . GetFileName ( Path . GetDirectoryName ( exePath ) ) . ToLower ( ) ;
580
- name = name . Replace ( "3ds max" , "" ) . Trim ( ) ;
581
- int version ;
582
- return int . TryParse ( name , out version ) && version < 2017 ;
605
+ int version = FindMaxVersion ( exePath ) ;
606
+ return version != - 1 && version < 2017 ;
583
607
}
584
608
585
609
public static string GetSelectedDCCPath ( )
0 commit comments