Skip to content

Commit 0269064

Browse files
author
AJubrey
committed
[ADDED] function to find Maya version from title of application
[CHANGED] a few minor efficiency things to make finding the newest version faster
1 parent 6a54c8a commit 0269064

File tree

1 file changed

+32
-9
lines changed

1 file changed

+32
-9
lines changed

Assets/FbxExporters/Editor/FbxExportSettings.cs

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,7 @@ public int FindMostRecentProgram()
324324
int newestMayaVersion = -1;
325325
int savedMayaVersionNumber = 0;
326326
int newestMaxVersion = -1;
327+
int savedMaxVersionNumber = 0;
327328

328329
for (int i = 0; i < instance.dccOptionPaths.Count; i++)
329330
{
@@ -332,33 +333,33 @@ public int FindMostRecentProgram()
332333
if (newestMayaVersion == -1)
333334
{
334335
newestMayaVersion = 0;
335-
savedMayaVersionNumber = int.Parse(AskMayaVersion(instance.dccOptionPaths[i]));
336+
savedMayaVersionNumber = FindMayaVersion(dccOptionPaths[i]);
336337
continue;
337338
}
338339

339340
//Check if the path we are considering is newer than the previously saved one
340-
int versionToCheck;
341-
if (int.TryParse(AskMayaVersion(instance.dccOptionPaths[i]), out versionToCheck))
342-
{
341+
int versionToCheck = FindMayaVersion(dccOptionPaths[i]);
343342
if (versionToCheck > savedMayaVersionNumber)
344343
{
345344
newestMayaVersion = i;
346345
savedMayaVersionNumber = versionToCheck;
347-
}
348-
}
346+
}
349347
}
350-
else if (instance.dccOptionPaths[i].ToLower().Contains("max") && newestMayaVersion == -1)
348+
else if (newestMayaVersion == -1 && instance.dccOptionPaths[i].ToLower().Contains("max"))
351349
{
352350
if (newestMaxVersion == -1)
353351
{
354352
newestMaxVersion = 0;
353+
savedMaxVersionNumber = FindMaxVersion(dccOptionPaths[newestMaxVersion]);
355354
continue;
356355
}
357356

358357
//Check if the path we are considering is newer than the previously saved one
359-
if (FindMaxVersion(dccOptionPaths[i]) > FindMaxVersion(dccOptionPaths[newestMaxVersion]))
358+
int versionToCheck = FindMaxVersion(dccOptionPaths[i]);
359+
if (versionToCheck > savedMaxVersionNumber)
360360
{
361361
newestMaxVersion = i;
362+
savedMaxVersionNumber = versionToCheck;
362363
}
363364

364365
}
@@ -400,6 +401,28 @@ private static int FindMaxVersion(string path)
400401
}
401402
}
402403

404+
/// <summary>
405+
/// Finds the Maya version based off of the title of the application
406+
/// </summary>
407+
/// <param name="path"></param>
408+
/// <returns> the year/version OR -1 if the year could not be parsed </returns>
409+
private static int FindMayaVersion(string path)
410+
{
411+
var fileName = Path.GetFileName(Path.GetDirectoryName(path)).ToLower();
412+
fileName = fileName.Replace("maya", "").Trim();
413+
414+
int version;
415+
416+
if (int.TryParse(fileName, out version))
417+
{
418+
return version;
419+
}
420+
else
421+
{
422+
return -1;
423+
}
424+
}
425+
403426
/// <summary>
404427
/// Find Maya and 3DsMax installations at default install path.
405428
/// Add results to given dictionary.
@@ -497,7 +520,7 @@ public static GUIContent[] GetDCCOptions(){
497520
var dccPath = instance.dccOptionPaths [i];
498521
if (!File.Exists (dccPath)) {
499522
if (i == instance.selectedDCCApp) {
500-
instance.selectedDCCApp = 0;
523+
instance.selectedDCCApp = instance.FindMostRecentProgram();
501524
}
502525
namesToDelete.Add (instance.dccOptionNames [i]);
503526
pathsToDelete.Add (dccPath);

0 commit comments

Comments
 (0)