Quote:
Originally Posted by fmfs10
If you want to update a file, you need to know the file version from the url (the updated) and the server (the possible outdated). So you need to compare the file version from url and from the server...
|
Nothing is impossible. There's several ways.
Start downloading file, check total file size, abort and then decide if you wanna download it is one way.
The best way of course would be if there was a php generated site to tell you only the information you want, download that. If that matches your current version, don't download the new. If it differs, download.
You could also download the file, load it as a separate plugin and then compare versions. Seems very unpractical though with so much downloading.
I made a small autoupdate example just to prove the point.
This would not be good enough for a plugin to use. (So don't!) It just shows the method.
Current plugin:
PHP Code:
#include <amxmodx>
#include <Download>
#define MyPluginUrl "http://DivinityX.net/test2.amxx"
new g_downloadTo[260];
public plugin_init() {
register_plugin("Test 2", "1.0", "DivinityX");
new filename[64];
new pluginsdir[260];
new modname[32];
// First we get the modname
get_modname(modname, 31);
// Next, we need plugins filename.
get_plugin (-1, filename, charsmax(filename), pluginsdir, charsmax(pluginsdir), pluginsdir, charsmax(pluginsdir), pluginsdir, charsmax(pluginsdir), pluginsdir, charsmax(pluginsdir));
// We also want to know where that file is stored. NO HARDCODING!
get_localinfo("amxx_pluginsdir", pluginsdir, charsmax(pluginsdir))
// Format it up to fit into 1 param.
formatex(g_downloadTo, charsmax(g_downloadTo), "%s/%s/%s", modname, pluginsdir, filename);
// Just wait.
set_task(10.0, "UpdateMyPluginPlz");
server_print("The anticipation is killing me...");
}
public UpdateMyPluginPlz() {
// Download the file, overwriting the original.
// If the server changed level while downloading
// the original will be destroyed.
// The safe way would be to download it to
// another location and then move it.
DownloadStart(MyPluginUrl, g_downloadTo);
server_print("Done");
// Well, not actually done.
// You have to wait for it to download.
// I used a small plugin for this example.
}
test2.amxx:
PHP Code:
#include <amxmodx>
public plugin_init() {
register_plugin("Test 2", "1.0", "DivinityX");
server_print("What do you know about auto-update?");
}
Running first plugin:
After restart (mapchange would have the same effect):