1. Dashboard
  2. Mitglieder
    1. Letzte Aktivitäten
    2. Benutzer online
    3. Team
    4. Mitgliedersuche
  3. Forenregeln
  4. Forum
    1. Unerledigte Themen
  • Anmelden
  • Registrieren
  • Suche
Alles
  • Alles
  • Artikel
  • Seiten
  • Forum
  • Erweiterte Suche
  1. AutoIt.de - Das deutschsprachige Forum.
  2. Mitglieder
  3. AspirinJunkie

Beiträge von AspirinJunkie

  • brauch Hilfe beim Code kürzen

    • AspirinJunkie
    • 15. April 2015 um 16:58

    Sind $sender0 die Control-IDs von nacheinander erstellten GUI-Controls?
    Falls ja wäre eine etwas krude Methode einfach auszunutzen, dass die Control-IDs fortlaufend nummeriert werden:

    [autoit]

    While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
    Case $GUI_EVENT_CLOSE, $exititem
    _exit()
    Case $bStart
    If $pause Then
    $oWMP.controls.play()
    $pause = False
    Else
    $oWMP.controls.stop()
    EndIf
    Case $bhome
    _homepage()
    Case $sender0 To $sender9
    $nbrx = $nMsg - $sender0
    _send()
    Case $infoitem
    _hilfe()
    EndSwitch
    WEnd

    [/autoit][autoit][/autoit][autoit][/autoit]
  • FTP Datei herunterladen

    • AspirinJunkie
    • 14. April 2015 um 11:53

    Hast du mal mein zweites Skript getestet (das mit den _FTP...-Funktionen)?
    Dort ist ein Errorhandling eingebaut welches dir detaillierte Informationen im Fehlerfall präsentieren sollte.

  • FTP Datei herunterladen

    • AspirinJunkie
    • 14. April 2015 um 10:26

    Ich habe dir keinen allgmeinen Hinweis zum lesen der Hilfe gegeben, sondern eine ganz konkrete Funktion benannt.
    Diese hast du aber anscheinend immer noch nicht angesehen/probiert sonst würdest du ja deinen Versuch hier posten um dir damit weiterhelfen zu können.

    Folgendes funktioniert bei mir absolut problemlos:

    [autoit]

    $DownloadURL = "ftp://ftp.adobe.com/pub/adobe/reader/win/11.x/11.0.00/de_DE/AdbeRdr11000_de_DE.msi"
    $FileNAME = "adobe_reader.msi"

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

    InetGet($DownloadURL, @ScriptDir & "\" & $FileNAME)
    MsgBox(0,"", "Download fertig")

    [/autoit]

    Auch die FTP-Funktionen erbringen das gewünschte Resultat bei mir:

    FTP-Download mit ausführlicher
    [autoit]

    #include <FTPEx.au3>
    #include <Array.au3>

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

    Global $hOpen = _FTP_Open('MyFTP Control')
    Global $hConn = _FTP_Connect($hOpen, "ftp.adobe.com", '', '')

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

    $dRet = _FTP_FileGet($hConn, "/pub/adobe/reader/win/11.x/11.0.00/de_DE/AdbeRdr11000_de_DE.msi", @ScriptDir & "\adobe_reader.msi")
    If @error Then GetAllNetworkErrors($dRet)

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

    _FTP_Close($hConn)
    _FTP_Close($hOpen)

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

    Func GetAllNetworkErrors(Const $ReturnValue = "", Const $err = @error, Const $ext = @extended)
    ; by AspirinJunkie
    Local $h_K32 = DllOpen("kernel32.dll")
    Local $dFTPError, $sFTPMessage

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

    Local $a_DllRet = DllCall($h_K32, "dword", "GetLastError")
    Local $d_APIError = @error ? 0 : $a_DllRet[0]
    Local $a_DllRet = DllCall("Wininet.dll", 'bool', 'InternetGetLastResponseInfoW', 'dword*', 0, 'wstr', "", 'dword*', 4096)
    Local $s_InetError = @error ? 0 : $a_DllRet[1]
    Local $s_InetErrorMsg = @error ? "" : $a_DllRet[2]
    Local $a_DllRet = DllCall($h_K32, "dword", "FormatMessageW", _
    "dword", 0x1100, _ ; Flags
    "ptr", 0, _ ; Source (hier unwichtig)
    "dword", $d_APIError, _ ; Error-Code
    "dword", 1031, _ ; Language-ID (per _WinAPI_MAKELANGID ermittelbar)
    "wstr*", "", _ ; Buffer für Ausgabestring
    "DWORD", 0, _ ; Buffersize (hier automatisch durch entsprechendes Flag)
    "ptr", 0)
    DllClose($h_K32)
    Local $s_APIMessage = @error Or $d_APIError == 0 ? "" : $a_DllRet[5]
    MsgBox(0, "Error-Report", ($ReturnValue ? "Return: " & $ReturnValue & @CRLF : "") & "@error: " & $err & @CRLF & "@extended: " & $ext & @CRLF & "API-Error: " & $d_APIError & " - " & $s_APIMessage & @CRLF & "WinINet-Error: " & $s_InetError & " - " & $s_InetErrorMsg)
    EndFunc ;==>GetAllFTPErrors

    [/autoit]
  • FTP Datei herunterladen

    • AspirinJunkie
    • 13. April 2015 um 17:47

    Schau dir die Funktion InetGet in der Hilfe an.

  • MY_WM_DEVICECHANGE ohne GUI

    • AspirinJunkie
    • 5. April 2015 um 14:52

    Ich verstehe noch nicht ganz das Problem.
    Ein einfaches GuiCreate("") an den Anfang des Skriptes und alles ist i.O.

    Wo gibt es da jetzt ein Problem bzw. was soll wie besser werden wenn das GuiCreate nicht benötigt würde?

  • Filterung von HTML/XML-Strings mit Css-Like Selektoren

    • AspirinJunkie
    • 1. April 2015 um 08:56

    Vielleicht braucht mal jemand soetwas.
    Ich wollte mir das Ziehen von Infos aus Webseiten etwas vereinfachen und habe mir eine Funktion geschrieben mit der man Elemente aus HTML-Strings mit Hilfe von CSS-Selektoren filtern kann.

    Aktuell habe ich nur die ID, Class und Attribut-Selektoren implementiert aber das sind ja auch erst einmal die wichtigsten.
    Ansonsten ist es sicherlich noch bisschen buggy.

    Hier mal ein Beispiel wie man damit den aktuellsten Thread hier auf der Seite ermitteln könnte:

    Spoiler anzeigen
    AutoIt
    #include-once
    #include <array.au3>
    
    
    Local $sHtml = BinaryToString(InetRead("https://autoit.de/"), 4) ; get the raw source
    
    
    Local $a_Elements = _CssSelectFromString($sHtml, "div#portalBox2 tr.wbbThread:first a:first")
    If Not @error Then MsgBox(0, "", "Aktuellster Thread im Forum: """ & $a_Elements[0][2] & '"')
    
    
    
    
    
    
    
    
    
    
    ; #FUNCTION# ======================================================================================
    ; Name ..........: _CssSelectFromString()
    ; Description ...: extract elements out of a html string with css-style selectors
    ; Syntax ........: _CssSelectFromString($s_String, $s_Selector, {Const $b_First = True})
    ; Parameters ....: $s_String      - the html string
    ;                  $s_Selector    - the css-style selector
    ;                  {$b_First}     - dont't touch! - for internal use only!
    ; Return values .: Success: Array[...][0] = element attributes string
    ;                           Array[...][1] = element content string
    ;                  Failure: ""
    ;                     @error = 1: no balanced elements found
    ; Remarks .......: The following CSS-Selector-Features are implemented:
    ;                  .class               - class of a element
    ;                  #ID                  - ID of a element
    ;                  [attribute]          - attribute exist
    ;                  [attribute="value"]  - elements with attribute=value
    ;                  [attribute^="value"] - elements where attribute starting with value
    ;                  [attribute~="value"] - elements where attribute containing value
    ;                  [attribute$="value"] - elements where attribute ending with value
    ;                  :first               - only the first element gets returned
    ;                  :nth-of-type(<number>) - match only the nth match of the element
    ;                  :has(<Selector>)     - elements which contain at least one element that matches the specified selector
    ;                  :nothas(<Selector>)  - elements which not contain a element that matches the specified selector
    ; Known bugs ....: - If Balancing is not correct in the string - the result is also not correct
    ;                  - If selector is too general - some result may get doubled - to solve this: be as exactly as possible
    ; Author ........: AspirinJunkie
    ; Version .......: 0.8.1
    ; =================================================================================================
    Func _CssSelectFromString($s_String, $s_Selector, Const $b_First = True, Const $b_SubCheck = False)
    	Local $s_Type = ""
    	Local $a_RegEx, $ID, $i, $j, $a_Ret, $s_Attrs
    	Local Static $o_Result
    	Local $d_RetCounter = 0
    
    
    	If $b_First Then
    		$s_String = StringRegExpReplace($s_String, "(?s)(?x)(?:<!--.+?)(?R)?(?:-->)", "") ; Kommentare killen
    		$s_String = StringRegExpReplace($s_String, "(?s)(?x)(?:<script.+?)(?R)?(?:</script)", "") ; Script-Elemente killen (Inhalt könnte Probleme beim Parsen bringen)
    		$s_String = StringRegExpReplace($s_String, "(?s)^.+<body\b(.+?)</body>.+$", "$1") ; Nur Inhalt des Bodys verwenden
    		$o_Result = ObjCreate('Scripting.Dictionary')
    	EndIf
    
    
    	$s_Selector = StringStripWS($s_Selector, 7)
    	Local $s_CurrentSelector = StringRegExp($s_Selector, '^((?:"\s*[^"]+\s*[^"]+"|\(((?:.|(?R))*)\)|\S)+)', 1)[0]
    	Local $s_SelectorRest = StringStripWS(StringTrimLeft($s_Selector, @extended), 1)
    
    
    	; Get the element type:
    	$a_RegEx = StringRegExp($s_CurrentSelector, "^(\w*)", 1)
    	If @error Then Return SetError(1, @error, "")
    	$s_Type = $a_RegEx[0]
    
    
    	; Alle Typen durchgehen und auf Übereinstimmung mit weiteren KLassifikatoren prüfen
    	Local $a_Types = _HtmlElements($s_String, $s_Type, True)
    
    
    	Local $a_HasProperty = StringRegExp($s_CurrentSelector, ":has\(\s*((?:.|(?R))*)\)", 3)
    	If @error Then Local $a_HasProperty[0]
    	Local $a_nothasProperty = StringRegExp($s_CurrentSelector, ":nothas\(\s*((?:.|(?R))*)\)", 3)
    	If @error Then Local $a_nothasProperty[0]
    	$s_CurrentSelector = StringRegExpReplace($s_CurrentSelector, ":(has|nothas)\(\s*((?:.|(?R))*)\)", "") ; delete :has and :nothas-Selectors because the inner Selector shouldn't processed by the following Selectors
    	Local $a_AttribOpt = StringRegExp($s_CurrentSelector, "\[(\w+)\s*([~\*|\^\$]?=)\s*['""](.+?)['""]\s*\]", 4)
    	If @error Then Local $a_AttribOpt[0]
    	Local $a_ClassesOpt = StringRegExp($s_CurrentSelector, "\.(\w+)", 3)
    	If @error Then Local $a_ClassesOpt[0]
    	Local $a_IDOpt = StringRegExp($s_CurrentSelector, "#(\w+)", 3)
    	If @error Then Local $a_IDOpt[0]
    	Local $b_EmptyProperty = StringRegExp($s_CurrentSelector, ":empty\b", 0)
    	$a_RegEx = StringRegExp($s_CurrentSelector, ":nth-of-type\((\d+)\)", 1)
    	Local $d_NthOfType = @error ? 0 : $a_RegEx[0]
    
    
    	For $j = 0 To UBound($a_Types) - 1
    		$s_Attrs = $a_Types[$j][1]
    		; Check for ID:
    		For $ID In $a_IDOpt
    			If Not StringRegExp($s_Attrs, "(?x)\bid=['""]\b" & $ID & "\b['""]") Then ContinueLoop 2
    		Next
    		; Check for class:
    		For $Class In $a_ClassesOpt
    			If Not StringRegExp($s_Attrs, "(?x)\bclass=['""][^'"">]*?\b" & $Class & "\b[^'"">]*?['""](?x)") Then ContinueLoop 2
    		Next
    		; Check for attributes:
    		; check for exist:
    		$a_RegEx = StringRegExp($s_CurrentSelector, "\[(\w+)\s*\]", 3)
    		If Not @error Then
    			For $Attr In $a_RegEx
    				If Not StringRegExp($s_Attrs, "(?x)\b" & $Attr & "\b[=\s$]") Then ContinueLoop 2
    			Next
    		EndIf
    		For $AttrVal In $a_AttribOpt
    			Switch $AttrVal[2]
    				Case "=" ; full match
    					If Not StringRegExp($s_Attrs, "(?x)" & $AttrVal[1] & "=['""]" & $AttrVal[3] & "['""]") Then ContinueLoop 2
    				Case "~=", "*=" ; partial match
    					If Not StringRegExp($s_Attrs, "(?x)" & $AttrVal[1] & "=['""][^'""]*" & $AttrVal[3] & "[^'""]*['""]") Then ContinueLoop 2
    				Case "|=", "^=" ; start match
    					If Not StringRegExp($s_Attrs, "(?x)" & $AttrVal[1] & "=['""]" & $AttrVal[3] & "[^'""]*['""]") Then ContinueLoop 2
    				Case "$=" ; end match
    					If Not StringRegExp($s_Attrs, "(?x)" & $AttrVal[1] & "=['""][^'""]*" & $AttrVal[3] & "['""]") Then ContinueLoop 2
    			EndSwitch
    		Next
    
    
    		;has(<Selector>)
    		For $HasSelector In $a_HasProperty
    			If Not _CssSelectFromString(StringMid($s_String, $a_Types[$j][4], $a_Types[$j][5] - $a_Types[$j][4]), $HasSelector, False, True) Then ContinueLoop 2
    		Next
    		;nothas(<Selector>)
    		For $NotSelector In $a_nothasProperty
    			If _CssSelectFromString(StringMid($s_String, $a_Types[$j][4], $a_Types[$j][5] - $a_Types[$j][4]), $NotSelector, False, True) Then ContinueLoop 2
    		Next
    		;:empty
    		If $b_EmptyProperty Then
    			If Not StringIsSpace(StringMid($s_String, $a_Types[$j][4], $a_Types[$j][5] - $a_Types[$j][4])) Then ContinueLoop
    		EndIf
    		;:nth-of-type()
    		If $d_NthOfType Then
    			$d_RetCounter += 1
    			If $d_RetCounter <> $d_NthOfType Then ContinueLoop
    		EndIf
    
    
    		; save result element
    		If $s_SelectorRest = "" Then
    			If $b_SubCheck Then Return True
    			Local $a_T[3] = [$a_Types[$j][0], $a_Types[$j][1], StringMid($s_String, $a_Types[$j][4], $a_Types[$j][5] - $a_Types[$j][4])]
    			$o_Result($o_Result.Count) = $a_T
    		Else
    			If $b_SubCheck Then
    				Return _CssSelectFromString(StringMid($s_String, $a_Types[$j][4], $a_Types[$j][5] - $a_Types[$j][4]), $s_SelectorRest, False, True)
    			Else
    				_CssSelectFromString(StringMid($s_String, $a_Types[$j][4], $a_Types[$j][5] - $a_Types[$j][4]), $s_SelectorRest, False)
    			EndIf
    		EndIf
    
    
    		; check for ":first" selector
    		If StringInStr($s_CurrentSelector, ":first", 2) Then ExitLoop
    		If $d_NthOfType And $d_RetCounter = $d_NthOfType Then ExitLoop ; :nth-of-type() - break because following elements could'nt match
    	Next
    
    
    	If $b_SubCheck Then Return False ; if recursion is inside a :has or :nothas-Selector
    
    
    	If $b_First Then
    		Local $n = $o_Result.Count
    		Local $a_Return[$n][3]
    		Local $v = 0
    		For $i In $o_Result.Items()
    			$a_Return[$v][0] = StringStripWS($i[0], 3)
    			$a_Return[$v][1] = StringStripWS($i[1], 3)
    			$a_Return[$v][2] = StringStripWS($i[2], 3)
    			$v += 1
    		Next
    		Return $a_Return
    	EndIf
    EndFunc   ;==>_CssSelectFromString
    
    
    
    
    
    
    
    
    ; #FUNCTION# ======================================================================================
    ; Name ..........: _HtmlElements()
    ; Description ...: extract all elements of type $s_Type from a html string
    ; Syntax ........: _HtmlElements(ByRef $s_Html, Const $s_Type)
    ; Parameters ....: $s_Html        - the html string
    ;                  $s_Type        - the html element type which should to extract
    ;                  $bN            - False: returns 4-column array with element content as a string
    ;                                 - True: returns 6-column array with substring positions of
    ;                                         element and it's content inside of $s_Html
    ; Return values .: Success: Array[...][0] = element attributes string
    ;                           Array[...][1] = element content string
    ;                  Failure: ""
    ;                     @error = 1: no balanced elements found
    ; Known bugs ....: If Balancing is not correct in the string - the result is also not correct
    ; Author ........: AspirinJunkie
    ; =================================================================================================
    Func _HtmlElements(ByRef $s_Html, Const $s_Type = "", Const $bN = False)
    	Local $d_Start, $d_End, $d_T, $d_Pos = 1, $x = 0, $a_Element
    	Local $s_Begin = "<" & $s_Type, $s_Ende = "</" & $s_Type
    	Local $nB = StringLen($s_Begin)
    	Local $oVoids = ObjCreate("Scripting.Dictionary") ; replace later with AutoIt-Maps
    
    
    	Local $s_Ends = "", $s_Begins = ""
    	Local $s_VoidEnds = "", $s_VoidBegins = ""
    	Local $dOff, $a_T, $s_ElType, $s_T
    
    
    	Local Const $s_REstart = ($s_Type = "") ? "(<\w+\b)" : "(<" & $s_Type & "\b)"
    	Local Const $s_REend = ($s_Type = "") ? "(</\w+\b)" : "(</" & $s_Type & "\b)"
    
    
    	; Alle Tag-Anfänge ermitteln:
    	Do
    		$a_T = StringRegExp($s_Html, $s_REstart, 1, $d_Pos)
    		$dOff = @extended
    		If $dOff = 0 Then ExitLoop
    		$d_T = $dOff - StringLen($a_T[0])
    
    
    		; void element form (e.g: <link href="fancy.css" type="text/css" /> )
    		$a_T = StringRegExp($s_Html, "\G<(area|base|br|col|command|embed|hr|img|input|keygen|link|meta|param|source|track|wbr)\s*([^<]*?)/?>", 1, $d_T)
    		$dOff = @extended
    		If $dOff Then
    			Local $aTemp[4] = [$a_T[0], $a_T[1], $d_T, $dOff]
    			$d_Pos = $dOff
    			$oVoids($d_T) = $aTemp
    		Else ; normal elements
    			$s_Begins &= $d_T & "|"
    			$d_Pos = $d_T + $nB
    		EndIf
    		$x += 1
    	Until 0
    
    
    	; Alle Tag-Enden ermitteln:
    	$d_Pos = 1
    	Do
    		$a_T = StringRegExp($s_Html, $s_REend, 1, $d_Pos)
    		$dOff = @extended
    		If $dOff = 0 Then ExitLoop
    		$s_Ends &= $dOff - StringLen($a_T[0]) & "|"
    		$d_Pos = $dOff
    	Until 0
    
    
    	If $s_Begins <> "" And $s_Ends <> "" Then
    		Local $a_Starts = StringSplit(StringTrimRight($s_Begins, 1), "|", 2)
    		Local $a_Ends = StringSplit(StringTrimRight($s_Ends, 1), "|", 2)
    		For $i = 0 To UBound($a_Starts) - 1
    			$a_Starts[$i] = Int($a_Starts[$i])
    		Next
    		For $i = 0 To UBound($a_Ends) - 1
    			$a_Ends[$i] = Int($a_Ends[$i])
    		Next
    
    
    		; Funde matchen
    		Local $dMax = UBound($a_Ends) > UBound($a_Starts) ? UBound($a_Starts) : UBound($a_Ends)
    		Local $a_Return[$dMax + $oVoids.Count][($bN ? 6 : 4)]
    		If $dMax > 0 Then
    			Local $d_End
    			For $i = 0 To UBound($a_Ends) - 1
    				$d_End = $a_Ends[$i]
    				For $j = UBound($a_Starts) - 1 To 0 Step -1
    					$d_Start = $a_Starts[$j]
    					If $d_Start = 1000000000 Then ContinueLoop
    					If $d_Start < $d_End Then
    						If $bN Then
    							$a_Element = StringRegExp($s_Html, "(?s)\G<(\w+)\b\s?(.*?)>", 1, $d_Start)
    							$dOff = @extended
    							If UBound($a_Element) < 2 Then ContinueLoop
    							$a_Return[$i][0] = $a_Element[0]
    							$a_Return[$i][1] = $a_Element[1]
    							$a_Return[$i][2] = Int($d_Start)
    							$a_Return[$i][3] = Int($d_End) + 3 + StringLen($a_Element[0])
    							$a_Return[$i][4] = $dOff
    							$a_Return[$i][5] = Int($d_End)
    						Else
    							$a_Element = StringRegExp(StringMid($s_Html, $d_Start, $d_End - $d_Start + StringLen($s_Ende)), "(?s)^<(\w+)\b\s?(.*?)>(.*)</" & $s_Type, 3)
    ;~ 						$a_Element = StringRegExp($s_Html, "(?s)\G<" & $s_Type & "\s?(.*?)>(.*?)</" & $s_Type, 3, $d_Start)
    							If UBound($a_Element) < 2 Then ContinueLoop
    							$a_Return[$i][0] = $a_Element[0]
    							$a_Return[$i][1] = $a_Element[1]
    							$a_Return[$i][2] = $a_Element[2]
    							$a_Return[$i][3] = Int($d_Start)
    						EndIf
    
    
    						$a_Starts[$j] = 1000000000
    						ContinueLoop 2
    					EndIf
    				Next
    			Next
    		EndIf
    	Else
    		Local $a_Return, $dMax = 0
    	EndIf
    
    
    	; add the void elements to the result array
    	If Not IsArray($a_Return) Then Local $a_Return[$oVoids.Count][($bN ? 6 : 4)]
    	Local $c = 0
    	For $i In $oVoids.Items
    		$a_Return[$dMax + $c][0] = $i[0]
    		$a_Return[$dMax + $c][1] = $i[1]
    		If $bN Then
    			$a_Return[$dMax + $c][2] = $i[2]
    			$a_Return[$dMax + $c][3] = $i[3]
    		Else
    			$a_Return[$dMax + $c][3] = $i[2]
    		EndIf
    		$c += 1
    	Next
    
    
    	_ArraySort($a_Return, 0, 0, 0, ($bN ? 2 : 3))
    	Return $a_Return
    EndFunc   ;==>_HtmlElements
    Alles anzeigen
  • primzahlenrechner

    • AspirinJunkie
    • 29. März 2015 um 14:33

    Optimierung sollte halt immer auf Algorithmenebene beginnen.
    In dem Fall wäre es erst einmal sinnvoll den Algorithmus von GegX zu übertragen.
    Das wurde in deinem C++-Programm nämlich nicht gemacht.

    Das Primzahlen nur ungerade sein können (außer der 2) hat Andy dir bereits erzählt.

    In deinem Programm wird zur Überprüfung auf eine Primzahl durch alle natürlichen Zahlen kleiner Wurzel der zu prüfenden Zahlen geteilt. Es geht aber noch deutlich effektiver: Jede natürliche Zahl ist durch eine Kombination von Primzahlen teilbar (siehe Primfaktorzerlegung). Wenn sie selbst eine Primzahl ist, so ist ihr Primfaktor schlicht die Zahl selbst. GegX' nutzt das in seinem Skript um die Zahl der nötigen Vergleiche nochmals deutlich zu reduzieren: indem er die Zahl nur gegen die bisher gefunden Primzahlen checkt (und das auch nur bis Wurzel(n)). Somit kann er die Anzahl der nötigen Vergleiche drastisch verringern.
    Es wäre also durchaus clever die Primzahlen zwischenzuspeichern. Da du C++ verwendest, suchst du also nach einer Datenstruktur bei der dynamisch Elemente ans Ende hinzugefügt werden können und die schnell durchiteriert werden kann. Mein Vorschlag hierfür wäre die std::deque.

    Das was dem Programm den Rest in Sachen Performance gibt, ist die Ausgabe aller Zahlen auf die Konsole. Entferne mal zum Spaß die couts und lass dir nur die letzte Zahl ausgeben - es sollte nun drastisch schneller laufen

  • Pc Modell auslesen und mit IF then verknpfen

    • AspirinJunkie
    • 26. März 2015 um 08:53

    WMI kann man direkt in AutoIt ansprechen.
    Irgendwelche Umstände über Konsolentools deren Ausgabe in Dateien geschrieben werden und dann wieder ausgelesen werden müssen braucht es nicht:

    Hier mal als Einzeiler:

    [autoit]

    $Modell = ObjGet("winmgmts:\\localhost\root\CIMV2").ExecQuery("SELECT Model FROM Win32_ComputerSystem", "WQL", 0).ItemIndex(0).Model

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

    MsgBox(0, "Computermodell", $Modell)

    [/autoit]
  • FTP - Verbindung als Laufwerk mappen

    • AspirinJunkie
    • 26. März 2015 um 08:29

    Interessanter Effekt.
    Ist natürlich etwas schwierig auf Ursachensuche zu gehen wenn ich das Verhalten bei mir nicht reproduzieren kann aber ich vermute mal ganz spontan, dass da sowas wie Reparse-Points mit drin stecken.
    Hab das Skript mal so erweitert, dass er sich meldet sobald ein Ordner mehr Dateiattribute gesetzt bekommen hat als nur ein einfaches Ordner-Flag.
    Falls es daran liegt können wir so vielleicht erfahren, was dies verursacht:

    Spoiler anzeigen
    [autoit]

    #include <ftpEx.au3>
    #include <array.au3>

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

    $server = 'ftp.csx.cam.ac.uk'
    $username = ''
    $pass = ''

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

    $hFTP = _FTP_Open('FTP_open')
    $hFTPCon = _FTP_Connect($hFTP, $server, $username, $pass)

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

    $aFileList = _FTP_FileList($hFTPCon, "/pub/software/")
    _ArrayDisplay($aFileList)

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

    ; #FUNCTION# ======================================================================================
    ; Name ..........: _FTP_FileList()
    ; Description ...: Listet die Ordnerstruktur einer FTP-Verbindung
    ; Syntax ........: _FTP_FileList($hConn, Const[ $sPath = '', Const[ $iF = 3]])
    ; Parameters ....: $hConn - Eine FTP-Connection wie von _FTP_Connect zurückgegeben
    ; Const $sPath - [optional] Ordner welche durchsucht werden sollen (mehrere gleichzeitig mit "|" trennen)
    ; Const $iF - [optional] 1=nur Dateien, 2=nur Ordner, 3=Dateien+Ordner (default:3)
    ; Const $iSSFlag - [optional] 0=Rückgabearray mit Anzahl Elemente in $Array0, 2=Rückgabearray ohne Anzahl Elemente
    ; Return values .: Ein Array mit den Datei/Ordner-Pfaden
    ; Author ........: AspirinJunkie
    ; =================================================================================================
    Func _FTP_FileList(Const $hConn, Const $sPath = "", Const $iF = 3, Const $iSSFlag = 2)
    ;by AspirinJunkie
    Local $hFFFF, $sRet = "", $sSubD = "", $sDir, $iC, $a_Ret, $s_File
    Local $t_FTPFileData = DllStructCreate($tagWIN32_FIND_DATA)

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

    For $i In StringSplit($sPath, '|', 2)
    If StringRight($i, 1) = '/' Then $i = StringTrimRight($i, 1)
    $sSubD &= '|' & $i
    Next

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

    Do
    $iC = StringInStr($sSubD, '|', 2, -1)
    If @error Or $iC = 0 Then ExitLoop
    $iC = StringLen($sSubD) - $iC
    $sDir = StringRight($sSubD, $iC)
    $sSubD = StringTrimRight($sSubD, $iC + 1)

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

    $a_Ret = DllCall($__g_hWinInet_FTP, 'handle', 'FtpFindFirstFileW', 'handle', $hConn, 'wstr', $sDir, 'struct*', $t_FTPFileData, 'dword', 0, 'dword*', 0)
    If @error Or Not $a_Ret[0] Then ContinueLoop
    $hFFFF = $a_Ret[0]
    $s_File = DllStructGetData($t_FTPFileData, "cFileName")
    If BitAND(DllStructGetData($t_FTPFileData, "dwFileAttributes"), $FILE_ATTRIBUTE_DIRECTORY) Then ; Directory
    If BitXOR(DllStructGetData($t_FTPFileData, "dwFileAttributes"), $FILE_ATTRIBUTE_DIRECTORY) Then MsgBox(0, "Ordnereigenschaften", $sDir & '/' & $s_File & '/: ' & DllStructGetData($t_FTPFileData, "dwFileAttributes"))
    $sSubD &= '|' & $sDir & '/' & $s_File
    If BitAND(2, $iF) Then $sRet &= $sDir & '/' & $s_File & '/|'
    ElseIf BitAND(1, $iF) Then ; a File
    $sRet &= $sDir & '/' & $s_File & '|'
    EndIf

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

    Do
    $a_Ret = DllCall($__g_hWinInet_FTP, 'bool', 'InternetFindNextFileW', 'handle', $hFFFF, 'struct*', $t_FTPFileData)
    If Not $a_Ret[0] Or @error Then ExitLoop
    $s_File = DllStructGetData($t_FTPFileData, "cFileName")

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

    If @error Then ExitLoop
    If BitAND(DllStructGetData($t_FTPFileData, "dwFileAttributes"), $FILE_ATTRIBUTE_DIRECTORY) Then ; Directory
    If BitXOR(DllStructGetData($t_FTPFileData, "dwFileAttributes"), $FILE_ATTRIBUTE_DIRECTORY) Then MsgBox(0, "Ordnereigenschaften", $sDir & '/' & $s_File & '/: ' & DllStructGetData($t_FTPFileData, "dwFileAttributes"))
    $sSubD &= '|' & $sDir & '/' & $s_File
    If BitAND(2, $iF) Then $sRet &= $sDir & '/' & $s_File & '/|'
    ElseIf BitAND(1, $iF) Then ; a File
    $sRet &= $sDir & '/' & $s_File & '|'
    EndIf
    Until 0
    DllCall($__g_hWinInet_FTP, 'bool', 'InternetCloseHandle', 'handle', $hFFFF)
    Until 0

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

    Return StringSplit(StringTrimRight($sRet, 1), '|', $iSSFlag)
    EndFunc ;==>_FTP_FileList

    [/autoit]
  • FTP - Verbindung als Laufwerk mappen

    • AspirinJunkie
    • 25. März 2015 um 16:12
    Zitat von De Rand Ere

    oder das Script verschwindet im Nirvana und wird nie fertig.

    Die Dateiauflistung ist ziemlich langatmig.
    Um zu schauen ob etwas gemacht wird, kannst du dir während des Iterierens mal die Ergebnisse ausgeben lassen:

    Spoiler anzeigen
    [autoit]

    #include <ftpEx.au3>
    #include <array.au3>

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

    $server = 'ftp.csx.cam.ac.uk'
    $username = ''
    $pass = ''

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

    $hFTP = _FTP_Open('FTP_open')
    $hFTPCon = _FTP_Connect($hFTP, $server, $username, $pass)

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

    $aFileList = _FTP_FileList($hFTPCon, "/pub/software/")
    _ArrayDisplay($aFileList)

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

    ; #FUNCTION# ======================================================================================
    ; Name ..........: FLwStr()
    ; Description ...: Listet die Ordnerstruktur einer FTP-Verbindung
    ; Syntax ........: _FTP_FileList($hConn, Const[ $sPath = '', Const[ $iF = 3]])
    ; Parameters ....: $hConn - Eine FTP-Connection wie von _FTP_Connect zurückgegeben
    ; Const $sPath - [optional] Ordner welche durchsucht werden sollen (mehrere gleichzeitig mit "|" trennen)
    ; Const $iF - [optional] 1=nur Dateien, 2=nur Ordner, 3=Dateien+Ordner (default:3)
    ; Const $iSSFlag - [optional] 0=Rückgabearray mit Anzahl Elemente in $Array0, 2=Rückgabearray ohne Anzahl Elemente
    ; Return values .: Ein Array mit den Datei/Ordner-Pfaden
    ; Author ........: AspirinJunkie
    ; =================================================================================================
    Func _FTP_FileList(Const $hConn, Const $sPath = "", Const $iF = 3, Const $iSSFlag = 2)
    ;by AspirinJunkie
    Local $hFFFF, $sRet = "", $sSubD = "", $sDir, $iC, $a_Ret, $s_File
    Local $t_FTPFileData = DllStructCreate($tagWIN32_FIND_DATA)

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

    For $i In StringSplit($sPath, '|', 2)
    If StringRight($i, 1) = '/' Then $i = StringTrimRight($i, 1)
    $sSubD &= '|' & $i
    Next

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

    Do
    $iC = StringInStr($sSubD, '|', 2, -1)
    If @error Or $iC = 0 Then ExitLoop
    $iC = StringLen($sSubD) - $iC
    $sDir = StringRight($sSubD, $iC)
    $sSubD = StringTrimRight($sSubD, $iC + 1)

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

    $a_Ret = DllCall($__g_hWinInet_FTP, 'handle', 'FtpFindFirstFileW', 'handle', $hConn, 'wstr', $sDir, 'struct*', $t_FTPFileData, 'dword', $INTERNET_FLAG_NO_CACHE_WRITE, 'dword*', 0)
    If @error Or Not $a_Ret[0] Then ContinueLoop
    $hFFFF = $a_Ret[0]
    $s_File = DllStructGetData($t_FTPFileData, "cFileName")
    If BitAND(DllStructGetData($t_FTPFileData, "dwFileAttributes"), $FILE_ATTRIBUTE_DIRECTORY) Then ; Directory
    $sSubD &= '|' & $sDir & '/' & $s_File
    If BitAND(2, $iF) Then $sRet &= $sDir & '/' & $s_File & '/|'
    ConsoleWrite($sDir & '/' & $s_File & '/' & @CRLF)
    ElseIf BitAND(1, $iF) Then ; a File
    $sRet &= $sDir & '/' & $s_File & '|'
    ConsoleWrite($sDir & '/' & $s_File & @CRLF)
    EndIf

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

    Do
    $a_Ret = DllCall($__g_hWinInet_FTP, 'bool', 'InternetFindNextFileW', 'handle', $hFFFF, 'struct*', $t_FTPFileData)
    If Not $a_Ret[0] Or @error Then ExitLoop
    $s_File = DllStructGetData($t_FTPFileData, "cFileName")

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

    If @error Then ExitLoop
    If BitAND(DllStructGetData($t_FTPFileData, "dwFileAttributes"), $FILE_ATTRIBUTE_DIRECTORY) Then ; Directory
    $sSubD &= '|' & $sDir & '/' & $s_File
    If BitAND(2, $iF) Then $sRet &= $sDir & '/' & $s_File & '/|'
    ConsoleWrite($sDir & '/' & $s_File & '/' & @CRLF)
    ElseIf BitAND(1, $iF) Then ; a File
    $sRet &= $sDir & '/' & $s_File & '|'
    ConsoleWrite($sDir & '/' & $s_File & @CRLF)
    EndIf
    Until 0
    DllCall($__g_hWinInet_FTP, 'bool', 'InternetCloseHandle', 'handle', $hFFFF)
    Until 0

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

    Return StringSplit(StringTrimRight($sRet, 1), '|', $iSSFlag)
    EndFunc ;==>_FTP_FileList

    [/autoit]


    Dann siehst du, ob das Skript noch läuft oder hängt.
    Alternativ kannst du statt der Consolewrites auch direkt mit den Dateien weiterarbeiten während du iterierst.

  • Ini: Alle Sectionen nach Wert durchsuchen

    • AspirinJunkie
    • 24. März 2015 um 17:10

    Das sollte das Skript schon so machen.
    Wenn nicht brauchen wir eine Beispieldatei bei der der von dir beschriebene Fehler auftritt.

  • FTP - Verbindung als Laufwerk mappen

    • AspirinJunkie
    • 24. März 2015 um 14:23
    Zitat von De Rand Ere

    Da ich zur Auflistung der rund 10.000 Dateien "_FileListRekursiv" nutzen möchte ist es notwendig die FTP-Verbindung als Laufwerk zu Mappen.

    Warum willst du dir die Dateiliste nicht direkt über die FTP-Funktionen holen?
    Mal als Beispiel:

    Ordnerauflistung auf FTP-Server
    [autoit]

    #include <ftpEx.au3>
    #include <array.au3>

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

    $server = 'ftp.csx.cam.ac.uk'
    $username = ''
    $pass = ''

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

    $hFTP = _FTP_Open('FTP_open')
    $hFTPCon = _FTP_Connect($hFTP, $server, $username, $pass)

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

    $aFileList = _FTP_FileList($hFTPCon, "pub/software/")
    _ArrayDisplay($aFileList)

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

    ; #FUNCTION# ======================================================================================
    ; Name ..........: FLwStr()
    ; Description ...: Listet die Ordnerstruktur einer FTP-Verbindung
    ; Syntax ........: _FTP_FileList($hConn, Const[ $sPath = '', Const[ $iF = 3]])
    ; Parameters ....: $hConn - Eine FTP-Connection wie von _FTP_Connect zurückgegeben
    ; Const $sPath - [optional] Ordner welche durchsucht werden sollen (mehrere gleichzeitig mit "|" trennen)
    ; Const $iF - [optional] 1=nur Dateien, 2=nur Ordner, 3=Dateien+Ordner (default:3)
    ; Const $iSSFlag - [optional] 0=Rückgabearray mit Anzahl Elemente in $Array0, 2=Rückgabearray ohne Anzahl Elemente
    ; Return values .: Ein Array mit den Datei/Ordner-Pfaden
    ; Author ........: AspirinJunkie
    ; =================================================================================================
    Func _FTP_FileList(Const $hConn, Const $sPath = "", Const $iF = 3, Const $iSSFlag = 2)
    ;by AspirinJunkie
    Local $hFFFF, $aNext, $sRet = "", $sSubD = "", $sDir, $iC

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

    For $i In StringSplit($sPath, '|', 2)
    If StringRight($i, 1) = '/' Then $i = StringTrimRight($i, 1)
    $sSubD &= '|' & $i
    Next

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

    Do
    $iC = StringInStr($sSubD, '|', 2, -1)
    If @error Or $iC = 0 Then ExitLoop
    $iC = StringLen($sSubD) - $iC
    $sDir = StringRight($sSubD, $iC)
    $sSubD = StringTrimRight($sSubD, $iC + 1)

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

    $aNext = _FTP_FindFileFirst($hConn, $sDir, $hFFFF)
    If @error Then ContinueLoop

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

    If BitAND($aNext[1], 16) Then
    $sSubD &= '|' & $sDir & '/' & $aNext[10]
    If BitAND(2, $iF) Then $sRet &= $sDir & '/' & $aNext[10] & '/|'
    ElseIf BitAND(1, $iF) Then
    $sRet &= $sDir & '/' & $aNext[10] & '|'
    EndIf

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

    Do
    $aNext = _FTP_FindFileNext($hFFFF)
    If @error Then ExitLoop
    If BitAND($aNext[1], 16) Then
    $sSubD &= '|' & $sDir & '/' & $aNext[10]
    If BitAND(2, $iF) Then $sRet &= $sDir & '/' & $aNext[10] & '/|'
    ElseIf BitAND(1, $iF) Then
    $sRet &= $sDir & '/' & $aNext[10] & '|'
    EndIf
    Until 0
    _FTP_FindFileClose($hFFFF)
    Until 0

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

    Return StringSplit(StringTrimRight($sRet, 1), '|', $iSSFlag)
    EndFunc ;==>_FTP_FileList

    [/autoit]
  • Ini: Alle Sectionen nach Wert durchsuchen

    • AspirinJunkie
    • 24. März 2015 um 10:36
    Zitat von x0r

    Hat den einfachen Sinn, wenn einer der Mitarbeiter seine ID bei anderen Namen einfügt, kann er die Stempelzeiten des jeweiligen sehen.

    Scheint ja ein richtig durchdachtes System zu sein... ;)

  • Ini: Alle Sectionen nach Wert durchsuchen

    • AspirinJunkie
    • 24. März 2015 um 08:39
    Zitat von Jensen..

    allerdings mit Leerzeichen vor und nach den = Zeichen [...] weiterhin sind einige "Values" in " " geschrieben.

    Bei IniRead egal - nutz diese.
    Hier eine Lösung auf Basis der Ini-Funktionen:

    Spoiler anzeigen
    [autoit]

    $s_Section = IniGetSectionByValue("Test.cfg", "ser_moni", "YLS01123666")

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

    If @error = 1 Then
    MsgBox(48,"Nichts gefunden", "Eintrag in ini-Datei nicht gefunden")
    ElseIf @error = 2 Then
    MsgBox(48,"Fehler", "Konnte ini-Datei nicht lesen")
    Else
    MsgBox(0,"", "ser_moni = YLS01123666 in Section [" & $s_Section & "] gefunden.")
    EndIf

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

    Func IniGetSectionByValue($s_IniFile, $s_SearchKey, $s_SearchValue)
    Local $a_Sections = IniReadSectionNames($s_IniFile)
    If @error Then Return SetError(2, @error, "")

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

    For $i = 1 To $a_Sections[0]
    If IniRead($s_IniFile, $a_Sections[$i], $s_SearchKey, Default) = $s_SearchValue Then Return $a_Sections[$i]
    Next

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

    Return SetError(1,0, "")
    EndFunc ;==>IniGetSectionByValue

    [/autoit]
    Zitat von x0r

    meine inis sind teilweise als *.dll gespeichert

    ???
    Du nennst deine Ini-Dateien "dll"?
    Was soll denn das?!?

  • Frage zum Run-Befehl und Show_Flag @SW_Hide

    • AspirinJunkie
    • 23. März 2015 um 21:54

    Du willst irgendwelche Systemeinstellungen über Fenster-Klick-Automatisierungen auslesen/ändern?
    Sag mal konkret was du am Ende erreichen willst - dann könnte man dir wirklich helfen.

  • primzahlenrechner

    • AspirinJunkie
    • 23. März 2015 um 21:02

    Die Idee ist ja der Hammer.
    Das ist ja wirklich genial :thumbup:

    @GegX
    Auf meinem i5 M560 dauerts 23s für ne Million.

    @ProgrammingDonkey
    Zeig mal deinen C++-Code.
    Ist das der selbe Ansatz wie GegX's?
    Dann wäre das ja nur gerade mal um den Faktor 7 schneller als die AutoIt-Variante.
    Da wird irgendwas schief gelaufen sein - zu erwarten wäre eine deutlich höhere Beschleunigung.

    Zitat von GegX

    c und c++ sind einfach beide super nach an der hardware dran aber wenn dus schnell willst dann assembler und fertig

    Wenn du schnelleren Assemblercode schreibst als ein aktueller C/C++-Compiler raushaut dann solltest du unbedingt mal an die Frische Luft gehen - du sast definitiv zu lange vorm PC. ;)

  • Script mit mehreren Unterscripten und globalen Variablen unverständliches Handling

    • AspirinJunkie
    • 19. März 2015 um 11:34

    Wie ich schrieb: Der Inhalt der zu includenden Datei wird an diese Stelle im Skript geschrieben.

    Wenn es sich anders verhält brauchen wir ein Beispiel.

  • While Schleifen

    • AspirinJunkie
    • 19. März 2015 um 11:31

    Es geht nur wenn die Shutdown-Zeit in etwa einer Minute ist.
    Dann ist die zweite Wartezeit auch so lange.

    Wenn ich es ausprobiere ist das Ergebnis wie erwartet:

    • $d_DiffSeconds bekommt in meinem Fall den Wert 6
    • $d_DiffSeconds2 dann logischerweise 66
    • Es dauert tatsächlich 6s bis die Msgbox erscheint
    • Dann warte ich 5s bis ich ja drücke (nun sollte das Skript noch 55s laufen)
    • Es dauert noch 66s ($d_DiffSeconds2) bis das Skript herunterfährt.

    So weit so schlecht.
    Jetzt probiere dein Skript mal aus, wenn der Shutdown-Zeitpunkt erst in einer Stunde kommen soll.
    Viel Spaß beim Warten...

    Edit:

    Zitat von Darnas

    ansonsten hätte man doch einfach angeben können der sleep soll zb 80000ms gehen oder so, dafür brauchte man kein datum etc

    Deine Aufgabenstellung war das Skript zu einem bestimmten Zeitpunkt herunterfahren zu lassen.
    Wenn du ein Sleep mit einem festen Wert schreibst hat das mit dem Zielzeitpunkt nicht mehr zu tun, da das Ende von der Uhrzeit zum Start der Sleep-Funktion abhängt.

  • While Schleifen

    • AspirinJunkie
    • 19. März 2015 um 11:21
    Zitat von Darnas

    naja ob der PC eine min oder 2min nach der meldung runterfährt is letzten endes egal , der user weiß er fährt runter

    Es geht nicht nur um zwei Minuten.
    Bei deinem Skript verhält es sich so: Wenn das Skript früh gestartet wird und es noch 8h bis zum Shutdown sind wartet es 8h bis die Msgbox kommt.
    Wenn der User dann ja drückt (oder auch gar nix macht - worauf ein Warten dann sowieso sinnlos wäre) wartet das Skript nocheinmal 8h + 60s bis es dann endlich runterfährt.

    Gib dir einfach mal den Wert von d_DiffSeconds2 aus - dann siehst du wieviel ms er beim zweiten Sleep noch wartet.

  • Script mit mehreren Unterscripten und globalen Variablen unverständliches Handling

    • AspirinJunkie
    • 19. März 2015 um 11:19

    Weißt du was ein Minimalbeispiel ist?
    Dies ist ein Skript, welches so klein wie möglich ist aber den Fehler reproduziert.
    Es ist so geschrieben, dass es direkt ohne jegliche weitere Änderung lauffähig ist, so dass dein Problem von anderen direkt nachvollzogen werden kann.
    Der Vorteil für dich: Mehr und bessere Hilfe zu deinem Anliegen.

    Ansonsten allgemein zu multiplen Source's in AutoIt:
    Der Inhalt einer Datei welche per #Include eingebunden wird, wird direkt an diese Stelle im Code eingetragen.
    Am Ende wird dem Interpreter immer nur kompletter Code zur Verfügung gestellt.
    Wenn du also etwas auslagerst muss es an die einzubindende Stelle im Code auch passen.

Spenden

Jeder Euro hilft uns, Euch zu helfen.

Download

AutoIt Tutorial
AutoIt Buch
Onlinehilfe
AutoIt Entwickler
  1. Datenschutzerklärung
  2. Impressum
  3. Shoutbox-Archiv
Community-Software: WoltLab Suite™