// enable extension in config // @handled @logs private static void ToggleExtension(PyRevitExtension ext, bool state) { logger.Debug("{0} extension \"{1}\"", state ? "Enabling" : "Disabling", ext.Name); var cfg = PyRevitConfigs.GetConfigFile(); cfg.SetValue(ext.ConfigName, PyRevitConsts.ExtensionDisabledKey, !state); }
// return a list of installed extensions found under registered search paths // @handled @logs public static List <PyRevitExtension> GetInstalledExtensions(string searchPath = null) { List <string> searchPaths; if (searchPath is null) { searchPaths = GetRegisteredExtensionSearchPaths(); } else { searchPaths = new List <string>() { searchPath } }; var installedExtensions = new List <PyRevitExtension>(); foreach (var path in searchPaths) { installedExtensions.AddRange(PyRevitExtension.FindExtensions(path)); } return(installedExtensions); }
// force update extension // @handled @logs public static void UpdateExtension(PyRevitExtension ext) { logger.Debug("Updating extension \"{0}\"", ext.Name); logger.Debug("Updating extension repo at \"{0}\"", ext.InstallPath); var res = GitInstaller.ForcedUpdate(ext.InstallPath); if (res <= UpdateStatus.Conflicts) { throw new PyRevitException( string.Format("Error updating extension \"{0}\" installed at \"{1}\"", ext.Name, ext.InstallPath) ); } }
// find all extensions under a given directory public static List <PyRevitExtension> FindExtensions(string searchPath) { var installedExtensions = new List <PyRevitExtension>(); logger.Debug("Looking for installed extensions under \"{0}\"...", searchPath); foreach (var subdir in Directory.GetDirectories(searchPath)) { if (PyRevitExtension.IsExtensionDirectory(subdir)) { logger.Debug("Found installed extension \"{0}\"...", subdir); installedExtensions.Add(new PyRevitExtension(subdir)); } } return(installedExtensions); }
// uninstalls an extension // @handled @logs public static void UninstallExtension(PyRevitExtension ext, bool removeSearchPath = false) { RemoveExtension(ext.InstallPath, removeSearchPath: removeSearchPath); }
// installs extension from repo url // @handled @logs public static void InstallExtension(string extensionName, PyRevitExtensionTypes extensionType, string repoPath, string destPath = null, string branchName = null, string username = null, string password = null) { // make sure extension is not installed already try { var existExt = GetInstalledExtension(extensionName); if (existExt != null) { throw new PyRevitException(string.Format("Extension \"{0}\" is already installed under \"{1}\"", existExt.Name, existExt.InstallPath)); } } catch { // extension is not installed so everything is fine } // determine repo folder name // Name.extension for UI Extensions // Name.lib for Library Extensions string extDestDirName = PyRevitExtension.MakeConfigName(extensionName, extensionType); // determine destination destPath = destPath ?? PyRevitConsts.DefaultExtensionsPath; string finalExtRepoPath = Path.Combine(destPath, extDestDirName).NormalizeAsPath(); // determine branch name branchName = branchName ?? PyRevitConsts.DefaultExtensionRepoDefaultBranch; logger.Debug("Extension branch name determined as \"{0}\"", branchName); logger.Debug("Installing extension into \"{0}\"", finalExtRepoPath); // start the clone process var repo = GitInstaller.Clone(repoPath, branchName, finalExtRepoPath, username, password); // Check installation if (repo != null) { // make sure to delete the repo if error occured after cloning var clonedPath = repo.Info.WorkingDirectory; if (GitInstaller.IsValidRepo(clonedPath)) { logger.Debug("Clone successful \"{0}\"", clonedPath); RegisterExtensionSearchPath(destPath.NormalizeAsPath()); } else { logger.Debug("Invalid repo after cloning. Deleting clone \"{0}\"", repoPath); try { CommonUtils.DeleteDirectory(repoPath); } catch (Exception delEx) { logger.Error(string.Format("Error post-install cleanup on \"{0}\" | {1}", repoPath, delEx.Message)); } } } else { throw new PyRevitException(string.Format("Error installing extension. Null repo error on \"{0}\"", repoPath)); } }
// get list of builtin extensions // @handled @logs public static List <PyRevitExtension> GetExtensions(string clonePath) { VerifyCloneValidity(clonePath); return(PyRevitExtension.FindExtensions(PyRevitClone.GetExtensionsPath(clonePath))); }