Moin Leute
Ich hab mich seit Monaten wieder mal dazu motivieren können, ein Script zu schreiben. Deshalb sind meine Kentnisse ein bisschen eingefrohren.
Es geht im wesentlichen darum, einen Ordner rekursiv nach Audiodateien zu untersuchen und doppelt vorhandene Lieder zu finden, um zu benennen, zu löschen usw..
Bis jetzt wird der Ordner erfolgreich durchsucht und alle Dateipfäde in einem Array gespeichert (in der jetzigen Version in einem .txt, das später eingelesen wird).
Doppelt Vorhandene Lieder werden erfolgreich ermittelt und in der ListBox dargestellt, per Doppelklick sollen nun die beiden Dateien geladen werden, so dass man sie vergleichen kann.
Da erscheint das Problem. Der Doppelklick wird per WM_COMMAND ermittelt, welcher die Funktion _LoadTracks() auslöst. Egal wie ich in dieser Funktion den vorherigen Array auslesen will (ob per Global oder durch _FileReadToArray), es funktioniert nicht und _ArrayDisplay() stürzt ab.
_ArraySearch sagt bloss, dass der gesuchte String nicht gefunden wurde.
MsgBox(0, "", $array[x]) zeigt den richtigen Inhalt an.
Weiss jemand, was genau ich falsch gemacht habe?
Die entsprechenden Zeilen sind markiert.
Ohne vorhandene Audiodateien stürzt das Script noch ab. Mindenstens eine muss doppelt vorhanden sein (in Unterordner).
Spoiler anzeigen
#AutoIt3Wrapper_Res_File_Add=searching.gif, rt_rcdata, ANI_GIF_1
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <Array.au3>
#include <File.au3>
#include <GuiListBox.au3>
#include <SliderConstants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <IE.au3>
#include <GDIPlus.au3>
#include <Misc.au3>
#include <WinAPI.au3>
#include <Timers.au3>
#include "resources.au3"
#include "_FileListToArrayrecursive.au3"
Opt("GuiOnEventMode", 1)
#Region ### START Koda GUI section ### Form=
$hGUI = GUICreate("Doppelte Tracks Finden", 618, 500, 193, 127)
$Group1 = GUICtrlCreateGroup("Titel 1", 8, 16, 257, 225)
$l_filename_left = GUICtrlCreateLabel("Dateiname:", 16, 40, 58, 17)
$l_length_left = GUICtrlCreateLabel("Länge:", 16, 64, 37, 17)
$l_filesize_left = GUICtrlCreateLabel("Dateigrösse:", 16, 88, 63, 17)
$l_filepath_left = GUICtrlCreateLabel("Dateipfad:", 16, 136, 53, 17)
$e_filepath_left = GUICtrlCreateEdit("", 16, 160, 241, 73, BitOR($ES_AUTOVSCROLL,$ES_AUTOHSCROLL,$ES_WANTRETURN,$WS_VSCROLL))
GUICtrlSetData(-1, "e_filepath_left")
$timeslide_left = GUICtrlCreateSlider(16, 112, 162, 21)
$b_playleft = GUICtrlCreatePic("playpause.jpg" , 233, 32, 25, 25)
$b_stopleft = GUICtrlCreatePic("stop.jpg", 233, 64, 25, 25)
$b_rename = GUICtrlCreateButton("Umbenennen", 188, 96, 71, 25)
$b_delete_left = GUICtrlCreateButton("Löschen", 208, 128, 51, 25)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Group2 = GUICtrlCreateGroup("Titel 2", 272, 16, 257, 225)
$b_stopright = GUICtrlCreatePic("Umbenennen", 472, 96, 51, 25)
$l_filename_right = GUICtrlCreateLabel("Dateiname:", 280, 40, 58, 17)
$l_length_right = GUICtrlCreateLabel("Länge:", 280, 64, 37, 17)
$l_filesize_right = GUICtrlCreateLabel("Dateigrösse:", 280, 88, 63, 17)
$e_filepath_right = GUICtrlCreateEdit("", 280, 160, 241, 73, BitOR($ES_AUTOVSCROLL,$ES_AUTOHSCROLL,$ES_WANTRETURN,$WS_VSCROLL))
GUICtrlSetData(-1, "e_filepath_right")
$l_filepath_right = GUICtrlCreateLabel("Dateipfad:", 280, 136, 53, 17)
$timeslide_right = GUICtrlCreateSlider(280, 112, 162, 21)
$b_delete_right = GUICtrlCreateButton("Löschen", 472, 128, 51, 25)
$b_delete_right = GUICtrlCreateButton("Umbenennen", 452, 96, 71, 25)
$b_playright = GUICtrlCreatePic("playpause.jpg" , 497, 32, 25, 25)
$b_stopright = GUICtrlCreatePic("stop.jpg", 497, 64, 25, 25)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Group3 = GUICtrlCreateGroup("Gefundene Tracks", 8, 250, 600, 200)
;~ $hListBox = GUICtrlCreateListView("", 16, 268, 580, 170)
$hListBox = _GUICtrlListBox_Create($hGUI, "", 16, 268, 580, 170)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$b_holdboth = GUICtrlCreateButton("Beide behalten", 536, 216, 75, 25)
$b_deleteboth = GUICtrlCreateButton("Beide löschen", 536, 184, 75, 25)
$IMG_Ctrl = GUICtrlCreateLabel("", 536, 23, 10, 10) ; For Drawing
$pleasewait = GUICtrlCreateLabel("Bitte warten... Sammlung wird analysiert...", 536, 75, 100, 41)
GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
#EndRegion ### END Koda GUI section ###
GUISetState(@SW_SHOW, $hGUI)
[/autoit] [autoit][/autoit] [autoit]GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")
[/autoit] [autoit][/autoit] [autoit]Global $GIF_TimerID, $hImage, $IMG_Ctrl, $GFC, $GFDC, $pDimensionIDs, $tDL
Global $Pause, $i = 0
Global $a_Titles[100000]
Global $a_Combos ;==> Array, in dem die Kombinationen gespeichert sind
Global $S_PATH = "X:\90_AutoIt\Doppelte Titel\TEST"
Global $filelist = @ScriptDir & "\filelist.txt"
GifInit()
; Start Animation: instead of using the time delays between frames given from GIF we use 100ms for simplicity
_Timer_SetTimer($hGUI, 100, "_Draw_Timer")
_SearchTitles($S_PATH)
[/autoit] [autoit][/autoit] [autoit]While 1
[/autoit] [autoit][/autoit] [autoit]Sleep(100)
[/autoit] [autoit][/autoit] [autoit]WEnd
[/autoit] [autoit][/autoit] [autoit]Func _SearchTitles($s_Path)
Global $filearray
_FileListToArrayRecursive($s_Path, $filearray)
For $i = 1 To $filearray[0]
$tmp_path = StringSplit($filearray[$i], "")
$a_Titles[$i] = $tmp_path[$tmp_path[0]]
Next
$a_Titles[0] = $i - 1
ReDim $a_Titles[$i]
ReDim $filearray[$i]
_ArrayDelete($a_Titles, 0)
;~ _ArrayDisplay($a_Titles)
$a_Combos = __ArrayUnique($a_Titles)
[/autoit] [autoit][/autoit] [autoit]For $i = 1 To UBound($a_Combos) - 1
_GUICtrlListBox_AddString($hListBox, StringTrimRight($a_Combos[$i], 4))
Next
GUICtrlSetState($IMG_Ctrl, $GUI_HIDE)
GUICtrlSetState($pleasewait, $GUI_HIDE)
;~ _ArrayDisplay($filearray, "filearray")
_FileWriteFromArray($filelist, $filearray)
[/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit] [autoit];=====> Hier funktionierts
_arraydisplay($filearray)
;=======> noch...
EndFunc
[/autoit] [autoit][/autoit] [autoit]Func _LoadTracks()
Local $tmp_filelist
$tmp_index = _GUICtrlListBox_GetCurSel($hListBox)
$tmp_title = _GUICtrlListBox_GetText($hListBox, $tmp_index)
_ArrayDisplay($filearray)
;====> hier funktionierts nicht mehr.. selbst wenn der array zuvor neu aus der datei $filelist ausgelesen wird..
EndFunc
[/autoit] [autoit][/autoit] [autoit]Func __ArrayUnique($aArray, $iDimension = 1, $iBase = 0, $iCase = 0, $vDelim = "|")
Local $iUboundDim
;$aArray used to be ByRef, but litlmike altered it to allow for the choosing of 1 Array Dimension, without altering the original array
If $vDelim = "|" Then $vDelim = Chr(01) ; by SmOke_N, modified by litlmike
If Not IsArray($aArray) Then Return SetError(1, 0, 0) ;Check to see if it is valid array
;Checks that the given Dimension is Valid
If Not $iDimension > 0 Then
Return SetError(3, 0, 0) ;Check to see if it is valid array dimension, Should be greater than 0
Else
;If Dimension Exists, then get the number of "Rows"
$iUboundDim = UBound($aArray, 1) ;Get Number of "Rows"
If @error Then Return SetError(3, 0, 0) ;2 = Array dimension is invalid.
;If $iDimension Exists, And the number of "Rows" is Valid:
If $iDimension > 1 Then ;Makes sure the Array dimension desired is more than 1-dimensional
Local $aArrayTmp[1] ;Declare blank array, which will hold the dimension declared by user
For $i = 0 To $iUboundDim - 1 ;Loop through "Rows"
_ArrayAdd($aArrayTmp, $aArray[$i][$iDimension - 1]) ;$iDimension-1 to match Dimension
Next
_ArrayDelete($aArrayTmp, 0) ;Get rid of 1st-element which is blank
Else ;Makes sure the Array dimension desired is 1-dimensional
;If Dimension Exists, And the number of "Rows" is Valid, and the Dimension desired is not > 1, then:
;For the Case that the array is 1-Dimensional
If UBound($aArray, 0) = 1 Then ;Makes sure the Array is only 1-Dimensional
Dim $aArrayTmp[1] ;Declare blank array, which will hold the dimension declared by user
For $i = 0 To $iUboundDim - 1
_ArrayAdd($aArrayTmp, $aArray[$i])
Next
_ArrayDelete($aArrayTmp, 0) ;Get rid of 1st-element which is blank
Else ;For the Case that the array is 2-Dimensional
Dim $aArrayTmp[1] ;Declare blank array, which will hold the dimension declared by user
For $i = 0 To $iUboundDim - 1
_ArrayAdd($aArrayTmp, $aArray[$i][$iDimension - 1]) ;$iDimension-1 to match Dimension
Next
_ArrayDelete($aArrayTmp, 0) ;Get rid of 1st-element which is blank
EndIf
EndIf
EndIf
Local $sHold ;String that holds the Unique array info
Local $sDouble, $sDoubleIndex ; String that holds the double array info
For $iCC = $iBase To UBound($aArrayTmp) - 1 ;Loop Through array
;If Not the case that the element is already in $sHold, then add it
If Not StringInStr($vDelim & $sHold, $vDelim & $aArrayTmp[$iCC] & $vDelim, $iCase) Then
$sHold &= $aArrayTmp[$iCC] & $vDelim
Else
$sDouble &= $aArrayTmp[$iCC] & printf("%003s\n", $iCC + 1) & $vDelim
EndIf
Next
If $sDouble Then
$aArrayTmp = StringSplit(StringTrimRight($sDouble, StringLen($vDelim)), $vDelim, 1) ;Split the string into an array
;~ _ArrayDisplay($aArrayTmp)
Return $aArrayTmp ;SmOke_N's version used to Return SetError(0, 0, 0)
EndIf
Return SetError(2, 0, 0) ;If the script gets this far, it has failed
EndFunc ;==>_ArrayUnique
Func WM_COMMAND($hWnd, $iMsg, $iwParam, $ilParam)
#forceref $hWnd, $iMsg
Local $hWndFrom, $iIDFrom, $iCode, $hWndListBox
If Not IsHWnd($hListBox) Then $hWndListBox = GUICtrlGetHandle($hListBox)
$hWndFrom = $ilParam
$iIDFrom = BitAND($iwParam, 0xFFFF) ; Niederwertiges Wort (WORD)
$iCode = BitShift($iwParam, 16) ; Höherwertiges Wort (WORD)
Switch $hWndFrom
Case $hListBox, $hWndListBox
Switch $iCode
Case $LBN_DBLCLK ; Wird gesendet, wenn der Benutzer einen Doppelklick auf einen String in einer ListBox ausführt
_DebugPrint("$LBN_DBLCLK" & @LF & "--> hWndFrom:" & @TAB & $hWndFrom & @LF & _
"-->IDFrom:" & @TAB & $iIDFrom & @LF & _
"-->Code:" & @TAB & $iCode)
_LoadTracks()
Case $LBN_ERRSPACE ; Wird gesendet, wenn eine ListBox nicht genug Speicher zugeteilt bekommt, um eine Anfrage entgegenzunehmen
_DebugPrint("$LBN_ERRSPACE" & @LF & "--> hWndFrom:" & @TAB & $hWndFrom & @LF & _
"-->IDFrom:" & @TAB & $iIDFrom & @LF & _
"-->Code:" & @TAB & $iCode)
; Kein Rückgabewert
Case $LBN_KILLFOCUS ; Wird gesendet, wenn eine ListBox den Tastatur-Fokus verliert
_DebugPrint("$LBN_KILLFOCUS" & @LF & "--> hWndFrom:" & @TAB & $hWndFrom & @LF & _
"-->IDFrom:" & @TAB & $iIDFrom & @LF & _
"-->Code:" & @TAB & $iCode)
; Kein Rückgabewert
Case $LBN_SELCANCEL ; Wird gesendet, wenn der Benutzer die Auswahl in einer ListBox abbricht
_DebugPrint("$LBN_SELCANCEL" & @LF & "--> hWndFrom:" & @TAB & $hWndFrom & @LF & _
"-->IDFrom:" & @TAB & $iIDFrom & @LF & _
"-->Code:" & @TAB & $iCode)
; Kein Rückgabewert
Case $LBN_SELCHANGE ; Wird gesendet, wenn die Auswahl in einer ListBox geändert wurde
_DebugPrint("$LBN_SELCHANGE" & @LF & "--> hWndFrom:" & @TAB & $hWndFrom & @LF & _
"-->IDFrom:" & @TAB & $iIDFrom & @LF & _
"-->Code:" & @TAB & $iCode)
;~ MsgBox(0, "", $iCode)
Case $LBN_SETFOCUS ; Wird gesendet, wenn eine Listbox den Tastatur-Fokus erhält
_DebugPrint("$LBN_SETFOCUS" & @LF & "--> hWndFrom:" & @TAB & $hWndFrom & @LF & _
"-->IDFrom:" & @TAB & $iIDFrom & @LF & _
"-->Code:" & @TAB & $iCode)
; Kein Rückgabewert
EndSwitch
EndSwitch
; Die internen Standard Autoit3-Messages-Befehle werden fortgesetzt.
; Die ganze Zeile kann auch weggelassen werden.
; !!! Aber wird nur 'Return' (ohne Rückgabewert) verwendet, so
; Werden spätere Standard Autoit3-Messages-Befehle nicht mehr verarbeitet !!!
Return $GUI_RUNDEFMSG
EndFunc ;==>WM_COMMAND
Func _DebugPrint($s_text)
$s_text = StringReplace($s_text, @LF, @LF & "-->")
ConsoleWrite("!===========================================================" & @LF & _
"+===========================================================" & @LF & _
"-->" & $s_text & @LF & _
"+===========================================================" & @LF)
EndFunc ;==>_DebugPrint
Func _Draw_Timer($hWnd, $Msg, $iIDTimer, $dwTime)
If Not $Pause Then
If $i = $GFC Then $i = 0 ; If $i = the frame count then reset $i to 0
GifDrawFrame($i)
$i += 1
EndIf
EndFunc
Func Quit()
_Timer_KillAllTimers($hGUI)
_GDIPlus_ImageDispose($hImage)
_GDIPlus_Shutdown()
Exit
EndFunc
Func GifInit()
_GDIPlus_Startup()
; Load your animated GIF (from file or from resources)
;~ $hImage = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\gif-Green-UFO.gif")
$hImage = _ResourceGetAsImage("ANI_GIF_1")
$tDL = DllStructCreate($tagGUID) ; Create a struct to hold the GUID.
$pDimensionIDs = DllStructGetPtr($tDL) ; Get a pointer to the GUID struct.
; Get the FrameDimensionsCount of the loaded gif
$GFDC = DllCall($ghGDIPDll, "int", "GdipImageGetFrameDimensionsCount", "ptr", $hImage, "int*", 0)
; Get the FrameDimensionsList , which fills the GUID struct by passing the GUID pointer and the FrameDimensionsCount.
DllCall($ghGDIPDll, "int", "GdipImageGetFrameDimensionsList", "ptr", $hImage, "ptr", $pDimensionIDs, "int", $GFDC[2])
; Get the FrameCount of the loaded gif by passing the GUID pointer
$GFC = DllCall($ghGDIPDll, "int", "GdipImageGetFrameCount", "int", $hImage, "ptr", $pDimensionIDs, "int*", 0)
$GFC = $GFC[3]
EndFunc
Func GifDrawFrame($i)
; Select the ActiveFrame in the loaded GIF by telling it. The frame starts at 0 ($i)
DllCall($ghGDIPDll, "int", "GdipImageSelectActiveFrame", "ptr", $hImage, "ptr", $pDimensionIDs, "int", $i)
; get current frame from GIF and draw it on the control
$hBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage)
_SetBitmapToCtrl($IMG_Ctrl, $hBitmap)
_WinAPI_DeleteObject($hBitmap)
EndFunc
Func Printf($format, $var1)
Return StringFormat($format, $var1)
EndFunc ;==>Printf