[Home] [Downloads] [Search] [Help/forum]


Register forum user name Search FAQ

Gammon Forum

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  Plugins
. . -> [Subject]  Plugin to install plugins

Plugin to install plugins

It is now over 60 days since the last post. This thread is closed.     [Refresh] Refresh page


Posted by Nick Gammon   Australia  (22,990 posts)  [Biography] bio   Forum Administrator
Date Thu 10 Jul 2008 06:03 AM (UTC)

Amended on Sat 12 Jul 2008 09:49 PM (UTC) by Nick Gammon

Message
I have been working on a few plugins recently, and found that it can be tedious to install all the correct plugins to achieve a job, if you move from one PC to another. This is especially the case if you have some "helper" plugins, and some "main" plugins, and want to install all of them (say 10 of them), but not all the others that might be in the MUSHclient plugins directory.

The plugin below is designed to solve that problem.

You create a subdirectory, in my example named "Aardwolf". Copy all the plugins you want automatically installed into that directory. Now put the plugin below into your main plugin directory, and install it. Once installed, it scans the subdirectory, looking for .xml files (that is, for plugins). If it finds one that is not already installed into your current world, it installs it.

The beauty of this is that you can roll out extra plugins in the future and instruct your plugin users to simply "drop the plugin into the plugin folder", and they will automatically be installed.

To help manage your plugins, it supports a few aliases:


  • check_plugins - re-scan the folder, in case you just dropped a new file there.
  • disable_plugins - disable all plugins, in case you want to see how the world behaves "raw" without plugins.
  • enable_plugins - enables all plugins
  • reload_plugins - forces all plugins to reload - useful if you have changed some of them.


To use, copy from between the lines below, save as Plugin_Installer.xml in your MUSHclient -> Worlds -> Plugins folder, and then use the File menu -> Plugins to install it.

Change the line below which reads < SUBDIRECTORY = "Aardwolf" > to match the name of the subdirectory you are planning to use.

This plugin can be downloaded from:

http://www.gammon.com.au/mushclient/plugins/Plugin_Installer.xml

RH click the link and "save file as" to download it.


<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE muclient>
<!-- Saved on Saturday, June 28, 2008, 1:40 PM -->
<!-- MuClient version 4.29 -->

<!-- Plugin "Plugin_Installer" generated by Plugin Wizard -->

<muclient>
<plugin
   name="Plugin_Installer"
   author="Nick Gammon"
   id="50c7d6499597808803009442"
   language="Lua"
   purpose="Installs plugins"
   date_written="2008-06-28 13:34:20"
   requires="4.29"
   version="1.0"
   save_state="y"
   >
<description trim="y">
<![CDATA[
This plugins scans a subdirectory and loads all plugins found in it, if not already loaded.

Aliases:

check_plugins    -- Rescans the subdirectory, installing any new plugins found.
disable_plugins  -- Disable all plugins (except this one) for testing or building, etc.
enable_plugins   -- Enable all plugins to return to normal operation
reload_plugins   -- Reload all plugins, in case you downloaded a new one

]]>
</description>

</plugin>


<aliases>
  <alias
   name="disable_plugins"
   script="disable_plugins"
   match="disable_plugins"
   enabled="y"
   sequence="100"
  >
  </alias>

  <alias
   name="enable_plugins"
   script="enable_plugins"
   match="enable_plugins"
   enabled="y"
   sequence="100"
  >
  </alias>

  <alias
   name="reload_plugins"
   script="reload_plugins"
   match="reload_plugins"
   enabled="y"
   sequence="100"
  >
  </alias>
  
  <alias
   name="check_plugins"
   script="check_installed_plugins_now"
   match="check_plugins"
   enabled="y"
   sequence="100"
  >
  </alias>
    
</aliases>


<!--  Script  -->


<script>
<![CDATA[

SUBDIRECTORY = "Aardwolf"

function disable_plugins (name, line, wildcards)

  -- find installed plugins
  local plugins = GetPluginList() or {}
  
  -- for each plugin, disable it, unless it is us

  local count = 0
  local already = 0
    
  for _, p in ipairs (plugins) do
    if p ~=  GetPluginID () then
      if GetPluginInfo (p, 17) then
        check (EnablePlugin (p, false))
        count = count + 1
      else
        already = already + 1
      end
    end -- if not us
  end -- each plugin file
  
  ColourNote ("white", "blue", string.format ("%i plugin(s) disabled.", count))
  ColourNote ("white", "blue", string.format ("%i plugin(s) already disabled.", already))
  
end -- disable_plugins

function enable_plugins (name, line, wildcards)

  -- find installed plugins
  local plugins = GetPluginList() or {}
  
  -- for each plugin, enable it

  local count = 0
  local already = 0
    
  for _, p in ipairs (plugins) do
    if p ~=  GetPluginID () then
      if not GetPluginInfo (p, 17) then
        check (EnablePlugin (p, true))
        count = count + 1
      else
        already = already + 1
      end
    end -- not us (we must be enabled)
  end -- each plugin file
  
  ColourNote ("white", "blue", string.format ("%i plugin(s) enabled.", count))
  ColourNote ("white", "blue", string.format ("%i plugin(s) already enabled.", already))
  
end -- enable_plugins

function reload_plugins (name, line, wildcards)

  -- find installed plugins
  local plugins = GetPluginList() or {}
  
  -- for each plugin, reload it

  local count = 0
    
  for _, p in ipairs (plugins) do
    if p ~= GetPluginID () then
      local status = ReloadPlugin (p)
      if status ~= error_code.eOK then
        ColourNote ("red", "", "Could not reload plugin ID: " .. 
                    (p or "unknown") .. ", name: " .. (GetPluginInfo (p, 1) or "unknown"))
        check (status)       
      end -- no good
      count = count + 1
    end -- not us (we can't be reloadeed)
  end -- each plugin file
  
  ColourNote ("white", "blue", string.format ("%i plugin(s) reloaded.", count))
  
end -- reload_plugins

function check_installed_plugins_now ()

  -- look for plugins under program install folder
  local dir = GetInfo (57) .. "plugins\\" .. SUBDIRECTORY .. "\\"
  
  -- find all xml files in that directory
  local t = utils.readdir (dir .. "*.xml")
  
  -- none? just warn them
  if not t then
    ColourNote ("white", "blue", "No plugins found in " .. dir)
    return
  end -- if
  
  -- build list of file names
  local plugins = {}
  
  -- copy from keys of the table of names, into a new table, dropping files starting with "."
  for k in pairs (t) do
    if k:sub (1, 1) ~= "." then
      table.insert (plugins, k)
    end -- not temporary files
  end -- for adding each one
  
  -- may as well do in alphabetic order
  table.sort (plugins)
  
  -- find installed plugins
  local installed_plugins = GetPluginList() or {}
  
  -- for each file, see if it is already installed
  for i, p in ipairs (plugins) do
    local installed = false
    
    -- check installed list
    for _, v in pairs (installed_plugins) do 
      if GetPluginInfo (v, 6) == (dir .. p) then
        installed = true
      end -- if already installed  
    end
  
    -- not there? load it
    if not installed then
      ColourNote ("white", "green", "Installing plugin " .. p)
      check (LoadPlugin (dir .. p))  -- load it
    end -- if
     
  end -- each plugin file

end -- check_installed_plugins_now

function OnPluginInstall ()
  -- give them time to load
  DoAfterSpecial (2, 
                  "check_installed_plugins_now ()", 
                  sendto.script)

end -- function OnPluginInstall 

]]>
</script>


</muclient>



- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).

To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.


8,907 views.

It is now over 60 days since the last post. This thread is closed.     [Refresh] Refresh page

Go to topic:           Search the forum


[Go to top] top

Quick links: MUSHclient. MUSHclient help. Forum shortcuts. Posting templates. Lua modules. Lua documentation.

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.

[Home]


Written by Nick Gammon - 5K   profile for Nick Gammon on Stack Exchange, a network of free, community-driven Q&A sites   Marriage equality

Comments to: Gammon Software support
[RH click to get RSS URL] Forum RSS feed ( https://gammon.com.au/rss/forum.xml )

[Best viewed with any browser - 2K]    [Hosted at HostDash]