PluginDevGuide PluginConfig

From VuzeWiki
Jump to: navigation, search
You can download the code for this tutorial here. The JAR file can be opened in any program which can open up ZIP files, and contains both the compiled code and the source code.
Version: 0.2
Link: Download
Description: Plugin configuration demonstration.

Plugin Development Guide: Storing data and changing config settings[edit]

First of all, we'll focus on where you can store your data. Plugins have access to their own PluginConfig object, available from the getPluginconfig method on the PluginInterface object.

Azureus stores all of its information in bencoded files in its configuration directory (more about that here). You can use the same mechanism that Azureus uses for its configuration values to store your data too.

Getting and setting plugin-specific values[edit]

So, let's get started. We'll do something basic - we'll record the time that our plugin was last loaded.

public void initialize(PluginInterface plugin_interface) {
  PluginConfig pconfig = plugin_interface.getPluginconfig();
	
  // Record the time we were initialised (and the last time we were started).
  long last_started = pconfig.getPluginLongParameter("last started");
  long now = System.currentTimeMillis();
  pconfig.setPluginParameter("last started", now);
}

And that's how easy it is. We grab the old value before overwriting it with the new one. We aren't actually going to do much with the value at this stage.

You don't need to put a unique prefix for plugin configuration values - this is actually done internally (so it doesn't clash with any core values or data stored for other plugins).

Getting and setting core configuration values[edit]

Not only can you use this to store values for your plugin, but you can also use this object to alter the main configuration values.

// We can set core config values too - let's show this by setting the download
// speed limit to 25 kbps.
pconfig.setCoreIntParameter(PluginConfig.CORE_PARAM_INT_MAX_DOWNLOAD_SPEED_KBYTES_PER_SEC , 25);

To set or get core values, use the constants on the PluginConfig object itself. Not all configuration values are exposed directly in this way - you can request to the Azureus developers to expose certain values. Alternatively, you could use the "unsafe" methods to change certain values - but we generally don't recommend you do this, as we won't guarantee that the behaviour will always work if we decide to make some changes in the future.

Writing data to disk[edit]

If you want to store files directly to disk (rather than using this API), then you can do - you should use the getPluginUserFile method to get an appropriate place to store files. The PluginInterface method has a getPluginDirectoryName method which exposes the location that the plugin is stored - but you should try to avoid storing files there (even if you want to share files between different users), due to possible problems you might run into with Windows Vista and [file virtualisation] behaviour.