So when the user Cancel the download, it reopens the FileDialog instead of getting out of the _DL func and waiting. I put the second $returnvalue2 at the beginning of _DL because when i get out of the loop and the func, it reenters in _DL for a reason i don't understand. That was the only way i had to get out of the _DL func. If the user say yes, it stops InetGet, delete the file, set the former button back, and try to get out of the DL loop by setting a flag $returnvalue to "True". Once the user push "Cancel", i pop a MsgBox to confirm cancelling. I had to add a message handler to be able to cancel the download or quit while it's downloading. So the user press "Télécharger" to "Download" the file, the button is changed in "Cancel" and the download begins.Īll is working fine until here. I stripped useless functions as my problem is somewhat targeted. InetClose ( $hInetget ) GUICtrlSetState ( Eval ( "btnopen" & GUICtrlRead ( $tab ) * 4 ), $GUI_ENABLE ) _RetabControls ( ) EndFunc =>_DL Func _RetabControls ( ) GUICtrlSetState ( $dlspeed, $GUI_HIDE ) GUICtrlSetData ( Eval ( "btndl" & GUICtrlRead ( $tab ) * 4 ), "Download" ) GUICtrlSetTip ( Eval ( "btndl" & GUICtrlRead ( $tab ) * 4 ), "Download the File" ) GUICtrlSetOnEvent ( Eval ( "btndl" & GUICtrlRead ( $tab ) * 4 ), _DL ) GUICtrlSetData ( $hprogress, 0 ) EndFunc =>_RetabControls Func _WM _SYSCOMMAND ( $hWnd, $Msg, $wParam, $lParam ) If $wParam = 0xF060 And InetGetInfo ( ) 0 Then _InterruptionDL ( ) EndIf Return 'GUI_RUNDEFMSG' EndFunc =>_WM_SYSCOMMAND Func WM _COMMAND ( $hWnd, $Msg, $wParam, $lParam ) #forceref $hWnd, $Msg, $lParam If _WinAPI_LoWord ( $wParam ) = Eval ( "btndl" & GUICtrlRead ( $tab ) * 4 ) And _WinAPI_HiWord ( $wParam ) = $BN_CLICKED And InetGetInfo ( ) 0 Then _CancelDL ( ) EndIf If _WinAPI_HiWord ( $wParam ) = $GUI_EVENT_CLOSE Or _WinAPI_LoWord ( $wParam ) = $Quitter And InetGetInfo ( ) 0 Then _InterruptionDL ( ) EndIf Return 'GUI_RUNDEFMSG' EndFunc =>WM_COMMAND Func _InterruptionDL ( ) If MsgBox ( 36, "Confirmation", "Cancel the DL and Quit ?" ) = 6 Then FileDelete ( $sSaveFile ) GUIDelete ( $DltGui ) Exit EndIf EndFunc =>_InterruptionDL Func _CancelDL ( ) If MsgBox ( 36, "Confirmation", "Cancel the DL ?" ) = 6 Then InetClose ( $hInetget ) FileDelete ( $sSaveFile ) $returnvalue = 1 _RetabControls ( ) EndIf EndFunc =>_CancelDL Func _Launch ( ) If FileExists ( $sSaveFile ) Then ShellExecute ( $sSaveFile ) Else MsgBox ( $MB_ICONERROR, "Error", "File does not exist" ) EndIf EndFunc =>_Launch Func _String _GetFormattedSize ( $iByteSize, $iRound = 2, $sRetFormat = - 1 ) Local $asBytes = Last two unreachable ) Local $iBytes_Val = 2 ^ 10 If $iByteSize = $iBytes_Val ^ $i ) Then Return Round ( $iByteSize / $iBytes_Val ^ $i, $iRound ) & ' ' & $asBytes EndIf Next EndFunc =>_String_GetFormattedSize Func _Exit ( ) GUIDelete ( $DltGui ) Exit EndFunc =>_Exit While 1 Sleep ( 100 ) Idle WEnd Expand collapse popup Opt ( "GUIOnEventMode", 1 ) Opt ( "TrayIconHide", 1 ) GUISetOnEvent ( $GUI_EVENT_CLOSE, _Exit ) GUIRegisterMsg ( $WM_COMMAND, "WM_COMMAND" ) GUIRegisterMsg ( $WM_SYSCOMMAND, "_WM_SYSCOMMAND" ) GUISetState (, $DltGui ) Global $returnvalue2 = 0 Func _DL ( ) Global $returnvalue = 0 If $returnvalue2 = 1 Then $returnvalue2 = 0 Return EndIf Local $snomfichierdl = _ArrayToString ( StringRegExp ( $aCSV, "/(+)$", 1 ) ) Global $sSaveFile = FileSaveDialog ( "Enregistrer le fichier", , "Tous (*.*)", 16, $snomfichierdl ) If Then Return GUICtrlSetData ( Eval ( "btndl" & GUICtrlRead ( $tab ) * 4 ), "Cancel" ) GUICtrlSetTip ( Eval ( "btndl" & GUICtrlRead ( $tab ) * 4 ), "Cancel the DL" ) GUICtrlSetOnEvent ( Eval ( "btndl" & GUICtrlRead ( $tab ) * 4 ), _CancelDL ) Global $hInetget = InetGet ( $urlfilauth, $sSaveFile, 1, 1 ) Local $Bytes, $NewBytes, $pourcent_New $size = InetGetSize ( $urlfilauth ) Local $nowRead = 0 Local $pourcent = 0 GUICtrlSetState ( $dlspeed, $GUI_SHOW ) Do If $returnvalue = 1 Then $returnvalue = 0 $returnvalue2 = 1 Return EndIf $Bytes = Round ( InetGetInfo ( $hInetget, 0 ) ) Sleep ( 1000 ) $NewBytes = Round ( InetGetInfo ( $hInetget, 0 ) ) GUICtrlSetData ( $dlspeed, _String _GetFormattedSize ( $NewBytes - $Bytes, 2, - 1 ) & "/s" ) $nowRead = InetGetInfo ( $hInetget, 0 ) $pourcent = Int ( ( $nowRead / $size ) * 100 ) GUICtrlSetData ( $hprogress, $pourcent ) Until InetGetInfo ( $hInetget, 2 ) Check if the download is complete.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |