Thanks for the replies. Yeah i was messing around with the FileGetSize and DataLength and tried both. I also tried the FileMD5()... and the two scripts agree with one another! So i Had previously downloaded a MD5 checker to compare the results against... IT WAS WRONG! I didn't think to flip it around and download several programs as a test, another thing Ive learned. The FileMD5() is very neatly setup and easy to use as an #Include so going to stick with that, but this script also worked once i modified as you said. Thank you all very much.
On another note, I wrote a loop to hash a folder and output the data, its 100% ready to run as is, but has some options that can be configured or made into a GUI which I might do later cause I like GUI's on my stuff.
Code:
; AutoHotkey Version: 1.x
; Language: English
; Platform: Win9x/NT
; Author: Computerspazzz the Technowizard <computerspazzz@gmail.com>
; Additional Credits: Credit goes to the author of FileMD5(), who I beleive to be "SKAN" from the AutoHotKey Forums. http://www.autohotkey.com/forum/topic8728-105.html
; Script Function:
; Hash MD5's for a selected folder and log them for future comparison.
;
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
#Include FileMD5.ahk ;FileMD5()
; Setup these options if you want to setup a GUI, MakeINI makes it as an INI, MakeFILE just makes a text file with filename on 1 line, and MD5 on next line. These options would be useful to set in a GUI.
MakeINI = 1
ININame = hash.ini
MakeFILE = 1
FileName = hash.txt
;Prior to Loops, select folder
FileSelectFolder, folder, %A_Desktop%,, Select Folder to Get Hashes
If ErrorLevel = 1 ; Exit App if User Cancels Select Folder Box
ExitApp
; Count number of files, this allows theo progress indicator to work properly.
Loop, %folder%\*, 0, 1
{
FileCounter := A_Index
}
ProgressUp := (100 / FileCounter)
ProgressCurrent = 0
Progress, b w400, Hashing Files, Hashing File, Hashing Files
; Do MD5's and output to specified output files.
Loop, %folder%\*, 0, 1
{
MD5Hash := FileMD5(A_LoopFileFullPath)
If MakeINI = 1
IniWrite, %MD5Hash%, %ININame%, MD5s, %A_LoopFileFullPath%
If MakeFILE = 1
FileAppend, %A_LoopFileFullPath%`n%MD5Hash%`n, %filename%
FileCount := A_Index
ProgressCurrent := (ProgressCurrent + ProgressUp)
Progress, %ProgressCurrent%
;sleep 20 ;Only use for slowing down for var and interface checking
}
Progress, Off
MsgBox, 4, Done Hashing MD5's, Hashing MD5's Done:`n%FileCounter% Files Found`n%FileCount% Files Processed.`n`nWould you like to see the results now?
IfMsgBox Yes
{
If MakeINI = 1
Run notepad.exe %A_ScriptDir%\%ININame%
If MakeFILE = 1
Run notepad.exe %A_ScriptDir%\%FileName%
}
ExitApp
Dont forget it requires FileMD5.ahk
Code:
FileMD5( sFile="", cSz=4 )
{
cSz := (cSz<0||cSz>8) ? 2**22 : 2**(18+cSz), VarSetCapacity( Buffer,cSz,0 )
hFil := DllCall( "CreateFile", Str,sFile,UInt,0x80000000, Int,1,Int,0,Int,3,Int,0,Int,0 )
IfLess,hFil,1, Return,hFil
DllCall( "GetFileSizeEx", UInt,hFil, Str,Buffer ), fSz := NumGet( Buffer,0,"Int64" )
VarSetCapacity( MD5_CTX,104,0 ), DllCall( "advapi32\MD5Init", Str,MD5_CTX )
Loop % ( fSz//cSz+!!Mod(fSz,cSz) )
DllCall( "ReadFile", UInt,hFil, Str,Buffer, UInt,cSz, UIntP,bytesRead, UInt,0 )
, DllCall( "advapi32\MD5Update", Str,MD5_CTX, Str,Buffer, UInt,bytesRead )
DllCall( "advapi32\MD5Final", Str,MD5_CTX ), DllCall( "CloseHandle", UInt,hFil )
Loop % StrLen( Hex:="123456789ABCDEF0" )
N := NumGet( MD5_CTX,87+A_Index,"Char"), MD5 .= SubStr(Hex,N>>4,1) . SubStr(Hex,N&15,1)
Return MD5
}
Or You can do the basic striped down single file version:
Code:
FileSelectFile, filefullpath, 3, %A_Desktop%, Chose a file to MD5 Hash, All Files (*.*)
Hash := FileMD5(filefullpath)
FileAppend, %filefullpath%`n, MD5Hash.log
FileAppend, %Hash%`n, MD5Hash.log
ExitApp
FileMD5( sFile="", cSz=4 )
{
cSz := (cSz<0||cSz>8) ? 2**22 : 2**(18+cSz), VarSetCapacity( Buffer,cSz,0 )
hFil := DllCall( "CreateFile", Str,sFile,UInt,0x80000000, Int,1,Int,0,Int,3,Int,0,Int,0 )
IfLess,hFil,1, Return,hFil
DllCall( "GetFileSizeEx", UInt,hFil, Str,Buffer ), fSz := NumGet( Buffer,0,"Int64" )
VarSetCapacity( MD5_CTX,104,0 ), DllCall( "advapi32\MD5Init", Str,MD5_CTX )
Loop % ( fSz//cSz+!!Mod(fSz,cSz) )
DllCall( "ReadFile", UInt,hFil, Str,Buffer, UInt,cSz, UIntP,bytesRead, UInt,0 )
, DllCall( "advapi32\MD5Update", Str,MD5_CTX, Str,Buffer, UInt,bytesRead )
DllCall( "advapi32\MD5Final", Str,MD5_CTX ), DllCall( "CloseHandle", UInt,hFil )
Loop % StrLen( Hex:="123456789ABCDEF0" )
N := NumGet( MD5_CTX,87+A_Index,"Char"), MD5 .= SubStr(Hex,N>>4,1) . SubStr(Hex,N&15,1)
Return MD5
}
P.S. I wrote all this as I plan to integrate it into a program "patcher" system where it checks MD5's and compares them to a downloaded manifest to see which files have changed and need to be re-downloaded (in case of corruption or updates available).