|
|||
|
The Downloader.dll has been finished, which is included in the attached sample. It contains two objects
The first one is ZHttpDownloader, to create it, use the following code Code:
var downloader = new ActiveXObject("SWFKit.ZHttpDownloader");
1) Download(url, filename, startPos, length, downloadAnyway) This function will download a remote file specified by [url] in a new thread so that it will not block the main program. It supports both HTTP and FTP files. However, it does not support to resume ftp files. The [filename] parameter specifies the local file name to save the downloaded data. The [startPos] specifies the start position of the remote file to download. For a ftp file, or a http file does not support to resume, this parameter can only be zero. The [length] parameter specifies the length of data to download. If it is zero, the entire remote file will be downloaded. If [startPos] is not set to zero, and the remote file does not support to resume, and [downloadAnyway] is set to true, the function will download from the beginning of the remote file, and will download the entire remote file. If startPos is not zero, and the length of the output file [filename] is less than startPos, download will fail. In that case, you will have to use the SetFileSize method of the ZFileUtilities object to set the size of the output file. 2) Stop() This function is used to stop the download started by the Download function The object has one property [BytesDownloaded], which specifies the number of bytes that have been downloaded by the Download function. The object has the following three events 1) OnFail If the download has failed, this event will be triggered 2) OnComplete 3) OnProgress(size) Triggered when the Download function have got some data, the size is the number of bytes received after the previous OnProgress event. By handling this event, you can display the download progress. Another object is ZFileUtilities, it can be created by the following code Code:
var fu = new ActiveXObject("SWFKit.ZFileUtilities");
SetFileSize(filename, length) [filename] is the name of the local file to set its size [length] is the size of the file to set. If the file does not exist, it will be created, and be filled up to [length] |
|
|||
|
You can also use this component to download a file by using multiple threads - use different thread to download different part of the remote file. Before you download the remote file, you must first create a local file with the same size as the remote file so that the different threads can write to different parts of the local file. However, the Downloader component uses wininet.dll to download files, which restricts the number of concurrent connections to a server. For Http 1.1, the default number of allowed concurrent connections is 2. Therefore, please do not use more than two threads to download a file. Otherwise, the extra threads will be blocked until the first two threads have finished downloading their parts.
The following ffish script code shows how to download a file using two threads Code:
var downloader = new ActiveXObject("SWFKit.ZHttpDownloader");
var downloader1 = new ActiveXObject("SWFKit.ZHttpDownloader");
downloader.onFail = downloader1.onFail = function (msg)
{
trace(msg);
}
downloader.onComplete = downloader1.onComplete = function ()
{
trace("finished!");
}
downloader.onProgress = function(iSize) {
trace(iSize);
}
var filename = "c:\\flash\\setup.exe";
var url = "http://www.swfkit.com/download/swfkit/frobjsetup.exe";
// get the size of the remote file
var inet = new Inet;
var size = inet.getHttpFileSize(url);
var part = Math.floor(size / 2);
var fu = new ActiveXObject("SWFKit.ZFileUtilities");
fu.setFileSize(filename, size);
// download use two threads
downloader.download(url, filename, 0, part, false);
downloader1.download(url, filename, part, 0, false);
|
|
|||
|
I wonder, if there is a way to pack this lib into my myapp.exe in SWFKit?
( As in mdm zinc: mdm.Application.Library.extractAllToDir(extractDir :String):Void )
__________________
#define true false //happy debugging, friends |
|
|||
|
http://www.swfkit.com/swfkit/doc/manual/node28.html
The attached sample "ZDownloader.dll" uses the "register" method to register the Downloader ActiveX component - first copy it into the system folder, and then register it. However, in this way, the exe file will require the administrator privilege. Using the setup file to register the dll is recommended. |
|
|||
|
Yes, i read that manual before. Anyway, i cant include the .dll in the compiled file.
Actually, I don't use installer. I add the file in the resource pannel and compile the app. But the size of the app does not changes..
__________________
#define true false //happy debugging, friends |
![]() |
Was this information helpful? Yes No
| Thread Tools | |
| Display Modes | |
|
|