#langscheme;; ##################################################################################
;; # ============================================================================== #
;; # plugin.ss #
;; # http://mred-designer.origo.ethz.ch #
;; # Copyright (C) Laurent Orseau, 2010 #
;; # ============================================================================== #
;; # #
;; # This program is free software; you can redistribute it and/or #
;; # modify it under the terms of the GNU General Public License #
;; # as published by the Free Software Foundation; either version 2 #
;; # of the License, or (at your option) any later version. #
;; # #
;; # This program is distributed in the hope that it will be useful, #
;; # but WITHOUT ANY WARRANTY; without even the implied warranty of #
;; # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
;; # GNU General Public License for more details. #
;; # #
;; # You should have received a copy of the GNU General Public License #
;; # along with this program; if not, write to the Free Software #
;; # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #
;; # #
;; ##################################################################################
;;; Generic Plugin Manager
(provideload-plugins)
(define (assoc-restlkey)
(let ([val (assockeyl)])
(if (andval (list?val))
(restval)
'())))
;; If this file is present at the root of the plugin directory,
;; then plugins are loaded in the order given in the first list of the
(defineload-preferences-file"loading-preferences.ssd")
(define (load-preferencesplugin-dir)
(let ([pref-file (build-pathplugin-dirload-preferences-file)])
(if (file-exists?pref-file)
(let ([pref-list (with-input-from-filepref-file
(λ()(read)))])
(if (list?pref-list)
pref-list
(begin (printf"Error: The plugin preferences are not a list.\n")
'())))
'())))
(define (load-plugin-from-pathplugin-dirprocpdir)
(let ([ppath (build-pathplugin-dirpdir)])
(if (directory-exists?ppath)
(parameterize ([current-directoryppath])
(list (procpdir)))
'())))
;; Plugin Loader
;; For each directory in the plugins-dir directory,
;; set the current-directory to that path,
;; and execute there hte procedure proc,
;; that receives the name of the directory.
;; Returns the list of applications of proc.
(define (load-pluginsplugin-dirproc)
(let* ([plugin-paths (directory-listplugin-dir)]
[prefs (load-preferencesplugin-dir)]
[plugin-sequence (assoc-restprefs'sequence)]
[dont-loads (assoc-restprefs'dont-load)]
[load-plugin (λ(pdir)
(if (memberpdirdont-loads)
'()
(load-plugin-from-pathplugin-dirprocpdir)))]
)
(append; first load plugin if a sequence is provided from the sequence file
(append-mapload-pluginplugin-sequence)
(append-mapload-plugin; remove plugins loaded in the first sequence
(filter (λ(p)(not (memberpplugin-sequence)))
(mappath->stringplugin-paths)))
)))