Filecopy () abbrechen

  • Hallo Leute,

    ich habe einen GUI, der vom Benutzer ausgewählte Softwarepakete auf den lokalen Rechner kopiert um die entsprechende Software nach dem Kopiervorgang zu installieren. Da die Paketverzeichnisse recht groß sind, möchte ich dem Benutzer die Möglichkeit geben die Kopieraktion abzubrechen bzw. zu pausieren. Leider habe ich hierzu nichts gefunden.

    Hier mal ein Code-Schnipsel der Kopierfunktion mit Progressbar:

    Spoiler anzeigen
    [autoit]


    Func ProgressCopy($current, $destination, $attrib = "-R", $overwrite = 1 ,$Run1 = 0 )
    ;FirstTimeRun Get original DirSize and set up Gui
    If $Run1 = 0 Then
    Global $OverallQty, $Overall, $source, $overallpercent, $Progress0Text, $progressbar1, $Progress1Text, $progressbar2, $Progress2Text, $LocalPercent
    If not FileExists ($destination) then DirCreate ($destination)
    $source = $current
    If StringRight($current, 1) = '\' Then $current = StringTrimRight($current, 1)
    If StringRight($destination, 1) <> '\' Then $destination = $destination & "\"
    $tosearch = $current
    $Overall = DirGetSize($tosearch, 1)
    $OverallQty = $Overall[1]
    $Progress0Text = GUICtrlCreateLabel("Please Wait", 16, 190, 441, 20)
    $progressbar1 = GUICtrlCreateProgress(16, 205, 441, 20)
    GUICtrlSetColor(-1, 32250)
    $Progress1Text = GUICtrlCreateLabel("", 16, 227, 441, 20)
    $progressbar2 = GUICtrlCreateProgress(16, 242, 441, 20)
    $Progress2Text = GUICtrlCreateLabel("", 16, 262, 441, 20)
    GUICtrlSetData($Progress1Text, "Working Directory " & $tosearch)
    $Run1 = 1
    EndIf

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

    $Size = DirGetSize($current, 3)
    $Qty = $Size[1]
    Local $search = FileFindFirstFile($current & "\*.*")
    While 1
    Dim $file = FileFindNextFile($search)
    ; end loop if all files are done or if an error happens
    If @error Or StringLen($file) < 1 Then ExitLoop
    ; Check that the next file to copy is no directory
    If Not StringInStr(FileGetAttrib($current & "\" & $file), "D") And ($file <> "." Or $file <> "..") Then
    ; Set values for GUI Labels
    $Qty -= 1
    $LocalPercent = 100 - (($Qty / $Size[1]) * 100)
    $OverallQty -= 1
    $overallpercent = 100 - (($OverallQty / $Overall[1]) * 100)
    ; set GUI Label content
    GUICtrlSetData($Progress0Text, "Download " & Int($overallpercent) & "% completed")
    GUICtrlSetData($progressbar1, $overallpercent)
    GUICtrlSetData($progressbar2, $LocalPercent)
    GUICtrlSetData($Progress2Text, "Copying File " & $file)
    ; Copy only if the source files modified date is different from the destination file (if already exists)
    $SourceFile = $current & "\" & $file
    $DestinationFile = $destination & StringTrimLeft($current, StringLen($source)) & "\" & $file
    If FileGetTime($SourceFile,0,1) <> FileGetTime($DestinationFile,0,1) Then
    FileCopy($current & "\" & $file, $destination & StringTrimLeft($current, StringLen($source)) & "\" & $file,$overwrite)
    FileSetAttrib($destination & StringTrimLeft($current, StringLen($source)) & "\" & $file, $attrib)
    EndIf
    EndIf
    ; If next file is a directory, create it and call the copy function again for this directory
    If StringInStr(FileGetAttrib($current & "\" & $file), "D") And ($file <> "." Or $file <> "..") Then
    DirCreate($destination & StringTrimLeft($current, StringLen($source)) & "\" & $file)
    FileSetAttrib($destination & StringTrimLeft($current, StringLen($source)) & "\" & $file, $attrib)
    GUICtrlSetData($Progress1Text, $current & "\" & $file)
    ProgressCopy($current & "\" & $file, $destination, $attrib, $overwrite,1)
    EndIf
    WEnd
    FileClose($search)
    ; when overall percent = 100, set end gui text, delete progressbars and reset run1 to 0
    If $overallpercent = 100 Then
    GUICtrlSetData($Progress0Text, "Package download 100% completed")
    GUICtrlSetData($progressbar1, 100)
    GUICtrlSetData($progressbar2, 100)
    GUICtrlSetData($Progress2Text, "Done!")
    Sleep(2000)
    GUICtrlDelete($Progress0Text)
    GUICtrlDelete($progressbar1)
    GUICtrlDelete($Progress1Text)
    GUICtrlDelete($progressbar2)
    GUICtrlDelete($Progress2Text)
    $Run1 = 0
    EndIf
    EndFunc

    [/autoit]


    Mein Ziel ist ein zusätzlicher Button, um die Function "ProgressCopy" (nutzt filecopy) komplett abzubrechen! Das eigentliche Problem ist, dass der GUI während der Kopieraktion keinerlei Eingaben zulässt, da die einzelnen Filecopy's sehr schnell aufeinander folgen...d.h. auch ein klick auf "X" beendet das Programm erst, nachdem die Funktion "ProgressCopy" beendet ist!
    Hat hier jemand ne Idee?FB_Addon_TelNo{
    height:15px !important;
    white-space: nowrap !important;
    background-color: #0ff0ff;}

    2 Mal editiert, zuletzt von Lazegalli (28. Juli 2010 um 18:50)

  • habe dasselbe Problem bei meinem RoyalLoader - nur das sich während des Downloadvorgangs nichts drücken lässt.
    Hab auch keine Lösungsidee dazu...
    Könnte mir aber für dein Problem vorstellen, die einzlenen Kopiervorgänge mit größerem Abstand aufeinanderabfolgen zu lassen

  • Füge zwischen den Paketen eine Pause ein (aber mit TimerInit, nicht Sleep!). Verwende z.B. eine Variable $Continue = False, mit Beginn des Kopierens auf True setzen, vor jedem neuen Paket abfragen ob True. Dann kannst du mit Button od. Hotkey den Wert bei Bedarf auf False setzen.

    Das war zuerst auch mein Ansatz.
    Leider beeinhalten Die Softwarepakete auch sehr große Einzeldateien. D.h. wird gerade eine 2GB Datei heruntergeladen, muss der User mit Deiner Lösung trotzdem warten bis diese Datei kopiert ist!

    Ich suche aber nach einer Möglichkeit die einzelne filecopy() action umgehend abzubrechen! Gibts da keine Möglichkeit?

  • Problem ist gelöst!

    Mit OnEventMode klappt alles wunderbar!
    Die Ursache war, dass GuiGetMsg() während while statements NICHT ausgeführt wird! GuiGetMsg() speichert den Event zwar in der Variable, die entsprechende Aktion wird aber erst ausgeführt nachdem alle while statements beendet sind.