|
@@ -55,6 +55,8 @@ Global POINTER_SIZE:Int = 4
|
|
|
Global _symbols$[]=[ "..","[]",":*",":/",":+",":-",":|",":&",":~~",":shr",":shl",":sar",":mod"]
|
|
|
Global _symbols_map$[]=[ "..","[]","*=","/=","+=","-=","|=","&=","^=",">>=", "<<=",">>=","%=" ]
|
|
|
|
|
|
+Global _fileHasher:TFileHash
|
|
|
+
|
|
|
Function PushErr( errInfo$ )
|
|
|
_errStack.AddLast _errInfo
|
|
|
_errInfo=errInfo
|
|
@@ -665,8 +667,62 @@ Type TCallback
|
|
|
Method Callback(obj:Object) Abstract
|
|
|
End Type
|
|
|
|
|
|
+Type TFileHash
|
|
|
+
|
|
|
+ Field statePtr:Byte Ptr
|
|
|
+
|
|
|
+ Method Create:TFileHash()
|
|
|
+ statePtr = bmx_hash_createState()
|
|
|
+ Return Self
|
|
|
+ End Method
|
|
|
+
|
|
|
+ Method CalculateHash:String(stream:TStream)
|
|
|
+ Const BUFFER_SIZE:Int = 8192
|
|
|
+
|
|
|
+
|
|
|
+ bmx_hash_reset(statePtr)
|
|
|
+
|
|
|
+ Local data:Byte[BUFFER_SIZE]
|
|
|
+
|
|
|
+ While True
|
|
|
+ Local read:Int = stream.Read(data, BUFFER_SIZE)
|
|
|
+
|
|
|
+ bmx_hash_update(statePtr, data, read)
|
|
|
+
|
|
|
+ If read < BUFFER_SIZE Then
|
|
|
+ Exit
|
|
|
+ End If
|
|
|
+
|
|
|
+ Wend
|
|
|
+
|
|
|
+ Return bmx_hash_digest(statePtr)
|
|
|
+
|
|
|
+ End Method
|
|
|
+
|
|
|
+End Type
|
|
|
+
|
|
|
+Function CalculateFileHash:String(path:String)
|
|
|
+ If Not _fileHasher Then
|
|
|
+ _fileHasher = New TFileHash.Create()
|
|
|
+ End If
|
|
|
+
|
|
|
+ If FileType(path) = FILETYPE_FILE Then
|
|
|
+ Local stream:TStream = ReadStream(path)
|
|
|
+ Local fileHash:String = _fileHasher.CalculateHash(stream)
|
|
|
+ stream.Close()
|
|
|
+
|
|
|
+ Return fileHash
|
|
|
+ End If
|
|
|
+
|
|
|
+ Return Null
|
|
|
+End Function
|
|
|
+
|
|
|
Extern
|
|
|
Function strlen_:Int(s:Byte Ptr)="strlen"
|
|
|
Function bmx_enum_next_power(char:Int, val:Long Var, ret:Long Var)
|
|
|
Function bmx_gen_hash:String(txt:String)
|
|
|
+ Function bmx_hash_createState:Byte Ptr()
|
|
|
+ Function bmx_hash_reset(state:Byte Ptr)
|
|
|
+ Function bmx_hash_update(state:Byte Ptr, data:Byte Ptr, length:Int)
|
|
|
+ Function bmx_hash_digest:String(state:Byte Ptr)
|
|
|
End Extern
|