Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 09/29/2015 in all areas

  1. Having used the _SelfDelete() function before, I knew it could be improved upon with adding more functionality to compensate for when an AutoIt error might occur. The version I updated includes the ability to monitor when the process is closed and/or the timer is reached, therefore if an error was to occur with your program and the _SelfDelete() function was called before, it will still delete the executable even with an AutoIt error (due to bad coding of course!) This can't be said for the old version of _SelfDelete() as you'll never have chance to call the function! I also included the option to check either the process name or PID, depending on your preference. Thanks. Function: Using a Batch script. Save as _SelfDelete.au3 #include-once #include <FileConstants.au3> #include <StringConstants.au3> ; #FUNCTION# ==================================================================================================================== ; Name ..........: _SelfDelete ; Description ...: Delete the current executable after it's finished processing and/or the timer has been reached. ; Syntax ........: _SelfDelete([$iDelay = 5[, $fUsePID = False[, $fRemoveDir = False]]]) ; Parameters ....: $iDelay - [optional] An integer value for the delay to wait (in seconds) before stopping the process and deleting the executable. ; If 0 is specified then the batch will wait indefinitely until the process no longer exits. Default is 5 (seconds). ; $fUsePID - [optional] Use the process name (False) or PID (True). Default is False. ; $fRemoveDir - [optional] Remove the script directory as well (True) or only the running executable (False). Default is False. ; Return values .: Success - Returns the PID of the batch file. ; Failure - Returns 0 & sets @error to non-zero ; Author ........: guinness ; Modified ......: ; Remarks .......: The idea for removing the directory came from: http://www.autoitscript.com/forum/topic/137287-delete-scriptdir/ ; Example .......: Yes ; =============================================================================================================================== Func _SelfDelete($iDelay = 5, $fUsePID = Default, $fRemoveDir = Default) If @Compiled = 0 Then Return SetError(1, 0, 0) EndIf Local $sTempFileName = @ScriptName $sTempFileName = StringLeft($sTempFileName, StringInStr($sTempFileName, '.', $STR_NOCASESENSEBASIC, -1) - 1) While FileExists(@TempDir & '\' & $sTempFileName & '.bat') $sTempFileName &= Chr(Random(65, 122, 1)) WEnd $sTempFileName = @TempDir & '\' & $sTempFileName & '.bat' Local $sDelay = '' $iDelay = Int($iDelay) If $iDelay > 0 Then $sDelay = 'IF %TIMER% GTR ' & $iDelay & ' GOTO DELETE' EndIf Local $sRemoveDir = '' If $fRemoveDir Then $sRemoveDir = 'RD /S /Q "' & FileGetShortName(@ScriptDir) & '"' & @CRLF EndIf Local $sAppID = @ScriptName, $sImageName = 'IMAGENAME' If $fUsePID Then $sAppID = @AutoItPID $sImageName = 'PID' EndIf Local Const $iInternalDelay = 2, _ $sScriptPath = FileGetShortName(@ScriptFullPath) Local Const $sData = 'SET TIMER=0' & @CRLF _ & ':START' & @CRLF _ & 'PING -n ' & $iInternalDelay & ' 127.0.0.1 > nul' & @CRLF _ & $sDelay & @CRLF _ & 'SET /A TIMER+=1' & @CRLF _ & @CRLF _ & 'TASKLIST /NH /FI "' & $sImageName & ' EQ ' & $sAppID & '" | FIND /I "' & $sAppID & '" >nul && GOTO START' & @CRLF _ & 'GOTO DELETE' & @CRLF _ & @CRLF _ & ':DELETE' & @CRLF _ & 'TASKKILL /F /FI "' & $sImageName & ' EQ ' & $sAppID & '"' & @CRLF _ & 'DEL "' & $sScriptPath & '"' & @CRLF _ & 'IF EXIST "' & $sScriptPath & '" GOTO DELETE' & @CRLF _ & $sRemoveDir _ & 'GOTO END' & @CRLF _ & @CRLF _ & ':END' & @CRLF _ & 'DEL "' & $sTempFileName & '"' Local Const $hFileOpen = FileOpen($sTempFileName, $FO_OVERWRITE) If $hFileOpen = -1 Then Return SetError(2, 0, 0) EndIf FileWrite($hFileOpen, $sData) FileClose($hFileOpen) Return Run($sTempFileName, @TempDir, @SW_HIDE) EndFunc ;==>_SelfDeleteFunction: Using a VBScript file. Save as _SelfDelete.au3 #include-once #include <FileConstants.au3> #include <StringConstants.au3> ; #FUNCTION# ==================================================================================================================== ; Name ..........: _SelfDelete ; Description ...: Delete the current executable after it's finished processing and/or the timer has been reached. ; Syntax ........: _SelfDelete([$iDelay = 5[, $fUsePID = False[, $fRemoveDir = False]]]) ; Parameters ....: $iDelay - [optional] An integer value for the delay to wait (in seconds) before stopping the process and deleting the executable. ; If 0 is specified then the script will wait indefinitely until the process no longer exits. Default is 5 (seconds). ; $fUsePID - [optional] Use the process name (False) or PID (True). Default is False. ; $fRemoveDir - [optional] Remove the script directory as well (True) or only the running executable (False). Default is False. ; Return values .: Success - Returns the PID of the batch file. ; Failure - Returns 0 & sets @error to non-zero ; Author ........: guinness ; Modified ......: ; Remarks .......: The idea for removing the directory came from: http://www.autoitscript.com/forum/topic/137287-delete-scriptdir/ ; Example .......: Yes ; =============================================================================================================================== Func _SelfDelete($iDelay = 5, $fUsePID = Default, $fRemoveDir = Default) If @Compiled = 0 Then Return SetError(1, 0, False) EndIf Local $sTempFileName = @ScriptName $sTempFileName = StringLeft($sTempFileName, StringInStr($sTempFileName, '.', $STR_NOCASESENSEBASIC, -1) - 1) While FileExists(@TempDir & '\' & $sTempFileName & '.bat') $sTempFileName &= Chr(Random(65, 122, 1)) WEnd $sTempFileName = @TempDir & '\' & $sTempFileName & '.vbs' Local $sDelay = '' $iDelay = Int($iDelay) If $iDelay > 0 Then $sDelay = @TAB & 'iTimeOut = iTimeOut + 1' & @CRLF _ & @TAB & 'If iTimeOut > ' & $iDelay & ' Then' & @CRLF _ & @TAB & @TAB & 'For Each oProcess in oWMIQuery' & @CRLF _ & @TAB & @TAB & @TAB & 'oProcess.Terminate()' & @CRLF _ & @TAB & @TAB & 'Next' & @CRLF _ & @TAB & @TAB & 'iExit = 2' & @CRLF _ & @TAB & 'End If' & @CRLF EndIf Local $sRemoveDir = '' If $fRemoveDir Then $sRemoveDir = 'oFileSystem.DeleteFolder "' & @ScriptDir & '", True' & @CRLF EndIf Local $sAppID = @ScriptName, $sImageName = 'Name' If $fUsePID Then $sAppID = @AutoItPID $sImageName = 'ProcessId' EndIf Local Const $iInternalDelay = 10, _ $sScriptPath = @ScriptFullPath Local Const $sData = 'Option Explicit' & @CRLF _ & 'Dim iExit, iTimeOut, oFileSystem, oProcess, oWMIQuery, oWMIService, sComputer, sFilePath, sWMIQuery' & @CRLF _ & @CRLF _ & 'sFilePath = "' & $sScriptPath & '"' & @CRLF _ & @CRLF _ & 'iExit = 0' & @CRLF _ & 'iTimeOut = 0' & @CRLF _ & 'sComputer = "."' & @CRLF _ & @CRLF _ & 'Set oWMIService = GetObject("winmgmts:" _' & @CRLF _ & @TAB & @TAB & '& "{impersonationLevel=impersonate}!\\" _' & @CRLF _ & @TAB & @TAB & '& sComputer & "\root\cimv2")' & @CRLF _ & @CRLF _ & 'sWMIQuery = "Select * From Win32_Process Where ' & $sImageName & ' = ''' & $sAppID & '''"' & @CRLF _ & @CRLF _ & 'While (iExit = 0)' & @CRLF _ & @TAB & 'Set oWMIQuery = oWMIService.ExecQuery(sWMIQuery)' & @CRLF _ & @TAB & 'If oWMIQuery.Count = 0 Then' & @CRLF _ & @TAB & @TAB & 'iExit = 1' & @CRLF _ & @TAB & 'End If' & @CRLF _ & @TAB & 'WScript.Sleep(1000)' & @CRLF _ & $sDelay _ & 'Wend' & @CRLF _ & @CRLF _ & 'WScript.Sleep(1000)' & @CRLF _ & 'iExit = 0' & @CRLF _ & 'iTimeOut = 0' & @CRLF _ & 'Set oFileSystem = CreateObject("Scripting.FileSystemObject")' & @CRLF _ & 'While (iExit = 0)' & @CRLF _ & @TAB & 'iTimeOut = iTimeOut + 1' & @CRLF _ & @TAB & 'If oFileSystem.FileExists(sFilePath) Then' & @CRLF _ & @TAB & @TAB & 'oFileSystem.DeleteFile sFilePath, True' & @CRLF _ & @TAB & 'End If' & @CRLF _ & @TAB & 'If oFileSystem.FileExists(sFilePath) <> True Then' & @CRLF _ & @TAB & @TAB & 'iExit = 1' & @CRLF _ & @TAB & 'End If' & @CRLF _ & @TAB & 'If iTimeOut > ' & $iInternalDelay & ' Then' & @CRLF _ & @TAB & @TAB & 'iExit = 2' & @CRLF _ & @TAB & 'End If' & @CRLF _ & 'Wend' & @CRLF _ & @CRLF _ & $sRemoveDir _ & 'oFileSystem.DeleteFile WScript.ScriptFullName, True' & @CRLF _ Local Const $hFileOpen = FileOpen($sTempFileName, $FO_OVERWRITE) If $hFileOpen = -1 Then Return SetError(2, 0, False) EndIf FileWrite($hFileOpen, $sData) FileClose($hFileOpen) Return ShellExecute($sTempFileName, @TempDir, @TempDir, '', @SW_HIDE) EndFunc ;==>_SelfDeleteExample use of Function: #include <MsgBoxConstants.au3> #include '_SelfDelete.au3' _SelfDelete(30, 0) ; Start the SelfDelete batch file with a 30 second timer and using the prcocess name rather than the PID. If @error Then Exit MsgBox($MB_SYSTEMMODAL, '_SelfDelete()', 'The script must be a compiled exe to work correctly.') ; Display a warning if the script isn't compiled. EndIf While 1 Sleep(100) ; Wait or manually close the application via the traymenu icon. WEndWARNING: This will delete your executable if the function is called, so take the proper precautions and make sure you backup.
    1 point
  2. are you familiar with _nowtime and _nowdate? https://www.autoitscript.com/autoit3/docs/libfunctions/_NowTime.htm https://www.autoitscript.com/autoit3/docs/libfunctions/_NowDate.htm
    1 point
  3. guinness

    Copy & delete itself

    An entirely different snippet of code, that's what that is.
    1 point
  4. guinness

    Copy & delete itself

    So how can I sued this in my own code? You haven't made it very configurable and I should know, as I create _SelfDelete().
    1 point
  5. Melba23

    Problem with PixelGetColor

    michu, Welcome to the AutoIt forums. I am sure it is more likely to be your code. That code snippet will act extremely quickly - are you sure that the "page" will have changed by the time you look for the "red" section and then click on one of the buttons? If the page has not yet correctly loaded then obviously none of the actions will happen on the "page" you think you are using. So how can you tell if the page has indeed changed? What allows you to confirm that the "red" section might be present and that he buttons are ready to be pressed? Once you can confirm that the "page" is correctly loaded, then you can start looking and actioning it. M23
    1 point
  6. Try ControlClick("T5Suite 2.0 information", "", "[CLASS:WindowsForms10.Window.b.app.0.33c0d9d; INSTANCE:1]")
    1 point
  7. Update Dbug 28.09.15.zip
    1 point
  8. Thanks guys, I finally have something to work with. One day I hope to earn FREE membership to Autoit Forums.... wait...
    1 point
  9. wolf9228

    Simple Compression

    Another experiment Compression.zip Compression.au3 #include <WinAPI.au3> #include <Memory.au3> Opt("MustDeclareVars", 1) Example() Func Example() Local $FileOpenA , $FileOpenB , $BinaryA , $BinaryB , $NewSizeA , $NewSizeB $NewSizeA = CompressionA("Untitled.ico","Rxr.Rxr") $NewSizeB = Decompressing("Rxr.Rxr","Untitled2.ico") $FileOpenA = FileOpen("Untitled.ico",16) $FileOpenB = FileOpen("Untitled2.ico",16) $BinaryA = FileRead($FileOpenA) $BinaryB = FileRead($FileOpenB) if $BinaryA == $BinaryB Then MsgBox(0,"MSG","OK") FileClose($FileOpenA) FileClose($FileOpenB) EndFunc Func CompressionA($InFile,$OutFile = "Rxr.Rxr") Local $nBytes , $hFile , $FileSize , $FileStruct , $Remainder , $FileStructPtr Local $TempDataStructA,$ReturnSt , $NewSize , $hFileA , $hFileB , $RemainderSt Local $NuA , $NuB , $NuC $FileSize = FileGetSize($InFile) if Not $FileSize Then Return SetError(1,0,0) $hFileA = _WinAPI_CreateFile($InFile,2,2) if Not $hFileA Then Return SetError(2,0,0) $hFileB = _WinAPI_CreateFile($OutFile,1) if Not $hFileB Then _WinAPI_CloseHandle($hFileA) Return SetError(3,0,0) EndIf if $FileSize < 254 Then $RemainderSt = DllStructCreate("byte Count;byte[" & $FileSize & "]") DllStructSetData($RemainderSt,1,$FileSize) _WinAPI_ReadFile($hFileA,DllStructGetPtr($RemainderSt,2),$FileSize,$nBytes) _WinAPI_WriteFile($hFileB,DllStructGetPtr($RemainderSt),DllStructGetSize($RemainderSt),$nBytes) _WinAPI_CloseHandle($hFileA) _WinAPI_CloseHandle($hFileB) Return SetError(0,0,($FileSize + 1)) Else $FileStruct = DllStructCreate("byte[" & $FileSize & "]") $FileStructPtr = DllStructGetPtr($FileStruct) _WinAPI_ReadFile($hFileA,$FileStructPtr,$FileSize,$nBytes) $Remainder = Mod($FileSize,254) if $Remainder Then $RemainderSt = DllStructCreate("byte Count;byte[" & $Remainder & "]") DllStructSetData($RemainderSt,1,$Remainder) _MemMoveMemory($FileStructPtr + ($FileSize - $Remainder),DllStructGetPtr($RemainderSt,2),$Remainder) _WinAPI_WriteFile($hFileB,DllStructGetPtr($RemainderSt),DllStructGetSize($RemainderSt),$nBytes) $NewSize = ($Remainder + 1) Else $RemainderSt = DllStructCreate("byte Count") DllStructSetData($RemainderSt,1,0) _WinAPI_WriteFile($hFileB,DllStructGetPtr($RemainderSt),DllStructGetSize($RemainderSt),$nBytes) $NewSize = 1 EndIf For $MovPos = 0 To ($FileSize - $Remainder) - 254 Step 254 $TempDataStructA = DllStructCreate("Byte[254]") _MemMoveMemory($FileStructPtr + $MovPos,DllStructGetPtr($TempDataStructA),254) $ReturnSt = CompressionB($TempDataStructA) _WinAPI_WriteFile($hFileB,DllStructGetPtr($ReturnSt),DllStructGetSize($ReturnSt),$nBytes) $NewSize += DllStructGetSize($ReturnSt) $NuA = "[ % " & StringLeft((($MovPos + 254) / ($FileSize - $Remainder) * 100),4) & " ]" $NuB = "[ File Size " & StringLeft((($MovPos + 254 + $Remainder) / 1024),4) & " KB ]" $NuC = "[ Compression Size " & StringLeft(($NewSize / 1024),4) & " KB ]" ToolTip( $NuA & " " & $NuB & " " & $NuC , 100, 100) Next EndIf _WinAPI_CloseHandle($hFileA) _WinAPI_CloseHandle($hFileB) Return SetError(0,0,$NewSize) EndFunc Func CompressionB($TempDataStructA) Local $TempDataStructB = DllStructCreate( "Byte[254]" ) Local $TempDataStructC = DllStructCreate( "Byte[254]" ) Local $TempDataStructE = DllStructCreate( "Byte[254]" ) Local $i = 0 , $NuA = 0 ,$NuB = 0 ,$NuC = 0 ,$PtrB , $ReturnSt Local $ByteE,$ByteB,$ByteC,$ByteD,$PtrA,$ByteA,$NuBPtr,$NuCPtr Local $ReturnStA , $ReturnStB , $ReturnStC , $PtrE $PtrA = DllStructGetPtr($TempDataStructA) $PtrE = DllStructGetPtr($TempDataStructE) _MemMoveMemory($PtrA,$PtrE,254) While 1 if (DllStructGetSize($TempDataStructA) - $i) < 2 Then ExitLoop $i += 2 $ByteE = CompressionC($TempDataStructA) $ByteA = DllStructGetData($TempDataStructA,1,$i - 1) $ByteB = DllStructGetData($TempDataStructA,1,$i) $NuA = 0 For $j = 2 To DllStructGetSize($TempDataStructA) Step 2 if (DllStructGetSize($TempDataStructA) - $j) = 1 Then ExitLoop $ByteC = DllStructGetData($TempDataStructA,1,$j - 1) $ByteD = DllStructGetData($TempDataStructA,1,$j) if $ByteA = $ByteC And $ByteB = $ByteD Then $NuA += 1 Next if $NuA > 3 Then $NuB = 0 For $n = 2 To DllStructGetSize($TempDataStructA) Step 2 $ByteC = DllStructGetData($TempDataStructA,1,$n - 1) $ByteD = DllStructGetData($TempDataStructA,1,$n) if $ByteA = $ByteC And $ByteB = $ByteD Then $NuB += 1 DllStructSetData($TempDataStructB,1,$ByteE,$NuB) Else $NuB += 1 DllStructSetData($TempDataStructB,1,$ByteC,$NuB) $NuB += 1 DllStructSetData($TempDataStructB,1,$ByteD,$NuB) EndIf if (DllStructGetSize($TempDataStructA) - $n) = 1 Then $NuB += 1 $ByteC = DllStructGetData($TempDataStructA,1,$n + 1) DllStructSetData($TempDataStructB,1,$ByteC,$NuB) ExitLoop EndIf Next $NuC += 1 DllStructSetData($TempDataStructC,1,$ByteE,$NuC) $NuC += 1 DllStructSetData($TempDataStructC,1,$ByteA,$NuC) $NuC += 1 DllStructSetData($TempDataStructC,1,$ByteB,$NuC) $TempDataStructA = DllStructCreate("Byte[" & $NuB & "]") $PtrA = DllStructGetPtr($TempDataStructA) $PtrB = DllStructGetPtr($TempDataStructB) _MemMoveMemory($PtrB,$PtrA,$NuB) EndIf WEnd if $NuC Then $ReturnStA = DllStructCreate("Byte CountB;Byte Type;Byte NuB[" & $NuB & "];" & "Byte CountC;Byte NuC[" & $NuC & "]") DllStructSetData($ReturnStA,"Type",1) DllStructSetData($ReturnStA,"CountB",$NuB) DllStructSetData($ReturnStA,"CountC",$NuC) $NuBPtr = DllStructGetPtr($ReturnStA,"NuB") $NuCPtr = DllStructGetPtr($ReturnStA,"NuC") _MemMoveMemory (DllStructGetPtr($TempDataStructA),$NuBPtr,$NuB) _MemMoveMemory (DllStructGetPtr($TempDataStructC),$NuCPtr,$NuC) Else $ReturnStA = DllStructCreate("Byte CountB;Byte NuB[254]") $NuBPtr = DllStructGetPtr($ReturnStA,"NuB") _MemMoveMemory (DllStructGetPtr($TempDataStructA),$NuBPtr,254) EndIf $TempDataStructA = DllStructCreate("Byte[254]") $PtrA = DllStructGetPtr($TempDataStructA) $PtrE = DllStructGetPtr($TempDataStructE) _MemMoveMemory($PtrE,$PtrA,254) $TempDataStructB = DllStructCreate( "Byte[254]" ) $TempDataStructC = DllStructCreate( "Byte[254]" ) $i = 0 $NuA = 0 $NuB = 0 $NuC = 0 While 1 if (DllStructGetSize($TempDataStructA) - $i) < 2 Then ExitLoop $i += 2 $ByteE = CompressionC($TempDataStructA) $ByteA = DllStructGetData($TempDataStructA,1,$i - 1) $ByteB = DllStructGetData($TempDataStructA,1,$i) $NuA = 0 For $j = 2 To DllStructGetSize($TempDataStructA) Step 2 if (DllStructGetSize($TempDataStructA) - $j) = 1 Then ExitLoop $ByteC = DllStructGetData($TempDataStructA,1,$j - 1) $ByteD = DllStructGetData($TempDataStructA,1,$j) if $ByteA = $ByteC And $ByteB = $ByteC And $ByteD = $ByteC Then $NuA += 1 Next if $NuA > 2 Then $NuB = 0 For $n = 2 To DllStructGetSize($TempDataStructA) Step 2 $ByteC = DllStructGetData($TempDataStructA,1,$n - 1) $ByteD = DllStructGetData($TempDataStructA,1,$n) if $ByteA = $ByteC And $ByteB = $ByteC And $ByteD = $ByteC Then $NuB += 1 DllStructSetData($TempDataStructB,1,$ByteE,$NuB) Else $NuB += 1 DllStructSetData($TempDataStructB,1,$ByteC,$NuB) $NuB += 1 DllStructSetData($TempDataStructB,1,$ByteD,$NuB) EndIf if (DllStructGetSize($TempDataStructA) - $n) = 1 Then $NuB += 1 $ByteC = DllStructGetData($TempDataStructA,1,$n + 1) DllStructSetData($TempDataStructB,1,$ByteC,$NuB) ExitLoop EndIf Next $NuC += 1 DllStructSetData($TempDataStructC,1,$ByteE,$NuC) $NuC += 1 DllStructSetData($TempDataStructC,1,$ByteA,$NuC) $TempDataStructA = DllStructCreate("Byte[" & $NuB & "]") $PtrA = DllStructGetPtr($TempDataStructA) $PtrB = DllStructGetPtr($TempDataStructB) _MemMoveMemory($PtrB,$PtrA,$NuB) EndIf WEnd if $NuC Then $ReturnStB = DllStructCreate("Byte CountB;Byte Type;Byte NuB[" & $NuB & "];" & "Byte CountC;Byte NuC[" & $NuC & "]") DllStructSetData($ReturnStB,"Type",2) DllStructSetData($ReturnStB,"CountB",$NuB) DllStructSetData($ReturnStB,"CountC",$NuC) $NuBPtr = DllStructGetPtr($ReturnStB,"NuB") $NuCPtr = DllStructGetPtr($ReturnStB,"NuC") _MemMoveMemory (DllStructGetPtr($TempDataStructA),$NuBPtr,$NuB) _MemMoveMemory (DllStructGetPtr($TempDataStructC),$NuCPtr,$NuC) Else $ReturnStB = DllStructCreate("Byte CountB;Byte NuB[254]") $NuBPtr = DllStructGetPtr($ReturnStB,"NuB") _MemMoveMemory (DllStructGetPtr($TempDataStructA),$NuBPtr,254) EndIf $TempDataStructA = DllStructCreate("Byte[254]") $PtrA = DllStructGetPtr($TempDataStructA) $PtrE = DllStructGetPtr($TempDataStructE) _MemMoveMemory($PtrE,$PtrA,254) $TempDataStructB = DllStructCreate( "Byte[254]" ) $TempDataStructC = DllStructCreate( "Byte[254]" ) $i = 0 $NuA = 0 $NuB = 0 $NuC = 0 While 1 if (DllStructGetSize($TempDataStructA) - $i) < 2 Then ExitLoop $i += 2 $ByteE = CompressionC($TempDataStructA) $ByteA = DllStructGetData($TempDataStructA,1,$i - 1) $ByteB = DllStructGetData($TempDataStructA,1,$i) $NuA = 0 For $j = 2 To DllStructGetSize($TempDataStructA) Step 2 if (DllStructGetSize($TempDataStructA) - $j) = 1 Then ExitLoop $ByteC = DllStructGetData($TempDataStructA,1,$j - 1) $ByteD = DllStructGetData($TempDataStructA,1,$j) if $ByteA = $ByteD And $ByteB = $ByteC Then $NuA += 1 Next if $NuA > 3 Then $NuB = 0 For $n = 2 To DllStructGetSize($TempDataStructA) Step 2 $ByteC = DllStructGetData($TempDataStructA,1,$n - 1) $ByteD = DllStructGetData($TempDataStructA,1,$n) if $ByteA = $ByteD And $ByteB = $ByteC Then $NuB += 1 DllStructSetData($TempDataStructB,1,$ByteE,$NuB) Else $NuB += 1 DllStructSetData($TempDataStructB,1,$ByteC,$NuB) $NuB += 1 DllStructSetData($TempDataStructB,1,$ByteD,$NuB) EndIf if (DllStructGetSize($TempDataStructA) - $n) = 1 Then $NuB += 1 $ByteC = DllStructGetData($TempDataStructA,1,$n + 1) DllStructSetData($TempDataStructB,1,$ByteC,$NuB) ExitLoop EndIf Next $NuC += 1 DllStructSetData($TempDataStructC,1,$ByteE,$NuC) $NuC += 1 DllStructSetData($TempDataStructC,1,$ByteB,$NuC) $NuC += 1 DllStructSetData($TempDataStructC,1,$ByteA,$NuC) $TempDataStructA = DllStructCreate("Byte[" & $NuB & "]") $PtrA = DllStructGetPtr($TempDataStructA) $PtrB = DllStructGetPtr($TempDataStructB) _MemMoveMemory($PtrB,$PtrA,$NuB) EndIf WEnd if $NuC Then $ReturnStC = DllStructCreate("Byte CountB;Byte Type;Byte NuB[" & $NuB & "];" & "Byte CountC;Byte NuC[" & $NuC & "]") DllStructSetData($ReturnStC,"Type",3) DllStructSetData($ReturnStC,"CountB",$NuB) DllStructSetData($ReturnStC,"CountC",$NuC) $NuBPtr = DllStructGetPtr($ReturnStC,"NuB") $NuCPtr = DllStructGetPtr($ReturnStC,"NuC") _MemMoveMemory (DllStructGetPtr($TempDataStructA),$NuBPtr,$NuB) _MemMoveMemory (DllStructGetPtr($TempDataStructC),$NuCPtr,$NuC) Else $ReturnStC = DllStructCreate("Byte CountB;Byte NuB[254]") $NuBPtr = DllStructGetPtr($ReturnStC,"NuB") _MemMoveMemory (DllStructGetPtr($TempDataStructA),$NuBPtr,254) EndIf Local $ReturnStASize = DllStructGetSize($ReturnStA) Local $ReturnStBSize = DllStructGetSize($ReturnStB) Local $ReturnStCSize = DllStructGetSize($ReturnStC) Local $ReturnSt , $ReturnStSize Local $ReturnStSize = $ReturnStASize , $ReturnSt = $ReturnStA if $ReturnStBSize < $ReturnStSize Then $ReturnStSize = $ReturnStBSize $ReturnSt = $ReturnStB EndIf if $ReturnStCSize < $ReturnStSize Then $ReturnSt = $ReturnStC Return $ReturnSt EndFunc Func CompressionC($TempDataStructA) Local $TestByte = False , $ByteE = 0 ; (Max $TempDataStructA Size Is 254) // (Max $v is 255 Start From Zero) // One Byte Out For $v = 0 To (255 - 1) $TestByte = True For $q = 1 To DllStructGetSize($TempDataStructA) $ByteE = DllStructGetData($TempDataStructA,1,$q) if $v = $ByteE Then $TestByte = False ExitLoop EndIf Next if $TestByte Then $ByteE = $v ExitLoop EndIf Next Return $ByteE EndFunc Func Decompressing($InFile,$OutFile) Local $nBytes,$FileSize ,$hFileA , $hFileB ,$FileSt,$FileStPtr ,$NuF,$Type Local $Remainder , $CountBSt , $CountB , $CountCSt , $CountC , $StructBPtr Local $StructCPtr , $NuG , $TempDataStructB , $TempDataStructC , $NewSize Local $ByteA,$ByteB,$ByteE,$vByteE, $TempDataStructD , $StructDPtr,$TypeSt $FileSize = FileGetSize($InFile) if Not $FileSize Then Return SetError(1,0,0) $hFileA = _WinAPI_CreateFile($InFile,2,2) if Not $hFileA Then Return SetError(2,0,0) $hFileB = _WinAPI_CreateFile($OutFile,1) if Not $hFileB Then _WinAPI_CloseHandle($hFileA) Return SetError(3,0,0) EndIf $FileSt = DllStructCreate("Byte[" & $FileSize & "]") $FileStPtr = DllStructGetPtr($FileSt) _WinAPI_ReadFile($hFileA,$FileStPtr,$FileSize,$nBytes) $Remainder = DllStructGetData($FileSt,1,1) $FileStPtr = DllStructGetPtr($FileSt) $NuF = ($FileSize - ($Remainder + 1)) if Not $NuF Then _WinAPI_WriteFile($hFileB,$FileStPtr + 1,$Remainder,$nBytes) _WinAPI_CloseHandle($hFileA) _WinAPI_CloseHandle($hFileB) Return SetError(0,0,$Remainder) Else $FileStPtr += ($Remainder + 1) EndIf While 1 if $NuF = 0 Then ExitLoop $CountBSt = DllStructCreate("Byte",$FileStPtr) $CountB = DllStructGetData($CountBSt,1) $FileStPtr += 1 $NuF -= 1 if $CountB = 0 Then _WinAPI_WriteFile($hFileB,$FileStPtr,254,$nBytes) $FileStPtr += 254 $NuF -= 254 Else $TypeSt = DllStructCreate("Byte",$FileStPtr) $Type = DllStructGetData($TypeSt,1) $FileStPtr += 1 $NuF -= 1 $NuG = 0 $TempDataStructB = DllStructCreate("Byte[" & $CountB & "]") $StructBPtr = DllStructGetPtr($TempDataStructB) _MemMoveMemory($FileStPtr,$StructBPtr,$CountB) $FileStPtr += $CountB $CountCSt = DllStructCreate("Byte",$FileStPtr) $CountC = DllStructGetData($CountCSt,1) $FileStPtr += 1 $NuF -= 1 $TempDataStructC = DllStructCreate("Byte[" & $CountC & "]") $StructCPtr = DllStructGetPtr($TempDataStructC) _MemMoveMemory($FileStPtr,$StructCPtr,$CountC) $FileStPtr += $CountC $NuF -= ($CountB + $CountC) Switch $Type Case 1,3 For $i = $CountC To 3 Step -3 $NuG = 0 $TempDataStructD = DllStructCreate("Byte[" & 254 & "]") $ByteE = DllStructGetData($TempDataStructC,1,$i - 2) $ByteA = DllStructGetData($TempDataStructC,1,$i - 1) $ByteB = DllStructGetData($TempDataStructC,1,$i) For $j = 1 To DllStructGetSize($TempDataStructB) $vByteE = DllStructGetData($TempDataStructB,1,$j) if $vByteE = $ByteE Then Switch $Type Case 1 $NuG += 1 DllStructSetData($TempDataStructD,1,$ByteA,$NuG) $NuG += 1 DllStructSetData($TempDataStructD,1,$ByteB,$NuG) Case 3 $NuG += 1 DllStructSetData($TempDataStructD,1,$ByteB,$NuG) $NuG += 1 DllStructSetData($TempDataStructD,1,$ByteA,$NuG) EndSwitch Else $NuG += 1 DllStructSetData($TempDataStructD,1,$vByteE,$NuG) EndIf Next $TempDataStructB = DllStructCreate("Byte[" & $NuG & "]") $StructBPtr = DllStructGetPtr($TempDataStructB) $StructDPtr = DllStructGetPtr($TempDataStructD) _MemMoveMemory($StructDPtr,$StructBPtr,$NuG) Next Case Else For $i = $CountC To 2 Step -2 $NuG = 0 $TempDataStructD = DllStructCreate("Byte[" & 254 & "]") $ByteE = DllStructGetData($TempDataStructC,1,$i - 1) $ByteA = DllStructGetData($TempDataStructC,1,$i) For $j = 1 To DllStructGetSize($TempDataStructB) $vByteE = DllStructGetData($TempDataStructB,1,$j) if $vByteE = $ByteE Then $NuG += 1 DllStructSetData($TempDataStructD,1,$ByteA,$NuG) $NuG += 1 DllStructSetData($TempDataStructD,1,$ByteA,$NuG) Else $NuG += 1 DllStructSetData($TempDataStructD,1,$vByteE,$NuG) EndIf Next $TempDataStructB = DllStructCreate("Byte[" & $NuG & "]") $StructBPtr = DllStructGetPtr($TempDataStructB) $StructDPtr = DllStructGetPtr($TempDataStructD) _MemMoveMemory($StructDPtr,$StructBPtr,$NuG) Next EndSwitch $StructBPtr = DllStructGetPtr($TempDataStructB) _WinAPI_WriteFile($hFileB,$StructBPtr,$NuG,$nBytes) $NewSize += $NuG EndIf WEnd $FileStPtr = DllStructGetPtr($FileSt) + 1 _WinAPI_WriteFile($hFileB,$FileStPtr,$Remainder,$nBytes) $NewSize += $Remainder _WinAPI_CloseHandle($hFileA) _WinAPI_CloseHandle($hFileB) Return SetError(0,0,$NewSize) EndFunc Compression.zip
    1 point
  10. Don't know, need to check. Maybe a StringSplit problem.
    1 point
  11. jguinch

    Run a program as admin

    j1 will send you a quotation for a new dev
    1 point
  12. Melba23

    A New Moderator

    Hi, For those of you still using monochrome monitors, or who have some degree of colour-blindness, I would like to announce that we have a new forum Moderator - JLogan3o13. He has kindly agreed to join the Mod team and I would like to take this opportunity to welcome him - I am sure you will all join with me in wishing him well , because he will certainly need it! M23
    1 point
×
×
  • Create New...