Call the ThunderAgent 1.0 Type Library

Source: Internet
Author: User
Tags ranges

Thunder API Interface

Appendix: The AddTask method is used. The parameters of this method are as follows: AddTask ("", "save file name", "Save directory", "task comment ", "Reference address", "Start mode", "Download from original address only", "Number of threads downloaded from original address ").
Parameter Name Description
PURL target URL, required Parameter
PFileName another storage name. The default value is null, indicating that it is processed by thunder. Optional Parameter
PPath storage directory. The default value is null, indicating that the directory is processed by thunder. Optional Parameter
PComments download comments. The default value is null. Optional.
PReferURL reference page URL. The default value is null. Optional.
NStartMode start mode. The value 0 starts manually. The value 1 starts immediately. The default value is-1, indicating that it is processed by thunder. An optional parameter.
Whether nOnlyFromOrigin can be downloaded only from the original URL, 1 can be downloaded only from the original URL, and 0 can be downloaded from multiple resources. The default value is 0. Optional Parameter
Number of threads downloaded from the original nOriginThreadCount address. The value ranges from 1 to 10. The default value is-1, indicating that the thread is processed by thunder. Optional Parameter

Public Function thunder download (URL: As String, Optional save path As String, Optional save As file name As String, Optional download comment As String, Optional reference page As String, Optional start mode As Long = 1, optional No download only from the original URL As Boolean = False, number of threads downloaded from the original Optional address As Long = 5) As Boolean
On Error GoTo Err
Dim ThunderAgent
'Nstartmode start mode. The value 0 starts manually and 1 starts immediately. The default value is-1, indicating that it is processed by thunder. An optional parameter
'Nonlyfromorigin indicates whether to download from the original URL only, 1 indicates to download from the original URL, and 0 indicates to download multiple resources. The default value is 0. This parameter is optional.
'Noriginthreadcount: the number of threads downloaded from the original address. The value range is 1-10. The default value is-1, indicating that the thread is processed by thunder. Optional Parameter
Set ThunderAgent = CreateObject ("ThunderAgent. Agent.1 ")
If ThunderAgent Is Nothing Then GoTo Err
Call ThunderAgent. AddTask (URL, save

File

File Name, save path, download comments, reference page, start mode, No download only from the original URL, number of threads downloaded from the original address)
Call ThunderAgent. CommitTasks2 (1)
Set ThunderAgent = Nothing
Thunder download = True
Exit Function
Err:
Thunder download = False
End Function

 


Call thunder download ("http://www.baidu.com/index.html", "c: \", "index.html", "http://www.baidu.com ")

First, make sure that the computer has been installed with Xunlei. Open VS. NET and click the menu: Project> Add reference> COM> Add to ThunderAgent 1.0.

Reference of Type Library
1. Create a record call object

Private ThunderEng As New THUNDERAGENTLib. Agent: Creates a record call object.

ThunderEng. AddTask ("", "save another file name", "Save directory", "task comment", "reference address", "Start mode ","

Only download from the original address "," Number of threads downloaded from the original address ")" add download task

ThunderEng. CommitTasks () 'submit the download task


2. Use Xunlei to call objects to query download task information

SFileSize = ThunderEng. GetTaskInfo (txtURL. Text, "FileSize") 'to get the downloaded file size
SDownedSize = ThunderEng. GetTaskInfo (txtURL. Text, "CompletedSize") 'to get the completed size
SFileName = ThunderEng. GetTaskInfo (txtURL. Text, "FileName") 'get the file name

Ii. Definition of interfaces of the thunder Platform

Obtain information

1. BSTR GetInfo (BSTR pInfoName)

Function: obtain information about thunder or platform.

Parameters:

Parameter Name Description
PInfoName information names, which can be found in the following four types:
. "ThunderExists": Does thunder exist?
. "ThunderRunning": whether or not thunder runs
. "ThunderVersion": the thunder version number
. "PlatformVersion": Platform version number

Return Value: The returned value is a string that corresponds to the pInfoName parameter.

Parameter Return Value
"ThunderExists" "true" and "false" do not exist
"ThunderRunning" and "true" are running, and "false" is not running.
"ThunderVersion": the version number "x. x"
"PlatformVersion" platform version "x. x"

2. HRESULT GetInfoStruct (INT pInfo)

Function: obtain all information related to thunder or platform.

Parameters:

Parameter Name Description
PInfo is actually a structure pointer of the THUNDER_INFO type. It is converted to the INT type before calling. After calling, the structure will fill in the platform information.

Is defined as follows:
Typedef struct _ THUNDER_INFO
{
BOOL bThunderExists;
BOOL bThunderRunning;
CHAR szThunderVersion [32];
CHAR szPlatformVersion [32];
} THUNDER_INFO;

After the function is called, the corresponding information is filled in the structure.

Return Value:

0: obtained successfully.
Failed to get non-0

Task operations

3. Add a task

HRESULT AddTask
(BSTR pURL,
BSTR pFileName = "",
BSTR pPath = "",
BSTR pComments = "",
BSTR pReferURL = "",
INT nStartMode =-1,
INT nOnlyFromOrigin = 0,
INT nOriginThreadCount =-1 );

Function:

Add the download task information to the platform, which is not yet reflected in thunder.

Parameters:

Parameter Name Description
PURL target URL, required Parameter
PFileName another storage name. The default value is null, indicating that it is processed by thunder. Optional Parameter
PPath storage directory. The default value is null, indicating that the directory is processed by thunder. Optional Parameter
PComments download comments. The default value is null. Optional.
PReferURL reference page URL. The default value is null. Optional.
NStartMode start mode. The value 0 starts manually. The value 1 starts immediately. The default value is-1, indicating that it is processed by thunder. An optional parameter.
Whether nOnlyFromOrigin can be downloaded only from the original URL, 1 can be downloaded only from the original URL, and 0 can be downloaded from multiple resources. The default value is 0. Optional Parameter
Number of threads downloaded from the original nOriginThreadCount address. The value ranges from 1 to 10. The default value is-1, indicating that the thread is processed by thunder. Optional Parameter

4. Start the task

HRESULT CommitTaskss ()

Function:

Submit the information of the AddTask download task to thunder for download and delete it from the platform.

Note: If the task added by AddTask is not submitted and canceled (CancelTasks is called), the Agent object will

So the caller should not leave any unsubmitted or canceled tasks to prevent the script executor from stopping the response.

5. Cancel the task

HRESULT CancelTasks ()

Function:

Cancel all download task information added by AddTask on the platform

6. Query Task Information

BSTR GetTaskInfo (BSTR pURL, BSTR pInfoName );

Parameters:

Parameter Name Description
PURL: the download URL to be queried.
PInfoName status names:

. "Exists": whether pURL is in the thunder task list
. "Path": storage directory
. "FileName": File Name
. "FileSize": File Size
. "CompletedSize": downloaded size
. "Percent": download progress
. "Status": Task Status

Return Value: The returned value is a string that corresponds to the pInfoName parameter.

Parameter Return Value
"Exists" "true" and "false" do not exist
"Path" storage directory, followed by backslash \, for example: C: \ TDDownload \
"FileName" File Name
"FileSize" file size, in bytes. 0 indicates the size is unknown.
"CompletedSize": downloaded size, in bytes
"Percent" download progress, with 1 decimal point, for example: 70.0
"Status" task Status, which has the following six statuses:

. "Running": running status
. "Stopped": stopped
. "Failed": failure status
. "Success": Successful
. "Creatingfile": creating a data file
. "Connecting": connecting

7. GetTaskInfoStruct (INT pTaskInfo)

Function: Query all information of a task.

Parameter Name Description
PTaskInfo is actually a structure pointer of the THUNDER_TASKINFO type. It is converted to the INT type before calling. The structure will be filled in after calling.

The platform information is defined as follows:

Typedef struct _ THUNDER_TASKINFO
{
CHAR szURL [1024]; // task URL, prefilled
BOOL bTaskExists; // whether the task exists. TRUE indicates that the task exists.
CHAR szPath [256]; // Local save path for download
CHAR szFileName [256]; // local file name
ULONGLONG nFileSize; // File Size
ULONGLONG nCompletedSize; // completed size
CHAR szPercent [16]; // percentage of completion, in the "56.8" Format
CHAR szStatus [16]; // The Current Status, defining the same function as GetTaskInfo
} THUNDER_TASKINFO;

The caller first fills in the szURL member in the structure to specify the URL of the task to be queried. Then, after the function returns, the caller can

Obtain information about the task.
All code in this example

Imports System
Imports System. Text
Public Class frmThunderClass frmThunder
Private _ iStartMode As Integer 'thunder task download start Mode
Private ThunderEng As New THUNDERAGENTLib. Agent: Creates a record call object.
Private Sub frmThunder_Load () Sub frmThunder_Load (ByVal sender As System. Object, ByVal e

System. EventArgs) Handles MyBase. Load
End Sub
Private Sub btnCancel_Click () Sub btnCancel_Click (ByVal sender As System. Object, ByVal e

System. EventArgs) Handles btnCancel. Click
Close ()
End Sub
'Start the download task
Private Sub btnStartDown_Click () Sub btnStartDown_Click (ByVal sender As System. Object, ByVal

E As System. EventArgs) Handles btnStartDown. Click
Dim iOnlyFromOrigin, iOriginThreadCount As Integer
IOnlyFromOrigin = IIf (chkOnlyFromOrigin. Checked = True, 1, 0)
IOriginThreadCount = CInt (txtOriginThreadCounts. Text)
If chkDefault. Checked Then
IOriginThreadCount =-1
End If
ThunderEng. AddTask (txtURL. Text, txtSaveAsFileName. Text, txtSaveDir. Text, txtComment. Text ,_
TxtReferencePage. Text, _ iStartMode, iOnlyFromOrigin, iOriginThreadCount)
ThunderEng. CommitTasks ()
Timer1.Enabled = True
End Sub


Private Sub radMaual_Click () Sub radMaual_Click (ByVal sender As System. Object, ByVal e

System. EventArgs) Handles radMaual. Click, radImmediate. Click, radDefault. Click
Dim rad As RadioButton = CType (sender, RadioButton)
_ IStartMode = CInt (rad. Tag)
End Sub
'Query the task download information regularly when the task starts.
Private Sub timereffectick () Sub timereffectick (ByVal sender As System. Object, ByVal e

System. EventArgs) Handles Timer1.Tick
Dim sFileSize, sDownedSize, sStatus, sFileName, sPercent As String
Try
SStatus = ThunderEng. GetTaskInfo (txtURL. Text, "Status ")
SFileSize = ThunderEng. GetTaskInfo (txtURL. Text, "FileSize ")
SDownedSize = ThunderEng. GetTaskInfo (txtURL. Text, "CompletedSize ")
SFileName = ThunderEng. GetTaskInfo (txtURL. Text, "FileName ")
LblDownedSize. Text = String. Format (lblDownedSize. Tag, sDownedSize)
LblFileSize. Text = String. Format (lblFileSize. Tag, sFileSize)
LblTaskStatus. Text = String. Format (lblTaskStatus. Tag, sStatus)
LblFilename. Text = String. Format (lblFilename. Tag, sFileName)
SPercent = ThunderEng. GetTaskInfo (txtURL. Text, "Percent") 'to get the download percentage
LblProgress. Text = String. Format (lblProgress. Tag, sPercent. Remove (3, Len (sPercent)-3 ))
Catch ex As Exception
End Try
End Sub
Private Sub chkOnlyFromOrigin_CheckedChanged_1 () Sub chkOnlyFromOrigin_CheckedChanged_1 (ByVal

Sender As System. Object, ByVal e As System. EventArgs) Handles

ChkOnlyFromOrigin. CheckedChanged
Panel1.Enabled = chkOnlyFromOrigin. Checked
End Sub
Private Sub groupbox‑enter () Sub groupbox‑enter (ByVal sender As System. Object, ByVal e

System. EventArgs) Handles GroupBox1.Enter
End Sub
End Class

Go to tool-configuration-advanced, and remove the check box before the option "use thunder download" in the shortcut menu of IE.
Keep the thunder on. When the above script is executed, the dialog box confirming task addition will not appear.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.