// This is a temporary method while we phase DynamoPathManager out. private static bool FindAlternativeAsm(string version, DynamoPathManager pathManager, out string hostLocation) { hostLocation = string.Empty; try { var libgFolder = Path.Combine(pathManager.MainExecPath, "libg_" + version); if (!Directory.Exists(libgFolder)) // Did not find the LibG folder. { return(false); } // The target binary file name to search for. var targetFileName = string.Format("ASMAHL{0}A.DLL", version); var directory = new DirectoryInfo(libgFolder); var files = directory.GetFiles("*.dll"); if (files.Any(f => f.Name.ToUpper() == targetFileName)) { hostLocation = libgFolder; } } catch (Exception) { return(false); } // Returns true if a host location is found. return(!String.IsNullOrEmpty(hostLocation)); }
/// <summary> /// Searches the user's computer for a suitable Autodesk host application containing ASM DLLs, /// determines the correct version of ASM and loads the binaries. /// </summary> public static bool PreloadAsmLibraries(DynamoPathManager pathManager) { if (PreloadAsmVersion("219", pathManager)) { return(true); } if (PreloadAsmVersion("220", pathManager)) { return(true); } return(false); }
/// <summary> /// Preload a specific version of ASM. /// </summary> /// <param name="version">The version as ex. "219"</param> /// <param name="pathManager"></param> public static bool PreloadAsmVersion(string version, DynamoPathManager pathManager) { Debug.WriteLine(string.Format("Attempting to preload ASM version {0}", version)); string hostLocation; if (!FindAlternativeAsm(version, pathManager, out hostLocation)) { if (!FindAsm(version, out hostLocation)) { Debug.WriteLine(string.Format("Could not load ASM version {0}", version)); return(false); } } pathManager.SetLibGPath(version); var libG = Assembly.LoadFrom(Instance.AsmPreloader); Type preloadType = libG.GetType("Autodesk.LibG.AsmPreloader"); MethodInfo preloadMethod = preloadType.GetMethod( "PreloadAsmLibraries", BindingFlags.Public | BindingFlags.Static); if (preloadMethod == null) { throw new MissingMethodException(@"Method ""PreloadAsmLibraries"" not found"); } var methodParams = new object[1]; methodParams[0] = hostLocation; preloadMethod.Invoke(null, methodParams); Debug.WriteLine(string.Format("Successfully loaded ASM version {0}", version)); return(true); }
/// <summary> /// Searches the user's computer for a suitable Autodesk host application containing ASM DLLs, /// determines the correct version of ASM and loads the binaries. /// </summary> public static bool PreloadAsmLibraries(DynamoPathManager pathManager) { if (PreloadAsmVersion("219", pathManager)) return true; if (PreloadAsmVersion("220", pathManager)) return true; return false; }
/// <summary> /// Preload a specific version of ASM. /// </summary> /// <param name="version">The version as ex. "219"</param> public static bool PreloadAsmVersion(string version, DynamoPathManager pathManager) { Debug.WriteLine(string.Format("Attempting to preload ASM version {0}", version)); string hostLocation; if (!FindAsm(version, out hostLocation)) { Debug.WriteLine(string.Format("Could not load ASM version {0}", version)); return false; } pathManager.SetLibGPath(version); var libG = Assembly.LoadFrom(Instance.AsmPreloader); Type preloadType = libG.GetType("Autodesk.LibG.AsmPreloader"); MethodInfo preloadMethod = preloadType.GetMethod( "PreloadAsmLibraries", BindingFlags.Public | BindingFlags.Static); if (preloadMethod == null) throw new MissingMethodException(@"Method ""PreloadAsmLibraries"" not found"); var methodParams = new object[1]; methodParams[0] = hostLocation; preloadMethod.Invoke(null, methodParams); Debug.WriteLine(string.Format("Successfully loaded ASM version {0}", version)); return true; }
internal static void DestroyInstance() { instance = null; }