ID:195034
 
//  Title: crc32
// Credit to: Kuruado
// Contributed by: Kuraudo

/*
The crc32(file) proc uses internal DM facilities to calculate a CRC-32
checksum from either a file reference or a filename. Since even slight
changes to file data dramatically changes the checksum, it is possible
to compare file equivalency.
*/




proc/crc32(f)
ASSERT(f)
if(istext(f))
ASSERT(fexists(f))
f = file(f)

var
savefile/F = new
data
start
list/info

F << f
data = F.ExportText()
start = findText(data, "\"") + 1

info = params2list(copytext(data, start, findText(data, ",", start)))
if(info)
return info["crc32"]
else
return "0x00000000"



///*
// Testing Code/Sample Implementation:

mob/verb/Test_File()
var/f = input(src, "Select a file:") as null|file

if(f)
usr << "CRC32: [crc32(f)]"

mob/verb/Test_Filename()
var/f = input(src, "Enter a filename:") as null|text
if(f)
if(fexists(f))
usr << "CRC32: [crc32(f)]"
else
usr << "File '[f]' was not found!"

//*/