Raised This Month: $399 Target: $400
 99%   Almost there!

Module: Download


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Black Rose
Veteran Member
Join Date: Feb 2011
Location: Upplands Väsby, Sweden
Old 02-27-2011 , 14:23   Module: Download
Reply With Quote #1

Update 2013-07-31: I removed the binary. It was a shitty module. If anyone is interested I'll leave the source, but have in mind it's much better to use sockets for three reasons. 1. Everyone has it. 2. It won't crash like this do. 3. It's easier to work with.

Please refer to my HTTP2 include instead of this module.

Download 1.0

Enables plugins to download files from http sources.
Basically a wrapper for URLDownloadToFile.
More info on that function:
http://msdn.microsoft.com/en-us/library/ms775123.aspx

Could enable, for example, auto-updating of plugins. (Not alone though)
Known problem:
When I placed 6+ downloads at server startup it would crash on me at restart. (Not first start) Reason: unknown. I'm not that good at C++... Either way, it basically works.

PHP Code:
/*
* native DownloadStart(const url[], const file[]);
*     Start the download of a file from http source.

* Arguments:

*     const url[]:
*         Source URL to download from.

*     const file[]:
*         Local filename to save to.
*         Can be used both with "C:\file.ext" or "/file.ext".
*         The latest will save the file under moddir.

* Returns:

*     On success:
*         Download Id
*             Integer 0-9
*     On fail:
*         -1
*             Error message displayed in console.

*     Note:    0-9 does not guarantee success.
*             If I was to make the module wait for the
*             status of the file, it will freeze the server.
*             You need to use the DownloadFailed forward.
*             If that forward is never called, successful.
* */
native DownloadStart(const url[], const file[]);


/*
* native DownloadAbort(Id);
*     Aborts a download.

* Arguments:

*     Id:
*         Download Id to abort.


* Returns:
*     0
* */
native DownloadAbort(Id);

/*
* forward DownloadDone(Id, KBDone, KBTotal);
*     This forward is called when any file is finished.

* Arguments:

*     Id:
*         Current Download Id.

*     KBDone:
*         KiBiBytes downloaded.

*     KBTotal
*         KiBiBytes total.

* Possible return values:
*     Return value is ignored.
* */
forward DownloadDone(IdKBDoneKBTotal);

/*
* forward Downloading(Id, BDone, BTotal);
*     This forward is called as long as any file is downloading.

* Arguments:

*     Id:
*         Current Download Id.

*     KBDone:
*         KiBiBytes downloaded.

*     KBTotal
*         KiBiBytes total.

* Possible return values:
*     Return value is ignored.
* */
forward Downloading(IdKBDoneKBTotal);

/*
* forward DownloadFailed(Id);
*     This forward is called when a download fail.
*     Reason is specified in console.

* Arguments:

*     Id:
*         The download Id that failed.

*     ErrorId:
*         The Id of the error, more information:
*         http://msdn.microsoft.com/en-us/library/ms775145.aspx

* Possible return values:
*     Return value is ignored.
* */
forward DownloadFailed(IdErrorId); 
Kind regards
Black Rose, also known here as [ --<[email protected] ] Black Rose or DivinityX
Attached Files
File Type: inc Download.inc (2.1 KB, 247 views)
File Type: zip Download Source.zip (116.9 KB, 223 views)

Last edited by Black Rose; 09-08-2013 at 07:04.
Black Rose is offline
ot_207
Veteran Member
Join Date: Jan 2008
Location: Romania The Love Country
Old 02-27-2011 , 15:14   Re: Module: Download
Reply With Quote #2

Just lol, and gj.
Will test this.
Maybe a port to linux?
__________________
My approved plug-ins | Good for newbies! | Problems?

Back, will come around when I have time.
ot_207 is offline
fmfs10
Senior Member
Join Date: Mar 2009
Location: Brasil
Old 02-27-2011 , 15:26   Re: Module: Download
Reply With Quote #3

You can make the possibility of compress files and uncompress this. Or just the ability of uncompress files after download a compressed files. It would help a lot servers when downloading big files (like models)

[email protected]

You should add the ability to read file version url side too =P
fmfs10 is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 02-27-2011 , 16:25   Re: Module: Download
Reply With Quote #4

Is this supposed to be an alternative to FTP? I think I would always prefer FTP.
__________________
fysiks is offline
fmfs10
Senior Member
Join Date: Mar 2009
Location: Brasil
Old 02-27-2011 , 17:29   Re: Module: Download
Reply With Quote #5

Quote:
Originally Posted by fysiks View Post
Is this supposed to be an alternative to FTP? I think I would always prefer FTP.
I don't know but I think it can change the file. FTP can't delete a data =x
fmfs10 is offline
Black Rose
Veteran Member
Join Date: Feb 2011
Location: Upplands Väsby, Sweden
Old 02-27-2011 , 17:37   Re: Module: Download
Reply With Quote #6

Quote:
Originally Posted by ot_207 View Post
Just lol, and gj.
Will test this.
Maybe a port to linux?
I don't know anything about linux.
All my modules are based on Windows functions.

Quote:
Originally Posted by fmfs10 View Post
You can make the possibility of compress files and uncompress this. Or just the ability of uncompress files after download a compressed files. It would help a lot servers when downloading big files (like models)
uncompress files is easily done with my ExecuteX plugin, combined win rar.exe (command line WinRAR). I might add it, but I wouldn't count on it.
As stated, I'm not that good at C++.
Quote:
Originally Posted by fmfs10 View Post
You should add the ability to read file version url side too =P
I don't quite understand what you mean. You can download a website and parse it like any file.

Quote:
Originally Posted by fysiks View Post
Is this supposed to be an alternative to FTP? I think I would always prefer FTP.
I don't understand. This works on ftp aswell.

Last edited by Black Rose; 02-27-2011 at 18:09.
Black Rose is offline
fmfs10
Senior Member
Join Date: Mar 2009
Location: Brasil
Old 02-27-2011 , 18:19   Re: Module: Download
Reply With Quote #7

Quote:
Originally Posted by Black Rose View Post
I don't quite understand what you mean. You can download a website and parse it like any file.
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...
fmfs10 is offline
Black Rose
Veteran Member
Join Date: Feb 2011
Location: Upplands Väsby, 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
fmfs10
Senior Member
Join Date: Mar 2009
Location: Brasil
Old 02-27-2011 , 18:57   Re: Module: Download
Reply With Quote #9

Yeah you are right =P

Sorry '-'
fmfs10 is offline
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 02-27-2011 , 19:04   Re: Module: Download
Reply With Quote #10

Advantages/disadvantages of using this instead of using the sockets module to do this manually, or even the HTTP Downloader plugin?
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 17:06.


Powered by vBulletin®
Copyright ©2000 - 2020, vBulletin Solutions, Inc.
Theme made by Freecode