#include <AutoItConstants.au3>
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <FileConstants.au3>
#include <GUIConstantsEx.au3>
#include <StringConstants.au3>
#include <WindowsConstants.au3>
Opt('MustDeclareVars', 1)
Global Const $eWinTitle = "Text-Regenerator"
Global Const $eName = " 2016 -Bazii-"
Global $g_hGUI, $g_idEdit_SearchText, $g_idEdit_TargetText, $g_idButton_End, $g_idButton_Fuse, _
$g_idButton_Start, $g_aidCheckbox, $g_idButton_SourceFolder, $g_idInput_Path, $g_aidCheckbox2
Global Const $g_eCheckbox[] = ["txt", "html", "htm", "php", "srt", "ini", "inf", "reg", "xml", "bat", "cfg", "rtf", "xxx", "xxx", "xxx", "xxx", "xxx", "xxx", "xxx", "xxx", "xxx", "xxx"]
; ---------- --------- -------- ------- ------ ----- ---- --- -- -
$g_hGUI = GUICreate($eWinTitle, 670, 530, -1, -1, BitOR($GUI_SS_DEFAULT_GUI, $WS_THICKFRAME))
$g_idEdit_SearchText = GUICtrlCreateEdit("(Suchtext)", 10, 120, 650, 153)
$g_idEdit_TargetText = GUICtrlCreateEdit("(Zieltext)", 10, 300, 650, 153)
$g_idButton_End = GUICtrlCreateButton("Beenden", 190, 8, 73, 33)
$g_idButton_Fuse = GUICtrlCreateButton("Sicherung", 100, 8, 73, 33)
GUICtrlSetTip(-1, "Eine Sicherung der ausgewählten Dateiendungen (Originale)" & @CRLF & "im Zielverzeichnis vor der Textersetzung erstellen")
$g_idButton_Start = GUICtrlCreateButton("Start", 10, 8, 73, 33)
GUICtrlSetTip(-1, "Die Textersetzung starten")
;~ GUICtrlCreateLabel($eName, 25, 500, 100, 17)
$g_aidCheckbox = __GUI_CreateCheckbox()
$g_idButton_SourceFolder = GUICtrlCreateButton("Quell Ordner", 611, 485, 34, 34, $BS_ICON)
GUICtrlSetImage(-1, "shell32.dll", 4)
$g_idInput_Path = GUICtrlCreateInput("Pfadauswahl nur über Icon Ordner", 125, 495, 466, 20, BitOR($GUI_SS_DEFAULT_INPUT, $ES_READONLY))
$g_aidCheckbox2 = GUICtrlCreateCheckbox("Mit Anfangsbuchstaben (Zieltext) ganze Zeilen im Dokument entfernen", 10, 460)
GUICtrlSetOnEvent($g_idButton_End, __idButton_End__)
GUICtrlSetOnEvent($g_idButton_SourceFolder, __idButton_SourceFolder__)
GUICtrlSetOnEvent($g_idButton_Fuse, __idButton_Fuse__)
GUICtrlSetOnEvent($g_idButton_Start, __idButton_Start__)
GUISetOnEvent($GUI_EVENT_CLOSE, GUI_EVENT_CLOSE)
; ---------- --------- -------- ------- ------ ----- ---- --- -- -
; ---------- --------- -------- ------- ------ ----- ---- --- -- -
Func _ReadCheckbox($sPath)
Local $sMask = _GetMask(";", "*.")
Local $avPath = _FileListToArrayRec($sPath, $sMask, $FLTAR_FILES, $FLTAR_RECUR, Default, $FLTAR_FULLPATH)
If @error Then Dim $avPath[1] = [0]
Return SetError(Not $sMask, 0, $avPath)
Func _GetMask($sSplit, $sPre = "")
For $iFor = 0 To UBound($g_aidCheckbox) -1
If GUICtrlRead($g_aidCheckbox[$iFor]) = $GUI_CHECKED Then $sMask &= $sPre & $g_eCheckbox[$iFor] & $sSplit
Return StringTrimRight($sMask, 1)
Local $iPID = Run('"7za.exe" ' & $sCMD, @ScriptDir, @SW_HIDE, $STDOUT_CHILD)
$sRead &= StdoutRead($iPID)
Func _ArchiveList($sPath, $sFilter)
Local Const $eCMD = '"l" "' & $sPath & '"'
Local Const $eRegEx = '[0-9 :-]{20}.{33}(.*\.(?:' & $sFilter & '))'
$avRegEx = StringRegExp(_Run7Zip($eCMD), $eRegEx, $STR_REGEXPARRAYGLOBALMATCH)
If IsArray($avRegEx) Then
_ArrayInsert($avRegEx, 0, UBound($avRegEx))
Func _ArchiveExtract($sPath, $sFile)
Local Const $eCMD = '"e" "' & $sPath & '" "' & $sFile & '" "-o' & @TempDir & '"'
Return StringRegExp($sFile, "(?:.*\\|)(.*)", $STR_REGEXPARRAYGLOBALMATCH)[0]
Func _ArchiveAdd($sPath, $sFile)
Local Const $eCMD = '"a" "' & $sPath & '" "' & $sFile & '"'
; ---------- --------- -------- ------- ------ ----- ---- --- -- -
Func __idButton_SourceFolder__()
Local $sPath = FileSelectFolder("Öffnen", @MyDocumentsDir, Default, "", $g_hGUI)
If @error Then Return ;--Return um nicht das Programm zu beenden, sondern um zur GUI zurückzukehren
GUICtrlSetData($g_idInput_Path, $sPath)
Func __idButton_Fuse__() ;--Sicherung anlegen
Local $iFor, $bChecked, $avPath
Local $sPath = GUICtrlRead($g_idInput_Path)
If $sPath <> "Pfadauswahl nur über Icon Ordner" Then
If FileExists($sPath & "\Text-Regenerator Backup Verzeichnis") And Not DirRemove($sPath & "\Text-Regenerator Backup Verzeichnis", $DIR_REMOVE) Then Return MsgBox(0, "Hinweis", "Es sind geöffnete Dateien im Backupverzeichnis enthalten. Bitte schließen Sie diese vor der Ausführung!", 0, $g_hGUI)
$avPath = _ReadCheckbox($sPath)
For $iFor = 1 To $avPath[0]
If FileCopy($avPath[$iFor], $sPath & "\Text-Regenerator Backup Verzeichnis\" & $iFor, $FC_CREATEPATH) Then
FileWriteLine($sPath & "\Text-Regenerator Backup Verzeichnis\Copy.txt", $iFor & " = " & $avPath[$iFor])
Return MsgBox(0, "Hinweis", "Es wurde keine Dateiendung ausgewählt!", 0, $g_hGUI)
Return MsgBox(0, "Hinweis", "Es wurde kein Pfad ausgewählt!", 0, $g_hGUI)
If $avPath[0] Then Return MsgBox(0, "Hinweis", "Backup wurde erfolgreich erstellt!", 0, $g_hGUI)
MsgBox(0, "Hinweis", "Keine Dateien zur Sicherung mit den gewählten Dateieindungen vorhanden.", 0, $g_hGUI)
Func __idButton_Start__()
Local $sPath = GUICtrlRead($g_idInput_Path)
Local $sSearch = GUICtrlRead($g_idEdit_SearchText)
Local $sTarget = GUICtrlRead($g_idEdit_TargetText)
Local $avPath, $iFor, $sText, $hFile, $sFail, $avArchive, $iIn, $sFile
If $sPath <> "Pfadauswahl nur über Icon Ordner" Then
$avPath = _ReadCheckbox($sPath)
For $iFor = 1 To $avPath[0]
$sText = FileRead($avPath[$iFor])
$sText = StringReplace($sText, $sSearch, $sTarget, 0, $STR_CASESENSE)
$hFile = FileOpen($avPath[$iFor], $FO_OVERWRITE)
FileWrite($hFile, $sText)
$sFail &= $avPath[$iFor] & @CRLF
$avPath = _FileListToArrayRec($sPath, "*.zip;*.7z", $FLTAR_FILES, $FLTAR_RECUR, Default, $FLTAR_FULLPATH)
For $iFor = 1 To $avPath[0]
$avArchive = _ArchiveList($avPath[$iFor], _GetMask("|"))
For $iIn = 1 To $avArchive[0]
$sFile = @TempDir & "\" & _ArchiveExtract($avPath[$iFor], $avArchive[$iIn])
$sText = FileRead($sFile)
$sText = StringReplace($sText, $sSearch, $sTarget, 0, $STR_CASESENSE)
$hFile = FileOpen($sFile, $FO_OVERWRITE)
FileWrite($hFile, $sText)
Return MsgBox(0, "Hinweis", "Es wurden keine entsprechend ausgewählten Dateiendungen gefunden!", 0, $g_hGUI)
Return MsgBox(0, "Hinweis", "Es wurde kein Pfad ausgewählt!", 0, $g_hGUI)
If $sFail Then $sFail = @CRLF & @CRLF & "Folgende Dateien konnten nicht überschrieben werden:" & @CRLF & $sFail
MsgBox(0, "Hinweis", "Der Text wurde erfolgreich ersetzt!" & $sFail, 0, $g_hGUI)
; ---------- --------- -------- ------- ------ ----- ---- --- -- -
Func __GUI_CreateCheckbox()
Local $iFor, $avCheckbox[UBound($g_eCheckbox)]
Local $iWidth = WinGetPos($g_hGUI)[2]
Local $iCtrl = Floor($iWidth / $eLeft)
For $iFor = 0 To $iCtrl -1
$avCheckbox[$iFor] = GUICtrlCreateCheckbox(" " & $g_eCheckbox[$iFor], $iFor * $eLeft + 10, 65, $eLeft, 20)
For $iFor = $iCtrl To UBound($g_eCheckbox) -1
$avCheckbox[$iFor] = GUICtrlCreateCheckbox(" " & $g_eCheckbox[$iFor], ($iFor - $iCtrl) * $eLeft + 10, 90, $eLeft, 20)
; ---------- --------- -------- ------- ------ ----- ---- --- -- -
;~ Func __GUI_CreateCheckbox2()
; ---------- --------- -------- ------- ------ ----- ---- --- -- -