Skip to content

Instantly share code, notes, and snippets.

@jNizM
Last active December 20, 2015 05:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jNizM/6080135 to your computer and use it in GitHub Desktop.
Save jNizM/6080135 to your computer and use it in GitHub Desktop.
[AHK] CoD4 - delete black Punkbuster screenshots
; ===================================================================================
; AHK Version ...: AHK_L 1.1.11.02 x64 Unicode
; Win Version ...: Windows 7 Professional x64 SP1
; Description ...: Delete Black Screenshots
; Version .......: 2013.08.07-1722
; Author ........:
; License .......: WTFPL
; License URL ...: http://www.wtfpl.net/txt/copying/
; ===================================================================================
;@Ahk2Exe-SetName del_blackscreens
;@Ahk2Exe-SetDescription Delete Black Screenshots
;@Ahk2Exe-SetVersion 2013.08.07-1722
;@Ahk2Exe-SetCopyright Copyright (c) 2013`,
;@Ahk2Exe-SetOrigFilename del_blackscreens.ahk
; GLOBAL SETTINGS ===================================================================
;#Warn
#NoEnv
#SingleInstance Force
SetBatchLines, -1
; SCRIPT ============================================================================
Gui, Margin, 10, 10
Gui, Add, Text, xm+70 ym w80, Anzahl
Gui, Add, Text, x+10 ym w120, Speicher
Gui, Add, Text, xm y+15 w60, Vorher
Gui, Add, Edit, x+10 yp-2 w80 0x0800 vC1,
Gui, Add, Edit, x+10 yp w120 0x0800 vS1,
Gui, Add, Text, xm y+10 w60, Gelöscht
Gui, Font, cDA4F49
Gui, Add, Edit, x+10 yp-2 w80 0x0800 vC2,
Gui, Add, Edit, x+10 yp w120 0x0800 vS2,
Gui, Font, c000000
Gui, Add, Text, xm y+10 w60, Nachher
Gui, Add, Edit, x+10 yp-2 w80 0x0800 vC3,
Gui, Add, Edit, x+10 yp w120 0x0800 vS3,
Gui, Font,, Consolas
Gui, Add, Edit, xm y+10 0x0800 w280 h200 vMyLog
Gui, Font
Gui, Add, Button, xm+200 y+12 w80 -Theme 0x8000, Delete
Gui, Show, AutoSize
FolderCount1 :=
FolderSize1 :=
LogClear()
loop, %A_WorkingDir%\*.*, 1, 0
{
if A_LoopFileExt in jpg,png,htm
{
global FolderCount1 += 1
global FolderSize1 += %A_LoopFileSize%
GuiControl,, C1, % FolderCount1
GuiControl,, S1, % calc_bytes(FolderSize1)
}
}
return
ButtonDelete:
QPX(True)
FolderCount2 :=
FolderSize2 :=
FolderCount3 :=
FolderSize3 :=
StartTime := A_TickCount
LogLn( "<JOB BEGIN>`n" )
loop, %A_WorkingDir%\*.*, 1, 0
{
if A_LoopFileExt in jpg, png, htm
{
FileGetSize, FileSize, %A_LoopFileFullPath%
if (FileSize < 8193)
{
FolderCount2 += 1
FolderSize2 += %A_LoopFileSize%
SecureDelete()
LogLn( "--> Delete: " . A_LoopFileName . " - " calc_bytes( A_LoopFileSize ) )
GuiControl,, C2, % FolderCount2 . " / " . FolderCount1
GuiControl,, S2, % calc_bytes( FolderSize2 ) . " / " . calc_bytes( FolderSize1 )
}
else
{
FolderCount3 += 1
FolderSize3 += %A_LoopFileSize%
LogLn( "<-- Retain: " . A_LoopFileName . " - " calc_bytes( A_LoopFileSize ) )
}
GuiControl,, C3, % FolderCount1 - FolderCount2
GuiControl,, S3, % calc_bytes( FolderSize1 - FolderSize2 )
}
}
Ti := QPX(False)
LogLn( "`n<JOB FINISHED> " . Ti . " sec`nFiles Deleted: " FolderCount2 " (" calc_bytes( FolderSize2 ) ")`nFiles Remaining: "
. ( FolderCount1 - FolderCount2 ) " (" ( calc_bytes( FolderSize1 - FolderSize2 ) ) ")" )
return
; FUNCTIONS =========================================================================
SecureDelete()
{
File_AES(A_LoopFileFullPath, A_LoopFileFullPath, RandomPw(), 256, True)
ClearMemory()
FreeMemory()
loop, 1
{
File := FileOpen( A_LoopFileFullPath, "rw" )
VarSetCapacity( v, File.Length < ( 10**8 ) ? File.Length : 10**8, A_Index )
loop, % floor( File.Length / ( 10**8 ) )
File.RawWrite( v, File.Length < ( 10**8 ) ? File.Length : 10**8 )
VarSetCapacity( v, mod( File.Length, 10**8 ), A_index )
File.RawWrite( v, mod( File.Length, 10**8 ) )
File.Close()
}
FileDelete, %A_LoopFileFullPath%
ClearMemory()
FreeMemory()
}
RandomPw()
{
Random, l, 10, 20
Chars := "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"
CharStr := ""
loop, % l
{
Random, Rand, 1, StrLen( Chars )
CharStr := CharStr . SubStr( Chars, Rand, 1 )
}
return CharStr
}
QPX(N = 0)
{
static F, A, Q, P, X
if (N && !P)
return DllCall("QueryPerformanceFrequency", Int64P, F) + (X := A := 0) + DllCall("QueryPerformanceCounter", Int64P, P)
DllCall("QueryPerformanceCounter", Int64P, Q), A := A + Q - P, P := Q, X := X + 1
return (N && X = N) ? (X := X - 1) << 64 : (N = 0 && (R := A / X / F)) ? (R + (A := P := X := 0)) : 1
}
calc_bytes( Bytes, dp = 2 )
{
return ( Bytes > 1073741824 ) ? Round( ( Bytes / 1073741824 ), dp ) " GB"
: ( ( Bytes > 1048576 ) ? Round( ( Bytes / 1048576 ), dp ) " MB"
: ( ( Bytes > 1024 ) ? Round( ( Bytes / 1024 ), dp ) " KB"
: ( ( Bytes > 1 ) ? Bytes . " Bytes"
: ) ) )
}
global mylogData := ""
LogLn( line )
{
global
mylogData .= line "`n"
GuiControl,, MyLog, % mylogData
}
LogClear()
{
global
mylogData := ""
GuiControl,, MyLog, % mylogData
}
File_AES( sFileFr, sFileTo, sPassword, SID = 256, bEncrypt = True )
{
if !( 1 + hFileFr := File_CreateFile( sFileFr, 3, 0x80000000, 1 ) )
LogLn( "*** ERROR : File not found!")
DllCall( "GetFileSizeEx", "Uint", hFileFr, "int64P", nSize )
VarSetCapacity( sData, nSize + ( bEncrypt ? 16 : 0 ) )
DllCall( "ReadFile", "Uint", hFileFr, "Uint", &sData, "Uint", nSize, "UintP", nSize, "Uint", 0 )
DllCall( "CloseHandle", "Uint", hFileFr )
if !( 1 + hFileTo := File_CreateFile( sFileTo, 2, 0x40000000, 1 ) )
LogLn( "*** ERROR : File not created/opened!")
nSize := Crypt_AES( &sData, nSize, sPassword, SID, bEncrypt )
DllCall( "WriteFile", "Uint", hFileTo, "Uint", &sData, "Uint", nSize, "UintP", nSize, "Uint", 0 )
DllCall( "CloseHandle", "Uint", hFileTo )
return nSize
}
Crypt_AES( pData, nSize, sPassword, SID = 256, bEncrypt = True )
{
CALG_AES_256 := 1 + CALG_AES_192 := 1 + CALG_AES_128 := 0x660E
CALG_SHA1 := 1 + CALG_MD5 := 0x8003
DllCall( "advapi32\CryptAcquireContext", "UintP", hProv, "Uint", 0, "Uint", 0, "Uint", 24, "Uint", 0xF0000000 )
DllCall( "advapi32\CryptCreateHash", "Uint", hProv, "Uint", CALG_SHA1, "Uint", 0, "Uint", 0, "UintP", hHash )
DllCall( "advapi32\CryptHashData", "Uint", hHash, "Uint", &sPassword, "Uint", StrLen(sPassword), "Uint", 0 )
DllCall( "advapi32\CryptDeriveKey", "Uint", hProv, "Uint", CALG_AES_%SID%, "Uint", hHash, "Uint", SID << 16, "UintP", hKey )
DllCall( "advapi32\CryptDestroyHash", "Uint", hHash)
bEncrypt
? DllCall( "advapi32\CryptEncrypt", "Uint", hKey, "Uint", 0, "Uint", True, "Uint", 0, "Uint", pData, "UintP", nSize, "Uint", nSize + 16 )
: DllCall( "advapi32\CryptDecrypt", "Uint", hKey, "Uint", 0, "Uint", True, "Uint", 0, "Uint", pData, "UintP", nSize )
DllCall( "advapi32\CryptDestroyKey", "Uint", hKey )
DllCall( "advapi32\CryptReleaseContext", "Uint", hProv, "Uint", 0 )
return nSize
}
File_CreateFile( sFile, nCreate = 3, nAccess = 0x1F01FF, nShare = 3, bFolder = False )
{
; CREATE_NEW = 1 | CREATE_ALWAYS = 2 | OPEN_EXISTING = 3 | OPEN_ALWAYS = 4
; GENERIC_READ = 0x80000000 | GENERIC_WRITE = 0x40000000 | GENERIC_EXECUTE = 0x20000000 | GENERIC_ALL = 0x10000000
; FILE_SHARE_READ = 1 | FILE_SHARE_WRITE = 2 | FILE_SHARE_DELETE = 4
return DllCall( "CreateFile", "Uint", &sFile, "Uint", nAccess, "Uint", nShare, "Uint", 0, "Uint", nCreate, "Uint", bFolder ? 0x02000000 : 0, "Uint", 0 )
}
ClearMemory()
{
for process in ComObjGet("winmgmts:").ExecQuery("Select * from Win32_Process")
{
handle := DllCall("OpenProcess", "UInt", 0x001F0FFF, "Int", 0, "Int", process.ProcessID)
DllCall("SetProcessWorkingSetSize", "UInt", handle, "Int", -1, "Int", -1)
DllCall("CloseHandle", "Int", handle)
}
return
}
FreeMemory()
{
return, DllCall("psapi.dll\EmptyWorkingSet", "UInt", -1)
}
; EXIT ==============================================================================
GuiClose:
GuiEscape:
ExitApp
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment