View Single Post
Author Message
MikeJS
Senior Member
Join Date: Nov 2008
Old 05-08-2009 , 12:44   Plugin Autoupdater
Reply With Quote #1

Allows plugin writers to add a few lines of code to their plugin to let it update itself.

Requires the Socket Extension.

Thanks to exvel for a seemingly endless stream of bug reports and p3tsin and Matthias Vance for help with downloading files.

Cvars:
sm_autoupdate_binary (1) - Download binaries?
sm_autoupdate_source (1) - Download sources?
sm_autoupdate_gamedata (1) - Download gamedata files?
sm_autoupdate_other (1) - Download other files?
sm_autoupdate_backup (1) - Save backups of old versions? When set to 1, saves backups of old versions to addons/sourcemod/plugins/disabled/backups

Commands:
sm_autoupdate_check [filename/idx] - Checks for updates but doesn't download anything. Leave idx blank to check all plugins. (logs results to sourcemod/logs/autoupdate.log)
sm_autoupdate_download [filename/idx] - Checks for updates and downloads them. Leave idx blank to update all plugins. (logs results to sourcemod/logs/autoupdate.log)
sm_autoupdate_list - Returns the list of plugins that will be updated.
sm_autoupdate_rem <filename/idx> - Stops a plugin being autoupdated. Get idx from sm_autoupdate_list.
sm_autoupdate_block_add <filename> - Adds a plugin to the block list. Plugins in the block list won't be added to the autoupdate list. (eg sm_autoupdate_block_add autoupdate.smx)
sm_autoupdate_block_rem <filename/idx> - Removes a plugin from the block list.
sm_autoupdate_block_list - Lists blocked plugins.

Todo:
Translation support

Making your plugin autoupdate:
Include autoupdate in your plugin and use the AutoUpdate_AddPlugin()/AutoUpdate_RemovePlugin() natives.
Example plugin:
PHP Code:
#pragma semicolon 1
#include <sourcemod>
#undef REQUIRE_PLUGIN
#include <autoupdate>
#define PL_VERSION "1.0"
public OnPluginStart() {
    
RegConsoleCmd("testau"Command_test);
}
public 
OnAllPluginsLoaded() {
    if(
LibraryExists("pluginautoupdate")) {
        
// only register myself if the autoupdater is loaded
        // AutoUpdate_AddPlugin(const String:url[], const String:file[], const String:version[])
        
AutoUpdate_AddPlugin("127.0.0.1""/plugins.xml"PL_VERSION);
    }
}
public 
OnPluginEnd() {
    if(
LibraryExists("pluginautoupdate")) {
        
// I don't need updating anymore
        // AutoUpdate_RemovePlugin(Handle:plugin=INVALID_HANDLE) - don't specifiy plugin to remove calling plugin
        
AutoUpdate_RemovePlugin();
    }
}
public 
Action:Command_test(clientargs) {
    
PrintToChatAll("Version %s"PL_VERSION);

127.0.0.1/plugins.xml looks like:
Code:
<plugin>
	<version>1.1</version>
	<changes>Changed version number.</changes>
	<binary>/auexample.smx</binary>
	<source>/auexample.sp</source>
	<gamedata>/folder/auexample.games.txt</gamedata>
	<other dir="newdir">/newfile.txt,/folder/newfile2.txt</other>
	<other dir="newdir2">/newfile3.txt</other>
</plugin>
Directory for <other> is relative to the mod folder.

When sm_autoupdate_download is ran, the plugin will try to download 127.0.0.1/auexample.smx, 127.0.0.1/auexample.sp, 127.0.0.1/folder/auexample.games.txt and so on.
You do not need to add gamedata/source/other. (you only need the version, but what use would that be?)


The plugin doesn't update itself because if I didn't keep making stupid mistakes it wouldn't need to
Attached Files
File Type: smx autoupdate.smx (11.9 KB, 7016 views)
File Type: sp Get Plugin or Get Source (autoupdate.sp - 4833 views - 19.0 KB)
File Type: inc autoupdate.inc (930 Bytes, 7365 views)
__________________

Last edited by MikeJS; 08-03-2009 at 09:50.
MikeJS is offline