#include-once #include ;############################################################################### ; ============================================================================== ; UDF ...........: _FF_DM.au3 ; Description ...: An UDF for FireFox-download-manager automation. ; Requirement ...: FF.au3 > V0.5.3.0 / MozRepl AddOn: ; http://hyperstruct.net/projects/mozlab ; http://wiki.github.com/bard/mozrepl/home ; Author(s) .....: Thorsten Willert ; Date ..........: Tue Apr 28 22:29:03 CEST 2009 @895 /Internet Time/ ; FireFox Version: Firefox/3.0.8 (required 3.x) ; Links .........: https://developer.mozilla.org/en/NsIDownloadManager ; https://developer.mozilla.org/en/nsIDownload ; ============================================================================== ; #CURRENT# ==================================================================== ; _FF_DM_CleanUp ; _FF_DM_DownloadPause ; _FF_DM_DownloadRemove ; _FF_DM_DownloadResume ; _FF_DM_DownloadCancel ; _FF_DM_DownloadRetry ; _FF_DM_GetActiveDownloadsIDs ; _FF_DM_GetActiveDownloadsCount ; _FF_DM_GetDownloadInfo ; _FF_DM_GetDownloadState ; _FF_DM_IsDownloading ;=============================================================================== ; #FUNCTION# =================================================================== ; Name ..........: _FF_DM_CleanUp ; Description ...: Removes completed, failed, and canceled downloads from the list ; AutoIt Version : V3.3.0.0 ; Requirement(s).: FF.au3 / MozRepl ; Syntax ........: _FF_DM_CleanUp() ; Parameter(s): .: ; Return Value ..: Success - 1 ; Failure - 0 ; @ERROR - 1 ; Author(s) .....: Thorsten Willert ; Date ..........: Sat Mar 28 00:22:51 CET 2009 ; Related .......: ; Link ..........: ; ============================================================================== Func _FF_DM_CleanUp() __FF_DM_Action("cleanUp()") If Not @error Then Local $RetVal = __FF_DM_Action("canCleanUp") If Not @error And $RetVal = 0 Then Return 1 EndIf SetError(1) Return 0 EndFunc ;==>_FF_DM_CleanUp ; #FUNCTION# =================================================================== ; Name ..........: _FF_DM_DownloadPause ; Description ...: Pauses the specified download ; AutoIt Version : V3.3.0.0 ; Requirement(s).: FF.au3 / MozRepl ; Syntax ........: _FF_DM_DownloadPause($iID) ; Parameter(s): .: $iID - Download ID ; Return Value ..: Success - 1 ; Failure - 0 ; @ERROR - ; Author(s) .....: Thorsten Willert ; Date ..........: Sat Mar 28 00:24:15 CET 2009 ; Related .......: ; Link ..........: ; ============================================================================== Func _FF_DM_DownloadPause($iID) If Not IsInt($iID) Then SetError(1) Return 0 EndIf Local $sRetVal = __FF_DM_Action("pauseDownload", $iID) If Not @error And $sRetVal <> -3 Then Return 1 SetError(1) Return 0 EndFunc ;==>_FF_DM_DownloadPause ; #FUNCTION# =================================================================== ; Name ..........: _FF_DM_DownloadRemove ; Description ...: Removes the download with the specified ID if it's not currently in progress. ; AutoIt Version : V3.3.0.0 ; Requirement(s).: FF.au3 / MozRepl ; Syntax ........: _FF_DM_DownloadRemove($iID) ; Parameter(s): .: $iID - Download ID ; Return Value ..: Success - 1 ; Failure - 0 ; @ERROR - ; Author(s) .....: Thorsten Willert ; Date ..........: Sat Mar 28 00:25:06 CET 2009 ; Related .......: ; Link ..........: ; ============================================================================== Func _FF_DM_DownloadRemove($iID) If Not IsInt($iID) Then SetError(1) Return 0 EndIf Local $sRetVal = __FF_DM_Action("removeDownload", $iID) If Not @error And $sRetVal <> -3 Then Return 1 SetError(1) Return 0 EndFunc ;==>_FF_DM_DownloadRemove ; #FUNCTION# =================================================================== ; Name ..........: _FF_DM_DownloadResume ; Description ...: Resumes the specified download. ; AutoIt Version : V3.3.0.0 ; Requirement(s).: FF.au3 / MozRepl ; Syntax ........: _FF_DM_DownloadResume($iID) ; Parameter(s): .: $iID - Download ID ; Return Value ..: Success - 1 ; Failure - 0 ; @ERROR - ; Author(s) .....: Thorsten Willert ; Date ..........: Sat Mar 28 00:25:44 CET 2009 ; Related .......: ; Link ..........: ; ============================================================================== Func _FF_DM_DownloadResume($iID) If Not IsInt($iID) Then SetError(1) Return 0 EndIf Local $sRetVal = __FF_DM_Action("resumeDownload", $iID) If Not @error And $sRetVal <> -3 Then Return 1 SetError(1) Return 0 EndFunc ;==>_FF_DM_DownloadResume ; #FUNCTION# =================================================================== ; Name ..........: _FF_DM_DownloadCancel ; Description ...: Cancels the download with the specified ID if it's currently in-progress. ; AutoIt Version : V3.3.0.0 ; Requirement(s).: FF.au3 / MozRepl ; Syntax ........: _FF_DM_DownloadCancel($iID) ; Parameter(s): .: $iID - Download ID ; Return Value ..: Success - 1 ; Failure - 0 ; @ERROR - ; Author(s) .....: Thorsten Willert ; Date ..........: Sat Mar 28 00:26:33 CET 2009 ; Related .......: ; Link ..........: ; ============================================================================== Func _FF_DM_DownloadCancel($iID) If Not IsInt($iID) Then SetError(1) Return 0 EndIf Local $sRetVal = __FF_DM_Action("cancelDownload", $iID) If Not @error And $sRetVal <> -3 Then Return 1 SetError(1) Return 0 EndFunc ;==>_FF_DM_DownloadCancel ; #FUNCTION# =================================================================== ; Name ..........: _FF_DM_DownloadRetry ; Description ...: Retries a failed download. ; AutoIt Version : V3.3.0.0 ; Requirement(s).: FF.au3 / MozRepl ; Syntax ........: _FF_DM_DownloadRetry($iID) ; Parameter(s): .: $iID - Download ID ; Return Value ..: Success - 1 ; Failure - 0 ; @ERROR - ; Author(s) .....: Thorsten Willert ; Date ..........: Sat Mar 28 00:27:06 CET 2009 ; Related .......: ; Link ..........: ; ============================================================================== Func _FF_DM_DownloadRetry($iID) If Not IsInt($iID) Then SetError(1) Return 0 EndIf Local $sRetVal = __FF_DM_Action("retryDownload", $iID) If Not @error And $sRetVal <> -3 Then Return 1 SetError(1) Return 0 EndFunc ;==>_FF_DM_DownloadRetry ; #FUNCTION# =================================================================== ; Name ..........: _FF_DM_GetActiveDownloadsIDs ; Description ...: Returns array with the IDs of all downloads. ; AutoIt Version : V3.3.0.0 ; Requirement(s).: FF.au3 / MozRepl ; Syntax ........: _FF_DM_GetActiveDownloadsIDs() ; Parameter(s): .: ; Return Value ..: Success - Array ; Failure - 0 ; @ERROR - ; Author(s) .....: Thorsten Willert ; Date ..........: Sat Mar 28 00:28:03 CET 2009 ; Related .......: ; Link ..........: ; ============================================================================== Func _FF_DM_GetActiveDownloadsIDs() __FF_DM_Action("activeDownloads") If Not @error Then Local $sRetVal = _FFCmd("FFau3.tmp='';while(FFau3.obj.hasMoreElements()){FFau3.tmp+=FFau3.obj.getNext().id+'|';}FFau3.tmp;") Local $aRet = StringSplit($sRetVal, "|") If Not @error Then For $i = 0 To UBound($aRet)-1 $aRet[$i] = Int($aRet[$i]) Next Return $aRet EndIf EndIf SetError(1) Return 0 EndFunc ;==>_FF_DM_GetActiveDownloadsIDs ; #FUNCTION# =================================================================== ; Name ..........: _FF_DM_GetActiveDownloadsCount ; Description ...: The number of files currently being downloaded. ; AutoIt Version : V3.3.0.0 ; Requirement(s).: FF.au3 / MozRepl ; Syntax ........: _FF_DM_GetActiveDownloadsCount() ; Parameter(s): .: ; Return Value ..: Success - >= 0 ; Failure - -1 ; @ERROR - ; Author(s) .....: Thorsten Willert ; Date ..........: Sat Mar 28 00:28:46 CET 2009 ; Related .......: ; Link ..........: ; ============================================================================== Func _FF_DM_GetActiveDownloadsCount() Local $iDownloads = __FF_DM_Action("activeDownloadCount") If Not @error And $iDownloads <> -3 Then Return $iDownloads SetError(1) Return -1 EndFunc ;==>_FF_DM_GetActiveDownloadsCount ; #FUNCTION# =================================================================== ; Name ..........: _FF_DM_GetDownloadInfo ; Description ...: Returns an array with all Attributes of the download with the specified ID. ; AutoIt Version : V3.3.0.0 ; Requirement(s).: FF.au3 / MozRepl ; Syntax ........: _FF_DM_GetDownloadInfo($iID) ; Parameter(s): .: $iID - Download ID ; Return Value ..: Success - array: ; [0] = targetFile ; [1] = percentComplete ; [2] = amountTransferred ; [3] = size ; [4] = source ; [5] = displayName ; [6] = startTime ; [7] = speed ; [8] = MIMEInfo ; [9] = id ; [10] = state ; [11] = referrer ; Failure - 0 ; @ERROR - ; Author(s) .....: Thorsten Willert ; Date ..........: Sat Mar 28 00:29:55 CET 2009 ; Related .......: ; Link ..........: https://developer.mozilla.org/en/nsIDownload ; ============================================================================== Func _FF_DM_GetDownloadInfo($iID) If Not IsInt($iID) Then SetError(1) Return "" EndIf Local $sRetVal = __FF_DM_Action("getDownload", $iID) If Not @error And $sRetVal <> -3 Then Local $sCommand = 'FFau3.tmp="";' $sCommand &= 'FFau3.tmp+=FFau3.obj.targetFile.target+"|";' $sCommand &= 'FFau3.tmp+=FFau3.obj.percentComplete+"|";' $sCommand &= 'FFau3.tmp+=FFau3.obj.amountTransferred+"|";' $sCommand &= 'FFau3.tmp+=FFau3.obj.size+"|";' $sCommand &= 'FFau3.tmp+=FFau3.obj.source.spec+"|";' ;$sCommand &= 'FFau3.tmp+=FFau3.obj.cancelable+"|";' $sCommand &= 'FFau3.tmp+=FFau3.obj.displayName+"|";' $sCommand &= 'FFau3.tmp+=FFau3.obj.startTime+"|";' $sCommand &= 'FFau3.tmp+=FFau3.obj.speed+"|";' $sCommand &= 'FFau3.tmp+=FFau3.obj.MIMEInfo.MIMEType+"|";' $sCommand &= 'FFau3.tmp+=FFau3.obj.id+"|";' $sCommand &= 'FFau3.tmp+=FFau3.obj.state+"|";' $sCommand &= 'FFau3.tmp+=FFau3.obj.referrer.spec+"\n";FFau3.tmp;' $sRetVal = _FFCmd($sCommand) Local $aRet = StringSplit($sRetVal, "|") If Not @error Then Return $aRet EndIf SetError(1) Return 0 EndFunc ;==>_FF_DM_GetDownloadInfo ; #FUNCTION# =================================================================== ; Name ..........: _FF_DM_GetDownloadState ; Description ...: State of the specified download ; AutoIt Version : V3.3.0.0 ; Requirement(s).: FF.au3 / MozRepl ; Syntax ........: _FF_DM_GetDownloadState($iID) ; Parameter(s): .: $iID - Download ID ; Return Value ..: Success - (int) ; | -1 = The download hasn't been started yet. ; | 0 = The download is in the process of being downloaded. ; | 1 = The download is complete. ; | 2 = The download failed. ; | 3 = The download failed. ; | 4 = The download is currently paused. ; | 5 = The download is in the queue but is not presently downloading. ; | 6 = The download has been blocked, either by parental controls or the ; virus scanner determining that a file is infected and cannot be cleaned. ; | 7 = The download is being scanned by a virus checking utility. ; Failure - -2 ; @ERROR - ; Author(s) .....: Thorsten Willert ; Date ..........: Sat Mar 28 00:24:15 CET 2009 ; Related .......: ; Link ..........: ; ============================================================================== Func _FF_DM_GetDownloadState($iID) If Not IsInt($iID) Then SetError(1) Return -2 EndIf Local $sRetVal = __FF_DM_Action("getDownload", $iID, ".state") If Not @error And $sRetVal <> -3 Then Return $sRetVal SetError(1) Return -2 EndFunc ;==> _FF_DM_GetDownloadState ; #FUNCTION# =================================================================== ; Name ..........: _FF_DM_IsDownloading ; Description ...: Returns if any download is active. ; AutoIt Version : V3.3.0.0 ; Requirement(s).: FF.au3 / MozRepl ; Syntax ........: _FF_DM_IsDownloading() ; Parameter(s): .: ; Return Value ..: Success - 1 ; Failure - 0 ; @ERROR - ; Author(s) .....: Thorsten Willert ; Date ..........: Sat Mar 28 00:33:25 CET 2009 ; Related .......: ; Link ..........: ; ============================================================================== Func _FF_DM_IsDownloading() Local $iCount = _FF_DM_GetActiveDownloadsCount() If Not @error And $iCount > 0 Then Return 1 SetError(1) Return 0 EndFunc ;==>_FF_DM_IsDownloading ; #INTERNAL_USE_ONLY# ========================================================== ; Name ..........: __FF_DM_Action ; Description ...: ; AutoIt Version : V3.3.0.0 ; Syntax ........: __FF_DM_Action($sAction[, $iID = -1[, $bState = False]]) ; Parameter(s): .: $sAction - ; $iID - Optional: (Default = -1) : ; $sAttr - Optional: (Default = "") : ; Return Value ..: Success - ; Failure - ; @ERROR - ; Author(s) .....: Thorsten Willert ; Date ..........: Sat Mar 28 00:34:22 CET 2009 ; ============================================================================== Func __FF_DM_Action($sAction, $iID = -1, $sAttr = "") Local $sState = "" If $iID > -1 Then $iID = '(' & $iID & ')' Else $iID = "" EndIf Local $RetVal = _FFCmd('try{FFau3.obj = Components.classes["@mozilla.org/download-manager;1"].getService(Components.interfaces.nsIDownloadManager).' & $sAction & $iID & $sAttr & ';}catch(e){-3;};') SetError(@error) Return $RetVal EndFunc ;==>__FF_DM_Action