示例#1
0
        // 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);
        }
示例#2
0
        // remove extension search path
        // @handled @logs
        public static void UnregisterExtensionSearchPath(string searchPath)
        {
            var cfg      = PyRevitConfigs.GetConfigFile();
            var normPath = searchPath.NormalizeAsPath();

            logger.Debug("Removing extension search path \"{0}\"", normPath);
            var searchPaths = GetRegisteredExtensionSearchPaths();

            searchPaths.Remove(normPath);
            cfg.SetValue(PyRevitConsts.ConfigsCoreSection, PyRevitConsts.ConfigsUserExtensionsKey, searchPaths);
        }
示例#3
0
        // updates the config value for registered clones
        public static void SaveRegisteredClones(IEnumerable <PyRevitClone> clonesList)
        {
            var cfg         = PyRevitConfigs.GetConfigFile();
            var newValueDic = new Dictionary <string, string>();

            foreach (var clone in clonesList)
            {
                newValueDic[clone.Name] = clone.ClonePath;
            }

            cfg.SetValue(PyRevitConsts.EnvConfigsSectionName, PyRevitConsts.EnvConfigsInstalledClonesKey, newValueDic);
        }
示例#4
0
        // uninstall all registered clones
        // @handled @logs
        public static void DeleteAllClones(bool clearConfigs = false)
        {
            foreach (var clone in GetRegisteredClones())
            {
                Delete(clone, clearConfigs: false);
            }

            if (clearConfigs)
            {
                PyRevitConfigs.DeleteConfig();
            }
        }
示例#5
0
        // uninstall primary or specified clone, has option for clearing configs
        // @handled @logs
        public static void Delete(PyRevitClone clone, bool clearConfigs = false)
        {
            logger.Debug("Unregistering clone \"{0}\"", clone);
            UnregisterClone(clone);

            logger.Debug("Removing directory \"{0}\"", clone.ClonePath);
            CommonUtils.DeleteDirectory(clone.ClonePath);

            if (clearConfigs)
            {
                PyRevitConfigs.DeleteConfig();
            }
        }
示例#6
0
        // add extension search path
        // @handled @logs
        public static void RegisterExtensionSearchPath(string searchPath)
        {
            var cfg = PyRevitConfigs.GetConfigFile();

            if (CommonUtils.VerifyPath(searchPath))
            {
                logger.Debug("Adding extension search path \"{0}\"", searchPath);
                var searchPaths = GetRegisteredExtensionSearchPaths();
                searchPaths.Add(searchPath.NormalizeAsPath());
                cfg.SetValue(PyRevitConsts.ConfigsCoreSection, PyRevitConsts.ConfigsUserExtensionsKey, searchPaths);
            }
            else
            {
                throw new pyRevitResourceMissingException(searchPath);
            }
        }
示例#7
0
        // get extension lookup sources
        // @handled @logs
        public static List <string> GetRegisteredExtensionLookupSources()
        {
            var cfg         = PyRevitConfigs.GetConfigFile();
            var normSources = new List <string>();
            var sources     = cfg.GetListValue(PyRevitConsts.EnvConfigsSectionName, PyRevitConsts.EnvConfigsExtensionLookupSourcesKey);

            if (sources != null)
            {
                foreach (var src in sources)
                {
                    var normSrc = src.NormalizeAsPath();
                    logger.Debug("Extension lookup source \"{0}\"", normSrc);
                    normSources.Add(normSrc);
                    SaveExtensionLookupSources(normSources);
                }
            }
            return(normSources);
        }
示例#8
0
        // return list of registered clones
        // @handled @logs
        public static List <PyRevitClone> GetRegisteredClones()
        {
            var validatedClones = new List <PyRevitClone>();

            // safely get clone list
            var cfg        = PyRevitConfigs.GetConfigFile();
            var clonesList = cfg.GetDictValue(PyRevitConsts.EnvConfigsSectionName, PyRevitConsts.EnvConfigsInstalledClonesKey);

            if (clonesList != null)
            {
                // verify all registered clones, protect against tampering
                foreach (var cloneKeyValue in clonesList)
                {
                    var clonePath = cloneKeyValue.Value.NormalizeAsPath();
                    if (CommonUtils.VerifyPath(clonePath))
                    {
                        try {
                            var clone = new PyRevitClone(clonePath, name: cloneKeyValue.Key);
                            if (clone.IsValid && !validatedClones.Contains(clone))
                            {
                                logger.Debug("Verified clone \"{0}={1}\"", clone.Name, clone.ClonePath);
                                validatedClones.Add(clone);
                            }
                        }
                        catch {
                            logger.Debug("Error occured when processing registered clone \"{0}\" at \"{1}\"", cloneKeyValue.Key, clonePath);
                        }
                    }
                }

                // rewrite the verified clones list back to config file
                SaveRegisteredClones(validatedClones);
            }

            return(validatedClones);
        }
示例#9
0
        // get list of registered extension search paths
        // @handled @logs
        public static List <string> GetRegisteredExtensionSearchPaths()
        {
            var validatedPaths = new List <string>();
            var cfg            = PyRevitConfigs.GetConfigFile();
            var searchPaths    = cfg.GetListValue(PyRevitConsts.ConfigsCoreSection, PyRevitConsts.ConfigsUserExtensionsKey);

            if (searchPaths != null)
            {
                // make sure paths exist
                foreach (var path in searchPaths)
                {
                    var normPath = path.NormalizeAsPath();
                    if (CommonUtils.VerifyPath(path) && !validatedPaths.Contains(normPath))
                    {
                        logger.Debug("Verified extension search path \"{0}\"", normPath);
                        validatedPaths.Add(normPath);
                    }
                }

                // rewrite verified list
                cfg.SetValue(PyRevitConsts.ConfigsCoreSection, PyRevitConsts.ConfigsUserExtensionsKey, validatedPaths);
            }
            return(validatedPaths);
        }
示例#10
0
        // save list of source exensio
        private static void SaveExtensionLookupSources(IEnumerable <string> sources)
        {
            var cfg = PyRevitConfigs.GetConfigFile();

            cfg.SetValue(PyRevitConsts.EnvConfigsSectionName, PyRevitConsts.EnvConfigsExtensionLookupSourcesKey, sources);
        }