Aktuellster Firefox Installer Download

  • Hi!


    Also, meine Funktion gibt den Downloadlink der aktuellsten Firefox
    Version zurück, klappt auch sehr gut nur dauert es 'relativ' lange und
    der Code ist auch ziemlich lang. Habe Sie hier gleich mit einer
    Testausgabe versehen.

    Also meine Frage an euch: Jemand eine Idee wie es besser klappt oder/und den Code kürzen?

    Spoiler anzeigen
    [autoit]


    $URL = firefoxlink()
    MsgBox(64,"Info", $URL)

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    Func firefoxlink()
    $Hilf = "0"
    $standard = "http://ftp.mozilla.org/pub/mozilla.org/firefox/releases/latest/win32/de/Firefox Setup "
    $zweite = "0"
    $dritte = "0"
    $null = "23"
    $version = $null & "." & $zweite & "." & $dritte & ".exe"
    $complete = $standard & $version

    [/autoit] [autoit][/autoit] [autoit]

    while InetGetSize($complete) = "0" and $Hilf = "0" ;1

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    if $zweite = 9 Then ;4
    $dritte = 0
    $zweite = 0
    $null = $null + 1
    if InetGetSize($standard & $null & ".0.exe") > 0 then $Hilf = "1"
    Else ;4
    EndIf ;4
    if $dritte = 9 Then ;3
    $dritte = 0
    $zweite = $zweite + 1
    if InetGetSize($standard & $null & "." & $zweite & ".exe") > 0 then $Hilf = "2"
    Else ;3
    EndIf ;3
    $dritte = $dritte + 1
    $version = $null & "." & $zweite & "." & $dritte & ".exe"
    $complete = $standard & $version
    WEnd
    ;1
    if $Hilf = "1" then
    $version = $null & "." & "0.exe"
    $complete = $standard & $version
    EndIf

    [/autoit] [autoit][/autoit] [autoit]

    if $Hilf = "2" then
    $version = $null & "." & $zweite & ".exe"
    $complete = $standard & $version
    EndIf

    [/autoit] [autoit][/autoit] [autoit]

    if InetGetSize($complete) = "0" then ;2
    MsgBox(4096, "NICHT VORHANDEN!", "ist nicht da" & " " & $complete)
    Else ;2
    return $complete
    EndIf ;2

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    EndFunc

    [/autoit]

    Vielen Dank für Die Hilfe im vorraus! :)


    Mit freundlichen Grüßen,

    blame

  • Hier mal eine schnelle Variante mit RegEx:

    [autoit]

    $sBaseURL = "http://ftp.mozilla.org/pub/mozilla.org/firefox/releases/latest/win32/de/"

    [/autoit][autoit][/autoit][autoit]

    $sHTML = BinaryToString(InetRead($sBaseURL, 1))

    [/autoit][autoit][/autoit][autoit]

    $s = StringRegExp($sHTML, "Firefox Setup [0-9][0-9].[0-9].exe", 1)
    $sDownloadLink = $sBaseURL & $s[0]

    [/autoit][autoit][/autoit][autoit]

    ConsoleWrite($sDownloadLink & @CRLF)
    InetGet($sDownloadLink, @ScriptDir & "" & $s[0])

    [/autoit]


    Solange sich das Dateinamen-Muster nicht ändert, also immer Firefox Setup **.*.exe bleibt, sollte diese Lösung funktionieren :)

    (Bitte nicht für den RegEx schlagen, bin noch kein RegEx-Veteran :whistling: )

    There's a joke that C has the speed and efficieny of assembly language combined with readability of....assembly language. In other words, it's just a glorified assembly language. - Teh Interwebz

    C makes it easy to shoot yourself in the foot; C++ makes it harder, but when you do, you blow off your whole leg. - Bjarne Stroustrup
    Genie zu sein, bedeutet für mich, alles zu tun, was ich will. - Klaus Kinski

  • (Bitte nicht für den RegEx schlagen, bin noch kein RegEx-Veteran :whistling: )


    Keine Angst, ich schlage nicht, aber der Pattern ist durchaus verbesserungswürdig...
    Es werden nur zweistellige Versionsnummern mit einer Nachkommastelle gefunden. Also nur "Firefox Setup XX.X.exe"
    D.h. bei v99,9 ist schluß ;(

    Deutlich flexibler wäre diese Variante:

    [autoit]

    $s = StringRegExp($sHTML, "Firefox Setup \d+\.\d+\.exe", 1)

    [/autoit]


    Der Pattern findet sowohl Dateinamen wie "Firefox Setup 1.0.exe" als auch "Firefox Setup 123456789.123456789.exe" bis unendlich. Da hast du was für die Zukunft :thumbup:
    Es würde zwar auch ein Name wie "Firefox Setup 0.0.exe" gefunden werden, was aber nicht vorkommen wird...
    Die Punkte muss man eigendlich nicht auskommentieren, weil ein Punkt für jedes Zeichen steht (also auch für den tatsächlichen Punkt), aber so ists "genauer".

  • Friesel:
    Ich leg nochmal nach, hier eine noch flexiblere Variante:

    [autoit]

    $s = StringRegExp($sHTML, "(?:[a-zA-Z]*)(?:\s)(?!Stub)(?:[a-zA-Z]*)(?:\s)(\d+\.\d+\.)(?:[a-zA-Z]*)", 1)

    [/autoit]

    :P
    Da ist es auch egal, wenn das Setup z.B. fdsaabgas fd 24.0.exe heißt.

    Mir war halt langweilig (Und es war eine gute Übung für mich) :whistling:

    There's a joke that C has the speed and efficieny of assembly language combined with readability of....assembly language. In other words, it's just a glorified assembly language. - Teh Interwebz

    C makes it easy to shoot yourself in the foot; C++ makes it harder, but when you do, you blow off your whole leg. - Bjarne Stroustrup
    Genie zu sein, bedeutet für mich, alles zu tun, was ich will. - Klaus Kinski