Dateien download Topic is solved

Stelle Fragen zur Programmierung mit Autohotkey

Moderator: jNizM

User avatar
glnklein
Posts: 90
Joined: 23 Oct 2020, 04:26

Dateien download  Topic is solved

23 Oct 2020, 05:37

ich habe diesen code noch von früher

Code: Select all

FileSize:=5555000 ;kb kenn ich eigentlich nicht 
URL:="http xyz.de/irgentwas.exe" 
dname :="irgentwas.exe"


Gui, Color, ControlColor, 383635
Gui, +LastFound -Caption -MinSize -MaxSize -E0x200 -Resize
Gui,Add,Progress,x0 y0 w500 h20 BackgroundTrans vProgress1 -Smooth cDefault,0
Gui,Add,Text,x0 y2 w20 h20 BackgroundTrans vText1,0`%
Gui,Show,xcenter ycenter BackgroundTrans w500 h20,LOAD
SetTimer,Updater,100
URLDownloadToFile,%URL%/%dname%,%A_WorkingDir%\%dname%


Return

Updater:
FileGetSize, Sizeist,%A_WorkingDir%\%dname%
IfExist,%A_WorkingDir%\%dname%
{
FileGetSize,AktSize,%A_WorkingDir%\%dname%
If(K==0)
Return
Pos:=Round((AktSize/FileSize)*100)
If(FileSize==Sizeist)
{
GuiControl,,Progress1,100

SetTimer,Updater,Off

ExitApp
Return
}
GuiControl,,Progress1,%Pos%

}
Return
Home::
GuiClose:
ExitApp


nun hab ich das Problem das ich die Dateiengrösse eigentlich nicht kenne
und das das script viel lang ist da es in einer Download schleife laufen soll , geht das nicht kürzer ?



verwende AutoHotkey104805
garry
Posts: 3763
Joined: 22 Dec 2013, 12:50

Re: Dateien download

23 Oct 2020, 14:42

Versuch mit aktuellster AHK-Version 1.1.33.02
URL size kann man feststellen
EDIT : kleine Aenderung added uridecode

Code: Select all

;-------- saved at 星期五 十月 2020-10-23  17:18 UTC --------------
;- Dateien download 
;- https://www.autohotkey.com/boards/viewtopic.php?f=9&t=82414
#Warn
#Noenv
setworkingdir,%a_scriptdir%
;-----------
;URL:="http://www.cheeseheadhosting.us/downloads/golden%20age%20of%20television%20vault%201/1955%20alfred%20hitchcock%20presents/Alfred%20Hitchcock%20Presents%201x30%20NeverAgain.avi"
url:="http://74.136.132.35/MUSIC/ORIG/J/Jim%20Reeves/The%20Essential%20Jim%20Reeves/Jim%20Reeves%20-%20The%20Essential%20Jim%20Reeves%20-%2010%20-%20I%20Love%20You%20Because.mp3"
SplitPath,url,name, dir, ext, name_no_ext, drive
name1:= uriDecode(name)            ;- remove %20 etc
dname=%a_scriptdir%\%name1%
;-----------
WebRequest := ComObjCreate("WinHttp.WinHttpRequest.5.1")
WebRequest.Open("HEAD", URL)
WebRequest.Send()
try
{
ByteSize      := WebRequest.GetResponseHeader("Content-Length")
KilobyteSize  := ByteSize/1024
;MegabyteSize := KilobyteSize/1024
;MB:=floor(MegabyteSize)
Filesize:=floor(KilobyteSize)
}
catch e
 {
 xxx:=e.Message
 msgbox, 262208,Failure ,URL not found
 exitapp
 }
FileGetSize,AktSize,%dname%,K
If(FileSize==Aktsize)
 {
 msgbox, 262208,,File already exist`n%dname%
 exitapp
 }
;-----------
Gui,1: +alwaysontop
GUI,1:Font,s12 cWhite,Lucida Console
Gui,color,black,blue
Gui, +LastFound -Caption -MinSize -MaxSize -E0x200 -Resize
Gui,Add,Progress,x0  y0  w500 h30 BackgroundTrans vProgress1 -Smooth cDefault,0
Gui,Add,Text    ,x20 y5  w50  h30 BackgroundTrans vText1 cWhite,0 `%
Gui,Show,xcenter ycenter  w500 h30,LOAD
;-----------
SetTimer,Updater,100
URLDownloadToFile,%URL%,%dname%
Return
;-------------------------------
Guiescape:
GuiClose:
ExitApp
esc::exitapp
;-------------------------------
Updater:
IfExist,%dname%
{
FileGetSize,AktSize,%dname%,K
Pos:=Round((AktSize/FileSize)*100)
If(FileSize==Aktsize)
 {
 GuiControl,1:,Progress1,100
 SetTimer,Updater,Off
 run,%dname%
 exitapp
 }
GuiControl,1:,Progress1,%Pos%
GuiControl,1:,Text1,%Pos% `%
}
Return
;---------------
uriDecode(str) {
   Loop
      If RegExMatch(str, "i)(?<=%)[\da-f]{1,2}", hex)
         StringReplace, str, str, `%%hex%, % Chr("0x" . hex), All
      Else Break
   Return, str
}
;===============================
Last edited by garry on 27 Oct 2020, 14:57, edited 1 time in total.
User avatar
glnklein
Posts: 90
Joined: 23 Oct 2020, 04:26

Re: Dateien download

26 Oct 2020, 07:24

garry wrote:
23 Oct 2020, 14:42
Versuch mit aktuellster AHK-Version 1.1.33.02
URL size kann man feststellen
würden den meine dateien weiter funktionieren oder müsste ich jeden code umschreiben ??
:D verwende AutoHotkey104805 :D ------------------------UPDATE auf ..1.1.33.02 erfolgreich , jetzt kommen neue Probleme :lolno:
garry
Posts: 3763
Joined: 22 Dec 2013, 12:50

Re: Dateien download

27 Oct 2020, 11:21

bei mir funktionieren noch die alten scripte , evtl kleine Nuancen anpassen
es gab denn neuere Befehle z.B try/catch , 'try' startet hier den downloaded script falls vorhanden , sonst Error-Meldung mit 'catch'
hier noch eine kleine Anpassung , ermittle den Namen vom URL , hier variable > 'name1' für download Ziel (where)

Code: Select all

#warn
#NoEnv
setworkingdir,%a_scriptdir%
url:="http://74.136.132.35/MUSIC/ORIG/J/Jim%20Reeves/The%20Essential%20Jim%20Reeves/Jim%20Reeves%20-%20The%20Essential%20Jim%20Reeves%20-%2017%20-%20Distant%20Drums.mp3"
SplitPath,url,name, dir, ext, name_no_ext, drive
name1:= uriDecode(name)            ;- remove %20 etc
where=%a_scriptdir%\%name1%
Splashimage,,x100 y400 w1000 h200 CWsilver m9 fs10 zh0,Running...`nDownload %name1% to=`n%where%
urldownloadtofile,%url%,%where%
Splashimage,off
try
 run,%where%
catch e 
 {
 xxx:=e.Message
 msgbox, 262208,ERROR,Error=`n%xxx%
 return
 }
return
;---------------
uriDecode(str) {
   Loop
      If RegExMatch(str, "i)(?<=%)[\da-f]{1,2}", hex)
         StringReplace, str, str, `%%hex%, % Chr("0x" . hex), All
      Else Break
   Return, str
}
;===================== END SCRIPT ==============

Return to “Ich brauche Hilfe”

Who is online

Users browsing this forum: No registered users and 18 guests