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
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
$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
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;}