AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Unapproved Plugins (https://forums.alliedmods.net/forumdisplay.php?f=109)
-   -   Plugin Autoupdater (https://forums.alliedmods.net/showthread.php?t=91992)

MikeJS 05-08-2009 12:44

Plugin Autoupdater
 
3 Attachment(s)
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 :D

mattressfish 05-08-2009 12:59

Re: Plugin Autoupdater
 
Wow, this is AWESOME. Good work!

exvel 05-08-2009 13:33

Re: Plugin Autoupdater
 
So I need a hosting for making a such plugin that is able to autoupdate, right?
Also if answer: yes, you can write a manual of how to post your plugin in free svn service or something like google code.

MikeJS 05-08-2009 14:02

Re: Plugin Autoupdater
 
Quote:

Originally Posted by exvel (Post 823654)
So I need a hosting for making a such plugin that is able to autoupdate, right?
Also if answer: yes, you can write a manual of how to post your plugin in free svn service or something like google code.

You do. I'm not sure how google code works, sorry. You should be able to use any free host though.

exvel 05-08-2009 14:06

Re: Plugin Autoupdater
 
Quote:

Originally Posted by MikeJS (Post 823668)
You do. I'm not sure how google code works, sorry. You should be able to use any free host though.

I've just created my first project on google code and it seems that it is perfectly suitable. All links are direct so I think it is a perfect place for uploading plugins. :)

p.s. anyway, good job +karma

exvel 05-08-2009 14:07

Re: Plugin Autoupdater
 
What should I write here? New version number or update description?
Quote:

<changes>Changed version number.</changes>

exvel 05-08-2009 14:09

Re: Plugin Autoupdater
 
Also about a suggestion that is already in your ToDo list. Custom files tag:
Quote:

<custom="directory_file_to_put_in">/some_file</custom>
I think it could be the best way.

p.s.
google code example: http://code.google.com/p/showhealth/downloads/list

MikeJS 05-08-2009 14:32

Re: Plugin Autoupdater
 
Quote:

Originally Posted by exvel (Post 823674)
What should I write here? New version number or update description?

Update description.

Quote:

Originally Posted by exvel (Post 823675)
Also about a suggestion that is already in your ToDo list. Custom files tag:

I think it could be the best way.

So something like this?
Code:

<other dir="sounds">annoying1.mp3,annoying2.mp3,annoying3.mp3</other>
<other dir="materials">overlay\overlay.vtf,overlay\overlay.vmt</other>


exvel 05-08-2009 14:45

Re: Plugin Autoupdater
 
Yeap this is very close to what I expected but this would be looks better I think:

Code:

<other dir="sounds">annoying1.mp3</other>
<other dir="sounds">annoying2.mp3</other>
<other dir="sounds">annoying3.mp3</other>

Also I've tested autoupdater and got an error:
Code:

sm_autoupdate_check
L 05/08/2009 - 22:42:19: [autoupdate.smx] Socket error: 1 (#11004)
sm_autoupdate_list
showhealth.smx ver 1.0.0
Autoupdating 1 plugin.

p.s. my plugin's source: http://showhealth.googlecode.com/files/showhealth.sp

MikeJS 05-08-2009 15:03

Re: Plugin Autoupdater
 
Try AutoUpdate_AddPlugin("showhealth.googlecode.c om", "/files/version.xml", PLUGIN_VERSION);

edit: I don't know why it's adding a space :|


All times are GMT -4. The time now is 15:30.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.