Skip to content

Commit d1af9a6

Browse files
author
MSI\Austin
committed
[CHANGED] added continues in a few places for efficiency
[CHANGED] made it so that we only start up Maya to check the version once per version, for efficiency [CHANGED] the script will now catch failures of parses from Maya versions without numbers (which is to say LT won't be compared to other versions) [ADDED] a FindMaxVersion() function so that comparisons wouldn't clutter up other functions (also checks to see if the version could not be parsed) [UPDATED] IsEarlierThanMax2017() function to use my new FindMaxVersion() function [FIXED] function summary of FindMostRecentProgram() to correct format
1 parent a15d30d commit d1af9a6

File tree

1 file changed

+49
-25
lines changed

1 file changed

+49
-25
lines changed

Assets/FbxExporters/Editor/FbxExportSettings.cs

Lines changed: 49 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -313,52 +313,56 @@ private static string GetUniqueName(string name){
313313
return uniqueName;
314314
}
315315

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>
324324
public int FindMostRecentProgram()
325325
{
326326
int newestMayaVersion = -1;
327+
int savedMayaVersionNumber = 0;
327328
int newestMaxVersion = -1;
328329

329330
for (int i = 0; i < instance.dccOptionPaths.Count; i++)
330331
{
331332
if (instance.dccOptionPaths[i].ToLower().Contains("maya"))
332333
{
333334
if (newestMayaVersion == -1)
335+
{
334336
newestMayaVersion = 0;
337+
savedMayaVersionNumber = int.Parse(AskMayaVersion(instance.dccOptionPaths[i]));
338+
continue;
339+
}
335340

336341
//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))
338344
{
339-
newestMayaVersion = i;
345+
if (versionToCheck > savedMayaVersionNumber)
346+
{
347+
newestMayaVersion = i;
348+
savedMayaVersionNumber = versionToCheck;
349+
}
340350
}
341351
}
342-
else if (instance.dccOptionPaths[i].ToLower().Contains("max"))
352+
else if (instance.dccOptionPaths[i].ToLower().Contains("max") && newestMayaVersion == -1)
343353
{
344354
if (newestMaxVersion == -1)
355+
{
345356
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+
}
354359

355360
//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]))
357362
{
358363
newestMaxVersion = i;
359364
}
360365

361-
362366
}
363367

364368
}
@@ -376,6 +380,28 @@ public int FindMostRecentProgram()
376380
return 0;
377381
}
378382

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+
379405
/// <summary>
380406
/// Find Maya and 3DsMax installations at default install path.
381407
/// Add results to given dictionary.
@@ -576,10 +602,8 @@ public static string GetMaxOptionName(string exePath){
576602
}
577603

578604
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;
583607
}
584608

585609
public static string GetSelectedDCCPath()

0 commit comments

Comments
 (0)