View Single Post
Black Rose
Veteran Member
Join Date: Feb 2011
Location: Stockholm, Sweden
Old 02-27-2011 , 18:54   Re: Module: Download
Reply With Quote #8

Quote:
Originally Posted by fmfs10 View Post
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(modname31);
    
    
// Next, we need plugins filename.
    
get_plugin (-1filenamecharsmax(filename), pluginsdircharsmax(pluginsdir), pluginsdircharsmax(pluginsdir), pluginsdircharsmax(pluginsdir), pluginsdircharsmax(pluginsdir));
    
    
// We also want to know where that file is stored. NO HARDCODING!
    
get_localinfo("amxx_pluginsdir"pluginsdircharsmax(pluginsdir))
    
    
// Format it up to fit into 1 param.
    
formatex(g_downloadTocharsmax(g_downloadTo), "%s/%s/%s"modnamepluginsdirfilename);
    
    
// 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(MyPluginUrlg_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):

Last edited by Black Rose; 07-31-2013 at 16:52.
Black Rose is offline