Jump to content

Script for InetGet and Router blinks


ripdad
 Share

Recommended Posts

;       by ripdad, feb 23, 2010
;
;   Routers "blink" or reset. They do this because:
;
;   1) they are doing a 24 hour reset. (some do - some don't)
;   2) a connection is briefly lost and the router reacquires.
;   3) power is quickly lost and comes back and the router reacquires.
;   4) a few other rare possibilities.
;
;   InetGet does not respond well to router blinks.
;
;   Scenario:
;
;   Sometime in the middle of a download the router blinks.
;   InetGet will go into a continuous loop - and not break out of it.
;   Traytip will close and display repeatedly, until one exits the program.
;
;   In case one wonders ... there's nothing wrong with the script.
;   This problem was in previous versions too.
;
;   I've come up with a way to handle this behavior when it occurs, with a simple counter.
;       (Sort of like MsgBox has to close the dialog when the timer has expired)

;   If one knows how long it normally takes to download a particular file, then this
;       script should be what you need. Just set $DL_Timer for 2 minutes or so ahead of normal.
;       In this way, it has an escape when it happens.
;
;   Along with some error handling - this is, in part, the example script:
;
Global $DL_Timer = 0
Global $error_code = 0
DL_01()
;
Func DL_01()
    ;
    $link = "http://www.somesite.com/somefile.txt"
    $temp = @TempDir & "/tempfile.txt"
    $SourceSize = InetGetSize($link)
    ;
    While 1
        Sleep(100)
        ;
        $DL_FileName = InetGet($link, $temp, 1, 1)
                ;
        $DL_Timer = 0
        $error_code = 0
        ;
        Do
            Sleep(1000); <-- one second every loop
            $DL_Timer = $DL_Timer + 1; <-- advance counter once every second
            TrayTip("Downloading", "File: " & $temp & "   Done: " & Int(InetGetInfo($DL_FileName, 0) / $SourceSize * 100) & '%' & "   ", 10, 5000)
        Until InetGetInfo($DL_FileName, 2) Or $DL_Timer = 300; <-- or until 300 seconds = 5 minutes has expired
        ;
        If InetGetInfo($DL_FileName, 4) Then; <-- error type: 1  (connection lost during download, etc.)
            InetClose($DL_FileName)
            TrayTip("", "", 5)
            $error_code = 1
            ExitLoop
        EndIf
        ;
        If InetGetInfo($DL_FileName, 0) < $SourceSize Then; <-- error type: 2  (incorrect filesize)
            InetClose($DL_FileName)
            TrayTip("", "", 5)
            $error_code = 2
            ExitLoop
        EndIf
        InetClose($DL_FileName)
        TrayTip("", "", 5)
        ExitLoop
    WEnd
EndFunc
;
If Not $error_code = 0 Then Connection_Error()
;
Func Connection_Error()
    ;
    ; From here, one can do error logging and then wait a few
    ; minutes and retry the download with some added code.
    ;
EndFunc
;

;

Edit("02-25-2010", "cleaned code a bit")

;

Edited by ripdad

"The mediocre teacher tells. The Good teacher explains. The superior teacher demonstrates. The great teacher inspires." -William Arthur Ward

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...