Jump to content

Small Problem


Recommended Posts

I am working on a simple downloader tool. I have got a perfectly working old version. And a non-working properly newer version wich includes the new features i want to add to the old version. My main weakness here is the structure of the code. Please help me out by fixing the code and if possible commenting on it, thanks.

Old Code:

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <ProgressConstants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
dim $DownloadProgress = 0
#Region ### START Koda GUI section ### Form=c:\documents and settings\haluk\desktop\form1_1.kxf
$Form1_1 = GUICreate("Falcon Downloader V1 By Falcon", 429, 295, 281, 205)
GUISetFont(20, 400, 0, "Arial")
$Pic1 = GUICtrlCreatePic("C:\Documents and Settings\Haluk\Desktop\FD.jpg", 16, 8, 396, 100, BitOR($SS_NOTIFY, $WS_GROUP, $WS_CLIPSIBLINGS))
$Label2 = GUICtrlCreateLabel("Direct Download Link:", 65, 121, 306, 36)
GUICtrlSetFont(-1, 22, 400, 0, "Arial")
$Input1 = GUICtrlCreateInput("", 11, 158, 401, 30)
GUICtrlSetFont(-1, 14, 400, 0, "Arial")
$Button1 = GUICtrlCreateButton("Download", 108, 244, 209, 41, $WS_GROUP)
GUICtrlSetFont(-1, 24, 400, 0, "Arial")
$Progress1 = GUICtrlCreateProgress(8, 200, 409, 25)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $size = GUICtrlRead($Input1)
    $nMsg = GUIGetMsg()
    If $nMsg = -3 Then Exit
    If $nMsg = $Button1 Then
        $msgsize = InetGetSize($size)
        $filesize = $msgsize/2^10
        $newfilesize = Round($msgsize/1048576, 1)
        $sizemsg = MsgBox(4 + 32, "Falcon Downloader", "The size of the file is " & $newfilesize & " Megabytes" & @CRLF & "Download the file?")
        If $sizemsg = 6 Then
            $var = StringSplit($size, "/")
            $newvar = $var[UBound($var) - 1]
            $filename = FileSaveDialog("Enter a filename and its appropiate file extension", @DesktopDir, "(*.*)", "", $newvar)
            InetGet($size, $filename, 0, 1)
            $DownloadProgress = 1
            While $DownloadProgress = 1
                While @InetGetActive
                $downloaded = @InetGetBytesRead/2^20
                    TrayTip("Downloading", $downloaded & " Megabytes downloaded", 10, 16)
                    Sleep(1000)
                WEnd
                MsgBox(0, "Falcon Downloader", $newvar & " has finished downloading.")
                $DownloadProgress = 0
            WEnd
            MsgBox(64, "Falcon Downloader", "Made By Falcon" & @CRLF & "www.se.curity.org")
        ElseIf $sizemsg = 7 Then
            MsgBox(64, "Falcon Downloader", "Made By Falcon" & @CRLF & "www.se.curity.org")
        EndIf
    EndIf
WEnd

New Code with features i want but not working.

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <ProgressConstants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
Dim $DownloadProgress = 0
Dim $filesize
Dim $KB = 2 ^ 10
Dim $MB = 2 ^ 20
Dim $GB = 2 ^ 30
#Region ### START Koda GUI section ### Form=c:\documents and settings\haluk\desktop\form1_1.kxf
$Form1_1 = GUICreate("Falcon Downloader V1 By Falcon", 429, 295, 281, 205)
GUISetFont(20, 400, 0, "Arial")
$Pic1 = GUICtrlCreatePic("C:\Documents and Settings\Haluk\Desktop\FD.jpg", 16, 8, 396, 100, BitOR($SS_NOTIFY, $WS_GROUP, $WS_CLIPSIBLINGS))
$Label2 = GUICtrlCreateLabel("Direct Download Link:", 65, 121, 306, 36)
GUICtrlSetFont(-1, 22, 400, 0, "Arial")
$Input1 = GUICtrlCreateInput("", 11, 158, 401, 30)
GUICtrlSetFont(-1, 14, 400, 0, "Arial")
$Button1 = GUICtrlCreateButton("Download", 108, 244, 209, 41, $WS_GROUP)
GUICtrlSetFont(-1, 24, 400, 0, "Arial")
$Progress1 = GUICtrlCreateProgress(8, 200, 409, 25)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $size = GUICtrlRead($Input1)
    $nMsg = GUIGetMsg()
    If $nMsg = -3 Then Exit
    If $nMsg = $Button1 Then
        $msgsize = InetGetSize($size)
        If $msgsize >= $KB Then
            $filesize = Round($msgsize / 2 ^ 10, 1)
        ElseIf $msgsize >= $MB Then
            $filesize = Round($msgsize / 2 ^ 20, 1)
        ElseIf $msgsize >= $GB Then
            $filesize = Round($msgsize / 2 ^ 30, 1)
        EndIf
        $sizemsg = MsgBox(4 + 32, "Falcon Downloader", "The size of the file is " & $filesize & " Megabytes" & @CRLF & "Download the file?")
    If $sizemsg = 6 Then
        $var = StringSplit($size, "/")
        $newvar = $var[UBound($var) - 1]
        $filename = FileSaveDialog("Enter a filename and its appropiate file extension", @DesktopDir, "(*.*)", "", $newvar)
        InetGet($size, $filename, 0, 1)
        $DownloadProgress = 1
        While $DownloadProgress = 1
            While @InetGetActive
                $downloaded = @InetGetBytesRead / 2 ^ 10
                If @InetGetBytesRead >= $KB Then
                    TrayTip("Downloading", $downloaded & " Kilobytes downloaded", 10, 16)
                ElseIf @InetGetBytesRead >= $MB Then
                    Sleep(1000)
                    $downloaded = @InetGetBytesRead / 2 ^ 20
                    TrayTip("Downloading", $downloaded & " Megabytes downloaded", 10, 16)
                    Sleep(1000)
                ElseIf @InetGetBytesRead >= $GB Then
                    $downloaded = @InetGetBytesRead / 2 ^ 30
                    TrayTip("Downloading", $downloaded & " Gigabytes downloaded", 10, 16)
                    Sleep(1000)
                EndIf
            WEnd
            MsgBox(0, "Falcon Downloader", $newvar & " has finished downloading.")
            $DownloadProgress = 0
        WEnd
        MsgBox(64, "Falcon Downloader", "Made By Falcon" & @CRLF & "www.se.curity.org")
    ElseIf $sizemsg = 7 Then
        MsgBox(64, "Falcon Downloader", "Made By Falcon" & @CRLF & "www.se.curity.org")
        EndIf
    EndIf
WEnd
Link to comment
Share on other sites

Hi,

You don't mention what is not working, but let me guess - it only shows kB DL'ed.

Just look at snippet below: your checking order is wrong, as soon as there's more

than > 1 kB 'If $msgsize >= $KB' will be true, so the other if's won't even be checked.

Reversing the checking order should help, note that the same goes for the other

If - ElseIf etc. lower down in your code.

Also, since you already defined $KB, $MB and $GB, what's the point in not using them ?

(in the snippet below e.g. $filesize = Round($msgsize / $KB, 1)

If $msgsize >= $KB Then
            $filesize = Round($msgsize / 2 ^ 10, 1)
        ElseIf $msgsize >= $MB Then
            $filesize = Round($msgsize / 2 ^ 20, 1)
        ElseIf $msgsize >= $GB Then
            $filesize = Round($msgsize / 2 ^ 30, 1)
        EndIf

HTH,

whim

Link to comment
Share on other sites

Hi,

You don't mention what is not working, but let me guess - it only shows kB DL'ed.

Just look at snippet below: your checking order is wrong, as soon as there's more

than > 1 kB 'If $msgsize >= $KB' will be true, so the other if's won't even be checked.

Reversing the checking order should help, note that the same goes for the other

If - ElseIf etc. lower down in your code.

Also, since you already defined $KB, $MB and $GB, what's the point in not using them ?

(in the snippet below e.g. $filesize = Round($msgsize / $KB, 1)

If $msgsize >= $KB Then
            $filesize = Round($msgsize / 2 ^ 10, 1)
        ElseIf $msgsize >= $MB Then
            $filesize = Round($msgsize / 2 ^ 20, 1)
        ElseIf $msgsize >= $GB Then
            $filesize = Round($msgsize / 2 ^ 30, 1)
        EndIf

HTH,

whim

You got it right. Thanks for your help.
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...