Skip to content

Commit 402a917

Browse files
committed
change MayaVersion to MayaLocation
Remove functions for returning the maya version.
1 parent 3d1ea86 commit 402a917

File tree

2 files changed

+18
-63
lines changed

2 files changed

+18
-63
lines changed

Assets/FbxExporters/Editor/InstallIntegration.cs

Lines changed: 16 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,15 @@ public MayaException(string message) : base(message) { }
3131
public MayaException(string message, System.Exception inner) : base(message, inner) { }
3232
}
3333

34-
public class MayaVersion {
34+
public class MayaLocation {
3535

3636
/// <summary>
3737
/// Find the Maya installation that has your desired version, or
3838
/// the newest version if the 'desired' is an empty string.
3939
///
4040
/// If MAYA_LOCATION is set, the desired version is ignored.
4141
/// </summary>
42-
public MayaVersion(string desiredVersion = "") {
42+
public MayaLocation(string desiredVersion = "") {
4343
// If the location is given by the environment, use it.
4444
Location = System.Environment.GetEnvironmentVariable ("MAYA_LOCATION");
4545
if (!string.IsNullOrEmpty(Location)) {
@@ -136,45 +136,6 @@ public string MayaExe {
136136
#endif
137137
}
138138
}
139-
140-
/// <summary>
141-
/// The version number.
142-
///
143-
/// This may involve running Maya so it can be expensive (a few
144-
/// seconds).
145-
/// </summary>
146-
public string Version {
147-
get {
148-
if (string.IsNullOrEmpty(m_version)) {
149-
m_version = AskVersion(MayaExe);
150-
}
151-
return m_version;
152-
}
153-
}
154-
string m_version;
155-
156-
/// <summary>
157-
/// Ask the version number by running maya.
158-
/// </summary>
159-
static string AskVersion(string exePath) {
160-
System.Diagnostics.Process myProcess = new System.Diagnostics.Process();
161-
myProcess.StartInfo.FileName = exePath;
162-
myProcess.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
163-
myProcess.StartInfo.CreateNoWindow = true;
164-
myProcess.StartInfo.UseShellExecute = false;
165-
myProcess.StartInfo.RedirectStandardOutput = true;
166-
myProcess.StartInfo.Arguments = "-v";
167-
myProcess.EnableRaisingEvents = true;
168-
myProcess.Start();
169-
string resultString = myProcess.StandardOutput.ReadToEnd();
170-
myProcess.WaitForExit();
171-
172-
// Output is like: Maya 2018, Cut Number 201706261615
173-
// We want the stuff after 'Maya ' and before the comma.
174-
// TODO: less brittle! Consider also the mel command "about -version".
175-
var commaIndex = resultString.IndexOf(',');
176-
return resultString.Substring(0, commaIndex).Substring("Maya ".Length);
177-
}
178139
};
179140

180141
// Use string to define escaped quote
@@ -205,12 +166,12 @@ public static bool IsHeadlessInstall ()
205166
return false;
206167
}
207168

208-
public static string GetModulePath(string version)
169+
public static string GetModulePath()
209170
{
210171
return System.IO.Path.Combine(GetUserFolder(), MAYA_MODULES_PATH);
211172
}
212173

213-
public static string GetModuleTemplatePath(string version)
174+
public static string GetModuleTemplatePath()
214175
{
215176
return System.IO.Path.Combine(Application.dataPath, MODULE_TEMPLATE_PATH);
216177
}
@@ -340,12 +301,12 @@ private static void WriteFile(string FileName, List<string> Lines )
340301
}
341302
}
342303

343-
public static int ConfigureMaya(MayaVersion version)
304+
public static int ConfigureMaya(MayaLocation mayaLoc)
344305
{
345306
int ExitCode = 0;
346307

347308
try {
348-
string mayaPath = version.MayaExe;
309+
string mayaPath = mayaLoc.MayaExe;
349310
if (!System.IO.File.Exists(mayaPath))
350311
{
351312
Debug.LogError (string.Format ("No maya installation found at {0}", mayaPath));
@@ -380,27 +341,24 @@ public static int ConfigureMaya(MayaVersion version)
380341
return ExitCode;
381342
}
382343

383-
public static bool InstallMaya(MayaVersion version = null, bool verbose = false)
344+
public static bool InstallMaya(bool verbose = false)
384345
{
385346
// What's happening here is that we copy the module template to
386347
// the module path, basically:
387348
// - copy the template to the user Maya module path
388349
// - search-and-replace its tags
389350
// - done.
390351
// But it's complicated because we can't trust any files actually exist.
391-
if (version == null) {
392-
version = new MayaVersion();
393-
}
394352

395-
string moduleTemplatePath = GetModuleTemplatePath(version.Version);
353+
string moduleTemplatePath = GetModuleTemplatePath();
396354
if (!System.IO.File.Exists(moduleTemplatePath))
397355
{
398-
Debug.LogError(string.Format("FbxExporters package doesn't have support for " + version.Version));
356+
Debug.LogError(string.Format("Missing Maya module file"));
399357
return false;
400358
}
401359

402360
// Create the {USER} modules folder and empty it so it's ready to set up.
403-
string modulePath = GetModulePath(version.Version);
361+
string modulePath = GetModulePath();
404362
string moduleFilePath = System.IO.Path.Combine(modulePath, MODULE_FILENAME + ".mod");
405363
bool installed = false;
406364

@@ -486,20 +444,20 @@ class IntegrationsUI
486444
{
487445
public static void InstallMayaIntegration ()
488446
{
489-
var mayaVersion = new Integrations.MayaVersion();
490-
if (!Integrations.InstallMaya(mayaVersion, verbose: true)) {
447+
if (!Integrations.InstallMaya(verbose: true)) {
491448
return;
492449
}
493450

494-
int exitCode = Integrations.ConfigureMaya (mayaVersion);
451+
var mayaLoc = new Integrations.MayaLocation();
452+
int exitCode = Integrations.ConfigureMaya (mayaLoc);
495453

496454
string title, message;
497455
if (exitCode != 0) {
498-
title = string.Format("Failed to install Maya {0} Integration.", mayaVersion.Version);
456+
title = "Failed to install Maya Integration.";
499457
message = string.Format("Failed to configure Maya, please check logs (exitcode={0}).", exitCode);
500458
} else {
501-
title = string.Format("Completed installation of Maya {0} Integration.", mayaVersion.Version);
502-
message = string.Format("Enjoy the new \"Unity\" menu in Maya {0}.", mayaVersion.Version);
459+
title = "Completed installation of Maya Integration.";
460+
message = "Enjoy the new \"Unity\" menu in Maya.";
503461
}
504462
UnityEditor.EditorUtility.DisplayDialog (title, message, "Ok");
505463
}

Assets/FbxExporters/Editor/UnitTests/IntegrationsTest.cs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,11 @@ public void BasicTest() {
3434

3535
LogNonEmptyString("location", maya.Location);
3636
LogNonEmptyString("binary ", maya.MayaExe);
37-
LogNonEmptyString("version ", maya.Version);
3837

3938
Assert.IsFalse(Editor.Integrations.IsHeadlessInstall());
4039

41-
LogNonEmptyString("module path (2017)", Editor.Integrations.GetModulePath("2017"));
42-
LogNonEmptyString("module template path (2017)", Editor.Integrations.GetModuleTemplatePath("2017"));
43-
Assert.That( () => Editor.Integrations.GetModuleTemplatePath("bad version"),
44-
Throws.Exception.TypeOf<Editor.Integrations.MayaException>());
40+
LogNonEmptyString("module path", Editor.Integrations.GetModulePath());
41+
LogNonEmptyString("module template path", Editor.Integrations.GetModuleTemplatePath());
4542

4643
LogNonEmptyString("app path", Editor.Integrations.GetAppPath());
4744
LogNonEmptyString("project path", Editor.Integrations.GetProjectPath());

0 commit comments

Comments
 (0)