zipengine password checking?

BlitzMax Forums/BlitzMax Programming/zipengine password checking?

It looks like numberOfBytes is what controls the password, if it is >0 then the password is correct and seems to come up with -3 if incorrect.

Anyone fancy trying this out and see if they get the same?


Method ExtractFileToDisk( fileName:String, outputFileName:String, caseSensitive:Int = False, password:String="" )
		Local extractedFile:TRamStream = ExtractFile ( fileName, caseSensitive, password )
		Local entrySize:Int = unzGetCurrentFileSize( m_zipFile )
		Local stream:TRamStream=ZipRamStream.ZCreate(entrySize,True,False)		
		Local numberOfBytes:Int = unzReadCurrentFile ( m_zipFile, stream._buf, entrySize )		
		If numberOfBytes<0 Then
			DebugLog("Password is invalid")
						
		Else
			Local outFile:TStream = WriteFile ( outputFileName )
			DebugLog("Password is ok")
			If ( outFile And extractedFile ) Then			
				CopyStream( extractedFile, outFile )
			End If 
			CloseStream( outFile )
		EndIf
	End Method





Framework BRL.Basic
Import pub.zipengine

' Create our zipwriter object
Global zrObject:ZipReader = New ZipReader
Global password$="aPassword"
readZip("filename")


Function readZip(filename$)	
	' Open the zip file we just created and extract
	' a file
	

	If ( zrObject.OpenZip(CurrentDir()+"/"+filename$+".zip") ) Then		
		' unzip information		
		For Local i:Int=0 To zrObject.getFileCount()-1	
			Print("filename: "+zrObject.getFileInfo(i).zipFileName)
			Print("simplefilename: "+zrObject.getFileInfo(i).simpleFileName)
			Print("path: "+zrObject.getFileInfo(i).path)
			Print("orig size: "+zrObject.getFileInfo(i).header.DataDescriptor.uncompressedsize)
			Print("comp size: "+zrObject.getFileInfo(i).header.DataDescriptor.compressedsize)		
			
			If zrObject.getFileInfo(i).header.DataDescriptor.uncompressedsize=0
				'do nothing, just check for folders and files that have zero data etc...			
			Else
				Local p$=zrObject.getFileInfo(i).path
				Local dir=ReadDir(CurrentDir()+"/"+p$)
				If Not dir 					
					CreateDir( CurrentDir()+"/"+p$,False )
				EndIf
				zrObject.ExtractFileToDisk(zrObject.getFileInfo(i).simpleFileName, CurrentDir()+"/"+zrObject.getFileInfo(i).simpleFileName, False, password$)			
							
			EndIf
		Next
		zrObject.CloseZip()
	End If	
End Function