Hi Leute,
Ich mal wieder ![]()
Ich komme gleich auf den Punkt.. Ich will ganz einfach ein kleines Programm schreiben was den Inhalt einer Datei verändert, um dies aber auch mit Executables zu machen läuft das ganze im Binary Mode.
Nun habe ich das Problem das ich das ganze nichtmal mit ner Txt hinbekomme.
Also man wählt ne Datei aus, gibt dann den String an den er suchen soll, und den String den er mit dem zu suchenden ersetzen soll.
Aber irgendwie schreibt er garnicht erst in die Datei ![]()
Bitte um Hilfe ![]()
Code:
Spoiler anzeigen
; #SCRIPT# ======================================================================================================================
; Name...........:
; Description ...:
; Author ........: Felix Lehmann alias eF_Hacks
; Modified.......: If you modify this Script, please enter your name here
; Remarks .......: None
; Related .......: -
; Link ..........;
; ===============================================================================================================================
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include-once
; ===============================================================================================================================
Global $file
Global $FoD
Global $hFile
; ===============================================================================================================================
; Display Desktop Centered GUI "Multipatcher"
#Region ### START Koda GUI section ### Form=
$Multipatcher = GUICreate("Multipatcher", 281, 199, -1, -1)
GUISetBkColor(0xFFFFFF)
$Group1 = GUICtrlCreateGroup("File", 8, 8, 265, 57)
$hG_Name = GUICtrlCreateInput("<>", 24, 32, 145, 21)
$Browse = GUICtrlCreateButton("Browse", 184, 30, 75, 25, 0)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Group2 = GUICtrlCreateGroup("Replacement", 8, 72, 265, 121)
$GSubStr = GUICtrlCreateInput("Find?", 24, 96, 225, 21)
$GRplcStr = GUICtrlCreateInput("Replace?", 24, 128, 225, 21)
$Patch = GUICtrlCreateButton("Patch!", 96, 160, 75, 25, 0)
GUICtrlCreateGroup("", -99, -99, 1, 1)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
; ===============================================================================================================================
; GUI Loop
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
FileClose($file)
Exit
Case $Patch
Patch()
Case $Browse
_Browse()
EndSwitch
WEnd
; ===============================================================================================================================
; Patch Function
Func Patch()
;===============================================================
;Existiert die datei?
Global $hName = GUICtrlRead($hG_Name)
If Not FileExists($hName) Then
MsgBox(0x10, "Error", "File doesn't exist:" & @error)
Exit
EndIf
;===============================================================
;Kann man sie öffnen?
$file = FileOpen($hName, 16)
If $file = -1 Then
MsgBox(0x10, "Error", "Unable to open file: " & $file)
Exit
EndIf
;===============================================================
;Mainpatching.. hier Hauts nicht richtig hin.
Local $SubStr = GUICtrlRead($GSubStr)
Local $RplcStr = GUICtrlRead($GRplcStr)
TrayTip("Patching file: " & $hName, "Please be patient", 1)
$FileText = FileRead($file)
MsgBox(0x40, "$FileText", $FileText)
$iLines = _CountLines($hName)
MsgBox(0x40, "$iLines", $iLines)
For $ctn = 1 To $iLines
$rLine = StringToBinary(FileReadLine($file, $ctn))
MsgBox(0x40, "$rLine", $rLine)
If StringInStr($rLine, StringToBinary($SubStr)) Then
$rpLc = StringReplace($rLine, $SubStr, $RplcStr)
MsgBox(0x40, "$rpLc", $rpLc)
_OverwriteLine($hName, StringToBinary($ctn), $rpLc, 1)
EndIf
Next
;===============================================================
FileClose($file)
EndFunc ;==>Patch
; ===============================================================================================================================
Func _Browse()
$FoD = FileOpenDialog("Open File To Patch", @DesktopDir, "All Files (*.*)")
GUICtrlSetData($hG_Name, $FoD)
EndFunc
; ===============================================================================================================================
Func _CountLines($sFilePath)
Local $hFile, $sFileContent, $aTmp
$hFile = FileOpen($sFilePath, 0)
If $hFile = -1 Then Return SetError(1, 0, 0)
$sFileContent = StringStripWS(FileRead($hFile), 2)
FileClose($hFile)
If StringInStr($sFileContent, @LF) Then
$aTmp = StringSplit(StringStripCR($sFileContent), @LF)
ElseIf StringInStr($sFileContent, @CR) Then
$aTmp = StringSplit($sFileContent, @CR)
Else
If StringLen($sFileContent) Then
Return 1
Else
Return SetError(2, 0, 0)
EndIf
EndIf
Return $aTmp[0]
EndFunc ;==>_CountLines
; ===============================================================================================================================
Func _OverwriteLine($sFile, $iLine, $sText, $fOverWrite = 1)
If $iLine <= 0 Then Return SetError(4, 0, 0)
If Not IsString($sText) Then Return SetError(6, 0, 0)
If $fOverWrite <> 0 And $fOverWrite <> 1 Then Return SetError(5, 0, 0)
If Not FileExists($sFile) Then Return SetError(2, 0, 0)
Local $filtxt = FileRead($sFile, FileGetSize($sFile))
$filtxt = StringSplit($filtxt, @CRLF, 1)
If UBound($filtxt, 1) < $iLine Then Return SetError(1, 0, 0)
Local $fil = FileOpen($sFile, 2)
If $fil = -1 Then Return SetError(3, 0, 0)
For $i = 1 To UBound($filtxt) - 1
If $i = $iLine Then
If $fOverWrite = 1 Then
If $sText <> '' Then
FileWrite($fil, $sText & @CRLF)
Else
FileWrite($fil, $sText)
EndIf
EndIf
If $fOverWrite = 0 Then
FileWrite($fil, $sText & @CRLF)
FileWrite($fil, $filtxt[$i] & @CRLF)
EndIf
ElseIf $i < UBound($filtxt, 1) - 1 Then
FileWrite($fil, $filtxt[$i] & @CRLF)
ElseIf $i = UBound($filtxt, 1) - 1 Then
FileWrite($fil, $filtxt[$i])
EndIf
Next
Return 1
EndFunc ;==>_OverwriteLine
Edit:
Inhalt meiner Datei sah so aus:
Und nach dem Test genauso ![]()