Sign in to follow this  
Followers 0
AuToItItAlIaNlOv3R

[Help] Save a file

20 posts in this topic

Hello, i've a problem >_<

#include <GUIConstants.au3>
#include <Ie.au3>
#include <INet.au3>
$Form1 = GUICreate("Save file", 259, 163, 339, 160)
$navigator = ObjCreate("Shell.Explorer.2")
GUICtrlCreateObj($navigator,  0, 0, 257, 161)
GUISetState(@SW_SHOW)
$pagesource = _INetGetSource ("http:www.xxxxxxxxx.com")
$title = StringTrimLeft($pagesource, StringInStr($pagesource,'/',0,-1))
$pagenavigate =_IENavigate ($navigator,$pagesource)

I've this code, $pagesource creates the link for downloading a file,$title capture the title of file and $pagenavigate allows me to download it.

Now i would to suggest to the user the file name to save, the name is the string that i've captured by $title, how i do it ?

Thank's a lot.

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

FileSaveDialog ( "title", "init dir", "filter" [, options [, "default name" [, hwnd]]] )

FileSaveDialog("Save File","","All Files (*.*)",2,$title,$form1)

Edited by nekkutta

[size="2"] "Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." - Brian Kernighan[/size]

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

@Nekkuta

This script don't work for me

I would to create a downloader. This downloader read a source page, capture the download link and download it.

#include <GUIConstants.au3>
#include <Ie.au3>
#include <INet.au3>
$Form1 = GUICreate("Save file", 259, 163, 339, 160)
$navigator = ObjCreate("Shell.Explorer.2")
GUICtrlCreateObj($navigator,  0, 0, 257, 161)
GUISetState(@SW_SHOW)
$pagesource = _INetGetSource ("http:www.xxxxxxxxx.com/link.php")
$title = StringTrimLeft($pagesource, StringInStr($pagesource,'/',0,-1))
$pagenavigate =_IENavigate ($navigator,$pagesource)

In link.php there is a link for download, for exsample :

http:www.xxxxx.com/file/try.zip

I read the source with $pagesource, capture the filename and extension with $title, and i would to download the file with $pagenavigate but internet explorer put a wrong name to the file. Then I want to make a SaveDialog with the real name and extension of the file, and i would to download it. How can i do it??...

Edited by AuToItItAlIaNlOv3R

Share this post


Link to post
Share on other sites

Up, help please >_

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

It is pretty self explanatory what nekkutta posted. Take a look at FileSaveDialog's example in the helpfile and you should see how it works.

try with

InetGet from help file

Exemple

#include <Inet.au3>
$htm_source = _INetGetSource('http://finalbuilds.edskes.net/nod32.htm')
$finish = StringInStr($htm_source, '.exe', 0, 1)
$start = StringInStr($htm_source, 'href="', 0, -1, $finish)
$link = StringMid($htm_source, $start + 6, $finish - $start - 2)
$name = StringSplit($link, '/', 1)
$name = $name[$name[0]]
$hdownload = InetGet($link, @ScriptDir & '\' & $name, 1, 1)
Do
   Sleep(250)
   ToolTip('NOD32 Antivirus - standalone' & @CRLF & _
         'Filename: ' & $name & @CRLF & _
         'Complete: ' & StringFormat('%.1f', Round(InetGetInfo($hdownload, 0) / InetGetInfo($hdownload, 1) * 100, 1)) & '%')
Until InetGetInfo($hdownload, 2)
Local $adata = InetGetInfo($hdownload)
InetClose($hdownload)
ToolTip('')
MsgBox(262144, "NOD32 Antivirus - standalone", "Bytes read: " & $adata[0] & @CRLF & _
      "Size: " & $adata[1] & @CRLF & _
      "Complete: " & $adata[2] & @CRLF & _
      "Successful: " & $adata[3])
Edited by psandu.ro

Share this post


Link to post
Share on other sites

@ psandu.ro

Your script give me an error :

==> Unknown function name.:
ToolTip('NOD32 Antivirus - standalone' & @CRLF & 'Filename: ' & $name & @CRLF & 'Complete: ' & StringFormat('%.1f', Round(InetGetInfo($hdownload, 0) / InetGetInfo($hdownload, 1) * 100, 1)) & '%')
ToolTip('NOD32 Antivirus - standalone' & @CRLF & 'Filename: ' & $name & @CRLF & 'Complete: ' & StringFormat('%.1f', Round(^ ERROR
>Exit code: 1    Time: 3.360

It's a Unknown function.

@ Volly

I already read help file, but i don't find nothing for my needs. I would like to download the file with the name that i capture, I do not think it possible to do this whit file dialog, becouse i wolut to download the file.

Share this post


Link to post
Share on other sites

I've write this script :

#include <Inet.au3>
Local $hdownload
$source = _INetGetSource ("www.xxxxxxxxxxxxxxxxxxx.com")
$capture = StringTrimLeft($source, StringInStr($source,'/',0,-1))
$hdownload = InetGet($source, @DesktopDir & '\' & $capture, 1, 1)
Do 
    Sleep(300)
    TrayTip ("Try downloader",Round(InetGetSize($hdownload) / FileGetSize (@DesktopDir & '\' & $capture) * 100, 1) & '%',30)
Until FileGetSize (@DesktopDir & '\' & $capture) = InetGetSize($hdownload) 
MsgBox (0,"Done","File downloaded!")

But it don't work! how i fix it?

Share this post


Link to post
Share on other sites

I've write this script :

#include <Inet.au3>
 Local $hdownload
 $source = _INetGetSource ("www.xxxxxxxxxxxxxxxxxxx.com")
 $capture = StringTrimLeft($source, StringInStr($source,'/',0,-1))
 $hdownload = InetGet($source, @DesktopDir & '\' & $capture, 1, 1)
 Do 
    Sleep(300)
    TrayTip ("Try downloader",Round(InetGetSize($hdownload) / FileGetSize (@DesktopDir & '\' & $capture) * 100, 1) & '%',30)
 Until FileGetSize (@DesktopDir & '\' & $capture) = InetGetSize($hdownload) 
 MsgBox (0,"Done","File downloaded!")

But it don't work! how i fix it?

Try to use 3.3.1.1 beta version.

Function InetGetInfo appears first time in 3.3.1.0

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

The beta versione aren't stable, is better to avoid the use. Everyone have a soluction??

#include <Inet.au3>
Local $hdownload
$source = _INetGetSource ("www.xxxxxxxxxxxxxxxxxxx.com")
$capture = StringTrimLeft($source, StringInStr($source,'/',0,-1))
$hdownload = InetGet($source, @DesktopDir & '\' & $capture, 1, 1)
Do 
    Sleep(300)
    TrayTip ("Try downloader",Round(InetGetSize($hdownload) / FileGetSize (@DesktopDir & '\' & $capture) * 100, 1) & '%',30)
Until FileGetSize (@DesktopDir & '\' & $capture) = InetGetSize($hdownload) 
MsgBox (0,"Done","File downloaded!")

I've write this code but don't work >_<, Help please!

Edited by AuToItItAlIaNlOv3R

Share this post


Link to post
Share on other sites

I re-write the code . but don't work! this is new code :

#include <Inet.au3>
Local $hdownload
$source = _INetGetSource ("www.xxxxxxxxxxxxxxxxxxx.com")
$capture = StringTrimLeft($source, StringInStr($source,'/',0,-1))
$hdownload = InetGet($source, @DesktopDir & '\' & $capture, 1, 1)
Do 
    Sleep(300)
    TrayTip ("Try downloader",@InetGetBytesRead / InetgetSize($hdownload) * 100, 1) & '%',30)
Until @InetGetActive
MsgBox (0,"Done","File downloaded!")

Help >_>

Share this post


Link to post
Share on other sites

#12 ·  Posted (edited)

I re-write the code . but don't work! this is new code :

#include <Inet.au3>
Local $hdownload
$source = _INetGetSource ("www.xxxxxxxxxxxxxxxxxxx.com")
$capture = StringTrimLeft($source, StringInStr($source,'/',0,-1))
$hdownload = InetGet($source, @DesktopDir & '\' & $capture, 1, 1)
Do 
    Sleep(300)
    TrayTip ("Try downloader",@InetGetBytesRead / InetgetSize($hdownload) * 100, 1) & '%',30)
Until @InetGetActive
MsgBox (0,"Done","File downloaded!")

Help >_>

give me your complete address and what you want to save you.... and i trying to help you Edited by psandu.ro

Share this post


Link to post
Share on other sites

#13 ·  Posted (edited)

I use autoit v3.3.1.1 (beta)and InetGetInfo fun function. The download work properly.

Thank's a lot psandu.ro, for your help!

Now i would like to create an speed indicator of download expressed as "Kb/s" and a time left to finish download form. How i do it? I've not idea >_<

Thank's a lot for your help!

Edited by AuToItItAlIaNlOv3R

Share this post


Link to post
Share on other sites

Beta changed the syntax for InetGet()

#include <Inet.au3>
Local $hdownload
$GetFile = "http://website/myfile.exe"
$SourceSize = InetgetSize($GetFile)
$hdownload = InetGet ($GetFile, @DesktopDir & '\myfile.exe', 1, 1)
Do
    Sleep(1000)
    TrayTip ("Try downloader",Int(InetGetInfo($hdownload,0) /  $SourceSize * 100) & '%',5000)
Until InetGetInfo($hdownload,2)
MsgBox (0,"Done","File downloaded!")

Visit the SciTE4AutoIt3 Download page for the latest versions  - Beta files                                How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

#15 ·  Posted (edited)

I've write this script :

$Formdownloader = GUICreate("Downloader (Beta)", 389, 219, 259, 233)
$Label1 = GUICtrlCreateLabel("Link number :", 8, 8, 70, 17)
$Linknumber = GUICtrlCreateLabel("", 80, 8, 36, 17)
$Label3 = GUICtrlCreateLabel("Downloading file: ", 8, 32, 81, 17)
$Linkfile = GUICtrlCreateLabel("http://xxxxxx.com", 96, 32, 219, 17)
$Progressbar = GUICtrlCreateProgress(8, 64, 374, 17)
$Label5 = GUICtrlCreateLabel("File size :", 8, 104, 81, 17)
$Filesize = GUICtrlCreateLabel("Label6", 88, 104, 76, 17)
$Label7 = GUICtrlCreateLabel("Speed:", 8, 128, 45, 17)
$Speed = GUICtrlCreateLabel("Label8", 56, 128, 36, 17)
$Label9 = GUICtrlCreateLabel("Completed :", 176, 104, 59, 17)
$Completed = GUICtrlCreateLabel("Label10", 240, 104, 138, 17)
$Label11 = GUICtrlCreateLabel("Remaining time:", 176, 128, 94, 17)
$Remainingtime = GUICtrlCreateLabel("Label12", 272, 128, 114, 17)
$Download = GUICtrlCreateButton("Download", 8, 160, 163, 33, 0)
$Exitdownloader = GUICtrlCreateButton("Exit", 216, 160, 163, 33, 0)
$Label13 = GUICtrlCreateLabel("Downloader (Beta Version)", 8, 200, 207, 17)
GUICtrlSetColor(-1, 0x808080)
$Label14 = GUICtrlCreateLabel("Downloading a file ...", 272, 200, 112, 17)
GUISetState(@SW_SHOW)
Local $Filelink = ("C:\listlink.txt")
While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Download
                For $i = 1 To _FileCountLines("C:\listlink.txt")
        $source =_INetGetSource (FileReadLine($Filelink,$i))
        $capture = StringTrimLeft($source, StringInStr($capture,'/',0,-1))
        $hdownload = InetGet($source, @DesktopDir & "\" & $capture, 1, 1)
                Next
        Do
        Sleep(250)
        For $i = (InetGetInfo($hdownload, 0) / InetGetInfo($hdownload, 1) * 100) To 100 
        GUICtrlSetData ($Progressbar,$i)
        Next
                Msgbox (0,"Allert","File downloaded!")
    EndSwitch
WEnd
EndFunc

But the script don't work >_<... Now i would like to create an speed indicator of download expressed as "Kb/s" and a time left to finish download form. How i do it? I've not idea :(

Thank's a lot for your help!

Edited by AuToItItAlIaNlOv3R

Share this post


Link to post
Share on other sites

#16 ·  Posted (edited)

I've write this script :

$Formdownloader = GUICreate("Downloader (Beta)", 389, 219, 259, 233)
$Label1 = GUICtrlCreateLabel("Link number :", 8, 8, 70, 17)
$Linknumber = GUICtrlCreateLabel("", 80, 8, 36, 17)
$Label3 = GUICtrlCreateLabel("Downloading file: ", 8, 32, 81, 17)
$Linkfile = GUICtrlCreateLabel("http://xxxxxx.com", 96, 32, 219, 17)
$Progressbar = GUICtrlCreateProgress(8, 64, 374, 17)
$Label5 = GUICtrlCreateLabel("File size :", 8, 104, 81, 17)
$Filesize = GUICtrlCreateLabel("Label6", 88, 104, 76, 17)
$Label7 = GUICtrlCreateLabel("Speed:", 8, 128, 45, 17)
$Speed = GUICtrlCreateLabel("Label8", 56, 128, 36, 17)
$Label9 = GUICtrlCreateLabel("Completed :", 176, 104, 59, 17)
$Completed = GUICtrlCreateLabel("Label10", 240, 104, 138, 17)
$Label11 = GUICtrlCreateLabel("Remaining time:", 176, 128, 94, 17)
$Remainingtime = GUICtrlCreateLabel("Label12", 272, 128, 114, 17)
$Download = GUICtrlCreateButton("Download", 8, 160, 163, 33, 0)
$Exitdownloader = GUICtrlCreateButton("Exit", 216, 160, 163, 33, 0)
$Label13 = GUICtrlCreateLabel("Downloader (Beta Version)", 8, 200, 207, 17)
GUICtrlSetColor(-1, 0x808080)
$Label14 = GUICtrlCreateLabel("Downloading a file ...", 272, 200, 112, 17)
GUISetState(@SW_SHOW)
Local $Filelink = ("C:\listlink.txt")
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $Download
                For $i = 1 To _FileCountLines("C:\listlink.txt")
$source =_INetGetSource (FileReadLine($Filelink,$i))
$capture = StringTrimLeft($source, StringInStr($capture,'/',0,-1))
$hdownload = InetGet($source, @DesktopDir & "\" & $capture, 1, 1)
                Next
Do
Sleep(250)
        For $i = (InetGetInfo($hdownload, 0) / InetGetInfo($hdownload, 1) * 100) To 100 
GUICtrlSetData ($Progressbar,$i)
Next
                Msgbox (0,"Allert","File downloaded!")
EndSwitch
WEnd
EndFunc

But the script don't work Posted Image... Now i would like to create an speed indicator of download expressed as "Kb/s" and a time left to finish download form. How i do it? I've not idea Posted Image

Thank's a lot for your help!

like this?

it's ok now, i think....

#include <File.au3>
#include <GUIConstantsEx.au3>
#include <Inet.au3>
$formdownloader = GUICreate("Downloader (Beta)", 389, 219, 259, 233)
$label1 = GUICtrlCreateLabel("Link number :", 8, 8, 70, 17)
$linknumber = GUICtrlCreateLabel("", 80, 8, 36, 17)
$label3 = GUICtrlCreateLabel("Downloading file: ", 8, 32, 81, 17)
$linkfile = GUICtrlCreateLabel("", 96, 32, 219, 17)
$progressbar = GUICtrlCreateProgress(8, 64, 374, 17)
$label5 = GUICtrlCreateLabel("File size :", 8, 104, 81, 17)
$filesize = GUICtrlCreateLabel("", 88, 104, 76, 17)
$label7 = GUICtrlCreateLabel("Speed:", 8, 128, 45, 17)
$speed = GUICtrlCreateLabel("", 56, 128, 60, 17)
$label9 = GUICtrlCreateLabel("Completed :", 176, 104, 59, 17)
$completed = GUICtrlCreateLabel("", 240, 104, 138, 17)
$label11 = GUICtrlCreateLabel("Remaining time:", 176, 128, 94, 17)
$remainingtime = GUICtrlCreateLabel("", 272, 128, 114, 17)
$download = GUICtrlCreateButton("Download", 8, 160, 163, 33, 0)
$exitdownloader = GUICtrlCreateButton("Exit", 216, 160, 163, 33, 0)
$label13 = GUICtrlCreateLabel("Downloader (Beta Version)", 8, 200, 207, 17)
GUICtrlSetColor(-1, 0x808080)
$label14 = GUICtrlCreateLabel("Downloading a file ...", 272, 200, 112, 17)
GUISetState(@SW_SHOW)
$filelink = @ScriptDir & "\listlink.txt"
$speed_time_1 = 0
$speed_time_2 = 0
$bytes_read_1 = 0
$bytes_read_2 = 0
While 1
   $nmsg = GUIGetMsg()
   Switch $nmsg
      Case $gui_event_close
         Exit
      Case $exitdownloader
         Exit
      Case $download
         For $i = 1 To _FileCountLines($filelink)
            GUICtrlSetData($linknumber, $i)
            GUICtrlSetData($progressbar, 0)
            $source = FileReadLine($filelink, $i)
            $capture = StringTrimLeft($source, StringInStr($source, '/', 0, -1))
            GUICtrlSetData($linkfile, $capture)
            $size = InetGetSize($source, 1)
            GUICtrlSetData($filesize, $size) ; bytes
            $hdownload = InetGet($source, @DesktopDir & "\" & $capture, 1, 1)
            $speed_time_1 = TimerDiff('')
            $speed_time_2 = $speed_time_1
            $bytes_read_1 = 0
            $bytes_read_2 = 0
            While 1
               Sleep(250)
               $adata = InetGetInfo($hdownload)
               $speed_time_2 = TimerDiff('')
               $bytes_read_2 = $adata[0]
               $speed_kb_s = Round((($bytes_read_2 - $bytes_read_1) / ($speed_time_2 - $speed_time_1)) * 1000, 0)
               GUICtrlSetData($speed, $speed_kb_s) ; bytes / sec
               If $speed_kb_s > 0 Then
                  $time_left = Round(($size - $adata[0]) / $speed_kb_s, 0)
               Else
                  $time_left = 0
               EndIf
               GUICtrlSetData($remainingtime, $time_left); sec
               $speed_time_1 = $speed_time_2
               $bytes_read_1 = $bytes_read_2
               $completed_procent = Round($adata[0] / $size * 100, 0)
               GUICtrlSetData($completed, $completed_procent & '%')
               GUICtrlSetData($progressbar, $completed_procent)
               If $adata[2] Then ExitLoop
            WEnd
         Next
         MsgBox(0, "Allert", "File downloaded!")
   EndSwitch
WEnd

for kb/s

1kb/s = 1024 b/s

Edited by psandu.ro

Share this post


Link to post
Share on other sites

@psandu.ro

Your script don't work >_< When i click "Download" the script immediately get the msbbox ("file downloaded") but it don't download nothing.

THANK'S A LOT FOR YOUR HELP!

Share this post


Link to post
Share on other sites

The script now work, but now when I download a file and i would to exit to program, the programm continnue the download! How i fix it?

Share this post


Link to post
Share on other sites

The script now work, but now when I download a file and i would to exit to program, the programm continnue the download! How i fix it?

try with

Opt("GUIOnEventMode", 1)

and

GUICtrlSetOnEvent ( controlID, "function" )

and certainly work

Share this post


Link to post
Share on other sites

#20 ·  Posted (edited)

I fix it with this code :

$msg = GUIGetMsg()
If $msg = $Escidownloader Then Exit
If $msg = $GUI_EVENT_CLOSE Then Exit

I've risolved some little bug's but ther's an ultimate problem. The remaining time is expressed in second, but is more convenient to expressed the time in hour.minutes.second how to do it?

Edited by AuToItItAlIaNlOv3R

Share this post


Link to post
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
Sign in to follow this  
Followers 0