VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
  Persistable = 0  'NotPersistable
  DataBindingBehavior = 0  'vbNone
  DataSourceBehavior  = 0  'vbNone
  MTSTransactionMode  = 0  'NotAnMTSObject
END
Attribute VB_Name = "clsISXDownload"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = True
Option Explicit
 'a basic wrapper for the freely available and open source ISX Download DLL at: http://www.istool.org
 'based on isxdl.dll version 4.0.8.0

 'Heres some text from the website:
 'This is a very simple DLL that you can use from My Inno Setup Extensions.
 'It allows you to download files from the Internet during the installation process.
 '
 'The DLL is very small, it will add less than 15K to your setup. Uncompressed the size is around 25K.
 'It uses the standard Internet API found in Internet Explorer version 3 or later.
 'Most computers should have this installed.
 'It will ask for user name and password for restricted web sites and proxys if needed.
 
 'This wrapper is free to use, modify, and distribute but USE IT AT YOURN OWN RISK.
 

 'PUBLIC PROPERTIES
 Private m_bGetFtpSize As Boolean
 Private m_sSimpleModeText As String
 Private m_bResume As Boolean
 Private m_sFormCaption As String
 Private m_sHeader As String
 Private m_sDescription As String


 'API CALLS
 Private Declare Function isxdl_Download Lib "isxdl.dll" _
        (ByVal hWnd As Long, ByVal sURL As String, ByVal sFileName As String) As Long
 
 Private Declare Function isxdl_AddFile Lib "isxdl.dll" _
        (ByVal sURL As String, ByVal sFileName As String) As Long
 
 Private Declare Function isxdl_AddFileSize Lib "isxdl.dll" _
        (ByVal sURL As String, ByVal sFileName As String, ByRef lFileSize As Long) As Long
 
 Private Declare Function isxdl_DownloadFiles Lib "isxdl.dll" (ByVal hWnd As Long) As Long
 
 Private Declare Sub isxdl_ClearFiles Lib "isxdl.dll" ()
 
 Private Declare Function isxdl_IsConnected Lib "isxdl.dll" () As Long
 
 Private Declare Function isxdl_SetOption Lib "isxdl.dll" _
        (ByVal sOption As String, ByVal sValue As String) As Long
 
 Private Declare Function isxdl_GetFileName Lib "isxdl.dll" (ByVal sURL As String) As String

Private Sub Class_Initialize()
    m_bGetFtpSize = True
    m_sSimpleModeText = ""
    m_bResume = True
    m_sFormCaption = "File Download"
    m_sHeader = "Download"
    m_sDescription = "Setup is now downloading additional files to your computer"
End Sub

Private Sub Class_Terminate()
    Call ClearFiles
End Sub

'Adds a file to the internal file list.
Public Sub AddFile(ByVal sURL As String, ByVal sFileName As String)
    'To access a url with basic password protection, enter something like
    'http://username:password@www.domain.com/path/page.html as url.
    
    Call isxdl_AddFile(sURL, sFileName)
End Sub

'Adds a file to the internal file list, and tells how big the file is.
Public Sub AddFileSize(ByVal sURL As String, ByVal sFileName As String, ByRef lFileSize As Long)
    'Use this if you know the size of the file, and know that it will not change.
    'Means that the DLL won't have to find the size,
    'which can take some time if you have many files to download.
    
    Call isxdl_AddFileSize(sURL, sFileName, lFileSize)
End Sub

'Clears the internal file list.
Public Sub ClearFiles()
    'Shouldn't be necessary since files will be removed as they are successfully downloaded.
    
    Call isxdl_ClearFiles
End Sub

'Immediately downloads a file from the Internet.
Public Function Download(ByVal hWndParent As Integer, ByVal sURL As String, ByVal sFileName As String) As Boolean
    'API Returns 1 if all files where downloaded successfully, otherwise 0.

    If isxdl_Download(hWndParent, sURL, sFileName) = 1 Then Download = True
End Function

'Downloads all files added with AddFile or AddFileSize.
Public Function DownloadFiles(ByVal hWndParent As Long) As Boolean
    'API Returns 1 if all files where downloaded successfully, otherwise 0.

    If isxdl_DownloadFiles(hWndParent) = 1 Then DownloadFiles = True
End Function

'Get the real file name of a downloaded file.
Public Function GetFileName(ByVal sURL As String) As String
    'The URL to download ISTool is 'http://www.bhenden.org/getfile.asp?file=15',
    'and before downloading isxdl_GetFileName returns 'getfile.asp?file=15'.
    'After downloading, the result will be 'istool-3.0.2.1.exe'.
    'API Returns the file name if the URL was found, otherwise returns NULL.

    GetFileName = isxdl_GetFileName(sURL)
End Function

'Tells wether the computer is connected to the Internet or not.
Public Function IsConnected() As Boolean
    'This is kind of experimental, and very little tested.
    'API Returns 1 if connected to the Internet, otherwise it returns 0.

    If isxdl_IsConnected = 1 Then IsConnected = True
End Function

'Set various options.
Public Function SetOptions(ByVal sOption As String, ByVal sValue As String) As Boolean
    'Currently these options can be set: Option Value
    'title          = The title to use for the download window.
    'noftpsize      = Don 't try to find the size of files using the FTP protocol.
                    'Valid values are "true" and "false".
    'debug          = Not used. Valid values are "true" and "false".
    'simple         = Turns on simple mode if the value is a string,
                    'turns off simple mode if the value is an empty string.
    'label          = Text for header label.
    'description    = Text for header description.
    'language       = Language file to get texts from.
    'resume         = Tell it to use resume. Default is true.
    
    'Returns 1 if the option was set successfully.
    'Returns 0 if the option was unknown, or the option could not be set.
    
    If isxdl_SetOption(sOption, sValue) = 1 Then SetOptions = True
End Function

Public Property Get Description() As String
    Description = m_sDescription
End Property

'Text for header description.
Public Property Let Description(ByVal sDescription As String)
    If SetOptions("description", sDescription) Then m_sDescription = sDescription
End Property

Public Property Get FormCaption() As String
    FormCaption = m_sFormCaption
End Property

'The title to use for the download window.
Public Property Let FormCaption(ByVal sFormCaption As String)
    If SetOptions("title", sFormCaption) = True Then m_sFormCaption = sFormCaption
End Property

Public Property Get GetFtpSize() As Boolean
    GetFtpSize = m_bGetFtpSize
End Property

'wether or not to find the size of files using the FTP protocol.
Public Property Let GetFtpSize(ByVal bGetFtpSize As Boolean)
    'Valid values are "true" and "false".
    
    Dim sValue As String
    
    If bGetFtpSize Then
        sValue = "true"
    Else
        sValue = "false"
    End If
    
    If SetOptions("noftpsize", sValue) Then m_bGetFtpSize = bGetFtpSize
End Property

Public Property Get Header() As String
    Header = m_sHeader
End Property

'Text for header label.
Public Property Let Header(ByVal sHeader As String)
    If SetOptions("label", sHeader) Then m_sHeader = sHeader
End Property

Public Property Get SimpleModeText() As String
    SimpleModeText = m_sSimpleModeText
End Property

Public Property Let SimpleModeText(ByVal sSimpleModeText As String)
    'Turns on simple mode if the value is a string,
    'turns off simple mode if the value is an empty string.
    
    If SetOptions("simple", sSimpleModeText) Then m_sSimpleModeText = sSimpleModeText
End Property

Public Property Get UseResume() As Boolean
    UseResume = m_bResume
End Property

Public Property Let UseResume(ByVal bResume As Boolean)
    'Tell it to use resume. Default is true.
    
    Dim sValue As String
    
    If bResume = True Then
        sValue = "true"
    Else
        sValue = "false"
    End If
    
    If SetOptions("resume", sValue) Then m_bResume = bResume
End Property
