View Single Post
Author Message
Black Rose
Veteran Member
Join Date: Feb 2011
Location: Stockholm, 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 [ --<-@ ] Black Rose or DivinityX
Attached Files
File Type: inc Download.inc (2.1 KB, 333 views)
File Type: zip Download Source.zip (116.9 KB, 315 views)

Last edited by Black Rose; 09-08-2013 at 07:04.
Black Rose is offline